Giving player health up to 99 - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Giving player health up to 99 (
/showthread.php?tid=604759)
Giving player health up to 99 -
ax1 - 09.04.2016
I want to create function that would give player health up to 99. For example if player has 80 health and I use GivePlayerHealth(playerid, 40) it would set player health to 99 and not to 120.
I tried something like this :
Код:
stock GivePlayerHealth(playerid,Float:Health)
{
new Float:health; GetPlayerHealth(playerid,health);
SetPlayerHealth(playerid,health+Health+1);
SetTimerEx("MinusHp", 50, false, "i", playerid); // It doesnt work if you take -1 health right away
}
forward MinusHp(playerid);
public MinusHp(playerid)
{
new Float:health;
GetPlayerHealth(playerid,health);
if(health>99)
{
SetPlayerHealth(playerid, 99);
}
return 1;
}
Well it works, but is there a way to do it without timer?
Re: Giving player health up to 99 -
AndySedeyn - 09.04.2016
I don't understand why you would use a timer. Is there a reason for the function to be delayed?
PHP код:
GivePlayerHealth(playerid, Float:health) {
new Float:loc_health;
GetPlayerHealth(playerid, loc_health);
if((loc_health + health) > 99.0) {
return SetPlayerHealth(playerid, 99);
}
return SetPlayerHealth(playerid, loc_health + health);
}
Re: Giving player health up to 99 -
Vanter - 09.04.2016
Or use OnPlayerUpdate
PHP код:
if(GetPlayerHealth(playerid) > 99)
{
SetPlayerHealth(playerid, 99);
}