Jump to content

Some troubles with creating gui


wlasser

Recommended Posts

Hello to everybody.

There is trouble with creating gui, and i'll try many thing's, but it's work not proper.

When player connecting and join - this gui is visible for him. What to do with it?

 

local sx, sy = guiGetScreenSize ( )
local eventButton
function centerGUI ( guiElement )
    local width, height = guiGetSize ( guiElement, false )
    local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 )
    guiSetPosition ( guiElement, x, y, false )
end

GUIEditor = {
    tab = {},
    staticimage = {},
    tabpanel = {},
    edit = {},
    button = {},
    window = {},
    label = {}
}

-- guiSetVisible(GUIEditor.window[1],false)

	GUIEditor.window[1] = guiCreateWindow(423, 331, 523, 367, "", false)
	guiSetVisible(GUIEditor.window[1],false)
	guiWindowSetSizable(GUIEditor.window[1], false)

	centerGUI(GUIEditor.window[1])
	-- GUIEditor.tabpanel[1] = guiCreateTabPanel(11, 109, 502, 241, false, GUIEditor.window[1])
	GUIEditor.button[1] = guiCreateButton(5, 5, 153, 42, "Закрыть", false, GUIEditor.window[1])

 

Link to post
local sx, sy = guiGetScreenSize ( )
local eventButton
function centerGUI ( guiElement )
    local width, height = guiGetSize ( guiElement, false )
    local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 )
    guiSetPosition ( guiElement, x, y, false )
end

GUIEditor = {
    tab = {},
    staticimage = {},
    tabpanel = {},
    edit = {},
    button = {},
    window = {},
    label = {}
}

-- guiSetVisible(GUIEditor.window[1],false)
addEventHandler("onResourceStart",resourceRoot,function()
	GUIEditor.window[1] = guiCreateWindow(423, 331, 523, 367, "", false)
	guiSetVisible(GUIEditor.window[1],false)
	guiWindowSetSizable(GUIEditor.window[1], false)

	centerGUI(GUIEditor.window[1])
	-- GUIEditor.tabpanel[1] = guiCreateTabPanel(11, 109, 502, 241, false, GUIEditor.window[1])
	GUIEditor.button[1] = guiCreateButton(5, 5, 153, 42, "Закрыть", false, GUIEditor.window[1])

 

Link to post

That's didn't work as it.

Now i'm rewrite some and get it like it need, but if before - clicking on buttons is working, now - not. How to gedt it work?

 

local sx, sy = guiGetScreenSize ( )
local eventButton
function centerGUI ( guiElement )
    local width, height = guiGetSize ( guiElement, false )
    local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 )
    guiSetPosition ( guiElement, x, y, false )
end

GUIEditor = {
    tab = {},
    staticimage = {},
    tabpanel = {},
    edit = {},
    button = {},
    window = {},
    label = {}
}

function showHide()
	if guiGetVisible(GUIEditor.window[1]) == true then
		guiSetVisible(GUIEditor.window[1],false)
		showCursor(false)
	elseif guiGetVisible(GUIEditor.window[1]) == false then
		guiSetVisible(GUIEditor.window[1],true)
		showCursor(true)
	end
end
addEventHandler("showHide",getLocalPlayer(),showHide)

function showGUI (event)
	GUIEditor.window[1] = guiCreateWindow(423, 331, 523, 367, "", false)
	guiSetVisible(GUIEditor.window[1],true)
	guiWindowSetSizable(GUIEditor.window[1], false)
	showCursor(true)
	centerGUI(GUIEditor.window[1])
	-- GUIEditor.tabpanel[1] = guiCreateTabPanel(11, 109, 502, 241, false, GUIEditor.window[1])
	GUIEditor.button[1] = guiCreateButton(5, 5, 153, 42, "Закрыть", false, GUIEditor.window[1])
    local memo = guiCreateMemo(11, 109, 502, 241,event['description'],false,GUIEditor.window[1])
    guiMemoSetReadOnly(memo, true)
    GUIEditor.button[2] = guiCreateButton(5, 55, 153, 42, "Принять", false, GUIEditor.window[1])
    eventButton = event
    -- print (event['description'])
end
addEvent("showEventGUI", true)
addEventHandler( "showEventGUI", localPlayer, showGUI )

function buttonClick()
	outputChatBox("Click")
	if source == GUIEditor.button[1] then
		showHide()
	elseif (source == GUIEditor.button[2]) then
		-- triggerServerEvent("startEvent")
		--function startEvent(eventId, player)
		triggerServerEvent("startEvent",resourceRoot, localPlayer, eventButton['id']) -- there is event_id?
		showHide()
	end
end
addEventHandler("onClientGUIClick",GUIEditor.window[1],buttonClick)

 

Link to post

In the first instance, you set it on the window element, not the button, that's why it only worked when you clicked on the window and nothing else. Using 

getResourceRootElement(getThisResource())

OR

resourceRoot

is advised, since you only want to hook the event to the GUI being created by this resource anyway. 

  • Thanks 1
Link to post

 

local sx, sy = guiGetScreenSize ( )

function centerGUI ( guiElement )
    local width, height = guiGetSize ( guiElement, false )
    local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 )
    guiSetPosition ( guiElement, x, y, false )
end

function showHide()
	if guiGetVisible(wind) then
		guiSetVisible(wind,false)
		showCursor(false)
		removeEventHandler("onClientGUIClick",getRootElement(),buttonClick)
	elseif guiGetVisible(wind) == false then
		guiSetVisible(wind,true)
		showCursor(true)
		addEventHandler("onClientGUIClick",getRootElement(),buttonClick)
	end
end
addEventHandler("showHide",getLocalPlayer(),showHide)

function showGUI (event)
	wind = guiCreateWindow(423, 331, 523, 367, "", false)
	guiWindowSetSizable(wind, false)
	showCursor(true)
	centerGUI(wind)
	-- tabpanel = guiCreateTabPanel(11, 109, 502, 241, false, wind)
	bt_close = guiCreateButton(5, 5, 153, 42, "Закрыть", false, wind)
    local memo = guiCreateMemo(11, 109, 502, 241,event['description'],false,wind)
    guiMemoSetReadOnly(memo, true)
    bt_accept = guiCreateButton(5, 55, 153, 42, "Принять", false, wind)
    eventButton = event
end
addEvent("showEventGUI", true)
addEventHandler( "showEventGUI", localPlayer, showGUI )

function buttonClick(bt, st)
	if bt == "left" and st == "down" then
		if source == bt_close then
			showHide()
		elseif source == bt_accept then
			-- triggerServerEvent("startEvent")
			--function startEvent(eventId, player)
			triggerServerEvent("startEvent",resourceRoot, localPlayer, eventButton['id']) -- there is event_id?
			showHide()
		end
	end
end

@wlasser

  • Thanks 1
Link to post
29 minutes ago, wlasser said:

Thanks guy's. Will be learn all your code.

local sx, sy = guiGetScreenSize ( )

function centerGUI ( guiElement )
    local width, height = guiGetSize ( guiElement, false )
    local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 )
    guiSetPosition ( guiElement, x, y, false )
end

function showHide()
	if isElement(wind) then
		destroyElement(wind)
		showCursor(false)
		removeEventHandler("onClientGUIClick",getRootElement(),buttonClick)
	end
end
addEventHandler("showHide",getLocalPlayer(),showHide)

function showGUI (event)
	wind = guiCreateWindow(423, 331, 523, 367, "", false)
	guiWindowSetSizable(wind, false)
	showCursor(true)
	centerGUI(wind)
	-- tabpanel = guiCreateTabPanel(11, 109, 502, 241, false, wind)
	bt_close = guiCreateButton(5, 5, 153, 42, "Закрыть", false, wind)
	local memo = guiCreateMemo(11, 109, 502, 241,event['description'],false,wind)
	guiMemoSetReadOnly(memo, true)
	bt_accept = guiCreateButton(5, 55, 153, 42, "Принять", false, wind)
	eventButton = event
  
	addEventHandler("onClientGUIClick",getRootElement(),buttonClick)
end
addEvent("showEventGUI", true)
addEventHandler( "showEventGUI", localPlayer, showGUI )

function buttonClick(bt, st)
	if bt == "left" and st == "down" then
		if source == bt_close then
			showHide()
		elseif source == bt_accept then
			-- triggerServerEvent("startEvent")
			--function startEvent(eventId, player)
			triggerServerEvent("startEvent",resourceRoot, localPlayer, eventButton['id']) -- there is event_id?
			showHide()
		end
	end
end

i made a little edit. Now it should work properly

@wlasser

  • Thanks 1
Link to post

Thank's alot. There is other question, not about GUI.

I just need to some direction in understood: how i can check what is weapon used for killing ped's? Can i cancel damage or something, if weapon not is what i need?

Next - what is element data and how i can store it into database? And what about security to use internal db?

Thank's for answer's.

Link to post
1 hour ago, wlasser said:

Thank's alot. There is other question, not about GUI.

I just need to some direction in understood: how i can check what is weapon used for killing ped's? Can i cancel damage or something, if weapon not is what i need?

Next - what is element data and how i can store it into database? And what about security to use internal db?

Thank's for answer's.

1. onClientPedDamage (2-nd parameter). cancelEvent() will disable damage

2. element data . You can store it into database by using triggerServerEvent

triggerServerEvent("your_event_name",localPlayer,getElementData(localPlayer,"name") )

3. I can't undestand this question a little bit.

@wlasser

  • Thanks 2
Link to post

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