AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   FM_Time (https://forums.alliedmods.net/showthread.php?t=319643)

LearninG 11-12-2019 14:12

FM_Time
 
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.

iNvectus 11-13-2019 02:30

Re: FM_Time
 
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 }

LearninG 11-13-2019 06:35

Re: FM_Time
 
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") }

^SmileY 11-13-2019 09:32

Re: FM_Time
 
This is because time is not get called in game, what you trying to do with it?

LearninG 11-13-2019 09:55

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

^SmileY 11-13-2019 19:53

Re: FM_Time
 
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!!");
    }



LearninG 11-13-2019 23:20

Re: FM_Time
 
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) }

Natsheh 11-14-2019 00:47

Re: FM_Time
 
How so it's better?

LearninG 11-14-2019 01:26

Re: FM_Time
 
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") }

Natsheh 11-14-2019 05:38

Re: FM_Time
 
So what about set_task? What's wrong with it
It also doesn't consume entities...


All times are GMT -4. The time now is 02:42.

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