Firespider Posted April 2, 2023 Share Posted April 2, 2023 Hello! I have a small problem, I want to create a menu, but for some reason the button does not flash and does not work, and it still flashes first, could you help? local sx, sy = guiGetScreenSize() local relx,rely = sx/1920,sy/1080; local DutyPanel = false local MenuPoints = {00.35 ,00.20} color1 = tocolor(30, 40, 50, 255) addEventHandler("onClientRender", root, function() if (DutyPanel) then if not (getElementData(localPlayer, "Duty")) then dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*.5, tocolor(50, 60, 70, 230))-- Panel dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*0.08, tocolor(20, 30, 40, 255))-- Panel fejléc dxDrawRectangle(sx*.4, sy*.4 , sx*.2, sy*0.080, color1) dxDrawText("Duty Felvételi Panel", sx*.800, sy*.4 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) dxDrawText("Duty Felvétel", sx*.800, sy*0.80 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) else dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*.5, tocolor(50, 60, 70, 230))-- Panel dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*0.08, tocolor(20, 30, 40, 255))-- Panel fejléc dxDrawRectangle(sx*.4, sy*.4 , sx*.2, sy*0.080, color1) dxDrawText("Duty Felvételi Panel", sx*.800, sy*.4 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) dxDrawText("Duty leadása", sx*.800, sy*0.80 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) 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 ) return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) ) end ---------- if isMouseInPosition(sx*.4, sy*.4 , sx*.2, sy*0.080) then color1 = tocolor(80, 90, 100, 255) else color1 = tocolor(30, 40, 50, 255) end addEventHandler("onClientClick", root, function(button, state) if (DutyPanel) then if ( button == "left" and state == "down" ) then if isMouseInPosition(sx*.4, sy*.4 , sx*.2, sy*0.080) then triggerServerEvent("Dutyon", root) DutyPanel = false end end end end ) end end end ) addEvent("OpenDutyPanel", true) addEventHandler("OpenDutyPanel", root, function() if not (DutyPanel) then DutyPanel = true else outputChatBox("#961f17[RENDSZER]: #ffffffMár menűbe vagy!", 0, 0, 0, true) end end ) function ShowCursor() if not isCursorShowing() then showCursor(true) else showCursor(false) end end bindKey("m", "Down", ShowCursor) Link to comment
Doongogar Posted April 2, 2023 Share Posted April 2, 2023 this code is not very readable, I recommend you remove the util function isMouseInPosition from within the panel, and also indent the code to organize it Link to comment
Firespider Posted April 2, 2023 Author Share Posted April 2, 2023 @SciptNovato Ok, I have it, I made it so that it works when you press it, but it doesn't flash when you move the cursor over it, can you help me with this Link to comment
Doongogar Posted April 2, 2023 Share Posted April 2, 2023 if you want the client to move the mouse over a dx, the dx is gone, you can use a reference topic of mine, the last code presented by the user "FelipeX" works well (topic is in Portuguese if translated with google translator some things may be wrong) DxChangeColorPortugueseTopic text translated by google translator Link to comment
AngelAlpha Posted April 2, 2023 Share Posted April 2, 2023 local sx, sy = guiGetScreenSize() local relx,rely = sx/1920,sy/1080; local DutyPanel = false local MenuPoints = {00.35 ,00.20} color1 = tocolor(30, 40, 50, 255) addEventHandler("onClientRender", root, function() if (DutyPanel) then if not (getElementData(localPlayer, "Duty")) then dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*.5, tocolor(50, 60, 70, 230))-- Panel dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*0.08, tocolor(20, 30, 40, 255))-- Panel fejléc dxDrawRectangle(sx*.4, sy*.4 , sx*.2, sy*0.080, color1) dxDrawText("Duty Felvételi Panel", sx*.800, sy*.4 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) dxDrawText("Duty Felvétel", sx*.800, sy*0.80 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) else dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*.5, tocolor(50, 60, 70, 230))-- Panel dxDrawRectangle(sx*(MenuPoints[1]), sy*(MenuPoints[2]), sx*.3, sy*0.08, tocolor(20, 30, 40, 255))-- Panel fejléc dxDrawRectangle(sx*.4, sy*.4 , sx*.2, sy*0.080, color1) dxDrawText("Duty Felvételi Panel", sx*.800, sy*.4 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) dxDrawText("Duty leadása", sx*.800, sy*0.80 , sx*.2, sy*0.080, tocolor(200, 200, 200, 255), relx*4, rely*4, "default-bold", "center", "center", false, false, false) end ---------- if isMouseInPosition(sx*.4, sy*.4 , sx*.2, sy*0.080) then color1 = tocolor(80, 90, 100, 255) else color1 = tocolor(30, 40, 50, 255) end end end) addEventHandler("onClientClick", root, function(button, state) if (DutyPanel) then if ( button == "left" and state == "down" ) then if isMouseInPosition(sx*.4, sy*.4 , sx*.2, sy*0.080) then triggerServerEvent("Dutyon", root) DutyPanel = false end end end end) 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 ) return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) ) end addEvent("OpenDutyPanel", true) addEventHandler("OpenDutyPanel", root, function() if not (DutyPanel) then DutyPanel = true else outputChatBox("#961f17[RENDSZER]: #ffffffMár menűbe vagy!", 0, 0, 0, true) end end) function ShowCursor() if not isCursorShowing() then showCursor(true) else showCursor(false) end end bindKey("m", "Down", ShowCursor) try this code Link to comment
FLUSHBICEPS Posted April 3, 2023 Share Posted April 3, 2023 seems like the issue with ur code is that the "isMouseInPosition" function and the "onClientClick" event are inside the "onClientRender" event u should move them out of the "onClientRender" event and make sure that they are only called when "DutyPanel" is true local sx, sy = guiGetScreenSize() local relx, rely = sx / 1920, sy / 1080 local DutyPanel = false local MenuPoints = {0.35, 0.20} color1 = tocolor(30, 40, 50, 255) 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) return ((cx >= x and cx <= x + width) and (cy >= y and cy <= y + height)) end addEventHandler("onClientRender", root, function() if (DutyPanel) then if not (getElementData(localPlayer, "Duty")) then -- Panel for Duty Felvétel dxDrawRectangle(sx * (MenuPoints[1]), sy * (MenuPoints[2]), sx * .3, sy * .5, tocolor(50, 60, 70, 230)) dxDrawRectangle(sx * (MenuPoints[1]), sy * (MenuPoints[2]), sx * .3, sy * 0.08, tocolor(20, 30, 40, 255)) else -- Panel for Duty leadása dxDrawRectangle(sx * (MenuPoints[1]), sy * (MenuPoints[2]), sx * .3, sy * .5, tocolor(50, 60, 70, 230)) dxDrawRectangle(sx * (MenuPoints[1]), sy * (MenuPoints[2]), sx * .3, sy * 0.08, tocolor(20, 30, 40, 255)) end -- Button dxDrawRectangle(sx * .4, sy * .4, sx * .2, sy * 0.080, color1) dxDrawText("Duty Felvételi Panel", sx * .800, sy * .4, sx * .2, sy * 0.080, tocolor(200, 200, 200, 255), relx * 4, rely * 4, "default-bold", "center", "center", false, false, false) -- Check if the mouse is hovering over the button if isMouseInPosition(sx * .4, sy * .4, sx * .2, sy * 0.080) then color1 = tocolor(80, 90, 100, 255) else color1 = tocolor(30, 40, 50, 255) end end end ) addEventHandler("onClientClick", root, function(button, state) if (DutyPanel) then if (button == "left" and state == "down") then if isMouseInPosition(sx * .4, sy * .4, sx * .2, sy * 0.080) then triggerServerEvent("Dutyon", root) DutyPanel = false end end end end ) addEvent("OpenDutyPanel", true) addEventHandler("OpenDutyPanel", root, function() if not (DutyPanel) then DutyPanel = true else outputChatBox("#961f17[RENDSZER]: #ffffffMár menűbe vagy!", 0, 0, 0, true) end end ) function ShowCursor() if not isCursorShowing() then showCursor(true) else showCursor(false) end end bindKey("m", "Down", ShowCursor) 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