golanu21 Posted August 4, 2013 Share Posted August 4, 2013 function skin1() local skin = getElementModel(source) if skin == 9 then setElementHealth(source, getElementHealth(source) -1) end end addEventHandler("onPlayerDamage", getRootElement(), skin1) i want when player havee skin ID 9 then when someone shoot him setElementHealth(source, getElementHealth(source) -1) Link to comment
Moderators IIYAMA Posted August 4, 2013 Moderators Share Posted August 4, 2013 You wear the correct skin? and you test it on a real player? Link to comment
Castillo Posted August 4, 2013 Share Posted August 4, 2013 function skin1 ( ) local skin = getElementModel ( source ) outputChatBox ( "THE SKIN IS: ".. tostring ( skin ) ) if ( skin == 9 ) then setElementHealth ( source, ( getElementHealth ( source ) - 1 ) ) else outputChatBox ( "SKIN ISN'T 9" ) end end addEventHandler ( "onPlayerDamage", getRootElement(), skin1 ) Try that and see what it outputs to chat when you damage a player. Link to comment
golanu21 Posted August 4, 2013 Author Share Posted August 4, 2013 [[[THE SKIN IS : 9 ]]] '' but -50 when i fall Link to comment
Castillo Posted August 4, 2013 Share Posted August 4, 2013 Hold on, you want when the skin is 9, only take 1% of damage and cancel the rest? Link to comment
Castillo Posted August 4, 2013 Share Posted August 4, 2013 Then you have to make the script client side, since onPlayerDamage can't be cancelled. function skin1 ( ) local skin = getElementModel ( source ) if ( skin == 9 ) then cancelEvent ( ) setElementHealth ( source, ( getElementHealth ( source ) - 1 ) ) end end addEventHandler ( "onClientPlayerDamage", localPlayer, skin1 ) Link to comment
golanu21 Posted August 4, 2013 Author Share Posted August 4, 2013 not working .. when i fall with skin ID 9 - 30 Link to comment
Castillo Posted August 4, 2013 Share Posted August 4, 2013 You changed the script type on the meta.xml to "client", right? Link to comment
Moderators IIYAMA Posted August 4, 2013 Moderators Share Posted August 4, 2013 Unfortunately when you change health of a player the same moment he got damaged, the damage doesn't got cancelled. I don't know why, but this is the way it works..... try this: Client local damageThePlayer = function () local newHealth = getElementHealth(localPlayer)-1 if newHealth > 0 then setElementHealth(localPlayer,newHealth) else setElementHealth(localPlayer,0) end end addEventHandler ( "onClientPlayerDamage",localPlayer, function () if getElementModel ( localPlayer ) == 9 then cancelEvent() setTimer(damageThePlayer,50,1) end end) The delay is 50 ms. 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