20.07.2017, 08:12
Here is a mini tutorial: (You can still copy paste but I suggest you to understand it)
PHP код:
//On top of your script
new StealTimer[MAX_PLAYERS]; //Declaring a variable to store the player timers in
new StealCount[MAX_PLAYERS]; //Declaring a variable to check where the timer has reached (counting)
CMD:steal(playerid) //A command using ZCMD include
{
StealTimer[playerid] = SetTimerEx("StealFromPlayer", 1000, true, "i", playerid); //Here we assigned the variable StealTimer to a player timer which repeats every one second
StealCount[playerid] = 5; //CHANGE THIS > Assign the time in seconds to do the action after (countdown variable)
new counttext[25]; //The following 3 lines just to print to the player a message on where the count has reached
format(counttext, sizeof(counttext), "~r~~h~%i Seconds Remaining", StealCount);
GameTextForPlayer(playerid, counttext, 1000, 4);
return 1;
}
forward StealFromPlayer(playerid); //Forwarded the function of the timer
public StealFromPlayer(playerid)
{
StealCount[playerid]--; //We decrese the counter every one second by one
if(StealCount[playerid] == 0) //This is if 5 seconds passed to the count (reached 0)
{
KillTimer(StealTimer[playerid]); //Don't forget to kill the timer so it doesn't stay on after you have done your things
GameTextForPlayer(playerid, "~g~~h~Done", 1000, 4);
//Robbed from player (YOUR CODES)
}
else //If the count didn't reach 0 yet. print him the remaining time
{
new counttext[25];
format(counttext, sizeof(counttext), "~r~~h~%i Seconds Remaining", StealCount);
GameTextForPlayer(playerid, counttext, 1000, 4);
}
return 1;
}