golanu21 Posted August 4, 2013 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) [Dev]BloWnRPG - We BloW the World [1%]
Castillo Posted August 4, 2013 Posted August 4, 2013 And what's the problem? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
golanu21 Posted August 4, 2013 Author Posted August 4, 2013 don't work.. [Dev]BloWnRPG - We BloW the World [1%]
Castillo Posted August 4, 2013 Posted August 4, 2013 Is it set as server side? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
golanu21 Posted August 4, 2013 Author Posted August 4, 2013 yes... [Dev]BloWnRPG - We BloW the World [1%]
Moderators IIYAMA Posted August 4, 2013 Moderators Posted August 4, 2013 You wear the correct skin? and you test it on a real player? 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
Castillo Posted August 4, 2013 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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
golanu21 Posted August 4, 2013 Author Posted August 4, 2013 [[[THE SKIN IS : 9 ]]] '' but -50 when i fall [Dev]BloWnRPG - We BloW the World [1%]
Castillo Posted August 4, 2013 Posted August 4, 2013 Hold on, you want when the skin is 9, only take 1% of damage and cancel the rest? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
golanu21 Posted August 4, 2013 Author Posted August 4, 2013 yes [Dev]BloWnRPG - We BloW the World [1%]
Castillo Posted August 4, 2013 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 ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
golanu21 Posted August 4, 2013 Author Posted August 4, 2013 not working .. when i fall with skin ID 9 - 30 [Dev]BloWnRPG - We BloW the World [1%]
Castillo Posted August 4, 2013 Posted August 4, 2013 You changed the script type on the meta.xml to "client", right? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Moderators IIYAMA Posted August 4, 2013 Moderators 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. 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
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