timer for heal

Started by Rupinder, Nov 20, 2020, 06:28 AM

Previous topic - Next topic

Rupinder

if(cmd == "heal")
   {
      local hp = player.Health;
      if(hp == 100) MessagePlayer("[#FF3636]Error - [#8181FF]Use this command when you have less than 100% hp !", player);
      else {
         player.Health = 100.0;
         EMessage("[#FFFF81]---> " + player.Name + " have been healed !");
      }
   }

i wanna add here 5 sec timer plus player not move for 5 sec
Vice City Servers
https://bit.ly/2Uw2usM

DizzasTeR

Okay, what have you tried so far? Give it a try, and let us know what issues you get so we can help you out :)

Rupinder

Quote from: DizzasTeR on Nov 20, 2020, 07:45 AMOkay, what have you tried so far? Give it a try, and let us know what issues you get so we can help you out :)

tried but can't find good  topic releted to my question
Vice City Servers
https://bit.ly/2Uw2usM

SHy^

http://wiki.adtec.ovh/wiki/Scripting/Squirrel/Functions/NewTimer

http://wiki.adtec.ovh/wiki/OnPlayerMove

Assign a value to player when he types /heal, and use the OnPlayerMove function, and make the value false and return a message to player "You moved!".

Inferno

#4
Quote from: Shy on Nov 20, 2020, 08:01 AMhttp://wiki.adtec.ovh/wiki/Scripting/Squirrel/Functions/NewTimer

http://wiki.adtec.ovh/wiki/OnPlayerMove

Assign a value to player when he types /heal, and use the OnPlayerMove function, and make the value false and return a message to player "You moved!".

Event OnPlayerMove is a bad idea to use.

Using variables to store pos and detect after 5 seconds is more effective



Also just as Dizzaster said,
You are not seeming to try anything.

Do it stepwise to learn better.
Start with an empty test cmd.
Make it simple heal cmd.
Add cash function in it.
Then make it fail if player moves.
Make it for 5 seconds. Etc



An example is.


else if(cmd == "help") { // simple
MessagePlayer("[#ffffff] How may i help you ",player);
return 0;
}

else if(cmd == "bighelp") { // with cash function.
if(player.Cash < 100) return MessagePlayer(" No money no honey ",player);
player.Cash -= 100;
MessagePlayer(" How may i help you sir ",player);
return 0;
}

else if(cmd == "heal") { // simplest heal command
if(player.Health < 100) return player.Health = 100;
else if(player.Health == 100) return MessagePlayer(" You dont need to be healed ",player);
return 0;
}
Viva la VU
VFS Developer
VCCNR Administrator

SHy^

#5
Quote from: Inferno on Nov 20, 2020, 08:05 AM
Quote from: Shy on Nov 20, 2020, 08:01 AMhttp://wiki.adtec.ovh/wiki/Scripting/Squirrel/Functions/NewTimer

http://wiki.adtec.ovh/wiki/OnPlayerMove

Assign a value to player when he types /heal, and use the OnPlayerMove function, and make the value false and return a message to player "You moved!".

Event OnPlayerMove is a bad idea to use.

Using variables to store pos and detect after 5 seconds is more effective.


Also just as Dizzaster said,
You are not seeming to try anything.

Do it stepwise to learn better.
Start with an empty test cmd.
Make it simple heal cmd.
Add cash function in it.
Then make it fail if player moves.
Make it for 5 seconds. Etc



An example is.


else if(cmd == "help") { // simple
MessagePlayer("[#ffffff] How may i help you ",player);
return 0;
}

else if(cmd == "bighelp") { // with cash function.
if(player.Cash < 100) return MessagePlayer(" No money no honey ",player);
player.Cash -= 100;
MessagePlayer(" How may i help you sir ",player);
return 0;
}

else if(cmd == "heal") { // simplest heal command
if(player.Health < 100) return player.Health = 100;
else if(player.Health == 100) return MessagePlayer(" You dont need to be healed ",player);
return 0;
}
Nothing is bad unless it's used in a bad way. I guess you were talking about that if you assign the player a value, check it if it's true and make it false with a error message onplayermove event and player instantly types /heal again, he'll be healed in a sec or two. Yes, this is actually bad. But if you do this:
 heal <- NewTimer("healplayer", 5000, 1, player.ID);
onPlayerMove:
heal.Stop();
Message("you moved..");
then it isn't bad. It is same as for timers. If you use timers in a bad way, they won't work like expected.. Both ways are good if used correctly and bad if used in a bad way :)

Inferno

I used to have OnPlayerMove event for all the functions checking if player moves and fails the process i.e gotoloc goto join etc
But it was suggested by Xmair to me that its a bad idea to use it and that variables are much more effective in this case. Which proved to be true.


Onplayermove sometimes doesnt get called or gets called even when u dont move.

About : nothing is bad unless used badly. Some functions are actually bad to use lol.




Also : Stopping/Pausing/Killling timers on Linux is highly not recommended as it cause weird memory leaks.

Viva la VU
VFS Developer
VCCNR Administrator