AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set And Remove Tasks (https://forums.alliedmods.net/showthread.php?t=93919)

Zombie Lurker 06-04-2009 10:41

Set And Remove Tasks
 
So if i set a task like so :
PHP Code:

#define TASKID_LOL 100
public plugin_init() {
     
set_task(1.0"LOL"TASKID_LOL+id)


How do I remove the task? I tried this :
PHP Code:

 if(task_exists(TASKID_LOL+id))
     
remove_task(TASKID_LOL+id

But that crashes my game. So can someone tell me the proper way to do that?

Dr.G 06-04-2009 10:45

Re: Set And Remove Tasks
 
if you only got one task in you script there is no need to add 100 to the id

Zombie Lurker 06-04-2009 10:47

Re: Set And Remove Tasks
 
Well, I have about 6 or more tasks so I need to add the 100 to remove the task separately.

Bugsy 06-04-2009 10:59

Re: Set And Remove Tasks
 
Adding a players id to the task id is only needed if you have more than 1 task that is called on a per-player basis.

If your tasks are called that call actions on all players (via a loop or w\e) then you can just define individual task id's for each task.

ConnorMcLeod 06-04-2009 11:13

Re: Set And Remove Tasks
 
You don't need to check if the task exist when you try to remove it.

Zombie Lurker 06-04-2009 19:58

Re: Set And Remove Tasks
 
I just need to know if what I used above is the correct way to remove the task because when I use it it crashes my game. My other tasks that I mentioned earlier have the same task id. (id) So if I remove_task(id) i'll remove my other tasks along with it.

Bugsy 06-04-2009 21:46

Re: Set And Remove Tasks
 
Show your full code and I will tell you if it is correct.

I can tell you that the below code is incorrect because you are trying to use the variable "id" which does not exist. Only some situations require adding a player id to the task id so don't always assume it is needed.

PHP Code:

#define TASKID_LOL 100
public plugin_init() {
     
set_task(1.0"LOL"TASKID_LOL+id)



Zombie Lurker 06-04-2009 23:33

Re: Set And Remove Tasks
 
Alright here's my code, but I only added the single task :
PHP Code:

#define TASKID_LOL 100
public plugin_init() {
     
set_task(1.0"LOL"TASKID_LOL+id)

public 
LOL(id) {
  new 
CsTeams:userTeam cs_get_user_team(id)
  if(
userTeam == CS_TEAM_T){
   
client_print(idprint_chat"[LOL] You are a terrorist.")  
   } else if(
userTeam == CS_TEAM_T){
   
client_print(idprint_chat"[LOL] You are a counter-terrorist.")
 }
 
remove_task(TASKID_LOL+id)



Bugsy 06-05-2009 00:13

Re: Set And Remove Tasks
 
In this case you are only calling the task once so as soon as LOL is called, the task will automatically be removed. The only time you need to remove a task when you set the task to repeat\loop.

In your code, you are trying to use the variable "id" that does not exist in the plugin_init() function. Below is an example on where you can pass a player id into set_task() to then be passed on to the called function.

PHP Code:

//client_putinserver() has the players id passed to it that can then be passed into set_task. 
public client_putinserverid )
{
    
set_task10.0 "LOL" id );
}

public 
LOLid 
{
    if ( 
is_user_connectedid ) )
    {
        new 
CsTeams:userTeam cs_get_user_teamid )
    
        if( 
userTeam == CS_TEAM_T )
            
client_print(idprint_chat"[LOL] You are a terrorist.")  
        else if( 
userTeam == CS_TEAM_T )
            
client_print(idprint_chat"[LOL] You are a counter-terrorist.")
    }



Zombie Lurker 06-05-2009 00:57

Re: Set And Remove Tasks
 
That isnt the actual code im using currently. I wanted the task to be auto-set on every round. Here's the code again but more exact :
PHP Code:

#define TASKID_LOL 100
 
public plugin_init() {
     
register_event("HLTV""event_new_round""a""1=0""2=0")
}
 
public 
event_new_round(id) {
     
set_task(13.0"LOL"TASKID_LOL+id)
}
 
public 
LOLid 
{
    if ( 
is_user_connectedid ) )
    {
        new 
CsTeams:userTeam cs_get_user_teamid )
 
        if( 
userTeam == CS_TEAM_T )
            
client_print(idprint_chat"[LOL] You are a terrorist.")  
        else if( 
userTeam == CS_TEAM_T )
            
client_print(idprint_chat"[LOL] You are a counter-terrorist.")
    }




All times are GMT -4. The time now is 13:53.

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