Countdown system
#1

Hello,
I have a countdown system which count down to 5 seconds.
pawn Код:
#include <a_samp>
#define COLOR_LIGHTBLUE 0x33CCFFAA
forward one();
forward two();
forward three();
forward four();
forward five();
forward start();
   new pName[30];
   new string[256];
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Count Down By *Aldi*");
    print("--------------------------------------\n");
    return 1;
}

#else
#endif
public five()
{
GameTextForAll("~g~5",2000,3);
return 1;
}

public four()
{
GameTextForAll("~y~4",2000,3);
return 1;
}

public three()
{
GameTextForAll("~p~3",2000,3);
return 1;
}

public two()
{
GameTextForAll("~b~2",2000,3);
return 1;
}

public one()
{
GameTextForAll("~w~1",2000,3);
return 1;
}

public start()
{
GameTextForAll("~r~Go Go Go!!!",3000,3);
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/count", cmdtext, true, 10) == 0){
SetTimer("five", 1000, 0);
SetTimer("four", 2000, 0);
SetTimer("three", 3000, 0);
SetTimer("two", 4000, 0);
SetTimer("one", 5000, 0);
SetTimer("start", 7000, 0);

{
   GetPlayerName(playerid, pName, 30);
   format(string, 280, ">> %s started Count-Down.<<", pName);
   SendClientMessageToAll(COLOR_LIGHTBLUE, string);

}
return 1;
}
return 0;
}
can someone change it from 5 seconds to 5 minutes..

like it would show
5:00
4:59
till 00:01
please, and also make it more efficient if possible.
thank you.
Reply
#2

This would be more logical

pawn Код:
#include <a_samp>
#define COLOR_LIGHTBLUE 0x33CCFFAA
forward timer();
new Time;
new timerid;

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Count Down By *Aldi*");
    print("--------------------------------------\n");
    return 1;
}
public timer()
{
    if(Time > 0)
    {
        Time--;
        new str[15];
        if(Time == 0) { format(str,sizeof(str),"~y~Go Go Go!"); }
        else { format(str,sizeof(str),"~g~%d",Time); }
        GameTextForAll(str,2000,3);
    }
    else
    {
        KillTimer(timerid);
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128],idx,tmp[64];
    cmd = strtok(cmdtext, idx);
    if(!strcmp(cmd, "/count", true))
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, -1, "TIP: /count [Seconds]"); return 1;
        }
        Time = strval(tmp);
        timerid = SetTimer("timer", 1000, 1);
        new n[24],str[30];
        GetPlayerName(playerid, n, sizeof(n));
        format(str, sizeof(str), ">> %s started Count-Down.<<", n);
        SendClientMessageToAll(COLOR_LIGHTBLUE, str);
        return 1;
    }
    return 0;
}
Always remember that you have to use sizeof() else you can crash your server, also players max name lenght can be only 24 chars, and use format() function as much as you can.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)