Thread: [Solved] Stopwatch for Server
View Single Post
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 06-16-2020 , 20:34   Re: Stopwatch for Server
Reply With Quote #8

Not Tested.
PHP Code:
#pragma semicolon 1
#include <amxmodx>
#include <fakemeta>

#define PLUGIN    "StopWatch"
#define VERSION    "0.1"
#define AUTHOR    "Aoi.Kagase"
#define TASK_ID    1122

enum _:WATCH_STATUS
{
    
STOP,
    
START,
}
new 
Float:g_starttime;
new 
Float:g_counttime;
new 
WATCH_STATUS:g_status;
new 
bool:g_stopwatch;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say""stopwatch");
    
register_forward(FM_PlayerPreThink"ThinkTime");
    
g_stopwatch false;
}

public 
stopwatch(id)
{
    new 
said[32];
    
read_argv(1saidcharsmax(said));

    if (
equali(said,"/start"))
    {
        
g_starttime get_gametime();
        
g_counttime 0.0;
        
g_stopwatch true;
        
g_status WATCH_STATUS:START;
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/stop"))
    {
        
g_stopwatch false;
        
g_counttime get_gametime() - g_starttime;
        
g_status WATCH_STATUS:STOP;
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/pause"))
    {
        
g_counttime get_gametime() - g_starttime;
        
g_status WATCH_STATUS:STOP;
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/resume"))
    {
        
g_starttime get_gametime();
        
g_status WATCH_STATUS:START;
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

public 
ThinkTime(id)
{
    static 
timeformat[12];

    if (
g_stopwatch)
    {
        switch(
g_status)
        {
            case 
START:
                
get_time_format((floatround(get_gametime()) - g_starttime) + g_counttimetimeformatcharsmax(timeformat), 0);
            case 
STOP:
                
get_time_format(g_counttimetimeformatcharsmax(timeformat), 0);
        }
        
set_hudmessage(1010255, -1.00.3500.51.00.00.1, -1);
        
show_hudmessage(0"[STOP WATCH]: %s"timeformat);
    }
}

get_time_format(Float:timesresult[], lenmode)
{
     new 
hour = (floatround(times) / 60) / 60;
     new 
min  = (floatround(times) / 60) % 60;
     new 
sec  = (floatround(times) % 60);

    switch(
mode)
    {
        case 
'H':
            
formatex(result[0], len"%02i"hour);
        case 
'M':
            
formatex(result[0], len"%02i"min);
        case 
'S':
            
formatex(result[0], len"%02i"sec);
        default:
            
formatex(result[0], len"%02i:%02i:%02i"hourminsec);
    }

2020.06.18 19:50 UPDATED.
__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 06-18-2020 at 06:48.
+ARUKARI- is offline