Adding health under onplayertakedamage? - 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: Adding health under onplayertakedamage? (
/showthread.php?tid=626309)
Adding health under onplayertakedamage? -
ax1 - 13.01.2017
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
GivePlayerHealth(playerid, amount);
return 1;
}
stock GivePlayerHealth(playerid, Float:health)
{
new Float:loc_health;
GetPlayerHealth(playerid, loc_health);
return SetPlayerHealth(playerid, loc_health + health);
}
This script supposed to keep player health at the certain level. But for some reason, when player takes damage, it adds more health than it should
Re: Adding health under onplayertakedamage? -
Lordzy - 13.01.2017
You should have a read over this topic -
https://sampforum.blast.hk/showthread.php?pid=876854#pid876854
Re: Adding health under onplayertakedamage? -
ISmokezU - 13.01.2017
Damn it ^^
Re: Adding health under onplayertakedamage? -
SickAttack - 13.01.2017
OnPlayerTakeDamage is called after a player takes damage, you'll have to prevent the normal damage.
Re: Adding health under onplayertakedamage? -
ax1 - 13.01.2017
Quote:
Originally Posted by Lordzy
|
so should I add health with timer?
Re: Adding health under onplayertakedamage? -
SickAttack - 13.01.2017
Quote:
Originally Posted by ax1
so should I add health with timer?
|
Use a variable and reduce only when you would like damage to be accepted. Keep setting the player's health to that otherwise.
Note that a minigun for example will always kill the player.
Re: Adding health under onplayertakedamage? -
ax1 - 13.01.2017
Quote:
Originally Posted by SickAttack
Use a variable and reduce only when you would like damage to be accepted. Keep setting the player's health to that otherwise.
Note that a minigun for example will always kill the player.
|
What if I want to give player only half a damage OnPlayerTakeDamage?
Re: Adding health under onplayertakedamage? -
Lordzy - 13.01.2017
OnPlayerTakeDamage is called after player takes the damage. So even if you add half of the health so it looks like player receives only half the damage, there are still chances where the player dies and then SetPlayerHealth is called. It's better to create a custom server sided health system which can then allow you to code such features.