Correct way to disable weapon damage
#1

I'm struggling to correctly disable weapon from the silenced pistol whilst the player has their taser armed. Sometimes it doesn't do any damage at all, sometimes it manages to kill the player, and sometimes it actually heals the player. Here's my code:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
    new string[128];
    if(tazerArmed[issuerid] == 1)
    {
        if(weaponid == 23)
        {
            new Float:health;
            GetPlayerHealth(playerid, health);
            SetPlayerHealth(playerid, (health + amount));
        }
    }
    return 1;
}
I'm just struggling to understand why it would heal the player.
Reply
#2

I see you aren't accounting for armour...
Reply
#3

Ah, yes. How would I differentiate between the player losing health and losing armour, though?

Also, all the tests have been conducted without the player having any armour so that's not the reason they're being healed.
Reply
#4

A person's max health/armour is 100.00. So, you would need to do something like this:

pawn Код:
new
    Float:fHealth,
    Float:fArmour,
    Float:fTemp;

GetPlayerHealth(playerid, fHealth);
GetPlayerArmour(playerid, fArmour);

fTemp = fHealth+value;

if(fTemp > 100.0)
{
    fTemp = (100.0 - fTemp);
    SetPlayerHealth(playerid, 100.0);
    SetPlayerArmour(playerid, fTemp);
}
else SetPlayerHealth(playerid, fTemp);
Untested, but I believe it'll work.

As for the issue.. do you have any code under OnPlayerGiveDamage?
Reply
#5

If the players health is below silenced pistol damage the player will die so that kind of messes up your system but there is a way around this to a certain extent.

You can use OnPlayerUpdate() to detect when a player has a target, you set both players to the same team while the player is being targeted then use OnPlayerGiveDamage() to detect a taser hit.
Reply
#6

Couldn't you just return 0 in OnPlayerTakeDamage? I'd assume it'd work just like OnPlayerUpdate, if you want to desync somebody, just return 0 in the callback.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
If the players health is below silenced pistol damage the player will die so that kind of messes up your system but there is a way around this to a certain extent.

You can use OnPlayerUpdate() to detect when a player has a target, you set both players to the same team while the player is being targeted then use OnPlayerGiveDamage() to detect a taser hit.
Quote:
Originally Posted by 2KY
Посмотреть сообщение
Couldn't you just return 0 in OnPlayerTakeDamage? I'd assume it'd work just like OnPlayerUpdate, if you want to desync somebody, just return 0 in the callback.
That won't work because you're not stopping the packet. If you desync them then they're in a loophole, you'd need to time them out to sync them back in. So to prevent that return false won't do anything inside OnPlayerTakeDamage.

The way it works is that amount passed on is valid however the GetPlayerHealth and GetPlayerArmour will return the values before they're shot or damaged. So what you want to do is something like this:

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float: fHealth, Float: fArmour;
    GetPlayerHealth(playerid, fHealth);
    GetPlayerArmour(playerid, fArmour);
    if(player tazed)
    {
        SetPlayerHealth(playerid, fHealth);
        SetPlayerArmour(playerid, fArmour);
    }
    return true;
}
However, if the server or the player is experiencing lag, the function will be called late or respond late. So if a laggy player gets tazed with low health, there is a high chance that they'll die because their lagging and calling the function too late.
Reply
#8

The player will still die if they have low HP though.
Reply
#9

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
The player will still die if they have low HP though.
That can be avoided by checking if the player is tazed under OnPlayerDeath and you can "revive" them. You'd know that their health is less than whatever the value of damage the SD pistol gives so you set their health back to that amount and put them back in the tazed state.

It's the most practical method.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)