Raised This Month: $ Target: $400
 0% 

remove_task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Unidentified
Senior Member
Join Date: Aug 2005
Location: Compton, L.A. Thug
Old 12-27-2005 , 17:58   remove_task
Reply With Quote #1

How would you use a remove_task? I find It confusing. Could someone help me out?
Unidentified is offline
Sneakpeek
Member
Join Date: Dec 2005
Location: Who cares really?
Old 12-27-2005 , 18:28  
Reply With Quote #2

remove_task

I think that explains it pretty good.
It will simply stop a set_task.

Code:
set_task(15.0, "my_task", id) // 10 secs later remove_task(id) // my_task gone :O

Actually remove_task will remove ALL set_tasks unless you give your set_task a special id.
Sneakpeek is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 12-27-2005 , 19:00  
Reply With Quote #3

Quote:
Originally Posted by Sneakpeek
Actually remove_task will remove ALL set_tasks unless you give your set_task a special id.
Nnnnoooesss. IIRC remove_task will remove all tasks with id=first parameter in your plugin (and also in all other plugins if the second parameter is non-zero).

Both parameters default to 0, ie. writing
Code:
remove_task();
is equivalent to
Code:
remove_task(0, 0);

This means that if you don't specify an id, remove_task will remove all tasks with id=0 in your plugin.

Also note that if you don't pass an id parameter to set_task, the id of the created task will be 0, so remove_task(0); / remove_task(); will remove those (and those with id set to 0 explicitly).
__________________
hello, i am pm
PM is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-27-2005 , 19:35  
Reply With Quote #4

I consider it to be a good idea to always give a random number as a task id, if you plan on manually ending it at some time.

For instance, in my plugins I do something like this:
Code:
#define TASKID_THISACTION  84278346
And then later:
Code:
// if i don't need to know the player's id that set off this task... set_task(timeLength, "myFunction", TASKID_THISACTION);  // or if I do need to know the player's id... set_task(timeLength, "myFunction", TASKID_THISACTION + id);
Finally, I might end the task like:
Code:
// ending the first example of the task I gave... remove_task(TASKID_THISACTION);
I'll leave what I would do in myFunction as an exercise for the reader.

Instead of trying to come up with your own pseduo-random number, I suggest using a site like this that will do it for you.
Brad is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 12-27-2005 , 19:56  
Reply With Quote #5

Alternatively, you could use xs stock library's weird task system - if it still works on today's releases of the Small compiler. (I wrote it more than a year ago [don't expect it to be bug-free =P ] ).

Code:
#include <xs> // somewhere: xs_task_begin(1.5, "my_task", -1); // id=-1 means to auto-choose a free id xs_task_pushint(0xdeadbeef); xs_task_pushfl(123.456); xs_task_pushstr("Hello BAIL!"); new id = xs_task_end(); // id now contains the id! // on global scope: XS_MAKE_TASKFUNC(my_task) {    new id = xs_task_readid(); // What else would it do    new pcount = xs_task_paramcount();    log_amx("my_task called; id=%d", id);    for (new i = 0; i < pcount; ++i)    {       new ptype = xs_task_paramtype(i);       if (ptype == xs_int)          log_amx("Param%d: int: %d", i, xs_task_paramint(i));       else if (ptype == xs_float)          log_amx("Param%d: float: %f", i, xs_task_paramfl(i));       else if (ptype == xs_string)       {          new str[256];          xs_task_paramstr(i, str, 255);          log_amx("Param%d: string: %s", i, str);       }    } }

You get the idea. The definitions of all these functions (and macros) are in xs.inc, if you are interested. Note that it might represent measurable overhead to use these functions, so better don't use it in really heavily used and performacne critical stuff.

(I'm tired so sorry for any mistakes)
__________________
hello, i am pm
PM is offline
Unidentified
Senior Member
Join Date: Aug 2005
Location: Compton, L.A. Thug
Old 12-28-2005 , 00:31  
Reply With Quote #6

Now...what about if task exists?
Unidentified is offline
Sneakpeek
Member
Join Date: Dec 2005
Location: Who cares really?
Old 12-28-2005 , 04:49  
Reply With Quote #7

The name explains it.
It checks if a task exists.
If its still going, or if its removed, or if it was ever made at all.

Code:
//I use Brads example here. #define TASKID_THISACTION  84278346 if(task_exist(TASKID_THISACTION)) {     //Do your stuff }
Sneakpeek 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 15:50.


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