Adde Posted January 2, 2014 Posted January 2, 2014 Hello, I want this to work so if I click on something in the world it should only trigger the event if the clicked object/element is a "player". Anc if the clicked player is me when I play it should set "aPlayer" as me, if I click on somone else then "aPlayer" should be set as that player. So if you can find the errors or what I should add then please help Bcs I can click on cars and players and the event will still trigger this is the part I need help with ( client side ). I can tell that the event will show a window with info about "aPlayer" that´s why I need no set "aPlayer" as the clicked element (player). function worldObject(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if ( clickedElement ) then local elementType = getElementType ( clickedElement ) if ( elementType ~= "localPlayer" ) then aPlayer = localPlayer elseif ( elementType ~= "source" ) then aPlayer = source end triggerEvent("showTheWindow", localPlayer, aPlayer) end end addEventHandler("onClientClick", getRootElement(), worldObject) I also want to ask if I can make it work when no guis are showing. Just an example so you understand, if ( not guiGetVisible(allGUI:s) ) then
Plean Posted January 2, 2014 Posted January 2, 2014 function worldObject(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if getElementType(clickedElement) == "player" then triggerEvent("showTheWindow", localPlayer, clickedElement) end end addEventHandler("onClientClick", getRootElement(), worldObject)
Adde Posted January 2, 2014 Author Posted January 2, 2014 function worldObject(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if getElementType(clickedElement) == "player" then triggerEvent("showTheWindow", localPlayer, clickedElement) end end addEventHandler("onClientClick", getRootElement(), worldObject) Oh, well that was easy. When I am scripting I am not thinking that it could be so easy. Now in retrospect, I understand that it ofcourse should be like this. Thank you.
Plean Posted January 2, 2014 Posted January 2, 2014 I also want to ask if I can make it work when no guis are showing. Just an example so you understand, if ( not guiGetVisible(allGUI:s) ) then function isAnyGuiWindowVisible() for k, v in ipairs(getElementsByType("gui-window")) do if guiGetVisible(v) then return true end end return false end function worldObject(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if getElementType(clickedElement) == "player" then if not isAnyGuiWindowVisible() then triggerEvent("showTheWindow", localPlayer, clickedElement) end end end addEventHandler("onClientClick", getRootElement(), worldObject)
Adde Posted January 2, 2014 Author Posted January 2, 2014 Thank you, you´ve been very helpfull. I thought about using "for k, v in ipairs(getElementsByType("gui-window")) do", but I didn´t know if it was possible to use gui-window there. I didn´t have time to check on wiki ether. But thanks for helping me out (y)
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