AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Solved Stopwatch for Server (https://forums.alliedmods.net/showthread.php?t=322631)

tepegoz 03-31-2020 18:55

Stopwatch for Server
 
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).

Napoleon_be 03-31-2020 20:33

Re: Stopwatch for Server
 
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);
    }



+ARUKARI- 03-31-2020 20:41

Re: Stopwatch for Server
 
I was late:3

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);



tepegoz 04-01-2020 05:29

Re: Stopwatch for Server
 
thanks it is working.

tepegoz 06-16-2020 10:57

Re: Stopwatch for Server
 
Quote:

Originally Posted by +ARUKARI- (Post 2689757)
I was late:3

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.

Alber9091 06-16-2020 11:16

Re: Stopwatch for Server
 
/start
/stop
/pause
/resume

Would be better? :p

tepegoz 06-16-2020 14:31

Re: Stopwatch for Server
 
Quote:

Originally Posted by Alber9091 (Post 2706024)
/start
/stop
/pause
/resume

Would be better? :p

yes

+ARUKARI- 06-16-2020 20:34

Re: Stopwatch for Server
 
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.

tepegoz 06-17-2020 08:58

Re: Stopwatch for Server
 
Quote:

Originally Posted by +ARUKARI- (Post 2706105)
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.


All times are GMT -4. The time now is 17:46.

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