Raised This Month: $ Target: $400
 0% 

Optimize tasks (replace with thinks)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
faki
Senior Member
Join Date: Jul 2013
Old 07-23-2013 , 13:05   Optimize tasks (replace with thinks)
Reply With Quote #1

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!

Last edited by faki; 07-23-2013 at 13:06.
faki is offline
DWIGHTpN
Senior Member
Join Date: Jan 2013
Location: Romania.
Old 07-24-2013 , 06:39   Re: Optimize tasks (replace with thinks)
Reply With Quote #2

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 );

DWIGHTpN is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-24-2013 , 07:59   Re: Optimize tasks (replace with thinks)
Reply With Quote #3

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.
__________________
Arkshine 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 06:31.


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