Newtimer vs OnPlayerTime Change?

Started by Debian, Sep 11, 2015, 01:02 PM

Previous topic - Next topic

Debian

I made a heal command without timer. What do think i used a good method or bad?
and i want to use this way for other cmds as a timer is it good way? What do you think?
Player class
CMD = "";
CMDTimer = 0;


function onTimeChange(oldHour, oldMin, newHour, newMin) {
seconds++;
        local plr;
foreach(i, val in playerson){
plr = FindPlayer(i);
if(stats[ plr.ID ].CMD == "heal"){
stats[ plr.ID ].CMDTimer++;
if (stats[ plr.ID ].CMDTimer == 3 ){
FindPlayer(i).Health = 100;
MessagePlayer("Healed", plr);
stats[ plr.ID ].CMD == "";
stats[ plr.ID ].CMDTimer == 0;
}
}
}
}

else if ( cmd == "heal" )
    {
    if ( !player.IsSpawned ) MessagePlayer( "[Error] - You haven't spawned yet..", player );
else if ( player.Health == 10 ) MessagePlayer( "[Error] - You don't need to be healed", player );
else if ( player.Cash < 0 ) MessagePlayer( "[Error] - You need $250 to heal yourself!", player );
else
{
   stats[ player.ID ].CMD = "heal";
               MessagePlayer( "Your will be healed in 3 seconds to prevent abuse...", player );
}
}

DizzasTeR


Debian

Quote from: Doom_Killer on Sep 11, 2015, 01:21 PMSimple thing already explained by @Stormeus.

Timers are not bad unless they are used badly
I'm sure you have not understood my question properly .
I know timers are not bad to use unless they are used for less than a second like  NewTimer( "MyTimer", 10, 0 ) and for database.

KAKAN

I shall prefer NewTimer, caz its difficult to handle it using the function onTimeChange
oh no

KAKAN

and yes, you are using  foreach(i, val in playerson)
SO for ex, if there are 2 or more players in the server, i had typed /heal, then it'll heal all the players present in the server, another BAD POINT
oh no

Debian

#5
Quote from: KAKAN on Sep 11, 2015, 01:54 PMand yes, you are using  foreach(i, val in playerson)
SO for ex, if there are 2 or more players in the server, i had typed /heal, then it'll heal all the players present in the server, another BAD POINT
You have not checked that code. if i want to heal all players then i could have have made it without a loop.
It is actually a Positive point for ontimechange where Newtimer for heal command uses a new timer for player.

I have used if - else if , i will use case-switch will make it more faster between the commands

DizzasTeR

Quote from: Debian on Sep 11, 2015, 01:44 PM
Quote from: Doom_Killer on Sep 11, 2015, 01:21 PMSimple thing already explained by @Stormeus.

Timers are not bad unless they are used badly
I'm sure you have not understood my question properly .
I know timers are not bad to use unless they are used for less than a second like  NewTimer( "MyTimer", 10, 0 ) and for database.


I understood you perfectly, you didn't get my point with that reply, my reply has a clean support for timer, do the stuff which needs to be done with timer, don't look for alternate method.

Stormeus

onTimeChange is terrible for timed events because it'll vary depending on the time rate and because NewTimer exists specifically for stuff like this.