Raised This Month: $ Target: $400
 0% 

Pass multiple parameters to set_task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
epix
Junior Member
Join Date: May 2011
Old 05-04-2011 , 18:12   Pass multiple parameters to set_task
Reply With Quote #1

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 ?
epix is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2011 , 18:59   Re: Pass multiple parameters to set_task
Reply With Quote #2

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

__________________

Last edited by fysiks; 05-05-2011 at 18:29. Reason: Fixed args order in function()
fysiks is offline
epix
Junior Member
Join Date: May 2011
Old 05-05-2011 , 04:18   Re: Pass multiple parameters to set_task
Reply With Quote #3

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" ?
epix is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-05-2011 , 04:37   Re: Pass multiple parameters to set_task
Reply With Quote #4

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.
__________________

Last edited by Hunter-Digital; 05-05-2011 at 12:26. Reason: fixed func param order
Hunter-Digital is offline
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
epix
Junior Member
Join Date: May 2011
Old 05-05-2011 , 18:21   Re: Pass multiple parameters to set_task
Reply With Quote #6

Thanks Bugsy! Great example
epix is offline
Reply



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 04:29.


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