Ask About Timer

Started by Saiyan Attack, May 19, 2017, 12:18 PM

Previous topic - Next topic

Saiyan Attack

hello everyone !!

i am here to ask about timer that use for every single player when they need arise ... Is it okay ? if i use like that ...
function onScriptLoad() {
loadtimerforplayer <- array(100,null);
}

function onPlayerCommand(player, cmd, text) {
if (cmd == "runforme") {
loadtimerforplayer[player.ID] = NewTimer("TimerRuns",1000,10,player.ID);
}
}
function TimerRuns(player) {
local plr = FindPlayer(player);
if(plr) {
MessagePlayer("this is just an example this is not the actual code !!",plr);
}
}

EK.IceFlake

#1
1. Why do you save it in an array? You do realize that you don't need to keep an instance to it, right?
2. While the timer is running, the player who this timer was intended for might leave and another player can take their ID. You'll need to add a few more checks:
NewTimer("TimerRuns", 1000, 10, player.ID, player.Name, player.UID, player.UID2, player.IP);function TimerRuns(id, name, uid, uid2, ip)
{
    local player = FindPlayer(id);
    if (player == null) return;
    if (player.ID != id || player.Name != name || player.UID != uid || player.UID2 != uid2 || player.IP != ip) return;

    MessagePlayer("This is just an example; this is not the actual code", player);
}
3. Alternatively, you could use this.

Saiyan Attack

#2
Quote from: EK.IceFlake on May 19, 2017, 12:50 PM1. Why do you save it in an array? You do realize that you don't need to keep an instance to it, right?
2. While the timer is running, the player who this timer was intended for might leave and another player can take their ID. You'll need to add a few more checks:
NewTimer("TimerRuns", 1000, 10, player.ID, player.Name, player.UID, player.UID2, player.IP);function TimerRuns(id, name, uid, uid2, ip)
{
    local player = FindPlayer(id);
    if (player == null) return;
    if (player.ID != id || player.Name != name || player.UID != uid || player.UID2 != uid2 || player.IP != ip) return;

    MessagePlayer("This is just an example; this is not the actual code", player);
}
3. Alternatively, you could use this.
i use array becoz i am working on a mission called terror the police station, that will completes in 24 minutes ... and get soon as player can ... or if someone leave server then we can stop timer or mission progress ... which the player start ....

!

Lets suppose on next connection player id has been changed.Mission f*ed up...

Discord: zeus#5155

Saiyan Attack

#4
topic locked !! problem solved !!