31.01.2014, 23:54
Example:
pawn Code:
// 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));
SetPVarFloat(playerid,"ScriptHealth",hp);
SetPlayerHealth(playerid, 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);
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");
}
//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 or fire ex
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;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
DamagePlayer(playerid, amount, weaponid, GetPlayerHealthEx(playerid), GetPlayerArmourEx(playerid));
return 1;
}