AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sending data through set_task not working (https://forums.alliedmods.net/showthread.php?t=85510)

fysiks 02-11-2009 20:56

sending data through set_task not working
 
This plugin that I have written works well if I don't use tasks and just execute my command immediately (engclient_cmd), but doesn't work right with a set task delay. It looks like the data isn't being passed correctly.

Code:
PHP Code:

#include <amxmodx>
#include <hamsandwich>
public plugin_init()
{
 
register_plugin("Bot Say Sorry for TK""1.0""Fysiks")
 
RegisterHam(Ham_Killed"player""ham_player_killed",1)
}
public 
ham_player_killedvictimkillergib// killer, victim, wpnindex, hitplace, TK)
{
 
// if(!is_user_bot(killer) || victim == killer || get_user_team(killer) != get_user_team(victim))
  // return
 
 // if(task_exists(killer)) remove_task(killer)  // If bot kills two teammates less than 3 seconds apart
 
 
new idstring[3]
 
num_to_str(killeridstring,2)
 
set_task(3.0"say_sorry",killer,idstring,0)
 
server_print("Task Set %d,%s"killer,idstring)
 return
}
public 
say_sorry(idstr[])
{
 new 
idnum str_to_num(idstr)
 if(
idnumengclient_cmd(idnum,"say","Sorry!")
 
server_print("Should have been done (%d,%s)"idnumidstr)


Some Results:
Code:


Task Set 8,8
Task Set 5,5
Should have been done (0,mFilter)
Should have been done (0,

And yes, there was nothing after that last comma :).

Bugsy 02-11-2009 21:38

Re: sending data through set_task not working
 
You are telling set_task the size of idstring is 0 and it should be 3.

set_task( 3.0 , "say_sorry" ,killer , idstring , 3 )

And

public say_sorry(idstr[3])

fysiks 02-12-2009 02:15

Re: sending data through set_task not working
 
That worked, Thanks, +karma.

I started thinking more about it and realized that I should pass the number through as direct as possible for effeciency(i.e. not using an intermediary string and conversion functions). So I put "killer" into a single cell array and passed the array:

Code:

new param[1]
 param[0] = killer
 set_task(3.0,"say_sorry",killer,param,1)

and
Code:

say_sorry(param[])

Arkshine 02-12-2009 02:42

Re: sending data through set_task not working
 
If you want to pass the id, just do :

set_task( 3.0, "say_sorry", killer );

public say_sorry ( id )
{

}

fysiks 02-12-2009 14:52

Re: sending data through set_task not working
 
Will that assign a task id as well as pass the actual id so that my remove task will work?

Arkshine 02-12-2009 14:55

Re: sending data through set_task not working
 
player's id is just a number, you can pass what you want as task id.

fysiks 02-12-2009 15:19

Re: sending data through set_task not working
 
Quote:

Originally Posted by arkshine (Post 760246)
If you want to pass the id, just do :

set_task( 3.0, "say_sorry", killer );

public say_sorry ( id )
{

}

Quote:

set_task ( Float:time, const function[], id = 0, parameter[]="", len = 0, flags[]="", repeat = 0 )
"killer" is in the argument for the task id but it passes it as a parameter is what you said. I need it to assign the task id "killer" and pass the value "killer" so that I can remove the task if there is a second kill before the first set_task(id=same killer) has executed.

I need to prevent: kill, sorry, kill, sorry, kill sorry. I need: kill, kill, kill, sorry.


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

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