SA-MP Forums Archive
I want only headshots to do damage. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I want only headshots to do damage. (/showthread.php?tid=654225)



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(playeridissueridFloat:amountweaponidbodypart)
{
    new 
Float:healthFloat:armour;
    
GetPlayerHealth(playeridhealth);
    
GetPlayerArmour(playeridarmour);
    if(
bodypart != 9) {
        
SetPlayerHealth(playeridhealth);
        
SetPlayerArmour(playeridarmour);
    }
    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(playeridweaponidSTREAMER_TAG_OBJECT objectidFloat:xFloat:yFloat: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.