OnPlayerTakeDamage causing troubles
#1

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        if(pData[issuerid][AdminDuty])return 1;
        new Float:health;
        new Float:armour;
        GetPlayerHealth(playerid, health);
        GetPlayerArmour(playerid, armour);
        if(weaponid == 7) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-12); return 1;}
                        SetPlayerHealth(playerid,health-12); }
        if(weaponid == 8) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-20); return 1;}
                        SetPlayerHealth(playerid,health-20); }
        if(weaponid == 4) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-20); return 1;}
                        SetPlayerHealth(playerid,health-20); }
        if(weaponid == 3) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-11); return 1;}
                        SetPlayerHealth(playerid,health-11); }
        if(weaponid == 5) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-9); return 1;}
                        SetPlayerHealth(playerid,health-9); }
        if(weaponid == 23) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-19); return 1;}
                        SetPlayerHealth(playerid,health-19); }
        if(weaponid == 24) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-65); return 1;}
                        SetPlayerHealth(playerid,health-65); }
        if(weaponid == 22) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-20); return 1; }
                        SetPlayerHealth(playerid,health-20); }
        if(weaponid == 27) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-32); return 1;}
                        SetPlayerHealth(playerid,health-32); }
        if(weaponid == 28) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-18); return 1;}
                        SetPlayerHealth(playerid,health-18); }
        if(weaponid == 29) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-22); return 1;}
                        SetPlayerHealth(playerid,health-22); }
        if(weaponid == 30) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-25); return 1;}
                        SetPlayerHealth(playerid,health-25); }
        if(weaponid == 31) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-25); return 1;}
                        SetPlayerHealth(playerid,health-25); }
        if(weaponid == 32) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-18); return 1;}
                        SetPlayerHealth(playerid,health-18); }
        if(weaponid == 34) {
                        if(GetPlayerArmour(playerid, armour) > 0) { SetPlayerArmour(playerid, armour-300); return 1;}
                        SetPlayerHealth(playerid,health-300); }
    }
    return 1;
}
Whenever I'm shooting a player with armour, it lowers his armour according to the damage that I wrote, but whenever I shoot him twice if he has like 30 armour and deagle takes 65 armour/health, he gets a 100% armour and it decreases his health.
Reply
#2

If you have 24 percent of armour, and you shoot three times, it gets (for the first one) 24 percent of armour and the rest 12 of the health. However, if you have 2 percent of armour, it won't set the armour.

Oh and by the way, armour is stored already to armour, so doing:
pawn Код:
if(GetPlayerArmour(playerid, armour) > 0)
is useless.

Switching through weaponid is faster that if statements. Anyways, to prevent what I told you above I made a fix. It should work.
pawn Код:
public OnPlayerTakeDamage( playerid, issuerid, Float: amount, weaponid )
{
    if( issuerid != INVALID_PLAYER_ID )
    {
        if( pData[ issuerid ][ AdminDuty ] ) return 1;
        new
            Float: health,
            Float: armour,
            Float: calc_rest
        ;
        GetPlayerHealth( playerid, health );
        GetPlayerArmour( playerid, armour );
        switch( weaponid )
        {
            case 7:
            {
                if( armour > 12.0 ) SetPlayerArmour( playerid, armour - 12.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 12.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 12.0 );

                }
            }
            case 8:
            {
                if( armour > 20.0 ) SetPlayerArmour( playerid, armour - 20.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 20.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 20.0 );

                }
            }
            case 4:
            {
                if( armour > 20.0 ) SetPlayerArmour( playerid, armour - 20.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 20.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 20.0 );

                }
            }
            case 3:
            {
                if( armour > 11.0 ) SetPlayerArmour( playerid, armour - 11.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 11.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 11.0 );

                }
            }
            case 5:
            {
                if( armour > 9.0 ) SetPlayerArmour( playerid, armour - 9.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 9.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 9.0 );

                }
            }
            case 23:
            {
                if( armour > 19.0 ) SetPlayerArmour( playerid, armour - 19.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 19.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 19.0 );

                }
            }
            case 24:
            {
                if( armour > 65.0 ) SetPlayerArmour( playerid, armour - 65.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 65.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 65.0 );

                }
            }
            case 22:
            {
                if( armour > 20.0 ) SetPlayerArmour( playerid, armour - 20.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 20.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 20.0 );

                }
            }
            case 27:
            {
                if( armour > 32.0 ) SetPlayerArmour( playerid, armour - 32.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 32.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 32.0 );

                }
            }
            case 28:
            {
                if( armour > 18.0 ) SetPlayerArmour( playerid, armour - 18.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 18.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 18.0 );

                }
            }
            case 29:
            {
                if( armour > 22.0 ) SetPlayerArmour( playerid, armour - 22.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 22.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 22.0 );

                }
            }
            case 30:
            {
                if( armour > 25.0 ) SetPlayerArmour( playerid, armour - 25.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 25.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 25.0 );

                }
            }
            case 31:
            {
                if( armour > 25.0 ) SetPlayerArmour( playerid, armour - 25.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 25.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 25.0 );

                }
            }
            case 32:
            {
                if( armour > 18.0 ) SetPlayerArmour( playerid, armour - 18.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 18.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 18.0 );

                }
            }
            case 34:
            {
                if( armour > 300.0 ) SetPlayerArmour( playerid, armour - 300.0 );
                else
                {
                    if( armour > 0.0 )
                    {
                        calc_rest = 300.0 - armour;
                        SetPlayerArmour( playerid, 0.0 );
                        SetPlayerHealth( playerid, health - calc_rest );
                    }
                    else SetPlayerHealth( playerid, health - 300.0 );

                }
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)