SA-MP Forums Archive
I need a timer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I need a timer (/showthread.php?tid=442070)



I need a timer - scout322 - 05.06.2013

Can somebody please have a script or can make a script for timer.

I have made a stat in /stats called : Cooldown
When i get a package or smth else it does this script :

PlayerInfo[playerid][pcooldown] = 10;

So i need timer what every 60 second does command or smth that takes off 1 point form Cooldown stats.
Sor for my bad english, i hope you understand.
Please help.


Re: I need a timer - scout322 - 05.06.2013

i just need timer what is reloading it self at 60 seconds. please help.....


Re: I need a timer - scout322 - 05.06.2013

Anybody ?


Re: I need a timer - Pottus - 05.06.2013

Why bother using a timer when you can use gettime() or GetTickCount()

It's pretty simple

pawn Код:
// Define your specific cool down time
#define COOLTIME_SOMETHING 300 // 5 Minutes

// Use time of the cool down time for each player
new UseTime[MAX_PLAYERS]


// Used in any command/function to check and set a players cool down time
.......
if(gettime() - UseTime[playerid] > COOLTIME_SOMETHING)
{
    UseTime[playerid] = gettime();
    ......
}
See absolutely no need for timer.


Re: I need a timer - scout322 - 05.06.2013

I made this :

forward Cooldowntimer(playerid, idx);
public Cooldowntimer(playerid, idx)
{
PlayerInfo[playerid][pcooldown] - 1;
return 1;
}


And to command i added this one :

SetTimer("cooldowntimer", 5000, true);


But its not working at all ;(


Re: I need a timer - scout322 - 05.06.2013

Whay isn't this ->> PlayerInfo[playerid][pcooldown] - 1; <-- working ?


Re: I need a timer - scout322 - 05.06.2013

BUUUMMMPPPP


Re: I need a timer - Vince - 05.06.2013

Quote:
Originally Posted by scout322
Посмотреть сообщение
Whay isn't this ->> PlayerInfo[playerid][pcooldown] - 1; <-- working ?
Because you're doing a calulation, but aren't saving the result anywhere. Correct is:
pawn Код:
PlayerInfo[playerid][pcooldown] = PlayerInfo[playerid][pcooldown] - 1;

// Or the shorthand version:
PlayerInfo[playerid][pcooldown] -= 1;

// Or even shorter:
PlayerInfo[playerid][pcooldown]--;
But do as Pottus said.


Re: I need a timer - GWMPT - 06.06.2013

Quote:
Originally Posted by scout322
Посмотреть сообщение
I made this :

forward Cooldowntimer(playerid, idx);
public Cooldowntimer(playerid, idx)
{
PlayerInfo[playerid][pcooldown] - 1;
return 1;
}


And to command i added this one :

SetTimer("cooldowntimer", 5000, true);


But its not working at all ;(
So, for other words, the function CoolDownTimer has 2 parameters, and you're simply trying to use that function without the parameters.
As well, you have the "idx" parameter, which isn't used in that function.
Try to use this:
pawn Код:
//// in the top of your gamemode
new Timer:CoolDown;
forward CoolDownTimer(playerid);
//// somewhere in your gamemode
public CoolDownTimer(playerid) {
     if(PlayerInfo[playerid][pcooldown] == 0) {
          KillTimer(CoolDown);
          return 1;
     }
     PlayerInfo[playerid][pcooldown]--;
     return 1;
}
//// On the command you want
CoolDown = SetTimerEx("CoolDownTimer", 5000, true, "i", playerid);
That should do the job.


Re: I need a timer - scout322 - 06.06.2013

But how i can make that when player comes online, automaticly start the timer ?