Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Saiyan Attack on May 19, 2017, 12:18 PM

Title: Ask About Timer
Post by: Saiyan Attack on May 19, 2017, 12:18 PM
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);
}
}
Title: Re: Ask About Timer
Post by: EK.IceFlake on May 19, 2017, 12:50 PM
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 (https://forum.vc-mp.org/?topic=4103).
Title: Re: Ask About Timer
Post by: Saiyan Attack on May 19, 2017, 02:44 PM
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 (https://forum.vc-mp.org/?topic=4103).
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 ....
Title: Re: Ask About Timer
Post by: ! on May 19, 2017, 06:19 PM
Lets suppose on next connection player id has been changed.Mission f*ed up...
Title: Re: Ask About Timer
Post by: Saiyan Attack on May 19, 2017, 08:42 PM
topic locked !! problem solved !!