Raised This Month: $ Target: $400
 0% 

Set And Remove Tasks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-04-2009 , 10:41   Set And Remove Tasks
Reply With Quote #1

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?
__________________
Zombie Lurker is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 06-04-2009 , 10:45   Re: Set And Remove Tasks
Reply With Quote #2

if you only got one task in you script there is no need to add 100 to the id
__________________
Dr.G is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-04-2009 , 10:47   Re: Set And Remove Tasks
Reply With Quote #3

Well, I have about 6 or more tasks so I need to add the 100 to remove the task separately.
__________________
Zombie Lurker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-04-2009 , 10:59   Re: Set And Remove Tasks
Reply With Quote #4

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.
__________________
Bugsy is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-04-2009 , 11:13   Re: Set And Remove Tasks
Reply With Quote #5

You don't need to check if the task exist when you try to remove it.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-04-2009 , 19:58   Re: Set And Remove Tasks
Reply With Quote #6

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.
__________________
Zombie Lurker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-04-2009 , 21:46   Re: Set And Remove Tasks
Reply With Quote #7

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)

__________________

Last edited by Bugsy; 06-04-2009 at 23:04.
Bugsy is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-04-2009 , 23:33   Re: Set And Remove Tasks
Reply With Quote #8

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)

__________________
Zombie Lurker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-05-2009 , 00:13   Re: Set And Remove Tasks
Reply With Quote #9

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

__________________
Bugsy is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-05-2009 , 00:57   Re: Set And Remove Tasks
Reply With Quote #10

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

__________________
Zombie Lurker 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 13:53.


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