Raised This Month: $32 Target: $400
 8% 

FM_Time


Post New Thread Reply   
 
Thread Tools Display Modes
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 11-14-2019 , 06:22   Re: FM_Time
Reply With Quote #11

set_task so much cpu usage... i was just thinking if i can do it properly with FM_Time
LearninG is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-14-2019 , 06:34   Re: FM_Time
Reply With Quote #12

The "proper" way is to keep checking the time at a constant interval one way or another(be it each 0.1 seconds, each second, be it inside pawn or c++). You simply need something that checks continously, so no idea what optimizations you are hoping for.
__________________

Last edited by HamletEagle; 11-14-2019 at 06:36.
HamletEagle is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-14-2019 , 07:21   Re: FM_Time
Reply With Quote #13

Quote:
Originally Posted by LearninG View Post
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.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Reply


Thread Tools
Display Modes

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


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