A timer question :| -
[Bm]rap45 - 13.02.2010
Well I'm making a little TDM gamemode (almost finished) but the thing is that i don't know how to make a time appears when the attacker/player enters the checkpoint
so if anybody would be kind enough to explain to me how would it go, i would put him in the credits as well xD but no seriously please.
Re: A timer question :| -
[HiC]TheKiller - 13.02.2010
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
SetTimer(....);
return 1;
}
Is that what you mean?
Re: A timer question :| -
[Bm]rap45 - 13.02.2010
Yea but you would need to put a "new timer" thingy on top right? cuz damn im bad timers
Re: A timer question :| -
mansonh - 13.02.2010
You mean the id of the timer.
You only need to have the id of a timer if you plan to kill it.
(If your using a looping timer
(settimer("function",time,true)), then you def need the id.)
Quite often if its player related then you can just use one per player.
ex
new mytimers[MAX_PLAYERS];
then
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
mytimers[playerid] = SetTimer(....);
return 1;
}
Re: A timer question :| -
[Bm]rap45 - 13.02.2010
ooooh so how would i be able to show it in-game screen? like in a textdraw or GameText? wouldn't be like
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
mytimers[playerid] = SetTimer(....);
GameTextForPlayer(bla bla bla)
return 1;
}
Re: A timer question :| -
mansonh - 13.02.2010
Oh you want to show the timer the countdown for their timer, i see.
Timers can't be directly shown, they work in the background, so you have to make a textdraw, and have another timer per second.
I don't know textdraws that well, so I would wait for thekiller to explain that, he knows textdraws better than i do.
Something like:
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
//your textdraw stuff
new mytimer = SetTimerEx("updateTextDraw",1000, true, "d", textdrawid)
mytimers[playerid] = SetTimerEX("yourfunction",30000,false,"dd", countdowntimer, countdowntextdraw );
return 1;
}
forward updateTextDraw(textdrawid);
public updateTextDraw(textdrawid)
{
//update textdraw stuff(aka minus one second)
}
forward yourfunction(timerid, textdrawid);
public yourfunction(timerid, textdrawid)
{
KillTimer(timerid);
//destroy textdraw
}
Re: A timer question :| -
[Bm]rap45 - 13.02.2010
yea thats what i was looking for
well now ima search bout textdraws to see if i can find something
Re: A timer question :| -
mansonh - 13.02.2010
I can tell you have scripted a lot before coming to samp
Yah whenever i use textdraws I use a textdraw creator to do the hard stuff for me.
http://forum.sa-mp.com/index.php?topic=143025.0
Then you can put that in the function and use
the set textdraw string and showfor player functions in the updatetextdraw function.
Re: A timer question :| -
[HiC]TheKiller - 13.02.2010
Well, firstly, you would need to get the textdraw info using the link that Mansonh posted, it should look something like:
pawn Код:
new Text:Textdraw0;
// In OnGameModeInit prefferably, we procced to create our textdraws:
Textdraw0 = TextDrawCreate(17.000000, 429.000000, "Timeleft: 432423");
TextDrawBackgroundColor(Textdraw0, 65535);
TextDrawFont(Textdraw0, 1);
TextDrawLetterSize(Textdraw0, 0.500000, 1.000000);
TextDrawColor(Textdraw0, 16777215);
TextDrawSetOutline(Textdraw0, 1);
TextDrawSetProportional(Textdraw0, 1);
Now, what we do from here is add the timer.
pawn Код:
new Timer;
new TimeM, TimeS;
public OnPlayerEnterCheckpoint(playerid)
{
//your textdraw stuff
Timer = SetTimer("UpdateTD",1000, true);
TimeM = 0/*However many minutes you want the timer to go for*/;
TimeS = 30/*However many seconds you want the timer to go for*/;
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
KillTimer(Timer);
TextDrawHideForAll(Textdraw0);
//Kill the timer because the player exited the CP.
return 1;
}
forward UpdateTD();
public UpdateTD()
{
TimeS --;
if(TimeS == 0 && TimeM == 0)
{
//The player has been in the CP long enough, the round ends?
}
new Str[35];
if(TimeS < 10) format(Str, 35, "%d:0%d", TimeM, TimeS);
if(TimeS > 9) format(Str, 35, "%d:%d", TimeM, TimeS);
TextDrawSetString(Textdraw0, Str);
return 1;
}
Re: A timer question :| -
[Bm]rap45 - 13.02.2010
ok ill try that thanks!