Raised This Month: $ Target: $400
 0% 

Solved calling function by its name from string


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 02-05-2019 , 05:16   calling function by its name from string
Reply With Quote #1

hello, let's say I have a functions name in string and I want to call it from there. is there any way to do it besides using the set_task?

PHP Code:
#include <amxmodx>
#include <amxmisc>

new const commands[6][32] = {
    
"/test""test_function",
    
"/change""change_function",
    
"/revert""revert_function"
};

public 
plugin_init()
    
register_clcmd("say""HookSay");

public 
HookSay(id) {
    new 
message[32];
    
read_args(messagecharsmax(message));
    
remove_quotes(message);
    
    for(new 
i=0i<sizeof(commands[]); i+=2)
        if(
equali(messagecommands[i]))
            
set_task(0.1commands[i+1], id//need a different method here
        
    
return PLUGIN_CONTINUE;    
}

public 
test_function(id)
    
client_print(idprint_chat"testttttt")

public 
change_function(id)
    
client_print(idprint_chat"changeeeeee")

public 
revert_function(id)
    
client_print(idprint_chat"reverttttttt"
also, would there be any benefit if I were to do what I stated above insted of:

Spoiler

because I plan on having a lot of register_clcmd(); hooks and I think it would be better if I were to use it once instead of 20+ times or so.

oh and I know there is callfunc, but it seems like my optimization would be pointless if I were to use that lol

Last edited by DjSoftero; 02-05-2019 at 10:05. Reason: grammar
DjSoftero is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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