Raised This Month: $231 Target: $400
 57% 

Solved Stopwatch for Server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tepegoz
Senior Member
Join Date: Apr 2019
Old 03-31-2020 , 18:55   Stopwatch for Server
Reply With Quote #1

I want to stopwatch plugin for my cs 1.6 server.
When I type /start , timer will start and when I type /stop timer will stop.
I want hud message as Hours:Minute:Seconds on screen(all players must see on their screens).

Last edited by tepegoz; 04-01-2020 at 05:30.
tepegoz is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-31-2020 , 20:33   Re: Stopwatch for Server
Reply With Quote #2

untested

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "StopWatch"
#define VERSION "1.0"
#define AUTHOR "NapoleoN#"

#define SWID 132465

new iSeconds;
new 
iMinutes;
new 
iHours;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd("say /start""StartStopWatch");
    
register_clcmd("say /stop""StopStartWatch");
}

#if AMXX_VERSION_NUM < 190
public client_disconnect(id)
#else
public client_disconnected(id)
#endif
{
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum);
    
    if(
iNum == 0)
    {
        
StopStartWatch(id);
    }
}

public 
StartStopWatch(id)
{
    
set_task(1.0"ShowHud"SWID__"b");
}

public 
ShowHud(id)
{
    if(
iSeconds++ > 60)
    {
        if(
iMinutes++ > 60)
        {
            
iHours++;
        }
    }
    
    
set_hudmessage(42170255, -1.00.7606.01.0);
    
show_hudmessage(id"Stopwatch: %i:%i:%i"iHoursiMinutesiSeconds);
}

public 
StopStartWatch(id)
{
    if(
task_exists(SWID))
    {
        
iSeconds 0;
        
iMinutes 0;
        
iHours 0;
        
        
remove_task(SWID);
    }

__________________

Last edited by Napoleon_be; 03-31-2020 at 22:02.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 03-31-2020 , 20:41   Re: Stopwatch for Server
Reply With Quote #3

I was late

PHP Code:
#pragma semicolon 1
#include <amxmodx>
#define PLUGIN    "StopWatch"
#define VERSION    "0.1"
#define AUTHOR    "Aoi.Kagase"
#define TASK_ID    1122

new g_stopwatch false;
new 
Float:g_starttime;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say""stopwatch");
}

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

    if (
equali(said,"/start"))
    {
        
g_stopwatch true;
        
g_starttime get_gametime();

        
set_task(0.1"show_sw"TASK_ID id);
        
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/stop"))
    {
        
g_stopwatch false;
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

public 
show_sw(task)
{
    if (
g_stopwatch)
    {
        new 
timeformat[8];
        
get_time_format((get_gametime() - g_starttime), timeformatcharsmax(timeformat));
        
set_hudmessage(00255, -1.00.3500.51.00.00.1, -1);
        
show_hudmessage(0"%s"timeformat);
        
set_task(1.0"show_sw"task);
    }
}

get_time_format(Float:timesresult[], len)
{
    new 
hour floatround(times) / 60 /60;
    new 
min  =(floatround(times) / 60) % 60;
    new 
sec  floatround(times) % 60;
    
formatex(result[0], len"%i:%i:%i"hourminsec);

__________________
+ARUKARI- is offline
tepegoz
Senior Member
Join Date: Apr 2019
Old 04-01-2020 , 05:29   Re: Stopwatch for Server
Reply With Quote #4

thanks it is working.
tepegoz is offline
tepegoz
Senior Member
Join Date: Apr 2019
Old 06-16-2020 , 10:57   Re: Stopwatch for Server
Reply With Quote #5

Quote:
Originally Posted by +ARUKARI- View Post
I was late

PHP Code:
#pragma semicolon 1
#include <amxmodx>
#define PLUGIN    "StopWatch"
#define VERSION    "0.1"
#define AUTHOR    "Aoi.Kagase"
#define TASK_ID    1122

new g_stopwatch false;
new 
Float:g_starttime;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say""stopwatch");
}

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

    if (
equali(said,"/start"))
    {
        
g_stopwatch true;
        
g_starttime get_gametime();

        
set_task(0.1"show_sw"TASK_ID id);
        
        return 
PLUGIN_HANDLED;
    } else
    if (
equali(said"/stop"))
    {
        
g_stopwatch false;
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

public 
show_sw(task)
{
    if (
g_stopwatch)
    {
        new 
timeformat[8];
        
get_time_format((get_gametime() - g_starttime), timeformatcharsmax(timeformat));
        
set_hudmessage(00255, -1.00.3500.51.00.00.1, -1);
        
show_hudmessage(0"%s"timeformat);
        
set_task(1.0"show_sw"task);
    }
}

get_time_format(Float:timesresult[], len)
{
    new 
hour floatround(times) / 60 /60;
    new 
min  =(floatround(times) / 60) % 60;
    new 
sec  floatround(times) % 60;
    
formatex(result[0], len"%i:%i:%i"hourminsec);

Hi I want to stop and resume the time. Can you help me? When I type /stop the timer will stop, and when I type /resume the timer will resume from old time.
tepegoz is offline
Alber9091
Veteran Member
Join Date: Jun 2014
Location: Some Where On Earth
Old 06-16-2020 , 11:16   Re: Stopwatch for Server
Reply With Quote #6

/start
/stop
/pause
/resume

Would be better? :p
__________________
Alber9091 is offline
tepegoz
Senior Member
Join Date: Apr 2019
Old 06-16-2020 , 14:31   Re: Stopwatch for Server
Reply With Quote #7

Quote:
Originally Posted by Alber9091 View Post
/start
/stop
/pause
/resume

Would be better? :p
yes
tepegoz is offline
+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.
__________________

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 #9

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


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 14:47.


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