SA-MP Forums Archive
[Tutorial] Making a simple count down with sscanf and YCMD. - 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] Making a simple count down with sscanf and YCMD. (/showthread.php?tid=291392)



Making a simple count down with sscanf and YCMD. - FireCat - 19.10.2011

Introduction

Hello all, I'm going to show you how to make a simple count down system


Resources


With this tutorial we will be using: Links included ^

Scripting

After you included both of the resources, and you don't have any errors, continue (:
On top of OnGameModeInit add the following:
pawn Code:
new iscountactivated = 0; //Creating the variable, to check if someone already started the count down.
new countamount;//Creating the variable, to store how much the count down is.
forward Count();//Forwarding the timer, to check if the count down is activated.
new CountTimer;//So we can disable the timer later on, at the finish of the count down.
Some where in your script, not in a callback (I suggest under OnPlayerCommandText) add the following:
pawn Code:
CMD:count(playerid,params[])
{
static amount;//creating the variable, where it will store the amount, that the player chose.
if(sscanf(params,"i",amount)) return SendClientMessage(playerid,-1,"USAGE: /count <amount>");//checking if the player inputs any params, and if its an integer.
if(iscountactivated == 1) return SendClientMessage(playerid,-1,"The countdown is already activated!");//Checking if someone already started a countdown.
if(amount > 10 || amount <= 0) return SendClientMessage(playerid,-1,"The amount can't be greater than 10");//Checking if the amount is higher than 10, so therefor the player can't spam/annoy other players.
CountTimer = SetTimer("Count",1000,true);//Setting the timer, for the count down.
countamount = amount;//Setting the variable countamount to the inputted amount.
iscountactivated = 1;//Setting the iscountactivated to 1 to prevent future spam.
return 1;
}
Alright now the timer.
Add this at the bottom of your game mode:
pawn Code:
public Count()
{
if(!iscountactivated){KillTimer(CountTimer);}//Checking if the timer is activated, if not kill the timer.
else
{
new string[4];//Creating the string variable, where we will store the count down value.
format(string,sizeof(string),"%i",countamount);//Formating it.
GameTextForAll(string,1000,3);//Showing it to everyone.
countamount--;//Counting less 1 to the count down variable.
if(countamount == -1) {iscountactivated = 0, GameTextForAll("~g~~h~Go!",1000,3);}//It's -1, because it was conflicting like, from 2 to Go. Setting the var to 0 if the count down variable reaches -1.
}
return 1;
}



Re: Making a simple count down with sscanf and YCMD. - [MWR]Blood - 19.10.2011

Hey yawd, good job!


Re: Making a simple count down with sscanf and YCMD. - FireCat - 19.10.2011

Quote:
Originally Posted by [MWR]Blood
View Post
Hey yawd, good job!
Thanks nawd :>


Re: Making a simple count down with sscanf and YCMD. - BaubaS - 19.10.2011

You can use just strval instead of sscanf


Re: Making a simple count down with sscanf and YCMD. - FireCat - 19.10.2011

Quote:
Originally Posted by BaubaS
View Post
You can use just strval instead of sscanf
Are you from the 20th century or what?
sscanf > strval.
'Nuff said.


Re: Making a simple count down with sscanf and YCMD. - KingHual - 19.10.2011

Good one.


Re: Making a simple count down with sscanf and YCMD. - FireCat - 19.10.2011

Quote:
Originally Posted by king_hual
View Post
Good one.
Thanks (:


Re: Making a simple count down with sscanf and YCMD. - BaubaS - 19.10.2011

Wait what, sscanf for one param and one command? No shit, sherlock


Re: Making a simple count down with sscanf and YCMD. - juraska - 19.10.2011

simple but nice


Re: Making a simple count down with sscanf and YCMD. - [MWR]Blood - 19.10.2011

Quote:
Originally Posted by BaubaS
View Post
Wait what, sscanf for one param and one command? No shit, sherlock
You better start learning the PAWN language instead of failing at trolling.