AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set_task with params? (https://forums.alliedmods.net/showthread.php?t=61527)

Arion 10-02-2007 20:05

Set_task with params?
 
First of all, I found many threads about the same question, but no one satisfied me entirely..

I only want to change this function to a task

sendMessage (totalPlayers, cont, color, teamName, player)


Something like this:

set_task (0.1, "sendMessage", id, "totalPlayers, cont, color, teamName, player")


This way it compiles with no errors, but doesn't work either..

M249-M4A1 10-02-2007 20:37

Re: Set_task with params?
 
You can only pass one parameter

Drak 10-02-2007 21:28

Re: Set_task with params?
 
You can do stuff like this:
Code:
public task_function() {     new args[2]     args[0] = 100     args[1] = 200     set_task(1.0,"function",0,args,2); } public function(value[]) {     server_print("Value: %d Value2: %d",value[0],value[1]); }

Arion 10-02-2007 22:05

Re: Set_task with params?
 
Thanks M249-M4A1, I knew I could pass only one parameter. But how can I pass all of them?


Drak, I tried this too... but how do I do if values are strings?

args[0] = teamName
copy (args[0], teamName)
?

Hawk552 10-02-2007 22:09

Re: Set_task with params?
 
It really depends on what each variable is. Are they arrays?

Please specify.

Arion 10-02-2007 22:17

Re: Set_task with params?
 
totalPlayers : int
cont: int
color: array (string?)
teamName: array
player: int


kp_uparrow 10-02-2007 22:48

Re: Set_task with params?
 
nope, limitation of the set task, but you can format it into one string and break it down after its called

Arion 10-02-2007 22:50

Re: Set_task with params?
 
And... How do I do that?

Arkshine 10-02-2007 23:17

Re: Set_task with params?
 
Hum try this. I don't know your color format so I've assumed something like "255255255".

Code:
my_function( id ) {       // color = "255255255"     // team = "TERRORIST" or "CT" or "UNASSIGNED", or "SPECTATOR"         static         param[23], // 9 (color) + 10 (team) + 3 (totalplayers/cont/player) + 1           len;         param[0]  = totalPlayers;     param[1]  = cont;     param[2]  = player;         len = formatex( param[3], sizeof param - 1, "%s-%s", color, teamName );         set_task ( 0.1, "sendMessage", id, param, len + 4 ); } public sendMessage( param[] ) {     static         sColor[10],         sTeam[10];             strtok( param[3], sColor, sizeof sColor - 1, sTeam, sizeof sTeam - 1, '-' );         log_amx( "totalPlayers: %d | cont: %d | player: %d | color: %s | team: %s", param[0], param[1], param[2], sColor, sTeam ); }

Arion 10-02-2007 23:26

Re: Set_task with params?
 
I'll try that... Thanks!


All times are GMT -4. The time now is 16:11.

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