thund3rbird23 Posted September 12, 2019 Share Posted September 12, 2019 I want to do, if I click to the close dxdrawrectangle then close the panel. What's wrong with this code?: local screenW, screenH = guiGetScreenSize() function renderPanel() dxDrawRectangle(screenW * 0.3324, screenH * 0.2799, screenW * 0.3609, screenH * 0.3581, tocolor(0, 0, 0, 205), false) closebutton = dxDrawRectangle(screenW * 0.6428, screenH * 0.2513, screenW * 0.0483, screenH * 0.0208, tocolor(254, 23, 23, 205), false) dxDrawText("Close", screenW * 0.6420, screenH * 0.2513, screenW * 0.6911, screenH * 0.2721, tocolor(255, 255, 255, 205), 1.00, "default", "center", "top", false, false, false, false, false) end function panel() addEventHandler("onClientRender", root, renderPanel) addEventHandler("onClientGUIClick", root, function (button, state) if button == "left" and state == up then if (source == closebutton) then removeEventHandler("onClientRender", getRootElement(), renderPanel) end end end) end addCommandHandler("openpanel", panel) Link to comment
Scripting Moderators ds1-e Posted September 13, 2019 Scripting Moderators Share Posted September 13, 2019 5 hours ago, thund3rbird23 said: I want to do, if I click to the close dxdrawrectangle then close the panel. What's wrong with this code?: local screenW, screenH = guiGetScreenSize() function renderPanel() dxDrawRectangle(screenW * 0.3324, screenH * 0.2799, screenW * 0.3609, screenH * 0.3581, tocolor(0, 0, 0, 205), false) closebutton = dxDrawRectangle(screenW * 0.6428, screenH * 0.2513, screenW * 0.0483, screenH * 0.0208, tocolor(254, 23, 23, 205), false) dxDrawText("Close", screenW * 0.6420, screenH * 0.2513, screenW * 0.6911, screenH * 0.2721, tocolor(255, 255, 255, 205), 1.00, "default", "center", "top", false, false, false, false, false) end function panel() addEventHandler("onClientRender", root, renderPanel) addEventHandler("onClientGUIClick", root, function (button, state) if button == "left" and state == up then if (source == closebutton) then removeEventHandler("onClientRender", getRootElement(), renderPanel) end end end) end addCommandHandler("openpanel", panel) dx ~= gui This doesn't work as it is in your code, example code with toggle on/off. local screenW, screenH = guiGetScreenSize() local enabled = true function renderPanel() if enabled then dxDrawRectangle(screenW * 0.3324, screenH * 0.2799, screenW * 0.3609, screenH * 0.3581, tocolor(0, 0, 0, 205), false) dxDrawRectangle(screenW * 0.6428, screenH * 0.2513, screenW * 0.0483, screenH * 0.0208, tocolor(254, 23, 23, 205), false) dxDrawText("Close", screenW * 0.6420, screenH * 0.2513, screenW * 0.6911, screenH * 0.2721, tocolor(255, 255, 255, 205), 1.00, "default", "center", "top", false, false, false, false, false) end end addEventHandler("onClientRender", getRootElement(), renderPanel) function openPanel() enabled = not enabled end addCommandHandler("openpanel", openPanel) Link to comment
thund3rbird23 Posted September 13, 2019 Author Share Posted September 13, 2019 It isn't possible to do with dx? I don't want toggle, I want to close the panel when clicked to close button Link to comment
Scripting Moderators ds1-e Posted September 13, 2019 Scripting Moderators Share Posted September 13, 2019 It is, but i couldn't help you. I prefer simple GUI. Link to comment
Lachuks Posted September 14, 2019 Share Posted September 14, 2019 Try to use https://wiki.multitheftauto.com/wiki/OnClientClick and check if cursor is on "button" https://wiki.multitheftauto.com/wiki/IsMouseInPosition 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