Timer explanation.
#1

Okay guys. Im not a newbie but i can say i cant handle the timers. Can i get explanation about how it works. And a hint how i can make a timer that counts 30 minutes and also displays on the screen the minutes and seconds left. I just want explanation a not the whole code just little parts so i can understand it. Im getting it fast. Thanks
Reply
#2

first, you forward your timer (read about it)
Код:
forward YipeeTimer();
Second, you set your timer where you need it
Код:
SetTimer("YipeeTimer",1800000,0); //Timer name, interval in milisecond, repetition( 0 = no 1 = yes)
Third, you make your timer
Код:
public YipeeTimer
{
  for (new i; i<MAX_PLAYERS;i++)// Will switch player
  {
  GameTextForPlayer(i,...)
  }
}
I don't have much time, I hope this helps
Reply
#3

Sorry for Bump, but how can I add a milisec timer for my reactiontests? so people know in what time a player have won the reactiontest. I'm a noob at scripting so I don't know.

I only have it like this: speedruntrainer has won the reactiontest!
BUT it has to be like this: speedruntrainer has won the reactiontest in [seconds.miliseconds]!

Here is the code for the current one. without the timer that I need to add.
http://pastebin.com/f365ed4de
Reply
#4

https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#5

Timers aren't accurate for doing time difference.

Using GetTickCount() (or gettime(), for seconds precision) is a lot better for this.

pawn Код:
//where you start counting:
new time_start = GetTickCount();


//where you want to know time difference:
new time_diff = GetTickCount() - time_start;
You get time difference in milliseconds.
Reply
#6

ok, no errors

I didn't get it to work because I need to add things i think.
This is the code now:

pawn Код:
public ReactionWin(playerid)
{
  //where you start counting:
new time_start = GetTickCount();


//where you want to know time difference:
new time_diff = GetTickCount() - time_start;
    GivePlayerMoney(playerid, 10000);
    SetTimer("SetBack",30,0); // required delay, for some reason.
    new reactionwinner[256];
    reactionwinnerid = playerid;
    new tempstring[256];
    GetPlayerName(playerid,reactionwinner,sizeof(reactionwinner));
    SendClientMessage(playerid,0x247C1BFF,"You have won the reactiontest!");
    format(tempstring,sizeof(tempstring),"%s has won the reactiontest!",reactionwinner);
    SendClientMessageToAll(0xFFFF00FF,tempstring);
    reactiongap = SetTimer("ReactionTest",time1+random(time2),0); // sets the timer to restart ReactionTest()
    return 1;
 }
at the %s has won the reactiontest! I need a time. i need to add something to it. do you know what mean? cause it's hard to explain. I want it like this:
%s has won the reactiontest in [seconds.miliseconds]!

So I guess I need to add something. you see I already used the timercode. but i need to add something like %d or %s or so, Am I right?

If you help and it works, I can update my server version to 1.3
Reply
#7

Bump, someone help me!
Reply
#8

Create your own topic... It's alil bit stupid to help you in someone's else topic.
Use gettime for what you needed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)