10.02.2014, 19:11
(
Last edited by DaniceMcHarley; 01/06/2017 at 02:49 AM.
)
------
amount The amount of dagmage the player took (health and armour combined). |
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
new Float:Armour,Float:HP;
GetPlayerArmour(playerid,Armour);
GetPlayerHealth(playerid,HP);
if (HP == 100)
{
SetPlayerArmour(playerid,Armour+amount);
if(weaponid == 24) SetPlayerArmour(playerid,Armour-45);
}
else
{
SetPlayerHealth(playerid,HP+amount);
if(weaponid == 24) SetPlayerHealth(playerid, HP-45);
}
}
//playerid, amount of damage, weaponid of damage, current player HP, current player armor
forward DamagePlayer(playerid, Float:amount, weaponid, Float:hp, Float:armour);
public DamagePlayer(playerid, Float:amount, weaponid, Float:hp, Float:armour)
{
if(weaponid == 41 || weaponid == 42) //spray
amount = amount-((25.0*amount)/100.0);
if(weaponid != 54 && weaponid != 53)
{
if(armour > 0.0)
{
new Float:tmp = armour;
tmp = tmp-amount;
if(tmp < 0.0)
{
amount = amount - armour;
armour = 0.0;
}
else
{
armour = tmp;
amount = 0;
}
if(armour > GetPlayerArmourEx(playerid))
armour = 0.0;
SetPlayerArmourEx(playerid, armour,weaponid);
}
hp = (hp - amount);
if(hp > GetPlayerHealthEx(playerid))
hp = 0.0;
SetPlayerHealthEx(playerid, hp, weaponid);
}
else
{
hp = (hp - amount);
if(hp > GetPlayerHealthEx(playerid))
hp = 0.0;
SetPlayerHealthEx(playerid, hp, weaponid);
}
return 1;
}
// reason = weaponid
// hp = hp to set
forward SetPlayerHealthEx(playerid,Float:hp,reason = 0);
stock SetPlayerHealthEx(playerid,Float:hp,reason = 0)
{
new Float:oldhp = GetPlayerHealthEx(playerid);
if(hp <= 0.0)
{
SetPlayerHealth(playerid,0);
hp = 0.0;
}
if(reason != 18 && reason != 37)
hp = float(floatround(hp,floatround_floor));
SetPlayerHealth(playerid, hp);
SetPVarFloat(playerid,"ScriptHealth",hp);
//insert here any hud function you have to update player HP
return 1;
}
forward SetPlayerArmourEx(playerid,Float:armour,reason = 0);
stock SetPlayerArmourEx(playerid,Float:armour,reason = 0)
{
if(armour < 0.0)
armour = 0.0;
if(reason != 18 && reason != 37)
armour = float(floatround(armour,floatround_floor));
SetPlayerArmour(playerid,armour);
SetPVarFloat(playerid,"ScriptArmour",armour);
// insert here any hud function you have to update player's armor
return 1;
}
forward Float:GetPlayerHealthEx(playerid);
stock Float:GetPlayerHealthEx(playerid)
{
return GetPVarFloat(playerid, "ScriptHealth");
}
forward Float:GetPlayerArmourEx(playerid);
stock Float:GetPlayerArmourEx(playerid)
{
return GetPVarFloat(playerid, "ScriptArmour");
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(weaponid == 24)
amount = amount + 45;
DamagePlayer(playerid, amount, weaponid, GetPlayerHealthEx(playerid), GetPlayerArmourEx(playerid));
return 1;
}
forward DamagePlayer(playerid, Float:amount, weaponid, Float:hp, Float:armour);
/*
playerid = player to give the damage
amount = amount of damage
weaponid = reason of damage
hp = CURRENT player's HP before applying the damage
armour = CURRENT player's armour before applying the damage
result:
Apply damage to armour (if any) then if armour goes out apply the resultant damage to the HP; Explosions remove HP directly
*/