itHyperoX Posted April 6, 2017 Share Posted April 6, 2017 addEventHandler("onClientClick", root, function(key, state, cx, cy) if isContactOpened == true then return end if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then isContactOpened = true addEventHandler("onClientRender",getRootElement(),contactBTN) else removeEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false end end end) mm.. How can i do this? Link to comment
External Posted April 6, 2017 Share Posted April 6, 2017 Do what? I can't understand your question Link to comment
itHyperoX Posted April 6, 2017 Author Share Posted April 6, 2017 if i click again on the button, remove the event handler Link to comment
#BrosS Posted April 6, 2017 Share Posted April 6, 2017 (edited) aBool = false addEventHandler("onClientClick", root, function(key, state, cx, cy) if aBool == false then if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then aBool = true addEventHandler("onClientRender",getRootElement(),contactBTN) else removeEventHandler("onClientRender",getRootElement(),contactBTN) aBool = false end end end end) Edited April 6, 2017 by #BrosS Link to comment
Tails Posted April 6, 2017 Share Posted April 6, 2017 (edited) local isContactOpened = false addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened then removeEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false else addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = true end end end end) You're welcome. Edited April 6, 2017 by Tails 1 Link to comment
AE. Posted April 6, 2017 Share Posted April 6, 2017 4 minutes ago, Tails said: local isContactOpened = false addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened then removeEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false else addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = true end end end end) You're welcome. just one thing is wrong :3 local isContactOpened = false addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened then addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = true else removeEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false end end end end) Link to comment
Tails Posted April 6, 2017 Share Posted April 6, 2017 No, yours is just the opposite. You want a bool that says IsPanelVisible, if it is then remove the handler. We know the panel is not visible at the start so we do local isContactOpened = false then onClick we check, is it opened? if it's not then we add the handler to show the panel and vice versa. Nice try though Link to comment
AE. Posted April 6, 2017 Share Posted April 6, 2017 1 minute ago, Tails said: No, yours is just the opposite. You want a bool that says IsPanelVisible, if it is then remove the handler. We know the panel is not visible at the start so we do local isContactOpened = false then onClick we check, is it opened? if it's not then we add the handler to show the panel and vice versa. Nice try though ahm noway m8 he want to make the button pressed one time this is not a check for a gui open Link to comment
Tails Posted April 6, 2017 Share Posted April 6, 2017 (edited) 5 minutes ago, 3laa33 said: he want to make the button pressed one time 4 hours ago, TheMOG said: if i click again on the button, remove the event handler @3laa33 I think he wants it toggled. Your example will throw an error because it's trying to remove a handler that doesn't yet exist. Edited April 6, 2017 by Tails Link to comment
AE. Posted April 6, 2017 Share Posted April 6, 2017 4 hours ago, TheMOG said: if i click again on the button, remove the event handler local isContactOpened = true addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened == true then addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false end end end end) well then it will be like this Link to comment
itHyperoX Posted April 6, 2017 Author Share Posted April 6, 2017 (edited) I want that, when player click on the button show the menu, if again click on the button hide the menu (remove the handler) Edited April 6, 2017 by TheMOG Link to comment
AE. Posted April 6, 2017 Share Posted April 6, 2017 1 minute ago, TheMOG said: I want that, when player click on the button show the menu, if again click on the button hide the menu (remove the handler) then use this isContactOpened = true addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened == true then addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false else removeEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = true end end end end Link to comment
Mr.Loki Posted April 6, 2017 Share Posted April 6, 2017 3 minutes ago, 3laa33 said: local isContactOpened = true addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened == true then addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false end end end end) well then it will be like this All this does is adding multiple eventHandlers to contactBTN every time you left click. 1 Link to comment
AE. Posted April 6, 2017 Share Posted April 6, 2017 5 minutes ago, Mr.Loki said: All this does is adding multiple eventHandlers to contactBTN every time you left click. if isContactOpened == true then Link to comment
Mr.Loki Posted April 6, 2017 Share Posted April 6, 2017 @3laa33 yeah but what happens when he needs to close it? You didn't remove the event so it just keeps adding more. What @Tails posted was the correct solution. 8 minutes ago, 3laa33 said: then use this isContactOpened = true addEventHandler("onClientClick", root, function(key, state, cx, cy) if key == "left" and state == "down" then if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then if isContactOpened == true then addEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = false else removeEventHandler("onClientRender",getRootElement(),contactBTN) isContactOpened = true end end end end What this code does is if isContactOpened then add an event even tho the contact is open thus creating another contactBTN no need to use == true unless checking for specific results if it has a var it will always return true. you need to swap your add and remove handlers... Link to comment
AE. Posted April 6, 2017 Share Posted April 6, 2017 (edited) 16 minutes ago, Mr.Loki said: @3laa33 yeah but what happens when he needs to close it? You didn't remove the event so it just keeps adding more. What @Tails posted was the correct solution. What this code does is if isContactOpened then add an event even tho the contact is open thus creating another contactBTN no need to use == true unless checking for specific results if it has a var it will always return true. you need to swap your add and remove handlers... it won't addEvents if it's false so when you click then the event will be aded and isContactOpened = false so when he click again it will be false so it will go to removeEvent Edited April 6, 2017 by 3laa33 Link to comment
#BrosS Posted April 7, 2017 Share Posted April 7, 2017 You know another solution Don't use addEventHandler and removeEventHandler Just try to show your panel by checking a variable is true Just define a vatiable as false first isShowing = false under the render addEventHandler("onClientRender",root,function() if isShowing then dxDraw........ In the click event do like this "onClientClick", ....... ..... isShowing = not isShowing 1 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