Raised This Month: $ Target: $400
 0% 

set_task() or hooking server_frame()


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 01:04.


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