Player Health problem
#6

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;
}
Reply


Messages In This Thread
Player Health problem - by Gilbonzo - 31.01.2014, 21:49
Re: Player Health problem - by MisterTickle - 31.01.2014, 22:48
Re: Player Health problem - by erminpr0 - 31.01.2014, 23:01
Re: Player Health problem - by EiresJason - 31.01.2014, 23:04
Re: Player Health problem - by Gilbonzo - 31.01.2014, 23:26
Re: Player Health problem - by CuervO - 31.01.2014, 23:54
Re: Player Health problem - by Gilbonzo - 01.02.2014, 10:03
Re: Player Health problem - by CuervO - 01.02.2014, 10:16

Forum Jump:


Users browsing this thread: 1 Guest(s)