[Tutorial] How to make a count - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make a count (
/showthread.php?tid=217813)
How to make a count -
Mean - 28.01.2011
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
Then you should forward the timer
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!
Re: How to make a count -
ricardo178 - 29.01.2011
Nice
Re: How to make a count -
Mean - 29.01.2011
Thankz
Re: How to make a count -
Tee - 30.01.2011
Thanks, this is simple, neat. I will use it.