Raised This Month: $51 Target: $400
 12% 

remove_task misc?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 02-04-2019 , 10:41   remove_task misc?
Reply With Quote #1

So I've got this piece of code
PHP Code:
public client_putinserver(id)
{
    
set_task (2.0"CheckName"id// CHECK HIS NAME

    
if( IsWarmupActive == true && !is_user_alive(id) )
        
set_task (5.0"task_respawn"id__"b"// The TASK that worries me.

}

public 
player_spawn(client// Basic Ham_Spawn Hook.
{
    
remove_task(client// Will this remove the "Infinite" task that checks if a player is dead?
    
    
if (IsMatchLive == true && is_user_alive(client)) {

    
set_task(0.3"show_money"client__"a"28)

    }

    if ( 
IsWarmupActive == true ) {
        
remove_task(client)
        
fm_strip_user_weapons(client)
        
cs_set_user_money(clientcs_get_user_money(client)-cs_get_user_money(client))
        
cs_set_user_armor(client100 ,CsArmorType:1)
        
give_item(client"weapon_knife")
        
cs_give_user_weapon(client"weapon_deagle"CSW_DEAGLE60)

            if(
cs_get_user_team(client) == CS_TEAM_CT)
                
cs_give_user_weapon(client"weapon_m4a1"CSW_M4A1120)

            if(
cs_get_user_team(client) == CS_TEAM_T)
                
cs_give_user_weapon(client"weapon_ak47"CSW_AK47120)
    }

        
}

public 
task_respawn(id)
{
    if(
cs_get_user_team(id) != CS_TEAM_SPECTATOR && cs_get_user_team(id) != CS_TEAM_UNASSIGNED) {
        
ExecuteHamB(Ham_CS_RoundRespawnid)
    }

Do I have to assign an ID @ the task_respawn, to be actually able to remove it when that player actually spawns or do I just leave it be like that and it's gonna remove every single task that was assigned to the id?

Pretty much commented my question in the code, thanks in advance!
__________________

Last edited by deprale; 02-04-2019 at 10:43.
deprale is offline
Oops9499
Junior Member
Join Date: Dec 2017
Old 02-04-2019 , 11:42   Re: remove_task misc?
Reply With Quote #2

If you have more than 1 task in your plugin, you should use id's for each, otherwise when you do "remove_task(id)" it will remove all of your tasks.

PHP Code:
 remove_task(client// Will this remove the "Infinite" task that checks if a player is dead? 
And yes, it will.

Last edited by Oops9499; 02-04-2019 at 11:45.
Oops9499 is offline
eat1k
Senior Member
Join Date: Apr 2018
Old 02-04-2019 , 12:02   Re: remove_task misc?
Reply With Quote #3

remove_task(id) will remove all the existing tasks in the plugin where it was called.
__________________
eat1k is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 02-04-2019 , 12:25   Re: remove_task misc?
Reply With Quote #4

What exactly you want to do with this plugin?
Since you do not need a task itself for spawn a player in some cases.
And in your case set_task is wrong
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 02-04-2019 at 12:25.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 02-04-2019 , 14:39   Re: remove_task misc?
Reply With Quote #5

Hook the event where player chooses team and set the task to not loop itself, then hook the event where player spawns and if player spawns before task is over, check if the task is valid and if necessary, remove it. And I don't know if it's a good practice, but instead, I use entities instead of tasks, as it is easier for me to handle everything in entities thinking function. But I only do that where I have to check certain things over and over again once every designated time interval.

Last edited by DjSoftero; 02-04-2019 at 14:47. Reason: change of mind
DjSoftero is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 02-04-2019 , 15:14   Re: remove_task misc?
Reply With Quote #6

Thanks, read that on amxx docs but wasn't sure on whether I understood it's meaning or not, cause I've seen people assigning ID's to their tasks always, but I've never bothered doing that.
__________________
deprale is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-04-2019 , 15:58   Re: remove_task misc?
Reply With Quote #7

Quote:
Originally Posted by deprale View Post
Thanks, read that on amxx docs but wasn't sure on whether I understood it's meaning or not, cause I've seen people assigning ID's to their tasks always, but I've never bothered doing that.
But you did:
PHP Code:
 set_task(0.3"show_money"client__"a"28
Here the task id is the player index(client). If you are talking about other people doing:
set_task(.., .., id + TASK_SOMETHING)

and then

id = id - TASK_SOMETHING

they are just doing that to create a unique id for their tasks(assuming you are using more than one task at the same time which need access to player's index). If you simply pass player id then all tasks will have the same index. So they add a random number to each task, for example one task may have index player id + 1234, the other one player id + 4234, creating unique task ids.
__________________

Last edited by HamletEagle; 02-04-2019 at 15:58.
HamletEagle 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 16:10.


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