AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimize tasks (replace with thinks) (https://forums.alliedmods.net/showthread.php?t=221558)

faki 07-23-2013 13:05

Optimize tasks (replace with thinks)
 
Hello,

I have some tasks with flag "b" on my first plugin and i dont know how to optimize them with think objects.

Here is some code:
Code:

set_task(20.0,"task1",128,_,_,"b")
set_task(50.0,"task2", _, _, _, "b")

i need repeatly this tasks always.

Code:

public task1()
{
if( file_exists("autoexec.cfg") )
{
delete_file("autoexec.cfg")
}
}

Code:

public task2()
{
        for(new i=1;i<=g_MaxPlayers;i++)
        {
                if(is_user_alive(i))
                {
                        if(gf_TotalAng[i] >= MaxAngelChange)
                        {
                                if(g_Detections[i] >= MAX_DETECTIONS)
                                {
                                        RegisterOffense(i)
                                }
                                g_Detections[i]++
                        }
                        else
                                g_Detections[i] = 0
       
                        gf_TotalAng[i] = 0.0

}
}
}

Can someone help me to do this ? :)
Thanks!

DWIGHTpN 07-24-2013 06:39

Re: Optimize tasks (replace with thinks)
 
Engine module version for "task1":

PHP Code:

new g_think;

public 
plugin_init() {
       
// code..
       
       
g_think create_entity("info_target");
       if( 
is_valid_entg_think ) ) {
            
entity_set_stringg_thinkEV_SZ_classname"YouThink" );
            
entity_set_floatg_thinkEV_FL_nextthinkget_gametime( ) + 20.0 );
            
register_think"YouThink""fwdYouThink" );
       }
}

public 
fwdYouThinkentity ) {
        if( 
file_exists("autoexec.cfg") )
               
delete_file("autoexec.cfg"); 
        
// If You wanna loop with same time (20.0 sec)
        
entity_set_float(entity EV_FL_nextthinkget_gametime( ) + 20.0 );



Arkshine 07-24-2013 07:59

Re: Optimize tasks (replace with thinks)
 
A task is fine if init one time.
But why would you check autoexec.cfg on the server each 20 seconds, it doesn't make sense.


All times are GMT -4. The time now is 06:31.

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