[FilterScript] Stopwatch
#1

Hello there,

This is small filterscript that I just made for my friend. Simple Stopwatch with hundredths.
To use timer just press Y or type /timer, to stop it same. If you want to see last time press N or type /last.
To split time just press LMB or type /split

As I think this filterscript is useless, but why not to publish something

Here are some pictures of it:

Starting Timer
Split time
Stoping timer
Checking last result

And finally the code:
The chamber of secrets

pawn Код:
#include <a_samp>
#include <zcmd>

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))


new Time[MAX_PLAYERS][6];
new Timer[MAX_PLAYERS];


public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Stopwatch by CoaPsyFactor a.k.a t0xIc_S");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    printf("Stopwatch ByeBye");
    return 1;
}

public OnPlayerConnect(playerid)
{
    Timer[playerid] = -1;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(Timer[playerid] != -1) KillTimer(Timer[playerid]);
    return 1;
}

CMD:timer(playerid, params[]){
    if(Timer[playerid] != -1) return StopTimer(playerid);
    Time[playerid][0] = 1;
    Time[playerid][1] = 0;
    Time[playerid][2] = 0;
    Time[playerid][3] = 0;
    Time[playerid][4] = 0;
    Time[playerid][5] = 0;
    Timer[playerid] = SetTimerEx("StartTime", 100, true, "d", playerid);
    return true;
}

CMD:last(playerid, params[]){
    new str[128];
    format(str, sizeof(str), "Your last time was %2d:%2d:%d", Time[playerid][2], Time[playerid][1], Time[playerid][0]);
    return SendClientMessage(playerid, 0x33AA33AA, str);
}

CMD:split(playerid, params[]){
    if(Timer[playerid] == -1) return true;
    Time[playerid][5] = Time[playerid][0];
    Time[playerid][4] = Time[playerid][1];
    Time[playerid][3] = Time[playerid][2];
    Time[playerid][0] = 1;
    Time[playerid][1] = 0;
    Time[playerid][2] = 0;
    return true;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
    if(PRESSED(KEY_YES)) cmd_timer(playerid, "");
    if(PRESSED(KEY_NO)) cmd_last(playerid, "");
    if(PRESSED(KEY_FIRE)) cmd_split(playerid, "");
    return false;
}

stock StopTimer(playerid){
    new str[128];
    KillTimer(Timer[playerid]);
    Timer[playerid] = -1;
    SaveTime(playerid);
    format(str, sizeof(str), "Timer Stoped ~n~~r~Last time: ~g~%2d~y~:~g~%2d~y~:~g~%d", Time[playerid][2], Time[playerid][1], Time[playerid][0]);
    GameTextForPlayer(playerid, str, 3000, 4);
    return true;
}

forward StartTime(playerid);
public StartTime(playerid){
    new str[128];
    Time[playerid][0]++;
    if(Time[playerid][0] > 9){
        Time[playerid][0] = 1;
        Time[playerid][1]++;
        if(Time[playerid][1] > 59){
            Time[playerid][1] = 0;
            Time[playerid][2]++;
        }
    }
    format(str, sizeof(str), "~r~Split: ~g~%2d~y~:~g~%2d~y~:~g~%d~n~~r~Current: ~g~%2d~y~:~g~%2d~y~:~g~%d", Time[playerid][3], Time[playerid][4], Time[playerid][5], Time[playerid][2], Time[playerid][1], Time[playerid][0]);
    return GameTextForPlayer(playerid, str, 150, 3);
}

stock SaveTime(playerid){
    new File:TimeLog = fopen("timers.txt", io_append);
    new pName[MAX_PLAYER_NAME], String[128];
    GetPlayerName(playerid, pName, sizeof(pName));
    format(String, sizeof(String), "Player %s Time: %2d:%2d:%d\n", pName, Time[playerid][2], Time[playerid][1], Time[playerid][0]);
    if(!fwrite(TimeLog, String)) return false;
    if(!fclose(TimeLog)) return false;
    return true;
}
Hope you like it.

Credits:
Zeex - zcmd
Me - Stopwatch Filterscript

* it could be laggy if many players use it, because it calls timer with time of 100 milliseconds
Reply
#2

Actually you did a good job.
Reply
#3

Thanks
Reply
#4

good job.
Reply
#5

Thanks thanks
Reply
#6

good FS., gonna use it
Reply
#7

I like it

GJ
Reply
#8

thank you all
Reply
#9

Link is dead..
Reply
#10

Quote:
Originally Posted by lamarr007
Посмотреть сообщение
Link is dead..
Confirmed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)