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 );
}
}
Simple thing already explained by
@Stormeus.
Timers are not bad unless they are used badly (http://viceunderdogs.com/index.php?topic=4452.0)
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 (http://viceunderdogs.com/index.php?topic=4452.0)
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 shall prefer NewTimer, caz its difficult to handle it using the function onTimeChange
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
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
Quote from: Debian on Sep 11, 2015, 01:44 PMQuote from: Doom_Killer on Sep 11, 2015, 01:21 PMSimple thing already explained by @Stormeus.
Timers are not bad unless they are used badly (http://viceunderdogs.com/index.php?topic=4452.0)
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.
onTimeChange is terrible for timed events because it'll vary depending on the time rate and because NewTimer exists specifically for stuff like this.