Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Crayder - 26.10.2014
-solved-
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Rudy_ - 26.10.2014
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.
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Crayder - 26.10.2014
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?
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Banditukas - 26.10.2014
No i think.
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Rudy_ - 26.10.2014
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;
}
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
DavidBilla - 26.10.2014
Just a small mistake
Quote:
Originally Posted by Rudy_
pawn Код:
if(GetPlayerArmour(playerid) > 0 && bodypart == 3)
|
pawn Код:
if(armour > 0 && bodypart == 3)
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Crayder - 26.10.2014
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?
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Rudy_ - 26.10.2014
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.
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Pottus - 26.10.2014
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
Re: Confusion between OnPlayerTakeDamage and OnPlayerWeaponShot -
Crayder - 26.10.2014
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