Realistic weapon damage
#1

------
Reply
#2

Same question for me.
+ if I use the 0.3z dammage, for exemple head/body etc. Will it be the same ?

Thank you.
Reply
#3

I am wrong here, sorry for incorrect info.
Reply
#4

For your code, if I got for example 1 armor, if I shot with a deagle would it work ?
Is that goin to reduce armor -1 then life -44 ?

Or something else ?





With the 0.3z we can reduce X health if I shot in your arm or 99 if I shot in your head for example.
How Should I adapt your code for the 0.3z ?
Reply
#5

I think he means the armor before the armor would be taken by the script. How-ever I believe the armor is lost before the callback even get's called... Might be wrong, though...
Reply
#6

Abagail, Yes you right, Danice or anou1 can use to ADD damage but by "wiki" OnplayerTakeDamage and OnPlayerGiveDamage
Quote:

amount The amount of dagmage the player took (health and armour combined).

P.S. Danice, No I think you can't, OnPlayerTakeDamage it is called when Player takes damage so you only can add damage to him...
EDIT: Really you can you need to add Float:amount and then minus damage what you want
This should work... But I don't really know how to add if player armour and hp(together) was lost
pawn Code:
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);
    }
}
Reply
#7

------
Reply
#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
#9

Heheh. I got you but CuervO was faster than me
Reply
#10

Thanks CuervO !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)