Jump to content

onClientGUIClick problem


thund3rbird23

Recommended Posts

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

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