Countdown format
#1

Hi all...
I have made a countdown format for timer of 15 minutes, in the game it looks:

15 minutes left
14 minutes left
13 minutes left
etc....

I want to make it with seconds together:

14:59 minutes left
14:58 minutes left
14:57 minutes left
14:56 minutes left
till zero etc...

Codes:
My defines:
Код:
new MinutesleftCD[MAX_PLAYERS];
new Minutesleft[MAX_PLAYERS];
On my command:
Код:
MinutesleftCD[playerid] = SetTimerEx("MinutesCD", 500, false, "d", playerid);
Minutesleft[playerid] = 16;
Public of timer:
Код:
forward MinutesCD(playerid);
public MinutesCD(playerid)
{
	new string[128];
	if(RobberyStatus[playerid] == 3)
	{
		Minutesleft[playerid] --;
		format(string,sizeof(string),"~y~%d minutes left", Minutesleft[playerid]);
		GameTextForPlayer(playerid, string, 5000, 1);
		SetTimerEx("MinutesCD", 60000, false, "d", playerid);
	}
	return 1;
}
Thanks in advance
Reply
#2

it would look something like this:
Create a variable for all players that will contain seconds, and this to your command.
pawn Код:
// 15 mins - 900 secs
if(variable < 900)
{
      minute = (900- variable) / 60;
      second = 60- (variable % 60);
}
Reply
#3

Something like

pawn Код:
//variables...

new MinutesleftCD[MAX_PLAYERS];
new Minutesleft[MAX_PLAYERS];
new Secondsleft[MAX_PLAYERS];



//n command...

MinutesleftCD[playerid] = SetTimerEx("MinutesCD", 1000, true, "d", playerid);
Minutesleft[playerid] = 16;
Secondsleft[playerid] = 0;





//function...

forward MinutesCD(playerid);
public MinutesCD(playerid)
{
    new string[128];
    if(RobberyStatus[playerid] == 3)
    {
        if(--Secondsleft[playerid] == 0) {
            Minutesleft[playerid] --;
            Secondsleft[playerid] = 60;
        }
        if(Minutesleft[playerid] == 0) KillTimer(MinutesleftCD[playerid]);
        format(string,sizeof(string),"~y~%d:%d minutes left", Minutesleft[playerid],Secondsleft[playerid]);
        GameTextForPlayer(playerid, string, 5000, 1);
    }
    return 1;
}
The timer repeat parameter to true.. means that the timer repeats every 1000 ms (1s)..
Reply
#4

Here's a function that converts Seconds into Minutes and Hours


http://forum.sa-mp.com/showpost.php?...postcount=4204

Sample Usage
pawn Код:
#include <a_samp>

main()
{
    printf("%s", ConvertTime(200));
}
Result
pawn Код:
00:03:20
Reply
#5

pawn Код:
enum eTimeData {
    MINUTES, SECONDS
};

new TimeLeft[MAX_PLAYERS][eTimeData];

// We're changing it to a repeating timer that triggers every second
MinutesleftCD[playerid] = SetTimerEx("MinutesCD", 1000, true, "d", playerid);

// Somewhere else
forward MinutesCD(playerid);
public MinutesCD(playerid)
{
    new string[128];
    if(RobberyStatus[playerid] == 3)
    {
        TimeLeft[playerid][SECONDS]--;
        if (TimeLeft[playerid][SECONDS] < 0)
        {
            TimeLeft[playerid][SECONDS] = 0;
            TimeLeft[playerid][MINUTES]--;
            if (TimeLeft[playerid][MINUTES] < 0) {
                TimeLeft[playerid][MINUTES] = 0;
            }
        }
       
        format(string,sizeof(string),"~y~%d:%02d minutes left", TimeLeft[MINUTES], TimeLeft[SECONDS]);
        GameTextForPlayer(playerid, string, 1000, 1);
        // SetTimerEx("MinutesCD", 60000, false, "d", playerid); We're removing this line, it's no longer needed.  
    }
    return 1;
}
Of course, remember to kill the timer when the countdown reaches zero.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)