OnPlayerTakeDamage
#1

I'm having some issues with my OnPlayerTakeDamage when being shot it only takes away the health and it completely ignores the Armour. Thanks for the help in advance.
Its from this script btw: https://sampforum.blast.hk/showthread.php?tid=641235

PHP код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(
issuerid != INVALID_PLAYER_ID)
    {
        new
            
Float:health
        
;
        
        
PlayerInfo[playerid][pLastDamagetime] = gettime();
        
GetPlayerHealth(playerid, health); 
        
        if(
GetPlayerTeam(playerid) != PLAYER_STATE_ALIVE && PlayerInfo[playerid][pDeathFix])
            
SetPlayerHealth(playerid, health); 
        
        if(
GetPlayerTeam(playerid) == PLAYER_STATE_ALIVE)
        {
            
SetPlayerHealth(playerid, health - amount); 
            
CallbackDamages(playerid, issuerid, bodypart, weaponid, amount); 
        }
        
        if(
health - amount <= 4)
        {
            if(
GetPlayerTeam(playerid) == PLAYER_STATE_ALIVE)
            {
                if(
IsPlayerInAnyVehicle(playerid))
                    
ClearAnimations(playerid); 
                
                
CallLocalFunction("OnPlayerWounded", "iii", playerid, issuerid, weaponid); 
                return 
0;
            }
            
            return 
0;
        }
        
        if(
GetPlayerTeam(playerid) == PLAYER_STATE_WOUNDED)
        {
            if(!
PlayerInfo[playerid][pDeathFix])
            {                
                
CallLocalFunction("OnPlayerDead", "iiii", playerid, issuerid, weaponid, 1);
                return 
0;
            }
            
            return 
0;
        }
        
        if(
GetPlayerTeam(playerid) != PLAYER_STATE_ALIVE)
        {
            
SetPlayerHealth(playerid, health);
            return 
0;
        }
    }
    return 
1;
} 
Reply
#2

I forgot to account for armor. I posted code for it when someone pointed it out.

PHP код:
new 
    
playerArmor, 
    
amoun;  
     
GetPlayerArmour(playerid, playerArmor);  
if(
GetPlayerTeam(playerid) == PLAYER_STATE_ALIVE) 
{ 
    if(
playerArmor > 0) // if their armor is greater than 0 
    
{ 
        
amoun = playerArmor - amount; // player's armor - amount of damage taken  
         
        
if(amoun <= 0) // if armor - amount taken is less than or equal to 0  
            
SetPlayerHealth(playerid, playerHealth - amount); // health is set 
             
        
else 
        { 
            if(
bodypart != BODY_PART_HEAD && bodypart != BODY_PART_RIGHT_LEG && bodypart != BODY_PART_LEFT_LEG) 
                
SetPlayerArmour(playerid, amoun); // if the bodypart doesn't equal head, left/right leg, we'll set their armor down 
                 
            
else SetPlayerHealth(playerid, playerHealth - amount); // else their armor is taken down 
        
} 
    } 
    else 
SetPlayerHealth(playerid, playerHealth - amount); 
} 
http://forum.sa-mp.com/showpost.php?...3&postcount=59
Reply
#3

Why don't you use SetPlayerArmour?

E: Nvm, my bad.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)