Quote:
Originally Posted by kww
is there some simple way to merge multiple tasks into one?
i want to merge three tasks and have one callable function instead of three that i have
here is nothing complex, but i just wonder if it possible
|
I don't see any good reason to do such a thing based on this code but yes, it's possible (note that Napoleon's implementation is flawed, see below). Can you not just give the grenade immediately (i.e. without the set_task)? I give a grenade to the user in grenade_throw() in my Day of Defeat plugin and it works flawlessly.
Quote:
Originally Posted by Napoleon_be
untested
PHP Code:
#include <amxmodx> #include <fun> #include <csx>
new g_wid;
public plugin_init() register_plugin("infinite_grenades", "latest", "kww")
public grenade_throw(id, gid, wid) { g_wid = wid; set_task(0.1, "giveGrenade", id); }
public giveGrenade(id) { switch(g_wid) { case CSW_HEGRENADE: give_item(id, "weapon_hegrenade"); case CSW_FLASHBANG: give_item(id, "weapon_flashbang"); case CSW_SMOKEGRENADE: give_item(id, "weapon_smokegrenade"); } }
|
You cannot put wid into a global variable and guarantee that it won't have changed by the time it is used by the called function (this is called a "race condition"). You would need to pass it as an additional argument of the task to guarantee that the function will execute with the correct data.
__________________