SA-MP Forums Archive
Damage bug - 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: Damage bug (/showthread.php?tid=626661)



Damage bug - AndreiWow - 18.01.2017

Why is this killing the player instantly?
Код:
	if(issuerid != INVALID_PLAYER_ID && weaponid == 24 && (bodypart == 9))
	{
		//SetPlayerArmour(playerid, -armour);
   		SetPlayerHealth(playerid, -2);
	    SendClientMessage(playerid, COLOR_YELLOW, "DEBUG: Ai fost lovit in cap.");
	}
	if(issuerid != INVALID_PLAYER_ID && weaponid == 24 && (bodypart == 3))
	{
		//SetPlayerArmour(playerid, -armour);
   		SetPlayerHealth(playerid, -50);
	    SendClientMessage(playerid, COLOR_YELLOW, "DEBUG: Ai fost lovit in piept.");
	}



Re: Damage bug - renatog - 18.01.2017

Cuz you're setting the player life to -2.0. If a player life is less than zero, he have to die.
If you're trying to subtract 2.0 from player life you have to use GetPlayerHealth first (same for armour) and store it in a Float:variable, then SetPlayerHealth(playerid, variable - 2.0);

Tip: Don't mix integers and floats, use (-2.0) instead of (-2).


Re: Damage bug - Lordzy - 18.01.2017

Obviously because you're setting player's health to negative values. Health amount <= 0 will cause instant death.
EDIT : Late.


Re: Damage bug - Injury - 18.01.2017

Quote:

SetPlayerHealth(playerid, -2);

Should be:

new Float:hp;
GetPlayerHealth(playerid,hp);
SetPlayerHealth(playerid,hp - 2);


Re: Damage bug - GoldenLion - 18.01.2017

You're setting player's health to a negative value. If you want to decrease player's health then you do GetPlayerHealth first then set player's health to returned value - amount.
Like this:
Код:
new Float:health;

GetPlayerHealth(playerid, health);
SetPlayerHealth(playerid, health - 50);
EDIT: 3 people were faster than me lol.


Re: Damage bug - AndreiWow - 18.01.2017

Wow guys, thanks ALOT, I'll try to REP all of you.