Jump to content

Click events


Recommended Posts

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
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
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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...