[Tutorial] How to make a count
#1

So today I am going to show you how to make counting system, backwards or forwards, w/e you want.

So, first we include a_samp

pawn Code:
#include <a_samp>
Then you should forward the timer
pawn Code:
forward test(playerid);
Then we need to make a timerid to kill the timer later, and a count:
pawn Code:
new timer;
new count = 0; // You may change this if you count backwards or w/e
Then we need to make the commands that activate the timers/counts:

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    //Command to start the count:
    if(strcmp("/startcount", cmdtext, true, 11) == 0)
    {
        timer = SetTimerEx("test", 1000, 1, "d", playerid);
        return 1;
    }
    //A command to stop the count:
    if(strcmp("/stopcount", cmdtext, true, 10) == 0)
    {
        KillTimer(timer);
        return 1;
    }
    //And a command to reset the count:
    if(strcmp("/resetcount", cmdtext, true, 11) == 0)
    {
        count = 0;
        return 1;
    }
    return 0;
}
Ok, after we made these three cmds, we need to make a public for the timer, which we forwarded before ^^:
pawn Code:
public test(playerid)
{
    count++; //Use ++ for counting forwards, and -- for counting the seconds backwards
    new string[24];
    format(string, sizeof(string), "Seconds playing: %d", count); // Formatted the count
    return GameTextForPlayer(playerid, string, 1000, 5);
}
GameTextForPlayer is used this way:
pawn Code:
GameTextForPlayer(playerid, const string[], time, style)
You can find styles here:
https://sampwiki.blast.hk/wiki/GameTextStyle

Ok now we got a working count of how many seconds we spent on the server! Congragulations!
Reply
#2

Nice
Reply
#3

Thankz
Reply
#4

Thanks, this is simple, neat. I will use it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)