I want only headshots to do damage. -
Exhibit - 23.05.2018
Hi, I want only headshots to do damage how can I do that?
Re: I want only headshots to do damage. -
Chipardeur - 23.05.2018
Use
https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage and check if bodypart is different of 9. If it is: SetPlayerHealth with his initial health, like:
PHP код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
new Float:health, Float:armour;
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
if(bodypart != 9) {
SetPlayerHealth(playerid, health);
SetPlayerArmour(playerid, armour);
}
return 1;
}
Re: I want only headshots to do damage. -
Exhibit - 23.05.2018
Thanks
Re: I want only headshots to do damage. -
NaS - 24.05.2018
The problem with that code is that you can still die from bodyshots if your health is lower or equal to the damage done.
If you don't yet use SAMP's team system in your mode (or minigame, where you use this) you can set all players' teams to the same team and then only process headshot damage (players will not be able to damage each other, except for the damage you specifically allow).
Furthermore this uses OnPlayerTakeDamage, so the headshot must be done on the target's screen. If you shoot someone's head but this doesn't happen on their screen as well, it won't work.
Use OnPlayerGiveDamage if you want it to be dependant on the shooter's hit position.
Re: I want only headshots to do damage. -
SeanDenZYR - 24.05.2018
Quote:
Originally Posted by NaS
The problem with that code is that you can still die from bodyshots if your health is lower or equal to the damage done.
If you don't yet use SAMP's team system in your mode (or minigame, where you use this) you can set all players' teams to the same team and then only process headshot damage (players will not be able to damage each other, except for the damage you specifically allow).
Furthermore this uses OnPlayerTakeDamage, so the headshot must be done on the target's screen. If you shoot someone's head but this doesn't happen on their screen as well, it won't work.
Use OnPlayerGiveDamage if you want it to be dependant on the shooter's hit position.
|
Actually, his code will work, returning 0 in this function will do no damage to the player what so ever.
Re: I want only headshots to do damage. -
jlalt - 24.05.2018
Quote:
Originally Posted by SeanDenZYR
Actually, his code will work, returning 0 in this function will do no damage to the player what so ever.
|
Nope, that's not like OnPlayerWeaponShot callback.
Nor its like weapon-config callbacks.
By the way I recommend him to use weapon-config and its callbacks for that purpose.
Re: I want only headshots to do damage. -
Logic_ - 24.05.2018
Quote:
Originally Posted by jlalt
Nope, that's not like OnPlayerWeaponShot callback.
Nor its like weapon-config callbacks.
By the way I recommend him to use weapon-config and its callbacks for that purpose.
|
Just an off-topic question: Does it work in 0.3-DL?
Re: I want only headshots to do damage. -
CodeStyle175 - 24.05.2018
yes it works, you need to add this callback
PHP код:
public OnPlayerShootDynamicObject(playerid, weaponid, STREAMER_TAG_OBJECT objectid, Float:x, Float:y, Float:z){
return 1;
}
Re: I want only headshots to do damage. -
jlalt - 25.05.2018
Quote:
Originally Posted by Logic_
Just an off-topic question: Does it work in 0.3-DL?
|
I have been using it on 3z for a while now.
You need to take rid of knief sync ( uses SpawnPlayerForWorld function ) which crashed the server... I just replaced that with normal spawnfunc.
Health bar, The set textdraw position function not working too so you have to destory the health bar and rebuild it.
So far I only faced this issues which were possible to fix.