AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with Forwarding Strings (https://forums.alliedmods.net/showthread.php?t=233185)

lobopack23 01-11-2014 02:16

Help with Forwarding Strings
 
So I read the Tutorial on Forwards. I know how to return integer/float based forwards but I can't seem to figure out how to do it for functions.

1st Goal:
Return a string from a function. (This has been one of my other issues)

2nd Goal: Forward that string, and use that string in another plugin.

For This Example, let us pretend someone wrote /increment twice.

Code:

#include <amxmodx>

new location[33]

enum LOCATION
{
        MYHOUSE = 0,
        FRIEND1,
        FRIEND2
}
 new const locationNames[LOCATION][] =
 {
        "My House",
        "First Friend House",
        "Second Friend House"
}

public plugin_init()
{
    register_plugin("Forward String Test", "1.0", "Lobopack23")
    register_concmd("say /mylocation","checklocation");
    register_concmd("say /increment","incrementlocation");  // just to make this more "realistic"
}

public incrementlocation(id)
{
    location[id]++
}

public checklocation(id)
{
    // TEST 1
    new iLocation = location[id]
    return locationNames[iLocation]

    /*
    // TEST 2, another way i tried to return it but failed..
    new iLocation = location[id]
    new temp[1024];
    formatex(temp, charsmax(temp), "%s", locationNames[iLocation] );
    return temp
    */
}

And this is how I was trying to forward the value to another plugin.

Code:

locationForward(id)
 {
    new temp_return, temp_forward = CreateMultiForward( "checklocation", ET_STOP, FP_STRING );
    ExecuteForward( temp_forward, temp_return, id );
    DestroyForward( temp_forward );
    return temp_return;
 }

Any help, suggestions or etc would be appreciated.

lobopack23 01-11-2014 02:31

Re: Help with Forwarding Strings
 
I just wanted to add this because it was funny..
https://forums.alliedmods.net/showpo...87&postcount=1

and this..
https://forums.alliedmods.net/showpo...33&postcount=6

hornet 01-11-2014 02:41

Re: Help with Forwarding Strings
 
Sounds like Dynamic Natives may be of better use here.

lobopack23 01-11-2014 05:41

Re: Help with Forwarding Strings
 
id prefer if someone taught me how to use the string method using COPY, that would be helpful

ConnorMcLeod 01-11-2014 06:56

Re: Help with Forwarding Strings
 
You can't, you have to use dynamic native as hornet said, then in the plugin api use set_string to set the string in the calling plugin.

There is a tutorial by Hawk552 about dynamic natives, i can't remember if strings are covered but this is a good place to start to understand how dynamic natives work.

lobopack23 01-11-2014 14:40

Re: Help with Forwarding Strings
 
Quote:

Originally Posted by ConnorMcLeod (Post 2084340)
You can't, you have to use dynamic native as hornet said, then in the plugin api use set_string to set the string in the calling plugin.

Ah for sure. And I took a look at dynamic natives, im not sure how to use set_string though in my cas.

hornet 01-12-2014 05:10

Re: Help with Forwarding Strings
 
Try having a look here https://forums.alliedmods.net/showthread.php?t=189454.
It's a short example on returning a string that I wrote some time ago - Scroll down to my first post.


All times are GMT -4. The time now is 10:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.