Quote:
Originally Posted by LearninG
server frame is called many times per second while the ent think is almost called every 1 hour.
function will be called in a time between 00:00:00 and 00:00:10
Code:
#include <amxmodx>
#include <engine>
new Float:g_Delay_Time
new iHour , iMinute , iSeconds
new g_Classname[] = "sOmE_ClAssName"
public plugin_init()
{
register_think(g_Classname , "callback")
new ent = create_entity("info_target")
entity_set_string(ent, EV_SZ_classname, g_Classname)
entity_set_float(ent, EV_FL_nextthink, halflife_time() + 0.1)
}
public callback(ent)
{
time(iHour , iMinute , iSeconds)
switch(iHour)
{
case 0:
{
if (iMinute == 0 && iSeconds <= 10) // if it's midnight
{
execute_a_function()
}
g_Delay_Time = 3600.0 // set nextthink to 1 hour
}
case 1..22: // set nextthink to 1 hour
{
g_Delay_Time = 3600.0
}
default: // it's not 0 or 1..22 , so it's 23
{
if (iMinute >= 49) // checking if time is greater than or equal to 23:49
{
g_Delay_Time = 5.0 // set nexthink to 5 second to get the exact time (midnight)
}
else
{
g_Delay_Time = 600.0 // set nexthink to 10 minutes for checking if iMinute is greater than or equal to 49
}
}
}
entity_set_float(ent, EV_FL_nextthink, halflife_time() + g_Delay_Time)
}
execute_a_function()
{
client_print(0 , print_chat , "It's midnight")
}
|
Not true in this case:
PHP Code:
#define FRAMES_IN_SECOND 100
Change for frame count that you need, since my example plugin use seconds precision. If you want to do with more delay, adjust define:
PHP Code:
#define FRAMES_IN_SECOND 100
#define FRAMES_IN_MINUTE 6000
#define FRAMES_IN_HOUR 360000
Also server_frame hooked via fakemeta can be disabled and enabled in some situations, and the hook itself without execute any task inside function (Only using if) will not affect server performance.
__________________