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

FM_Time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 11-12-2019 , 14:12   FM_Time
Reply With Quote #1

I found no info about this forward after searching long time .
it is used in register_forward ( fakemeta )
can you give me some information about when it is called and how do you handle callback function ( what values we can assign to it )
thanks.

Last edited by LearninG; 11-12-2019 at 14:13.
LearninG is offline
iNvectus
Member
Join Date: Sep 2014
Location: Bulgaria
Old 11-13-2019 , 02:30   Re: FM_Time
Reply With Quote #2

FM_Time is the total uptime of the server. It needs no arguments from what I see in the source:

Code:
    case FM_Time:         fId = MF_RegisterSPForwardByName(amx, funcname, FP_DONE);         ENGHOOK(Time);         break;

and it is natively calling engfunc:
Code:
// pfnTime SIMPLE_FLOAT_HOOK_VOID(Time);

Code:
#define SIMPLE_FLOAT_HOOK_VOID(call) \     float call () \     { \         FM_ENG_HANDLE(FM_##call, (Engine[FM_##call].at(i))); \         RETURN_META_VALUE(mswi(lastFmRes), (float)mFloatResult); \     } \     float call##_post () \     { \         FM_ENG_HANDLE_POST(FM_##call, (EnginePost[FM_##call].at(i))); \         RETURN_META_VALUE(MRES_IGNORED, (float)mFloatResult); \     }

So what we have so far?

You have several ways of doing this:
  • Hooking FM_Time for unknown reason
  • Calling engfunc directly

Code:
#include <amxmodx> #include <fakemeta> public plugin_init() {     register_plugin("Blabla", "1.0", "blabla");     register_forward(FM_Time, "fwFmTime");     register_srvcmd("fmtest", "cmdFmTest"); } /*! EngFunc */ public fmTest() {     server_print("FM_Time aka EngFunc_Time: %f", engfunc(EngFunc_Time)); } /*! Hooking */ public fwFmTime() {     // We are inside }
__________________
iNvectus is offline
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 11-13-2019 , 06:35   Re: FM_Time
Reply With Quote #3

no message in game
Code:
#include <amxmodx> #include <fakemeta> public plugin_init() {     register_forward(FM_Time , "fwFmTime") } public fwFmTime() {     client_print( 0 , print_chat , "FM_Time has been called") }
LearninG is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-13-2019 , 09:32   Re: FM_Time
Reply With Quote #4

This is because time is not get called in game, what you trying to do with it?
__________________
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
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 11-13-2019 , 09:55   Re: FM_Time
Reply With Quote #5

Excuting a function in an specific time. ( 4 AM for example )

Last edited by LearninG; 11-13-2019 at 09:57.
LearninG is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-13-2019 , 19:53   Re: FM_Time
Reply With Quote #6

you can try with ServerFrame no?

PHP Code:
#include <amxmodx>
#include <fakemeta>

#define FRAMES_IN_SECOND 100

public plugin_init()
{
    
register_plugin("Get Ready for 2020","0.1","SmileY");
    
    
register_forward(FM_StartFrame,"StartFrame");
}

public 
StartFrame()
{
    static 
Time FRAMES_IN_SECOND;
    
    if(--
Time
    {
        return;
    }
    
    
Time FRAMES_IN_SECOND;
    
    
// Do task here
    
server_print("One Second Passed, checking time!");
    
    new 
Time[32];
    
get_time("%m/%d/%Y - %H:%M:%S",Time,charsmax(Time)); // Change format for desired result
    
    
if(equali(Time,"12/31/2019 - 23:59:59"))
    {
        
// Do task here!
        
client_print(0,print_chat,"[AMXX] Get Ready for 2020 bro!!");
    }

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 11-13-2019 at 20:08.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 11-13-2019 , 23:20   Re: FM_Time
Reply With Quote #7

I think this is better than hooking server_frame , but i thought if i can do something better with FM_Time
Code:
#include <amxmodx> #include <engine> #define THINK_TIME 1.0 new g_Classname[] = "SoME_ClAssNamE" new g_iHour new Float:g_Delay_Time = THINK_TIME public plugin_init() {     register_think(g_Classname , "callback")     new ent     ent = create_entity("info_target")     entity_set_string(ent , EV_SZ_classname , g_Classname)     entity_set_float(ent , EV_FL_nextthink , halflife_time() + 0.01) } public callback(ent) {     time(g_iHour , _ , _)     if(g_iHour == 4)     {         client_print(0 , print_chat , "It's 4 am.")     }     if(g_iHour == 16)     {         client_print(0 , print_chat , "It's 4 pm.")     }     entity_set_float(ent , EV_FL_nextthink , halflife_time() + g_Delay_Time) }

Last edited by LearninG; 11-13-2019 at 23:21.
LearninG is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-14-2019 , 00:47   Re: FM_Time
Reply With Quote #8

How so it's better?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-14-2019 at 00:47.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 11-14-2019 , 01:26   Re: FM_Time
Reply With Quote #9

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") }
LearninG is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-14-2019 , 05:38   Re: FM_Time
Reply With Quote #10

So what about set_task? What's wrong with it
It also doesn't consume entities...
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-14-2019 at 05:39.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 07:47.


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