Realistic weapon damage
#8

This is the whole damage system I use at the TF2 Gamemode, take a look at it, there are two DamagePlayer functions, one which only removes HP and other which actually takes armor calculation the way you want it.

http://pastebin.com/VaS1qSAG

EDIT NOTE: Don't set the player's health to 999999 unless you've got a custom hud system or something; by not doing this you will not be able to stop a player from falling to death, though.

This is the bit of code you would want specifically, change the functions.

pawn Code:
//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;
}
pawn Code:
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
*/

If you want to directly remove the damages and then set whatever values you want, then refeer to SetPlayerTeam parts and the damage reduction/increasement part.
Reply


Messages In This Thread
Realistic weapon damage - by DaniceMcHarley - 10.02.2014, 19:11
Re: Realistic weapon damage - by anou1 - 10.02.2014, 19:16
Re: Realistic weapon damage - by [EnErGyS]KING - 10.02.2014, 19:22
Re: Realistic weapon damage - by anou1 - 10.02.2014, 19:37
Re: Realistic weapon damage - by Abagail - 10.02.2014, 19:40
Re: Realistic weapon damage - by [EnErGyS]KING - 10.02.2014, 19:51
Re: Realistic weapon damage - by DaniceMcHarley - 10.02.2014, 20:08
Re: Realistic weapon damage - by CuervO - 10.02.2014, 20:13
Re: Realistic weapon damage - by [EnErGyS]KING - 10.02.2014, 20:17
Re: Realistic weapon damage - by DaniceMcHarley - 11.02.2014, 06:21

Forum Jump:


Users browsing this thread: 5 Guest(s)