Jump to content

Please help me


Recommended Posts

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

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

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