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

set_task() or hooking server_frame()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 07-22-2011 , 03:01   set_task() or hooking server_frame()
Reply With Quote #1

Simple question... I'm wondering what would be the more efficient/effective method of using a continually looped task.

Using set_task() on a loop...

Code:
public plugin_init( )
{
	set_task( 1.0, "TaskUpdateList", _, _, _, "b" );
	set_task( 0.1, "TaskUpdateKeys", _, _, _, "b" );
}

public TaskUpdateList( )
{
	
}

public TaskUpdateKeys( )
{
	
}
Or using something else, perhaps server_frame(), and using a global variable to check if some code should be executed:

Code:
new Float:g_fNextUpdate_Keys;
new Float:g_fNextUpdate_List;

public server_frame()
{
	static Float:fGlobalTime;
	fGlobalTime = get_gametime( );
	
	if( g_fNextUpdate_Keys >= fGameTime )
	{
		//execute code...
		
		g_fNextUpdate_Keys = fGameTime + 0.1;
	}
	
	if( g_fNextUpdate_List >= fGameTime )
	{
		//execute code...
		
		g_fNextUpdate_List = fGameTime + 0.1;
	}
}
shadow.hk is offline
Send a message via MSN to shadow.hk
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 07-22-2011 , 03:06   Re: set_task() or hooking server_frame()
Reply With Quote #2

https://forums.alliedmods.net/showth...=thinking+ents
Doc-Holiday is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-22-2011 , 05:19   Re: set_task() or hooking server_frame()
Reply With Quote #3

Server_frame is absolutely not a good idea, use set_task unless you need to set delays of > 0.1, in such case you should use an entities think otherwise.
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
jim_yang
Veteran Member
Join Date: Aug 2006
Old 07-22-2011 , 05:28   Re: set_task() or hooking server_frame()
Reply With Quote #4

amxx's task system is using the mode just like the second one you gave. So the first one is more efficient because you let module to do the work.(I'm talking about the server_frame hooking)
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang 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 15:23.


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