BriGhtx3 Posted September 7, 2012 Share Posted September 7, 2012 Hey, when someone shoots at me I want that only after the second bullet which hits me I get a message (in onPlayerDamage): if weapon then if getElementData(player, "shot1") == false then setElementData(player, "shot1", true) return end end if getElementData(player, "shot1") then setElementData(player, "shot1", false) end if place == 7 then outputChatBox("You broke your left leg", player) end The problem is that the message gets output after the first time I get shot. Link to comment
AMARANT Posted September 7, 2012 Share Posted September 7, 2012 Maybe it's because of setting element data to 'true'. Eventually your player's element data gets 'true' value and it's saved even if you restart resource. So the right way is to set it to 'false' after resource starts and then test your code. Link to comment
BriGhtx3 Posted September 7, 2012 Author Share Posted September 7, 2012 Already did it like this Link to comment
AMARANT Posted September 7, 2012 Share Posted September 7, 2012 Put a debug message at the top of the code and see what your element data returns. EDIT*: BTW is this your full code? You gave a piece of it and it's hard to help you. Link to comment
BriGhtx3 Posted September 7, 2012 Author Share Posted September 7, 2012 Of course its not my full code. This is in my onPlayerDamage event. Link to comment
AMARANT Posted September 7, 2012 Share Posted September 7, 2012 Then how do I now what is your 'place' value? Link to comment
BriGhtx3 Posted September 7, 2012 Author Share Posted September 7, 2012 onPlayerDamage: bodypart Link to comment
AMARANT Posted September 7, 2012 Share Posted September 7, 2012 So your the only one condition of getting your leg broken is to be hit in a left leg. Have you checked what element data returns with debug message? It seems that it returns 'true' and script performs its actions including your message with broken leg. Link to comment
BriGhtx3 Posted September 7, 2012 Author Share Posted September 7, 2012 I can't test it right now The condition is that I get shot twice in the leg and thus it gets broken. Link to comment
AMARANT Posted September 7, 2012 Share Posted September 7, 2012 function onBrokenLeg ( attacker, weapon, bodypart ) if weapon then if not getElementData(source, "shot1") then setElementData(source, "shot1", true) return end end if getElementData(source, "shot1") then setElementData(source, "shot1", false) end if bodypart == 7 then outputChatBox("You broke your left leg") end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onBrokenLeg ) This code works if you get shot twice. Element data 'shot1' must be set to 'false' when your resource starts. Link to comment
BriGhtx3 Posted September 7, 2012 Author Share Posted September 7, 2012 Now I only need one shot. Link to comment
Anderl Posted September 7, 2012 Share Posted September 7, 2012 local aShot = { }; addEventHandler( 'onClientResourceStart', resourceRoot, function( ) for _, pUser in ipairs( getElementsByType 'player' ) do aShot[pUser] = 0; end -- addEventHandler( 'onClientPlayerDamage', root, onShot ); addEventHandler( 'onClientPlayerQuit', root, onLeave ); end ); onShot = function( pAttacker, iWeapon, iBPart ) if( pAttacker and iWeapon ) then if( aShot[pAttacker] ) then aShot[pAttacker] = aShot[pAttacker] + 1; end -- if( aShot[pAttacker] == 2 ) then if( iBPart == 7 ) then outputChatBox( 'You broke your left leg!', source, 255, 255, 255, false ); aShot[pAttacker] = 0; end end end end onLeave = function( ) if( aShot[source] ) then aShot[source] = nil; end end Not tested. Link to comment
AMARANT Posted September 7, 2012 Share Posted September 7, 2012 BriGhtx3 said: Now I only need one shot. function onBrokenLeg ( attacker, weapon, bodypart ) if weapon then if bodypart == 7 and not getElementData(source,"brokenleft") then setElementData(source, "brokenleft", true) outputChatBox("You broke your left leg") end end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onBrokenLeg ) ? Link to comment
BriGhtx3 Posted September 7, 2012 Author Share Posted September 7, 2012 I already got it. I set the data in another function -.- But thank you very much 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