I want only headshots to do damage.
#1

Hi, I want only headshots to do damage how can I do that?
Reply
#2

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;

Reply
#3

Thanks
Reply
#4

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.
Reply
#5

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.
Reply
#6

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.
Reply
#7

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?
Reply
#8

yes it works, you need to add this callback
PHP код:
public OnPlayerShootDynamicObject(playeridweaponidSTREAMER_TAG_OBJECT objectidFloat:xFloat:yFloat:z){
    return 
1;

Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)