| closedif(task_exists(something)) |
| Started by Dr.G on 02-08-2009, 08:46 AM |
Threads: 75
Joined: Nov 2007
can someone explain to how task_exists and remove_task works? i dont get it... Please show me with this exsample:rnrnrn
/* Plugin generated by AMXX-Studio */rn////////////////////////////////////////////////////////////////////////////////////////////////////rn#include <amxmodx>rn#include <amxmisc>rn#include <hamsandwich>rn////////////////////////////////////////////////////////////////////////////////////////////////////rn#define PLUGIN "task thing"rn#define VERSION "1.0"rn#define AUTHOR "Dr.G"rn////////////////////////////////////////////////////////////////////////////////////////////////////rnpublic plugin_init() rn{rn register_plugin(PLUGIN, VERSION, AUTHOR)rn rn RegisterHam(Ham_Spawn,"player","reset_task",1)rn rn register_clcmd("say /settask","SetaTaskOnMe")rn rn}rn////////////////////////////////////////////////////////////////////////////////////////////////////rnpublic reset_task(id)rn{rn if(is_user_alive(id) && is_user_connected(id) && get_user_team(id))rn {rn //REMOVE TASK HERE BUT HOWrn }rn return HAM_IGNOREDrn}rn////////////////////////////////////////////////////////////////////////////////////////////////////rnpublic SetaTaskOnMe(id)rn{rn set_task(10.0,"ChatSpamScripterNoob",id,_,_,"b")rn return PLUGIN_CONTINUErn}rn////////////////////////////////////////////////////////////////////////////////////////////////////rnpublic ChatSpamScripterNoob(id)rn{rn client_print(id,print_chat,"haha u cant remove this shit now")rn return PLUGIN_CONTINUErn}rn////////////////////////////////////////////////////////////////////////////////////////////////////Threads: 15
Joined: Mar 2007
Basically in the reset_task function, You would do something like this:rnrn
rnif(task_exists(id)) // Check if a task that was created with this ID existsrn{rn remove_task(id) // Remove a task that has this IDrn}rnrnrnSince the task ID is set using the player's ID in the SetaTaskOnMe function, we will need to use the player ID from when they spawn to first check if that the task exists and if so, remove it. The ID can technically be any number but when you have to setup multiple timers say individually for each player like in this case, you need to assign unique IDs per task and the easiest way is by player ID. This allows you to easily check each task whether it is running or not and the ability to remove it.Threads: 75
Joined: Nov 2007
Thanks so if i do like that all tasks(lets say there are more then one) on that id will be removed? its just cuz ive seen so many times something like:rnrn
#define EFFECT_TASK 21198rnrnif(task_exists(EFFECT_TASK+id))rn remove_task(EFFECT_TASK+id)rnrnbut why do it like that? I need this to function with more then one task.. but again if a task is a task its easy...Threads: 103
Joined: May 2005
well if you are using lets say the client id as the task id, and you going to have the possibility of more then one task running with that id but only want to stop for example one of those tasks at a specific time but let the rest stay, remove_task(id) would remove them all.. but using a define set to some random number (and a different define and value for each different task) + the id value, you will have a unique id for each of the different tasks..nnthe only problem with that then is the id passed to the function called in the set_task will have to have the define subtracted from it to get the proper client id (or you could pass it in an array as a parameter of the set_task native)nni just got home from work after several nights of drinking whiskey.. so i might very well have fucked that all up haha
Threads: 75
Joined: Nov 2007
haha ok well it starts clicking to me i think lol... so u can just say that u do the define to keep track of more then one task on a id, right? The exsample:rnrn
#define EFFECT_TASK 21198 rnrnis from something u made once, but last question, whats up with the odd number? 21198 i mean?Threads: 103
Joined: May 2005
well pretty much just a random number lol
Threads: 75
Joined: Nov 2007
hahaha ok, Thank you Uber G33ks :D

