AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Pass multiple parameters to set_task (https://forums.alliedmods.net/showthread.php?t=156342)

epix 05-04-2011 18:12

Pass multiple parameters to set_task
 
If I had some function like this:

PHP Code:

public testFunc(idsomeString[]) {
     
// Dummy


then how could I do something like this:

PHP Code:

public delayTestFunc(idsomeString[]) {
     
set_task(5.0"testFunc"1, ??, ??)


what would you pass as parameter array and parameter length ?

fysiks 05-04-2011 18:59

Re: Pass multiple parameters to set_task
 
PHP Code:

new array[2]
array[
0] = integer_info
array[1] = other_integer_info
set_task
(1.0"function"12345, array, sizeof(array)) 

PHP Code:


public function(thisarray[], task_id)
{
    
thisarray[0] = // integer_info
    
thisarray[1] = // other_integer_info



epix 05-05-2011 04:18

Re: Pass multiple parameters to set_task
 
Thanks for your reply. However I was wondering if this is possible when one of the needed parameters is a string..

In your example, why is task_id an argument of "function" ?

Hunter-Digital 05-05-2011 04:37

Re: Pass multiple parameters to set_task
 
Because taskid is the task's ID, in fysiks' example 12345 is the task id.

For strings, you can make an array containing all kinds of stuff.
PHP Code:

new data[33]

get_user_name(iddata31/* a string */

data[32] = 53 /* a number */

set_task(1.0"function"12345datasizeof data

PHP Code:

public function(data[], taskid)
{
    new 
szName[32]
    
copy(szNamecharsmax(szName), data/* will copy the first 32 chars of data */

    
new iVal data[32/* your integer */


Not tested, I could be off on the array indexes :/

Hmm, but I belive you can make that better with hacked enums... I'll leave that for others that have experience with these.

Bugsy 05-05-2011 08:58

Re: Pass multiple parameters to set_task
 
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]

epix 05-05-2011 18:21

Re: Pass multiple parameters to set_task
 
Thanks Bugsy! Great example :)


All times are GMT -4. The time now is 04:29.

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