AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   remove_task (https://forums.alliedmods.net/showthread.php?t=22474)

Unidentified 12-27-2005 17:58

remove_task
 
How would you use a remove_task? I find It confusing. Could someone help me out?

Sneakpeek 12-27-2005 18:28

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.

PM 12-27-2005 19:00

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).

Brad 12-27-2005 19:35

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.

PM 12-27-2005 19:56

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)

Unidentified 12-28-2005 00:31

Now...what about if task exists?

Sneakpeek 12-28-2005 04:49

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 }


All times are GMT -4. The time now is 15:50.

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