lolcatsareawesome Posted July 23, 2013 Share Posted July 23, 2013 Hi there, I've made a script when the player click on a vehicle, the vehicle is destroyed via the event onClientClick. The problem is that, when the player open a window (admin panel per example) and do his stuff into it, the event onClientClick continue to do his things. I want to limit it, when the player click in a GUI, onClientClick doesn't do anything. The element argument from onClientClick doesn't detect the GUI elements. It allways return false. Thanks for your help ! Link to comment
Jaysds1 Posted July 23, 2013 Share Posted July 23, 2013 Do you use a command to show the cursor or a bind function? As of using addCommandHandler or bindKey. If you do then you could add the event handler for clicking on elements like the vehicle and remove it if the cursor isn't shown. Link to comment
lolcatsareawesome Posted July 23, 2013 Author Share Posted July 23, 2013 Do you use a command to show the cursor or a bind function?As of using addCommandHandler or bindKey. If you do then you could add the event handler for clicking on elements like the vehicle and remove it if the cursor isn't shown. You don't understand my previous post. Link to comment
Jaysds1 Posted July 23, 2013 Share Posted July 23, 2013 Sorry, but there's no other way to disable it. Post your code here please. Link to comment
lolcatsareawesome Posted July 23, 2013 Author Share Posted July 23, 2013 Sorry, but there's no other way to disable it.Post your code here please. addEventHandler("onClientClick", getRootElement(), function(button, state, x, y, wx, wy, wz, element) if (button == "left") and (state == "down") then if element and (getElementType(element) == "vehicle") then blowVehicle(element) else -- CHECK IF THE ELEMENT WHERE THE USER CLICK IS A GUI, IF IT'S THEN DO NOTHING end end end) Link to comment
lolcatsareawesome Posted July 23, 2013 Author Share Posted July 23, 2013 Any errors in Debug Script? I think you don't understand what i'm talking about. I'll try to explain more... (forgot the blowVehicle thing) As you know, the event onClientClick is actived when the user click with his mouse. This event give us a parameter, that parameter is an element. This element is the element where the player clicked on GTA world. This element can be vehicle, player, object etc. The fact is that, when I open any GUI and click on it (example: admin panel), the onClientClick still running. (Using the admin panel example, I want to press a button, unfortunly, a vehicle is at the same place in my screen. Then the event onClientClick will detect that click.) The element that onClientClick returns is a MTA element but it works only for vehicle, player, objects etc not GUI elements (As far i know, GUI elements are MTA elements: https://wiki.multitheftauto.com/wiki/Element ) How can I know if the player click in a GUI element or in a element in the GTA world? I hope you understand guys... Link to comment
Josmis Posted July 23, 2013 Share Posted July 23, 2013 If i understood what you want you should try this: local gui = false local isGui = false local guiItems = {"Button", "Checkbox", "Combobox", "Edit field", "Gridlist", "Memo", "Progress bar", "Radio button", "Scrollbar", "Scrollpane", "Static image", "Tab panel", "Tab", "Text label", "Window"} function onFocus() for i, item in ipairs(guiItems) do if source == item then isGui = true break end end end addEventHandler("onClientGUIFocus", root, onFocus, true) function onBlur() isGui = false end addEventHandler("onClientGUIBlur", root, onBlur, true) addEventHandler("onClientClick", getRootElement(), function(button, state, x, y, wx, wy, wz, element) if (button == "left") and (state == "down") then if element and (getElementType(element) == "vehicle") then if not gui then blowVehicle(element) end end end end) Maybe it's the most complicated method to do it (i don't know if it works because i didn't test it) but... try it ahaha Link to comment
lolcatsareawesome Posted July 23, 2013 Author Share Posted July 23, 2013 If i understood what you want you should try this: local gui = false local isGui = false local guiItems = {"Button", "Checkbox", "Combobox", "Edit field", "Gridlist", "Memo", "Progress bar", "Radio button", "Scrollbar", "Scrollpane", "Static image", "Tab panel", "Tab", "Text label", "Window"} function onFocus() for i, item in ipairs(guiItems) do if source == item then isGui = true break end end end addEventHandler("onClientGUIFocus", root, onFocus, true) function onBlur() isGui = false end addEventHandler("onClientGUIBlur", root, onBlur, true) addEventHandler("onClientClick", getRootElement(), function(button, state, x, y, wx, wy, wz, element) if (button == "left") and (state == "down") then if element and (getElementType(element) == "vehicle") then if not gui then blowVehicle(element) end end end end) Maybe it's the most complicated method to do it (i don't know if it works because i didn't test it) but... try it ahaha Some errors in your code but you understand what I mean. GUI focus isn't the good way to do that. Based on your idea, I find the solution. isGui = false addEventHandler("onClientMouseEnter", getRootElement(), function() if source then isGui = true; end end) addEventHandler("onClientMouseLeave", getRootElement(), function() if source then isGui = false; end end) Thank you ! 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