AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set_task() or hooking server_frame() (https://forums.alliedmods.net/showthread.php?t=162710)

shadow.hk 07-22-2011 03:01

set_task() or hooking server_frame()
 
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;
        }
}


Doc-Holiday 07-22-2011 03:06

Re: set_task() or hooking server_frame()
 
https://forums.alliedmods.net/showth...=thinking+ents

abdul-rehman 07-22-2011 05:19

Re: set_task() or hooking server_frame()
 
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.

jim_yang 07-22-2011 05:28

Re: set_task() or hooking server_frame()
 
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)


All times are GMT -4. The time now is 01:04.

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