DouglaS666 Posted May 27, 2018 Share Posted May 27, 2018 function MakePlayerHeadshot( attacker, weapon, bodypart, loss ) if getElementType ( attacker ) == "ped" then if bodypart == 9 then triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) setPedHeadless ( source, true ) killPed( source, attacker, weapon, bodypart ) setTimer( BackUp, 900, 1, source ) end end end function MakeHeadshot( source, attacker, weapon, loss ) triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) killPed( source, attacker, weapon, 9 ) setPedHeadless ( source, true ) setTimer( BackUp, 900, 1, source ) end function BackUp( source ) if getElementType ( source ) == "player" then setPedHeadless ( source, false ) end end function outputHeadshotIcon (killer, weapon, bodypart) if bodypart == 9 then cancelEvent() exports.killmessages:outputMessage ( {getPlayerName(killer),{"padding",width=3},{"icon",id=weapon},{"padding",width=3},{"icon",id=256},{"padding",width=3},{"color",r=r1,g=g1,b=b1},getPlayerName(source) }, getRootElement(),r2,g2,b2) end end addEvent ( "onServerHeadshot", true ) addEventHandler( "onPlayerDamage", getRootElement(), MakePlayerHeadshot ) addEventHandler( "onPlayerKillMessage", getRootElement(), outputHeadshotIcon ) addEventHandler( "onServerHeadshot", getRootElement(), MakeHeadshot ) Link to comment
WiBox Posted May 27, 2018 Share Posted May 27, 2018 this one; if getElementType ( attacker ) == "ped" then or this one; if getElementType ( source ) == "player" then Link to comment
DouglaS666 Posted May 27, 2018 Author Share Posted May 27, 2018 (edited) Thanks Edited May 27, 2018 by DouglaS666 Link to comment
Moderators IIYAMA Posted May 27, 2018 Moderators Share Posted May 27, 2018 1. Not error proof: if getElementType ( attacker ) == "ped" then 2. More error proof: if attacker and getElementType ( attacker ) == "ped" then 3. 100/100 error proof if isElement(attacker) and getElementType ( attacker ) == "ped" then But the function isElement isn't always needed, because sometimes MTA functions/events give you either an element back or false/nil back. Which means I would rather pick option 2, for the optimization of my code. In some cases while using variables/elementdata to store data for later, only option 3 will work. Yet sometimes you do not want to check for the element type, if you know what you have stored. So in the end, lets strip it to the basic: 1. Not error proof: --nothing 2. More error proof: if element then 3. 100/100 error proof if isElement(element) then Link to comment
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