AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved set_task help (https://forums.alliedmods.net/showthread.php?t=329524)

lexzor 12-28-2020 00:22

set_task help
 
hello. I have this code

PHP Code:

public plugin_init(){
register_event("HLTV""roundstart""a""1=0""2=0"
}

public 
roundstart(id){
    
stopplugin=false
    set_task
25.0"roundcounters"___"b");
    
ColorChat(0GREEN"^3[JoiNET]^1 Anti-rush plugin is ^3enabled^1!")
    
ColorChat(0GREEN"^3[JoiNET]^1 Counter-Terrorists can't rush for^3 25 seconds^1.")

}

public 
roundcounters(id){

stopplugin=true
ColorChat
(0GREEN"^3[JoiNET]^1 test.")



everything is working, but there is a problem with set_task.

after a few rounds, there are more task at different times. i want this task to disable plugin after first 25 seconds, but with more tasks working, sometimes plugin is disabled after a random num of seconds.

fysiks 12-28-2020 02:21

Re: set_task help
 
You're creating an infinitely repeating task (flag "b") every time the HLTV event occurs. So, you are creating several simultaneous tasks that never stop. So, after 5 HLTV events, you have 5 tasks that will all keep run until the map changes.

You should probably describe what you are actually trying to do so that we can give you the proper advice. Your "stopplugin" variable doesn't do anything. To run a task only once, don't use any flags.

Napoleon_be 12-28-2020 20:34

Re: set_task help
 
^

And using the HLTV event is not the proper way of catching roundstart, read this for more info: https://forums.alliedmods.net/showthread.php?t=42159

lexzor 12-29-2020 13:04

Re: set_task help
 
that is how i hook roundstart now
PHP Code:

register_logevent("logevent_round_start"2"1=Round_Start"

I said very clearly what I want to do in the first post. I want that task to run 25 seconds after the start of the round and not have multiple tasks on top of each other. Usually I get the tasks from the last round to the current round and i used task like this:

PHP Code:

set_task25.0"roundcounters"____); 

and
PHP Code:

set_task25.0"roundcounters"); 

but still don't works

and i have another ask.
can i use set_task like this
PHP Code:

new Float:time 15

set_task
time"public_func"

?

Bugsy 12-29-2020 13:20

Re: set_task help
 
This is not complicated
PHP Code:


#include <amxmodx>

const RoundTaskID 57882;

public 
plugin_init() 
{
    
register_logevent("logevent_round_start"2"1=Round_Start"
}

public 
logevent_round_start()
{
    
remove_taskRoundTaskID );
    
set_task25.0 "roundcounters" RoundTaskID );
}

public 
roundcounters()
{
    
client_printprint_chat "round counters called" );



lexzor 12-29-2020 13:24

Re: set_task help
 
Thank you guys, but my server is running a csgo mode and i have warmup round, so that's why in first round my tasks are more than normal

how can i do something like.. if an task is starting, to stop previously task ?

Bugsy 12-29-2020 13:44

Re: set_task help
 
See above

lexzor 12-29-2020 13:49

Re: set_task help
 
omg i didn t read all lines, thank you

lexzor 12-29-2020 14:00

Re: set_task help
 
is this ok ?
PHP Code:

if(task_exists1024 ))
        
remove_task1024 );
        
set_task25.0 "antirushoff" 1024 ); 


Bugsy 12-29-2020 14:44

Re: set_task help
 
You do not need to first call task_exists() before calling remove_task(), just do what I posted. task_exists() should only be used if you want to know if the task exists for other reasons/conditions.


All times are GMT -4. The time now is 14:07.

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