I need that someone explain me how I could create a counter with GameTextForPlayer.
With a Trashmaster I go to a point and I perform /command.
This command send a nearByMessage and,a GameTextForPlayer, show me how many second remain for the end of the action.
pawn Код:
#include <a_samp>
new
p_Countdown[MAX_PLAYERS] = 30;
forward CountingDown(playerid);
public CountingDown(playerid)
{
switch(p_Countdown[playerid])
{
case 30: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 29: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 28: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 27: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 26: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 25: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 24: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 23: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 22: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 21: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 20: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 19: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 18: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 17: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 16: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 15: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 14: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 13: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 12: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 11: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 10: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 9: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 8: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 7: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 6: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 5: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 4: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 3: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 2: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 1: {
GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
}
case 0: //The end.
{
GameTextForPlayer(playerid, "~g~Go!", 3, 100);
p_Countdown[playerid] = 30;
TogglePlayerControllable(playerid, 1); //Unfreeze them.
SendClientMessage(playerid, 0xFFFFFFFF, "Go!");
}
}
p_Countdown[playerid]--;
return true;
}
//Put this in your command to start this.
SetTimerEx("CountingDown", 1000, true, "i", playerid);
pawn Код:
#include <a_samp>
forward CountingDown(playerid, time);
public CountingDown(playerid, time)
{
if(time != 0)
{
new string[5];
format(string, sizeof(string), "%d", time);
GameTextForPlayer(playerid, string, 1200, 4);
SetTimerEx("CountingDown", 1000, true, "ii", playerid, time-1);
}
else
{
GameTextForPlayer(playerid, "~g~Go!", 2500, 3);
TogglePlayerControllable(playerid, 1);
SendClientMessage(playerid, -1, "Go!");
}
return true;
}
//Put this in your command to start this.
SetTimerEx("CountingDown", 1000, true, "ii", playerid, 30);
This is much better because it doesn't require a variable and it doesn't need a switch statement. Also, yours wouldn't work because it's trying to use an integer for a string parameter.
Sorry for this off topic. But I wonder why that guy bump this old thread.