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

set task disable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thebest24
Member
Join Date: Sep 2018
Location: Georgia
Old 01-09-2022 , 12:21   set task disable
Reply With Quote #1

hi i need help in this:

for example if i do this
PHP Code:
if(cs_get_user_team(id) == CS_TEAM_SPECTATOR
          
set_task(31.1"removeweapons"id
this work fine after 31 second your weapons get removed
but when you transfer to spectator and then transfer to ct/t immediaetly after 31 sec your weapons still will be removed.

how can i disable this set task for ct and t ? i want it to work only for spectators.
__________________
Hello!
thebest24 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-09-2022 , 12:59   Re: set task disable
Reply With Quote #2

Check the team again inside the "removeweapons" function?
__________________

Last edited by OciXCrom; 01-09-2022 at 12:59.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
thebest24
Member
Join Date: Sep 2018
Location: Georgia
Old 01-09-2022 , 13:13   Re: set task disable
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
Check the team again inside the "removeweapons" function?
yeah that maybe useful in this situation but isnt there any code that destroy this set task function?
__________________
Hello!
thebest24 is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 01-09-2022 , 13:43   Re: set task disable
Reply With Quote #4

Hi, what about :
PHP Code:
if(cs_get_user_team(id) == CS_TEAM_SPECTATOR
          
set_task(31.1"removeweapons"id 100000
then :
PHP Code:
public function_check(id)
{
    if(
task_exists(id 100000))
    {
        
client_print(idprint_chat,"Your Task is running!!");

        
remove_task(id 100000);
        return 
PLUGIN_HANDLED;
    }
    else
    {
        
client_print(idprint_chat,"Your Task is  not running!!");
        return 
PLUGIN_HANDLED;
    }
     return 
PLUGIN_HANDLED;

__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
thebest24
Member
Join Date: Sep 2018
Location: Georgia
Old 01-09-2022 , 13:54   Re: set task disable
Reply With Quote #5

Quote:
Originally Posted by abdobiskra View Post
Hi, what about :
PHP Code:
if(cs_get_user_team(id) == CS_TEAM_SPECTATOR
          
set_task(31.1"removeweapons"id 100000
then :
PHP Code:
public function_check(id)
{
    if(
task_exists(id 100000))
    {
        
client_print(idprint_chat,"Your Task is running!!");

        
remove_task(id 100000);
        return 
PLUGIN_HANDLED;
    }
    else
    {
        
client_print(idprint_chat,"Your Task is  not running!!");
        return 
PLUGIN_HANDLED;
    }
     return 
PLUGIN_HANDLED;

i dont know exactly how it working can you send me any sma (here php) with this code included to check it?
or can u show me example?
__________________
Hello!
thebest24 is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-09-2022 , 14:07   Re: set task disable
Reply With Quote #6

Quote:
Originally Posted by abdobiskra View Post
Code:
public function_check(id) {
    if(task_exists(id + 100000))
    {         client_print(id, print_chat,"Your Task is running!!");
        remove_task(id + 100000);
        return PLUGIN_HANDLED;     }     else     {         client_print(id, print_chat,"Your Task is  not running!!");         return PLUGIN_HANDLED;     }      return PLUGIN_HANDLED; }
That is wrong, because you already pass (id + 100000) value when you set task. So, if you print out (id) it will show you (id /* a integer value already*/ + 100000), you don't need to add again 100000 on those lines.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-09-2022 , 14:10   Re: set task disable
Reply With Quote #7

Quote:
Originally Posted by thebest24 View Post
yeah that maybe useful in this situation but isnt there any code that destroy this set task function?
You can remove a task with the "remove_task" function.
But you still would need to make the check and even if the user is still in the server.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
thebest24
Member
Join Date: Sep 2018
Location: Georgia
Old 01-09-2022 , 14:52   Re: set task disable
Reply With Quote #8

this is actually what im trying to fix:
i give players boss and survivor with amx_event
and i added special powers on them which work with set task
only for this 2 class but when you give them boss/survivor again
and if this old tasks are still active they get mixed together.
so i want solution for this when u give amx_event again i want this old tasks to be removed


PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <basebuilder>
#include <hamsandwich>

new PowerUsed[33];

public 
plugin_init() {
    
register_plugin("amx_cheat","1.0","watch")
    
register_concmd("amx_event","amx_godmode",ADMIN_LEVEL_F,"<target>")
    
RegisterHam(Ham_Spawn"player""FwdHamSpawn_Post"1);
}
public 
FwdHamSpawn_Post(id)
{
    
PowerUsed[id] = false;
}
public 
plugin_precache() 
{
                 
precache_model("models/player/shbb_sparrow/shbb_sparrow.mdl")
                 
precache_sound("misc/godmodbb.wav");
                 
precache_sound("misc/healingdem.wav");
                 
precache_sound("misc/fireratebb.wav");
}
public 
amx_godmode(id,level,cid) {
    if (!
cmd_access(id,level,cid,2))
        return 
PLUGIN_HANDLED
    
    
new arg[32], admin_name[32], target_name[32]
    
read_argv(1,arg,31)

    new 
player cmd_target(id,arg,14)
    if (!
player) return PLUGIN_HANDLED

    get_user_name
(id,admin_name,31)
    
get_user_name(player,target_name,31)

    if(!
zp_get_user_zombie(player)) {
               
set_task(0.5"change"player)
                
set_task(40.0"boost"player)
                
set_task(55.0"reboost"player)
                
set_task(95.0"boost"player)
                
set_task(110.0"reboost"player)
                
set_task(150.0"boost"player)
                
set_task(165.0"reboost"player)
                
set_task(205.0"boost"player)
                
set_task(220.0"reboost"player)
                
set_task(260.0"boost"player)
                
set_task(275.0"reboost"player)
                
set_task(315.0"boost"player)
                
set_task(330.0"reboost"player)
                
set_task(370.0"boost"player)
                
set_task(385.0"reboost"player)
                
set_task(425.0"boost"player)
                
set_task(440.0"reboost"player)
                
set_task(480.0"boost"player)
                
set_task(495.0"reboost"player)
                
set_task(535.0"boost"player)
                
set_task(550.0"reboost"player)
                
set_user_maxspeed(player320.0)
                
set_user_health(player500)
        
cs_set_user_model(player,"shbb_sparrow")
        
set_user_gravity(player450.0 800)
                
strip_user_weapons(player)
            
give_item(player,"weapon_knife")
                
client_cmd(player"give_qbz")
                
give_item(player"weapon_elite")
                
cs_set_user_bpammo(playerCSW_FAMAS200)
                
cs_set_user_bpammo(playerCSW_ELITE200)
        switch(
get_cvar_num("amx_show_activity")) {
            case 
2:    client_print(0,print_chat,"ADMIN: Transfered %s to Survivor",target_name)
            case 
1:    client_print(0,print_chat,"ADMIN: Transfered %s to Survivor",target_name)
        }
    } else {
        
bb_set_user_zombie_class(player10)
      
set_task(0.5"change"player)
      
set_task(35.0"give_health"player)
      
set_task(70.0"give_health"player)
      
set_task(105.0"give_health"player)
      
set_task(140.0"give_health"player)
      
set_task(175.0"give_health"player)
      
set_task(210.0"give_health"player)
      
set_task(250.0"give_health"player)
      
set_task(280.0"give_health"player)
      
set_task(315.0"give_health"player)
      
set_task(350.0"give_health"player)
      
set_task(385.0"give_health"player)
      
set_task(430.0"give_health"player)
      
set_task(455.0"give_health"player)
      
set_task(490.0"give_health"player)
      
set_task(525.0"give_health"player)
                
set_task(60.0"give_godmode"player)
                
set_task(65.0"remove_godmode"player)
                
set_task(120.0"give_godmode"player)
                
set_task(125.0"remove_godmode"player)
                
set_task(180.0"give_godmode"player)
                
set_task(185.0"remove_godmode"player)
                
set_task(240.0"give_godmode"player)
                
set_task(245.0"remove_godmode"player)
                
set_task(300.0"give_godmode"player)
                
set_task(305.0"remove_godmode"player)
                
set_task(360.0"give_godmode"player)
                
set_task(365.0"remove_godmode"player)
                
set_task(420.0"give_godmode"player)
                
set_task(425.0"remove_godmode"player)
                
set_task(480.0"give_godmode"player)
                
set_task(485.0"remove_godmode"player)
                
set_task(540.0"give_godmode"player)
                
set_task(545.0"remove_godmode"player)
                
ExecuteHamB(Ham_CS_RoundRespawnplayer)
        switch(
get_cvar_num("amx_show_activity")) {
            case 
2:    client_print(0,print_chat,"ADMIN: Transfered %s to Boss",target_name)
            case 
1:    client_print(0,print_chat,"ADMIN: Transfered %s to Boss",target_name)
        }
    }
    return 
PLUGIN_HANDLED
}
public 
give_godmode(id
{
if(
zp_get_user_zombie(id) & PowerUsed[id])
set_user_godmode(id1),
            
emit_sound(idCHAN_STATIC"misc/godmodbb.wav"1.0ATTN_NORM0PITCH_NORM),
set_user_rendering(id,kRenderFxGlowShell,255,150,38,kRenderNormal,25),
            
set_task(0.95"alarm"id),
            
set_task(1.9"alarm"id),
            
set_task(2.85"alarm"id),
            
set_task(3.8"alarm"id)

public 
remove_godmode(id
{
set_user_godmode(id0),
set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderNormal,25)

public 
alarm(id
{
if(
zp_get_user_zombie(id) & PowerUsed[id])
emit_sound(idCHAN_STATIC"misc/godmodbb.wav"1.0ATTN_NORM0PITCH_NORM)

public 
give_health(id
{
if(
zp_get_user_zombie(id) & PowerUsed[id])
set_user_health(idget_user_health(id) + 5000),
emit_sound(idCHAN_STATIC"misc/healingdem.wav"1.0ATTN_NORM0PITCH_NORM),
set_user_rendering(id,kRenderFxGlowShell,0,255,0,kRenderNormal,25),
set_task(0.8"remglow"id)

public 
remglow(id
{
set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderNormal,25)
}
public 
boost(id
{
if(!
zp_get_user_zombie(id) & PowerUsed[id])
emit_sound(idCHAN_STATIC"misc/fireratebb.wav"1.0ATTN_NORM0PITCH_NORM),
set_user_rendering(id,kRenderFxGlowShell,255,0,0,kRenderNormal,25),
strip_user_weapons(id),
give_item(id,"weapon_knife"),
client_cmd(id"give_qbz2"),
give_item(id"weapon_elite"),
cs_set_user_bpammo(idCSW_FAMAS200),
cs_set_user_bpammo(idCSW_ELITE200)
}
public 
reboost(id
{
if(!
zp_get_user_zombie(id) & PowerUsed[id])
set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderNormal,25),
strip_user_weapons(id),
give_item(id,"weapon_knife"),
client_cmd(id"give_qbz"),
give_item(id"weapon_elite"),
cs_set_user_bpammo(idCSW_FAMAS200),
cs_set_user_bpammo(idCSW_ELITE200)
}
public 
change(id
{
      
PowerUsed[id] = true;

__________________
Hello!
thebest24 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-09-2022 , 15:31   Re: set task disable
Reply With Quote #9

If you have multiple tasks in your plugin and want to remove them individually, you should assign them an unique id.

Code:
const YOUR_TASK_ID = 123800 const ANOTHER_TASK_ID = 123900

The numbers don't matter, but it's important that there's at least 32 numbers between them so they don't get mixed up with player slots. You will be combining these ids with a player id.

Code:
set_task(31.1, "removeweapons", id + YOUR_TASK_ID)

Then in task callback function:

Code:
public removeweapons(id) {     id -= YOUR_TASK_ID     // your code here... }
__________________

Last edited by OciXCrom; 01-09-2022 at 15:31.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-09-2022 , 15:35   Re: set task disable
Reply With Quote #10

Why do you have all of this repetitive code?

PHP Code:
set_task(35.0"give_health"player)
set_task(70.0"give_health"player)
set_task(105.0"give_health"player)
set_task(140.0"give_health"player)
set_task(175.0"give_health"player)
set_task(210.0"give_health"player)
set_task(250.0"give_health"player)
set_task(280.0"give_health"player)
set_task(315.0"give_health"player)
set_task(350.0"give_health"player)
set_task(385.0"give_health"player)
set_task(430.0"give_health"player)
set_task(455.0"give_health"player)
set_task(490.0"give_health"player)
set_task(525.0"give_health"player
Creating tasks is an expensive operation.
Tasks can be assigned custom flags to make them work differently, e.g. make them repeat X times or until you stop them.

https://amxx-bg.info/api/amxmodx/set_task

All of the above code can be replaced with a repeating task:

Code:
set_task(40.0, "give_health", player, + TASK_GIVE_HEALTH .flags = "b")

Or one that is repeated X times:

Code:
set_task(40.0, "give_health", player, + TASK_GIVE_HEALTH .flags = "a", .repeat = 15)

Then simply stop it if you need it to:

Code:
remove_task(player + TASK_GIVE_HEALTH)

You should always avoid repetitive lines of code in your plugin.
__________________

Last edited by OciXCrom; 01-09-2022 at 15:36.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply


Thread Tools
Display Modes

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 05:15.


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