View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-05-2011 , 08:58   Re: Pass multiple parameters to set_task
Reply With Quote #5

You can pack anything into an array and pass it to a function via set_task as long as you keep the data organized so it can be retrieved in the called function. The easiest way to do this is with an enum to create a 'hacked' structure. Also make sure your called function has parameters in the correct order; the data/array is first then task-id.
PHP Code:
#include <amxmodx>
#include <amxmisc>

//You can include anything including integers, strings, arrays, floats
enum _:TaskData
{
    
PlayerIndex,
    
PlayerName33 ],
    
SteamID35 ],
    
Health,
    
Float:Whatever,
    
ArrayNumbers]
}

public 
plugin_init() 
{
    
register_plugin"Set_task Example" "0.1" "bugsy" );
    
    
register_clcmd"say test" "CmdTask" );
}

public 
CmdTaskid )
{
    new 
tdDataTaskData ];
    
    
tdDataPlayerIndex ] = id;
    
get_user_nameid tdDataPlayerName ] , charsmaxtdDataPlayerName ] ) );
    
get_user_authidid tdDataSteamID ] , charsmaxtdDataSteamID ] ) );
    
tdDataHealth ] = get_user_healthid );
    
tdDataWhatever ] = _:55.25;
    
tdDataArrayNumbers ][ ] = 12
    
tdDataArrayNumbers ][ ] = 34;
    
tdDataArrayNumbers ][ ] = 56;
    
    
set_task1.0 "YourFunc" 12345 tdData sizeoftdData ) );
}

public 
YourFunctdIncomingTaskData ] , iTaskID )
{
    
server_print"TaskID=%d ^"%d^" ^"%s^" ^"%s^" ^"%d^" ^"%f^" [%d,%d,%d]" iTaskID tdIncomingPlayerIndex ] , 
                                                                                     
tdIncomingPlayerName ] , 
                                                                                     
tdIncomingSteamID ] , 
                                                                                     
tdIncomingHealth ] , 
                                                                                     
tdIncomingWhatever ] , 
                                                                                     
tdIncomingArrayNumbers ][ ] , 
                                                                                     
tdIncomingArrayNumbers ][ ] , 
                                                                                     
tdIncomingArrayNumbers ][ ] );

Code:
TaskID=12345 "1" "bugsy" "STEAM_0:0:123456" "100" "55.250000" [12,34,56]
__________________

Last edited by Bugsy; 05-05-2011 at 09:21.
Bugsy is offline