Raised This Month: $ Target: $400
 0% 

Solved Stopwatch for Server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 06-16-2020 , 20:34   Re: Stopwatch for Server
Reply With Quote #1

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
tepegoz
Senior Member
Join Date: Apr 2019
Old 06-17-2020 , 08:58   Re: Stopwatch for Server
Reply With Quote #2

Quote:
Originally Posted by +ARUKARI- View Post
Not Tested.
PHP Code:
#pragma semicolon 1
#include <amxmodx>
#include <hamsandwich>

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

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

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say""stopwatch");
    
RegisterHam(Ham_Think"player""ThinkTime");
}

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

    if (
equali(said,"/start"))
    {
        
g_starttime get_systime();
        
g_counttime 0;
        
g_status WATCH_STATUS:START;
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/stop"))
    {
        
g_counttime = (get_systime() - g_starttime);
        
g_status WATCH_STATUS:STOP;
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/pause"))
    {
        
g_counttime = (get_systime() - g_starttime);
        
g_status WATCH_STATUS:STOP;
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/resume"))
    {
        
g_status WATCH_STATUS:START;
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

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

    switch(
g_status)
    {
        case 
START:
        {
            
get_time_format((get_systime() - g_starttime) + g_counttimetimeformatcharsmax(timeformat), 0);
            
set_hudmessage(00255, -1.00.3500.51.00.00.1, -1);
            
show_hudmessage(0"[STOP WATCH]: %s"timeformat);
        }
        case 
STOP:
        {
            
get_time_format(g_counttimetimeformatcharsmax(timeformat), 0);
            
set_hudmessage(00255, -1.00.3500.55.00.00.1, -1);
            
show_hudmessage(0"[STOP WATCH]: %s"timeformat);
        }
    }
}

get_time_format(timesresult[], lenmode)
{
    switch(
mode)
    {
        case 
'H':
            
format_time(resultlen"%H"times);
        case 
'M':
            
format_time(resultlen"%M"times);
        case 
'S':
            
format_time(resultlen"%S"times);
        default:
            
format_time(resultlen"%H:%M:%S"times);
    }

Thanks but not working.
tepegoz is offline
Reply



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 00:52.


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