Countdown
#1

Is there any kind of a function that could count down from 3 mins in textdraw? Like over the hud? I really need it but dont have a idea how to make it. And also make something when its over.. Please. Didnt find anything on search and ****** :/
Reply
#2

pawn Код:
//Global
new Text:draw1;
//OnGameModeInit
draw1 = TextDrawCreate(0,0,"default");
//Global
new Text:draw2;
//OnGameModeInit
draw2 = TextDrawCreate(0,0,"default");
//Global
new Mins = 3;
//config of textdraw [...]

forward Minute();
public Minute() {
    for(new i = 60; i > 0; i--;) {
        TextDrawHideForAll(draw1);
        new ts[10];
        valstr(ts,i);
        TextDrawHideForAll(draw1);
        TextDrawSetString(draw1,ts);
        TextDrawShowForAll(draw1);
    }
    return 1;
}
forward Decrease();
public Decrease() {
    Mins--;
    new ts[10];
    valstr(ts,Mins);
    format(ts,sizeof(ts),"%s:",ts);
    TextDrawHideForAll(draw2);
    if(Mins == 0) {
        TextDrawHideForAll(draw1);
        return MyFunc();
    }
    TextDrawSetString(draw2,ts);
    TextDrawShowForAll(draw2);
    return 1;
}
If it isn't working, then I think you can fix it.
Reply
#3

Quote:
Originally Posted by Seven_of_Nine
Посмотреть сообщение
pawn Код:
//Global
new Text:draw1;
//OnGameModeInit
draw1 = TextDrawCreate(0,0,"default");
//Global
new Text:draw2;
//OnGameModeInit
draw2 = TextDrawCreate(0,0,"default");
//Global
new Mins = 3;
//config of textdraw [...]

forward Minute();
public Minute() {
    for(new i = 60; i > 0; i--;) {
        TextDrawHideForAll(draw1);
        new ts[10];
        valstr(ts,i);
        TextDrawHideForAll(draw1);
        TextDrawSetString(draw1,ts);
        TextDrawShowForAll(draw1);
    }
    return 1;
}
forward Decrease();
public Decrease() {
    Mins--;
    new ts[10];
    valstr(ts,Mins);
    format(ts,sizeof(ts),"%s:",ts);
    TextDrawHideForAll(draw2);
    if(Mins == 0) {
        TextDrawHideForAll(draw1);
        return MyFunc();
    }
    TextDrawSetString(draw2,ts);
    TextDrawShowForAll(draw2);
    return 1;
}
If it isn't working, then I think you can fix it. :)
How about making it 3:00 [mins:secs]

How would that go?
Reply
#4

That is Mins:Seconds. But a little bit formatted..

Just fix the errors (I didn't test it) and it'll work. (I think..)
Reply
#5

pawn Код:
#define MAX_TIME    180 //Add here your time in seconds. 180 seconds/60 seconds per minute makes 3 minutes

new Text:TimeText, ticked, countdowntimer;

forward Tick();

public Tick()
{
    ticked++;
    new ticktime = MAX_TIME-ticked, tempticktime = ticktime, minutes = 0;
    while(tempticktime > 59)
    {
        minutes++;
        tempticktime = tempticktime-60;
    }
    format(str, sizeof(str), "%02d:%02d", minutes, tempticktime);
    TextDrawSetString(TimeText, str);
    if(ticktime == 0)
    {
        KillTimer(countdowntimer);
        //Do here your things when the time end.
    }
}

public OnGameModeInit()
{
    TimeText = TextDrawCreate(550.0, 33.0, "--:--");
    new ticktime = MAX_TIME, minutes = 0;
    while(ticktime > 59)
    {
        minutes++;
        ticktime = ticktime-60;
    }
    new str[128];
    format(str, sizeof(str), "%02d:%02d", minutes, ticktime);
    TextDrawSetString(TimeText, str);
    countdowntimer = SetTimer("Tick", 1000, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid, TimeText);
    return 1;
}
Reply
#6

Quote:
Originally Posted by BigETI
Посмотреть сообщение
pawn Код:
#define MAX_TIME    180 //Add here your time in seconds. 180 seconds/60 seconds per minute makes 3 minutes

new Text:TimeText, ticked, countdowntimer;

forward Tick();

public Tick()
{
    ticked++;
    new ticktime = MAX_TIME-ticked, tempticktime = ticktime, minutes = 0;
    while(tempticktime > 59)
    {
        minutes++;
        tempticktime = tempticktime-60;
    }
    format(str, sizeof(str), "%02d:%02d", minutes, tempticktime);
    TextDrawSetString(TimeText, str);
    if(ticktime == 0)
    {
        KillTimer(countdowntimer);
        //Do here your things when the time end.
    }
}

public OnGameModeInit()
{
    TimeText = TextDrawCreate(550.0, 33.0, "--:--");
    new ticktime = MAX_TIME, minutes = 0;
    while(ticktime > 59)
    {
        minutes++;
        ticktime = ticktime-60;
    }
    new str[128];
    format(str, sizeof(str), "%02d:%02d", minutes, ticktime);
    TextDrawSetString(TimeText, str);
    countdowntimer = SetTimer("Tick", 1000, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid, TimeText);
    return 1;
}
Fucking awesome dude, you got credits :)
Reply
#7

Quote:

//=====================forwords
forward DMTimer(playerid);
//==============================[Others]========================================
new DMTime;
new dmtimer;
//================================================== ============================
public OnGameModeInit()
{
DMTime = 300; // change time that show in ur textdraw here i add 5 mints
//=============================[Timers]=========================================
dmtimer = SetTimer("DMTimer", 300, 1);
return 1;
}
//================================================== ============================
public DMTimer()
{
DMTime --;
new tmp[256];
format(tmp, sizeof tmp, "%s", TimeConvert(DMTime));
TextDrawSetString(Text:Time, tmp);
TextDrawShowForAll(Text:Time);
}
return 1;
}

working code 10/10
Reply
#8

Quote:
Originally Posted by Markx
Посмотреть сообщение
Fucking awesome dude, you got credits
Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)