Lorder Posted June 28, 2017 Author Posted June 28, 2017 1 minute ago, IIYAMA said: answer my question. yes 10% 10%
Moderators IIYAMA Posted June 28, 2017 Moderators Posted June 28, 2017 If it sets your health to 90, then you still haven't set the 90 to 0. local newHealth = math.max(playerOriginalHealth - headshotDamage, 0) ... Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Lorder Posted June 28, 2017 Author Posted June 28, 2017 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 )
Moderators IIYAMA Posted June 28, 2017 Moderators Posted June 28, 2017 restarted the resource? And: headshotDamage = 200? Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
kikos500 Posted June 28, 2017 Posted June 28, 2017 (edited) 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 June 28, 2017 by kikos500
Lorder Posted June 28, 2017 Author Posted June 28, 2017 @IIYAMA @kikos500 I've tried it twice, but it did not work, it does not get much damage from his head
kikos500 Posted June 28, 2017 Posted June 28, 2017 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
Moderators IIYAMA Posted June 28, 2017 Moderators Posted June 28, 2017 Send me the full script in a zip file. Your poor debug skills are getting the better of me, looking at the freaking debug console isn't enough. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Lorder Posted June 28, 2017 Author Posted June 28, 2017 3 minutes ago, IIYAMA said: Send me the full script in a zip file. Your poor debug skills are getting the better of me, looking at the freaking debug console isn't enough. Download link
kikos500 Posted June 28, 2017 Posted June 28, 2017 man look at my code carefully.. replace this one addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) with addEventHandler( "onClientPlayerDamage", localPlayer, checkHeadDamage )
Moderators IIYAMA Posted June 28, 2017 Moderators Posted June 28, 2017 http://s6.dosya.tc/server9/ssefpp/hs.zip.html Working. 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Lorder Posted June 28, 2017 Author Posted June 28, 2017 4 minutes ago, IIYAMA said: http://s6.dosya.tc/server9/ssefpp/hs.zip.html Working. I will try
xMKHx Posted June 29, 2017 Posted June 29, 2017 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 ) UDC:RPG Owner 13 Years Experience ______________________________________ Spoiler - ATM Robbery Script. - Police Shield Script - Army Animations Script - Criminal Skills Script - Drop Weapons Script
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now