05.02.2014, 03:20
I've once posted a function called DamagePlayer, but here's the same function which is improved!
This functions damages the player just like in-game normal damage. It reduces the armour in case if player got that and if the damage is higher than the armour, it reduces health too.
pawn Code:
stock DamagePlayer(playerid, Float:damage)
{
static
Float:temp_hp,
Float:temp_ar;
GetPlayerHealth(playerid, temp_hp);
GetPlayerArmour(playerid, temp_ar);
if(temp_ar > 0)
{
if(damage > temp_ar)
{
SetPlayerArmour(playerid, 0.0);
SetPlayerHealth(playerid, floatsub(damage, temp_ar));
}
else if(damage < temp_ar)
{
SetPlayerArmour(playerid, floatsub(temp_ar,damage));
}
}
else if(temp_ar <= 0)
{
if(damage > temp_hp)
{
SetPlayerHealth(playerid, 0.0);
}
else if(damage < temp_hp)
{
SetPlayerHealth(playerid, floatsub(temp_hp,damage));
}
}
return 1;
}

