rusztamas Posted April 12, 2017 Share Posted April 12, 2017 Hi! I made a dxDraw Gui and it contains 3 texts, and 3 rectangles. All of them has been defined, as values/instructions, so they could be used as variables. Script: function dxDraw() showCursor(true) local mX, mY = 1366, 768 local jX, jY = guiGetScreenSize() hatter = dxDrawRectangle (jX/3.2, jY/4, 500, 350, tocolor(0, 0, 0, 150)) -- háttér hattertext = dxDrawText ("Csatlakozol?", jX/3.2+130, jY/4+75, _, _, _, 3, "sans", "left", "top") -- háttér szöveg igen = dxDrawRectangle (jX/3, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- igen igentext = dxDrawText ("Igen", jX/2-195, jY-300, _, _, _, 3, "sans", "left", "top") -- igen szöveg nem = dxDrawRectangle (jX/3+295, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- nem nemtext = dxDrawText ("Nem", jX/3+325, jY-297, _, _, _, 3, "sans", "left", "top") -- nem szöveg end addEventHandler ("onClientRender", getRootElement(), dxDraw) function nemclick() destroyElement (hatter) end addEventHandler("onClientGUIClick", nem, nemclick) my problem, is when i click on rectangle "nem" the rectangle "hatter" is not getting destroyed, but stays the same. what the problem could be? Link to comment
Fist Posted April 12, 2017 Share Posted April 12, 2017 (edited) you can not use 'destroyElement' to destroy/hide dx drawing function 'cause it's not an element. You have to use some kind of variable to know if that dx drawing need to be draw. Also don't use 'guiGetScreenSize' or 'showCursor' function in 'onClientRender' eventHandler. It's no need for that it will do fine if you call it once not constantly when player updates frames. local mX, mY = 1366, 768 local jX, jY = guiGetScreenSize() local showDxDrawing = false; function dxDraw() if (not showDxDrawing) then return; end hatter = dxDrawRectangle (jX/3.2, jY/4, 500, 350, tocolor(0, 0, 0, 150)) -- háttér hattertext = dxDrawText ("Csatlakozol?", jX/3.2+130, jY/4+75, _, _, _, 3, "sans", "left", "top") -- háttér szöveg igen = dxDrawRectangle (jX/3, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- igen igentext = dxDrawText ("Igen", jX/2-195, jY-300, _, _, _, 3, "sans", "left", "top") -- igen szöveg nem = dxDrawRectangle (jX/3+295, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- nem nemtext = dxDrawText ("Nem", jX/3+325, jY-297, _, _, _, 3, "sans", "left", "top") -- nem szöveg end addEventHandler ("onClientRender", getRootElement(), dxDraw) function nemclick() showDxDrawing = not showDxDrawing; showCursor(not isCursorShowing()) end addEventHandler("onClientGUIClick", nem, nemclick) EDIT: @rusztamas just noticed, you used GUI event handler to detect DX click. You CAN NOT use GUI events to detect DX 'cause DX is not same as GUI. You can use "useful function" from wiki 'isMouseInPosition' and event 'onClientKey' to detect dx click. correct code would be this local mX, mY = 1366, 768 local jX, jY = guiGetScreenSize() local showDxDrawing = false; function dxDraw() if (not showDxDrawing) then return; end dxDrawRectangle (jX/3.2, jY/4, 500, 350, tocolor(0, 0, 0, 150)) -- háttér dxDrawText ("Csatlakozol?", jX/3.2+130, jY/4+75, _, _, _, 3, "sans", "left", "top") -- háttér szöveg dxDrawRectangle (jX/3, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- igen dxDrawText ("Igen", jX/2-195, jY-300, _, _, _, 3, "sans", "left", "top") -- igen szöveg dxDrawRectangle (jX/3+295, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- nem dxDrawText ("Nem", jX/3+325, jY-297, _, _, _, 3, "sans", "left", "top") -- nem szöveg end addEventHandler ("onClientRender", getRootElement(), dxDraw) -- function from wiki.multitheftauto.com (not written by me) function isMouseInPosition ( x, y, width, height ) if ( not isCursorShowing( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end function nemclick(button,press) if (isMouseInPosition(jX/3+295, jY-300, 150, 50)) then if (button == "mouse1" and press) then showDxDrawing = not showDxDrawing; showCursor(not isCursorShowing()); end end end addEventHandler("onClientKey", root, nemclick); Edited April 12, 2017 by Fist 1 Link to comment
Function Posted April 13, 2017 Share Posted April 13, 2017 if source == (nem) then destroyElement(nem) Link to comment
Mr.Loki Posted April 13, 2017 Share Posted April 13, 2017 @Function you can't destroy an element which does not exist. Maybe read the whole topic next time because Fist explains why. Link to comment
Gordon_G Posted April 13, 2017 Share Posted April 13, 2017 There's something more easy to stop the onClientRender().. removeEventHandler() You could use this in futur. 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