Jump to content

[Help] Head Damage


Lorder

Recommended Posts

1 minute ago, IIYAMA said:

If it sets your health to 90, then you still haven't set the 90 to 0.


local newHealth = math.max(playerOriginalHealth - headshotDamage, 0)

...

I did so

function onPlayerHeadshot( attacker, _, bodypart, loss )

	local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health
	local newHealth = math.max(playerOriginalHealth - headshotDamage, 0)
	setElementHealth( localPlayer, newHealth) -- set the player's new health
  	
  	iprint("playerOriginalHealth:", playerOriginalHealth, ", newHealth:", newHealth)
end 
addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot )

 

Link to comment
local multiply = 5
function checkHeadDamage(attacker, weapon, part, loss)
	if not attacker or not ( getElementType( attacker ) == "player" ) then return false end
	if part == 9 then
		setElementHealth(localPlayer, (getElementHealth(localPlayer) - (loss * multiply)))
	end
end
addEventHandler( "onClientPlayerDamage", localPlayer, checkHeadDamage)

if this doesn't work try

addEventHandler( "onClientPlayerDamage", getRootElement(), checkHeadDamage)

but try the code i posted up first

Edited by kikos500
Link to comment
local multiply = 5
function checkHeadDamage(attacker, weapon, part, loss)
	if not attacker or not ( getElementType( attacker ) == "player" ) then return false end
	if part == 9 then
		outputChatBox("This is a test output the player u shot at should be dead now", root)
		setElementHealth(localPlayer, 0)
	end
end
addEventHandler( "onClientPlayerDamage", localPlayer, checkHeadDamage)

try this

function damage( attacker, weapon, bodypart, loss )
	if ( bodypart == 9 ) then
        outputChatBox ( "Headshot!", getRootElement (), 255, 170, 0 )
	    setElementHealth(source, (getElementHealth(source)/2))
	end
end
addEventHandler ( "onPlayerDamage", getRootElement (), damage)

try this one too but try this one server sided

Link to comment

You can check MTA Resources Directory 

You find headshot script

Here is the code 

addEvent "onPlayerHeadshot"

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then
			if ( getPlayerWeapon(attacker) == wepID )
				killPed(source, attacker, weapon, bodypart) -- This to kill the player with one shot 
        		setElementHealth(source, HowMuchHealYouWant) -- This will damage him how much you want
			end
		end
	end
)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...