Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot
#1

-solved-
Reply
#2

Well as the name Suggests, OnPlayerTakeDamage is called when a player Takes damage, While OnPlayerWeaponShot is called whenever a player Shots ..
If you want to detect to detect body parts, Use OnPlayerGiveDamage or OnPlayerTakeDamage.
Reply
#3

Quote:
Originally Posted by Rudy_
Посмотреть сообщение
Well as the name Suggests, OnPlayerTakeDamage is called when a player Takes damage, While OnPlayerWeaponShot is called whenever a player Shots ..
If you want to detect to detect body parts, Use OnPlayerGiveDamage or OnPlayerTakeDamage.
Ok, now if the bullet is canceled in onplayerweaponshot, does onplayertakedamage still get called?
Reply
#4

No i think.
Reply
#5

Well this will not let the player who was shot lose HP if he had armor on and got shot on torso

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 3) //example
    {
        new Float:armour, Float:health;
        GetPlayerArmour(playerid, armour);
        GetPlayerHealth(playerid, health);
        if(GetPlayerArmour(playerid) > 0 && bodypart == 3)
        {
            SetPlayerHealth(playerid, health);
            SetPlayerArmour(playerid, armour);
        }
        else
        {
            //Player had no armor or body part was different
        }
    }
    return 1;
}
Reply
#6

Just a small mistake
Quote:
Originally Posted by Rudy_
Посмотреть сообщение
pawn Код:
if(GetPlayerArmour(playerid) > 0 && bodypart == 3)
pawn Код:
if(armour > 0 && bodypart == 3)
Reply
#7

So... SetPlayerHealth cancels the damage? That's really confusing... Can someone give an explanation on this? It works and all, but why? Doesn't the damage get done after OnPlayerTakeDamage is returned?
Reply
#8

pawn Код:
if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 3)
If the player who shot is not invalid player and if the weapon is 34 (example) and if the body part is 3 = torso.

pawn Код:
new Float:armour, Float:health;
        GetPlayerArmour(playerid, armour);
        GetPlayerHealth(playerid, health);
Storing the player Health and armor (Don't worry, It will save the health and armor before he had taken the damage)

pawn Код:
if(GetPlayerArmour(playerid) > 0 && bodypart == 3)
        {
            SetPlayerHealth(playerid, health);
            SetPlayerArmour(playerid, armour);
        }
If player had armor on and got shot in torso, Setplayerhealth and armor to the one he had before taking damage.
Reply
#9

If your using lagcomp I would recommend using OnPlayerGiveDamage() as your damage system with server sided health. This way you can completely eliminate health hacking and also be able to do any sort of custom damage/damage effects easily. On top of this lagcomp is not very reliable in fact a lot of shots that should do damage don't even though the shot has hit the skin it's really annoying.

So you will need to set all players to the same team I have created a include which does that but also allows you to use SetPlayerTeam() GetPlayerTeam() the hooked functions do the dirty work of setting the players to the same team behind the scenes.

You will also need to still use OnPlayerTakeDamage() for explosions / car killing / heliblading / rockets then pass that even to OnPlayerGiveDamage()

pawn Код:
#include <YSI\y_hooks>

static PlayerTeam[MAX_PLAYERS];

forward TF_SetPlayerTeam(playerid, team);
public TF_SetPlayerTeam(playerid, team)
{
    PlayerTeam[playerid] = team;
    return SetPlayerTeam(playerid, 999);
}

#if defined _ALS_SetPlayerTeam
    #undef SetPlayerTeam
#else
    #define _ALS_SetPlayerTeam
#endif

#define SetPlayerTeam TF_SetPlayerTeam

forward TF_GetPlayerTeam(playerid);
public TF_GetPlayerTeam(playerid)
{
    return PlayerTeam[playerid];
}

#if defined _ALS_GetPlayerTeam
    #undef GetPlayerTeam
#else
    #define _ALS_GetPlayerTeam
#endif

#define GetPlayerTeam TF_GetPlayerTeam
Reply
#10

Quote:
Originally Posted by Rudy_
Посмотреть сообщение
(Don't worry, It will save the health and armor before he had taken the damage)
Considering this, what if the damage kills the player, you can't give health to a dead player...?

Ps: Thanks Pottus
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)