Ryder! Posted February 14, 2009 Share Posted February 14, 2009 hi, why i can only attach the "onClientPlayerTarget" and "onPlayerTarget" (client side and server side) to the root element (getRootElement() ) it doesn't work if i attach those event to a ped for example. function onTarget(element) setPedAnimation( element, "ped", "handsup" ) end addEventHandler( "onClientPlayerTarget", getElementByID( "testPed" ), onTarget ) Map File: <ped id="testPed" posX="2089.5925292969" posY="2213.3474121094" posZ="10.8203125" model="0" /> Thanks bye Link to comment
Gamesnert Posted February 14, 2009 Share Posted February 14, 2009 If the way you prefer doesn't work, you just need to find a workaround. function onTarget(element) if element==getElementByID("testped") then --If getElementByID("testped") is targeted by the source then... setPedAnimation( element, "ped", "handsup" ) -- Raise his hands! end end addEventHandler( "onClientPlayerTarget", getRootElement(), onTarget ) -- getRootElement() should make it do the same if someone else targets the ped. If you only want it to happen with the local player, replace it with getLocalPlayer() Untested, but should work. Note that you can also replace... if element==getElementByID("testped") then ...With... if getElementType(element)=="ped" then ... To make it work with all peds you have. This might save you quite some time if you want it to work on all of your peds. Link to comment
Ryder! Posted February 15, 2009 Author Share Posted February 15, 2009 Thanks for your answer, The reason why i want to attach the event to some particular peds it's because i need to retrieve when the player is not targetting the ped anymore. This is what i want to do: function onTarget( element ) if not element then -- im sure that the player is not targetting the ped anymore because the event is attached to a particular ped. --my code end end addEventHandler( "onClientPlayerTarget", getElementByID("testPed"), onTarget ) I can't do the same by attaching the event to the root element because "my code" will be executed when i'm not targetting any element anymore. Link to comment
Mr.Hankey Posted February 15, 2009 Share Posted February 15, 2009 I don't think it will work this way because the element you are attaching the event to is the element that is supposed to target and peds can't even target with weapons atm. Link to comment
Ryder! Posted February 15, 2009 Author Share Posted February 15, 2009 How can i do the same attaching the event to the root element ? it's possible ? Thanks again Link to comment
Ryder! Posted February 15, 2009 Author Share Posted February 15, 2009 =( D= D: help up Link to comment
Gamesnert Posted February 15, 2009 Share Posted February 15, 2009 Did you already try the piece of code I posted up a small while ago? Because I don't really understand what else you could possibly mean... =/ Link to comment
Ryder! Posted February 16, 2009 Author Share Posted February 16, 2009 i'll explain mysefl, I'm trying to do a robbing system. So to rob the store the player must target one of the salesman ped ( defined in map file ) for x seconds but if he stop targetting the ped, the robbery fails. Link to comment
Gamesnert Posted February 16, 2009 Share Posted February 16, 2009 Ok, I'll try to help you on your way. -- Code from before, note that this should work. Especially because I still didn't hear that it didn't from you. function onTarget(element) if element==getElementByID("testped") then setPedAnimation( element, "ped", "handsup" ) setTimer(checkTargeted,500,1,source,element) -- We want the ped to drop his hands if he's not being targeted anymore, in a simple way. For that reason, we're executing checkTargeted. This is located between line 11 and line 17. end end addEventHandler( "onClientPlayerTarget", getRootElement(), onTarget ) function checkTargeted(thePlayer,element) -- source is now renamed thePlayer, because I entered the argument name different here if getPedTarget(thePlayer)~=element then -- Is the ped still being targeted? (note: ~= means "isn't equal to" in Lua) setPedAnimation(element) -- No. Therefor, lower his hands else setTimer(checkTargeted,500,1,thePlayer,element) -- Yes. Therefor, check back later end end Note that this is a very simple way, but it should be synched. So when someone else targets the ped, you should see the animation too. Note though that the script is (still) client-side, so don't forget to add type="client" in the meta.xml! For more info on the functions I used: getPedTarget setTimer setPedAnimation EDIT: Forgot about targeting for xx seconds, but you should be able to make it with the functions given. For instance setTimer. However, if you want to use setTimer, you might also want to use killTimer. Try to make something with it, it doesn't matter if it fails, just post it up and we'll see what went wrong. Link to comment
Ryder! Posted February 16, 2009 Author Share Posted February 16, 2009 thanks! I did not realize that getPedTarget existed 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