Count Down fix?
#1

Hi guys,

I made a count down like 300 seconds ( 5 minutes ) but it shows ingame how many seconds that are left so fom 300 to 0. What I want is that it shows the minutes : seconds e.g. 04:49 . How can I fix it?

My codes:
PHP Code:
 // Counter
        
CountDownFromAmount 300// 5minutes
        
SetTimer("CountDownTimer"9991); 
PHP Code:
new CountDownFromAmount;
                
forward CountDownTimer(); 
PHP Code:
public CountDownTimer()
{
    
CountDownFromAmount--;
    new 
string[128];
    
format(string128"%d"CountDownFromAmount);
    
TextDrawSetString(Text:MissionCountstring);
    
TextDrawShowForAll(Text:MissionCount);
    if (
CountDownFromAmount == 0)
    {
        
GameTextForAll(""30005);
    }
    return 
1;

Peace
Reply
#2

PHP Code:
 new CountDownSecondsCountDownMinutesCountDownTimer
        
CountDownSeconds 60;
        
CountDownMinutes 5;
        
CountDownTimer SetTimer("CountDownTimer"9991); 
forward CountDownTimer();  
public 
CountDownTimer() 

    
CountDownSeconds--;
    if(
CoundDownSeconds == 0)
    {
         
CountDownMinutes--;
         
CountDownSeconds 60;
    }
    new 
string[128]; 
    
format(string128"%d:%d"CountDownMinutesCountDownSeconds); 
    
TextDrawSetString(Text:MissionCountstring); 
    
TextDrawShowForAll(Text:MissionCount); 
    if (
CountDownMinutes == 0
    { 
        
GameTextForAll(""30005);
        
KillTimer(CountDownTimer);
    } 
    return 
1

Would most likely work, didn't tested it tho'.
Reply
#3

Hello x)
Code:
//minutes
new mins;
mins = floatround(CountDownFromAmount/60, floatround_floor);
//seconds
new seconds;
seconds = CountDownFromAmount;
while (seconds > 60)
{
    seconds -= 60;
}
Doing this for the first time so I am not sure if this will work, here are some SA-MP Wiki links you can use
https://sampwiki.blast.hk/wiki/Floatround
https://sampwiki.blast.hk/wiki/Floatround_method
Reply
#4

Quote:
Originally Posted by Balcan Fox
View Post
Hello x)
Code:
//minutes
new mins;
mins = floatround(CountDownFromAmount/60, floatround_floor);
//seconds
new seconds;
seconds = CountDownFromAmount;
while (seconds > 60)
{
    seconds -= 60;
}
Doing this for the first time so I am not sure if this will work, here are some SA-MP Wiki links you can use
https://sampwiki.blast.hk/wiki/Floatround
https://sampwiki.blast.hk/wiki/Floatround_method
I am beginner so I don't know how to use that for my script Thanks btw
Reply
#5

pawn Code:
seconds = timeleft % 60;
minutes = timeleft / 60;
Very simple and based on the fact that an integer divided by an integer remains an integer; any fractional part is discarded. And as such, for example, 119 divided 60 yields 1.

Also kindly note that your countdown will run into negative values. You have a repeating timer which you cannot kill because you didn't assign it to a variable.
Reply
#6

floatround will round a value(for example: timer is on 280 seconds, it will do this 280/60=4.67, this function will round 4.67 to 4(closest integet lower than 4.67). That means there are 4 minutes in 280 seconds.)
while function - will repeat "seconds = seconds - 60" until it gets to lower than 60(lower than 1 minute) and it will show exact number of seconds in that minute.
Use this for seconds and minutes:
Code:
format(string, 128, "Minutes: %d  Seconds: %d", mins, seconds);
Add my code under CountDownTimer public.
Reply
#7

Quote:
Originally Posted by Balcan Fox
View Post
timer is on 280 seconds, it will do this 280/60=4.67
In normal math, yes. In computer math, no. Read my reply.
Reply
#8

This works in reverse, it will add time
however display
05:00 04:59 ...

//start CountDownFromAmount = 0, stop 300
PHP Code:
public CountDownTimer(){  //This function must be performed every 1 second
    
CountDownFromAmount++; 
    new 
string[128], timesmintimessek
    
timesmin = ((300-(CountDownFromAmount))/60);
    
timessek = (300-((CountDownFromAmount)+((timesmin)*(60))));
    
format(stringsizeof(string), "%02d:%02d"timesmintimessek); 
    
TextDrawSetString(Text:MissionCountstring); 
    
TextDrawShowForAll(Text:MissionCount); 
    if(
CountDownFromAmount == 300){ 
        
GameTextForAll(""30005); 
    }
    return 
1

Example:
https://www.youtube.com/watch?v=desa4vyIHGs
Reply
#9

@Vince:I am doing this for the first time and I though it will work in Pawn as well. I have learned something new today, thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)