Is there any way to cancel out OnPlayerTakeDamage?
#1

I would like players to take no damage in certain and specific situations while keeping them vulnerable in others, so I have tried with putting return 0; in such conditions, but I keep taking damage. Is there any way to achieve what I want?
Reply
#2

Try putting, for each shot / disaster increase the life of the player!
xD
Reply
#3

Well actually I have already made a custom RestoreDamage function with the parameters (playerid, Float:amount), calling this function in OnPlayerTakeDamage under some conditions. However, what if the player has armour too? OnPlayerTakeDamage doesn't tell you if the damage has been made to the armour or to the player's health. If I could somehow make the damage null it would be much better.
Reply
#4

Tried
pawn Код:
return false;
}
??
Reply
#5

Well, you can use "SetPlayerTeam" and then players can kill each other if they are in the same team, unless they use knife...

Example:

pawn Код:
public OnPlayerConnect(playerid)
{
    SetPlayerTeam(playerid, 7);
    return 1;
}
Reply
#6

To see if a player is in a certain area use https://sampwiki.blast.hk/wiki/Useful_Fu...IsPlayerInArea.

Also GetPlayerHealth, GetPlayerArmour.
Reply
#7

Quote:
Originally Posted by @Riichard
Посмотреть сообщение
Tried
pawn Код:
return false;
}
??
I have just tried it but doesn't work.
Reply
#8

This would be pretty hard to do because even if you try to restore the players health/armour they might still die before you can. The best way would be to use teams like kizla said. But that means you must know in advance if you want to cancel a players damage
Reply
#9

Ok, thanks to all of you for your replies, but I think I have just found the solution and the truth is that such solution is really easy: I found out that if you use GetPlayerHealth and GetPlayerArmour in OnPlayerTakeDamage, these functions return the health and armour values that you had BEFORE taking damage, so for example if you have full health and full armour, and suddenly you fall some meters and your health drops to 95, both functions will return 100, not 95 and 100. And I have also found out that if you use SetPlayerHealth and SetPlayerArmour in the OnPlayerTakeDamage callback, these two functions will have priority over the callback. Therefore, the solution to my problem seems to be the following:

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:health, Float:armour;
    GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
    if( blah blah blah put your conditional here)
    {
        SetPlayerHealth(playerid, health);
        SetPlayerArmour(playerid, armour);
        // With this, the player will take no damage.
    }
    return 1;
}
Reply
#10

Nice i thought it was called after taking damage.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)