Raised This Month: $62 Target: $400
 15% 

Solved Stopwatch plugin edit request


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tepegoz
Senior Member
Join Date: Apr 2019
Old 07-05-2020 , 12:56   Stopwatch plugin edit request
Reply With Quote #1

I have this plugin and there are /start and /stop commands. I want to also
/pause and /resume commands. When I paused the stopwatch, I type /resume and the stopwatch will resume.
thanks.
HTML 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(PLUGIN, VERSION, AUTHOR);
    register_clcmd("say", "stopwatch");
}

public stopwatch(id)
{
    new said[32];
    read_argv(1, said, charsmax(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), timeformat, charsmax(timeformat));
        set_hudmessage(0, 0, 255, -1.0, 0.35, 0, 0.5, 1.0, 0.0, 0.1, -1);
        show_hudmessage(0, "%s", timeformat);
        set_task(1.0, "show_sw", task);
    }
}

get_time_format(Float:times, result[], 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", hour, min, sec);
}

Last edited by tepegoz; 07-06-2020 at 04:58.
tepegoz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-05-2020 , 17:13   Re: Stopwatch plugin edit request
Reply With Quote #2

Here ya go.
Attached Files
File Type: sma Get Plugin or Get Source (stopwatch.sma - 41 views - 1.5 KB)
__________________
fysiks is online now
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 07-06-2020 , 03:54   Re: Stopwatch plugin edit request
Reply With Quote #3


Didn't you see the update on 2020.06.18?
https://forums.alliedmods.net/showpo...05&postcount=8


Use the fysiks's
__________________

Last edited by +ARUKARI-; 07-06-2020 at 22:13.
+ARUKARI- is online now
tepegoz
Senior Member
Join Date: Apr 2019
Old 07-06-2020 , 04:59   Re: Stopwatch plugin edit request
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
Here ya go.
Thanks working.

Quote:
Originally Posted by +ARUKARI- View Post
Didn't you see the update on 2020.06.18?
https://forums.alliedmods.net/showpo...05&postcount=8
Sorry I didn't see. Thanks your plugin is working.
tepegoz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-06-2020 , 21:54   Re: Stopwatch plugin edit request
Reply With Quote #5

Quote:
Originally Posted by +ARUKARI- View Post
Didn't you see the update on 2020.06.18?
https://forums.alliedmods.net/showpo...05&postcount=8
There are many things wrong with your code. Namely: PreThink is called way too often for this type of functionality and your pause and resume won't work properly.
__________________
fysiks is online now
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 22:30.


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