kieran Posted July 13, 2017 Share Posted July 13, 2017 I made a simple gui for information etc, trying to bind the F1 key to the gui... Worked fine when I just tried onClientResourceStart and done nothing with key binds, but no debug errors, so I can't see where I gone wrong. helpTabs = {} helphelpTabsPan = {} helpLabel = {} helpButton = {} helpWindow = {} helpMemo = {} --helpState is false. helpState = false function ShowHelp(key, keyState) --Checking if "helpState" is true. if ( keyState == "down" ) and helpState == true then guiSetVisible(helpWindow, false) destroyElement(helpWindow) helpWindow = nil showCursor(false) else if helpState == false then guiSetInputEnabled(false) showCursor(true) --Random GUI crap. local screenW, screenH = guiGetScreenSize() helpWindow = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(helpWindow, false) guiSetAlpha(helpWindow, 0.92) guiSetProperty(helpWindow, "CaptionColour", "FFD7E21C") helpButton = guiCreateButton(485, 489, 96, 35, "Close", false, helpWindow) guiSetProperty(helpButton, "NormalTextColour", "FFFE0000") helphelpTabsPan = guiCreateTabPanel(9, 28, 572, 461, false, helpWindow) helpTabs = guiCreateTab("Rules", helphelpTabsPan) memo = guiCreateMemo(6, 32, 561, 399, "Text goes here.", false, helpTabs) label = guiCreateLabel(13, 10, 544, 26, "Label text goes here.", false, helpTabs) guiLabelSetColor(label, 255, 100, 25) helpTabs2 = guiCreateTab("Commands", helphelpTabsPan) memo2 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpTabs2) label2 = guiCreateLabel(15, 10, 544, 26, "Label text goes here.", false, helpTabs2) guiLabelSetColor(label2, 255, 100, 25) helpTabs3 = guiCreateTab("Buttons", helphelpTabsPan) memo3 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpTabs3) helpState = true addEventHandler("onClientGUIClick", helpButton,onClickCloseBut) end end end --This closes it, but am I setting "helpState" correctly? function onClickCloseBut(button,state) if(button == "left" and state == "up") then if (source == helpButton) then guiSetVisible(helpWindow, false) destroyElement(helpWindow) helpWindow = nil showCursor(false) helpState = false end end end --KEY BIND. function bindTheKeys () bindKey ( "F1", "down", ShowHelp ) end addEventHandler("onClientPlayerJoin", getRootElement(), bindTheKeys ) Basically this is a lot to read, so top part before guiGetScreenSize and after the GUI stuff is probably where the problem is.... It is obvious but I have never tried binding keys to client before. Thanks for help! Link to comment
kikos500 Posted July 13, 2017 Share Posted July 13, 2017 (edited) helpGUI = {} local screenW, screenH = guiGetScreenSize() function ShowHelp() -- window helpGUI.window = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(helpGUI.window, false) guiSetAlpha(helpGUI.window, 0.92) guiSetProperty(helpGUI.window, "CaptionColour", "FFD7E21C") -- close button and tab panel helpGUI.close = guiCreateButton(485, 489, 96, 35, "Close", false, helpGUI.window) guiSetProperty(helpGUI.close, "NormalTextColour", "FFFE0000") helpGUI.tabpanel = guiCreateTabPanel(9, 28, 572, 461, false, helpGUI.window) -- Rules tab helpGUI.rules = guiCreateTab("Rules", helpGUI.tabpanel) helpGUI.memo1 = guiCreateMemo(6, 32, 561, 399, "Text goes here.", false, helpGUI.rules) helpGUI.label1 = guiCreateLabel(13, 10, 544, 26, "Label text goes here.", false, helpGUI.rules) guiLabelSetColor(helpGUI.label1, 255, 100, 25) -- Commands tab helpGUI.rules = guiCreateTab("Commands", helpGUI.tabpanel) helpGUI.memo2 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpGUI.rules) helpGUI.label2 = guiCreateLabel(15, 10, 544, 26, "Label text goes here.", false, helpGUI.rules) guiLabelSetColor(helpGUI.label2, 255, 100, 25) -- Buttons tab? wtf weird name ;-; helpGUI.buttons = guiCreateTab("Buttons", helpGUI.tabpanel) helpGUI.memo3 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpGUI.buttons) end addEventHandler( "onClientResourceStart", resourceRoot, ShowHelp) function guiClose() if source == helpGUI.close then guiSetVisible(helpWindow, false) showCursor(false) end end addEventHandler( "onClientGUIClick", root, guiClose) -- bind if u want it function bind() guiSetVisible(helpGUI.window, not guiGetVisible(helpGUI.window)) showCursor(guiGetVisible(helpGUI.window)) end bindKey("f1", "down", bind) try this i think it will work @kieran Edited July 13, 2017 by kikos500 1 Link to comment
kieran Posted July 13, 2017 Author Share Posted July 13, 2017 @kikos500 Nope, doesn't work.... Also the GUI was perfectly fine..... I was just wanting to bind a key to the function when player logged in and then check if the gui was visible, close it, else I wanted to open it..... Link to comment
kikos500 Posted July 13, 2017 Share Posted July 13, 2017 (edited) what doesn't work and i just cleaned up your code a bit ;( and btw helpTabs = {} helphelpTabsPan = {} helpLabel = {} helpButton = {} helpWindow = {} helpMemo = {} why were u adding tables while u r not using them? from what i saw u were replacing them with variables in ur script if u need i can give u a detailed explanation about how tables work helpGUI = {} local screenW, screenH = guiGetScreenSize() function ShowHelp() -- window helpGUI.window = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(helpGUI.window, false) guiSetAlpha(helpGUI.window, 0.92) guiSetProperty(helpGUI.window, "CaptionColour", "FFD7E21C") -- close button and tab panel helpGUI.close = guiCreateButton(485, 489, 96, 35, "Close", false, helpGUI.window) guiSetProperty(helpGUI.close, "NormalTextColour", "FFFE0000") helpGUI.tabpanel = guiCreateTabPanel(9, 28, 572, 461, false, helpGUI.window) -- Rules tab helpGUI.rules = guiCreateTab("Rules", helpGUI.tabpanel) helpGUI.memo1 = guiCreateMemo(6, 32, 561, 399, "Text goes here.", false, helpGUI.rules) helpGUI.label1 = guiCreateLabel(13, 10, 544, 26, "Label text goes here.", false, helpGUI.rules) guiLabelSetColor(helpGUI.label1, 255, 100, 25) -- Commands tab helpGUI.rules = guiCreateTab("Commands", helpGUI.tabpanel) helpGUI.memo2 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpGUI.rules) helpGUI.label2 = guiCreateLabel(15, 10, 544, 26, "Label text goes here.", false, helpGUI.rules) guiLabelSetColor(helpGUI.label2, 255, 100, 25) -- Buttons tab? wtf weird name ;-; helpGUI.buttons = guiCreateTab("Buttons", helpGUI.tabpanel) helpGUI.memo3 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpGUI.buttons) end addEventHandler( "onClientResourceStart", resourceRoot, ShowHelp) function guiClose() guiSetVisible(helpWindow, false) showCursor(false) end addEventHandler("onClientGUIClick", helpGUI.close, guiClose) -- bind if u want it function bind() guiSetVisible(helpGUI.window, not guiGetVisible(helpGUI.window)) showCursor(guiGetVisible(helpGUI.window)) end bindKey("f1", "down", bind) Edited July 13, 2017 by kikos500 Link to comment
Gordon_G Posted July 13, 2017 Share Posted July 13, 2017 (edited) Then, juste trigger the function bindKey clientside from serverside when the player login onPlayerLogin triggerClientEvent Edited July 13, 2017 by Gordon_G 1 Link to comment
kieran Posted July 14, 2017 Author Share Posted July 14, 2017 (edited) 2 hours ago, Gordon_G said: Then, juste trigger the function bindKey clientside from serverside when the player login onPlayerLogin triggerClientEvent Omg I feel so stupid ? I was thinking I needed to make event on it but wasn't too sure, thanks! 3 hours ago, kikos500 said: what doesn't work and i just cleaned up your code a bit ;( and btw helpTabs = {} helphelpTabsPan = {} helpLabel = {} helpButton = {} helpWindow = {} helpMemo = {} why were u adding tables while u r not using them? from what i saw u were replacing them with variables in ur script if u need i can give u a detailed explanation about how tables work helpGUI = {}local screenW, screenH = guiGetScreenSize()function ShowHelp() -- window helpGUI.window = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(helpGUI.window, false) guiSetAlpha(helpGUI.window, 0.92) guiSetProperty(helpGUI.window, "CaptionColour", "FFD7E21C") -- close button and tab panel helpGUI.close = guiCreateButton(485, 489, 96, 35, "Close", false, helpGUI.window) guiSetProperty(helpGUI.close, "NormalTextColour", "FFFE0000") helpGUI.tabpanel = guiCreateTabPanel(9, 28, 572, 461, false, helpGUI.window) -- Rules tab helpGUI.rules = guiCreateTab("Rules", helpGUI.tabpanel) helpGUI.memo1 = guiCreateMemo(6, 32, 561, 399, "Text goes here.", false, helpGUI.rules) helpGUI.label1 = guiCreateLabel(13, 10, 544, 26, "Label text goes here.", false, helpGUI.rules) guiLabelSetColor(helpGUI.label1, 255, 100, 25) -- Commands tab helpGUI.rules = guiCreateTab("Commands", helpGUI.tabpanel) helpGUI.memo2 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpGUI.rules) helpGUI.label2 = guiCreateLabel(15, 10, 544, 26, "Label text goes here.", false, helpGUI.rules) guiLabelSetColor(helpGUI.label2, 255, 100, 25) -- Buttons tab? wtf weird name ;-; helpGUI.buttons = guiCreateTab("Buttons", helpGUI.tabpanel) helpGUI.memo3 = guiCreateMemo(5, 32, 561, 399, "Text goes here.", false, helpGUI.buttons) endaddEventHandler( "onClientResourceStart", resourceRoot, ShowHelp)function guiClose() guiSetVisible(helpWindow, false) showCursor(false)endaddEventHandler("onClientGUIClick", helpGUI.close, guiClose)-- bind if u want it function bind() guiSetVisible(helpGUI.window, not guiGetVisible(helpGUI.window)) showCursor(guiGetVisible(helpGUI.window))endbindKey("f1", "down", bind) I done it that way because I used GUI editor, it is easier for me as I can just check top to see if I made typos etc. Also buttons tab is so I my list buttons as I have various binds, I was just struggling to bind GUI's, this is the second one I done, so still learning. Sorry for quoting, on tablet and it doesn't like mentions Edited July 14, 2017 by kieran Link to comment
kieran Posted July 14, 2017 Author Share Posted July 14, 2017 Thanks @kikos500..... But I wanted it so you didn't have to show GUI to get it visible I'll figure it out haha Link to comment
Simple0x47 Posted July 14, 2017 Share Posted July 14, 2017 3 hours ago, kieran said: Thanks @kikos500..... But I wanted it so you didn't have to show GUI to get it visible I'll figure it out haha What do you want being more detailed? 1 Link to comment
kieran Posted July 14, 2017 Author Share Posted July 14, 2017 23 minutes ago, Uknown. said: What do you want being more detailed? Okay, basically for now only way my GUI works is player logs in, it shows the GUI, then it checks visibility. The thing is I want to make it so my GUI doesn't have to come up for the script to notice an element is there.... Could I do this by simply binding a key to create gui or is it a little more complicated? Here's the current code (Yes I just kept it as is, easier than changing the original working script.) Server function HelpBinds() triggerClientEvent (source,"Help_Panel",getRootElement()) triggerClientEvent (source,"Help_Login",getRootElement()) end addEventHandler("onPlayerLogin", root, HelpBinds) Client local screenW, screenH = guiGetScreenSize() function ShowHelp() guiSetInputEnabled(false) showCursor(true) helpWindow = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(helpWindow, false) guiSetAlpha(helpWindow, 0.92) guiSetProperty(helpWindow, "CaptionColour", "FFD7E21C") CloseInfo = guiCreateLabel(230, 499, 196, 35, "F1 to close window", false, helpWindow) guiSetProperty(CloseInfo, "NormalTextColour", "FFFE0000") helphelpTabsPan = guiCreateTabPanel(9, 28, 572, 461, false, helpWindow) helpTabs = guiCreateTab("Tab1", helphelpTabsPan) memo = guiCreateMemo(6, 32, 561, 399, "Line 1. \n\nLine 2.", false, helpTabs) label = guiCreateLabel(13, 10, 544, 26, "Label", false, helpTabs) guiLabelSetColor(label, 255, 100, 25) helpTabs2 = guiCreateTab("Tab2", helphelpTabsPan) memo2 = guiCreateMemo(5, 32, 561, 399, "Line 1 \n/Line 2", false, helpTabs2) label2 = guiCreateLabel(15, 10, 544, 26, "Label", false, helpTabs2) guiLabelSetColor(label2, 255, 100, 25) helpTabs3 = guiCreateTab("Tab3", helphelpTabsPan) memo3 = guiCreateMemo(5, 32, 561, 399, "Line 1.\nLine2.", false, helpTabs3) end addEvent("Help_Login", true) addEventHandler("Help_Login", getRootElement(), ShowHelp) function DestroyGUI() if ( guiGetVisible ( helpWindow ) == false ) then guiSetVisible ( helpWindow, true ) showCursor(true) else guiSetVisible ( helpWindow, false ) showCursor(false) end end function binds() bindKey("f1", "down", DestroyGUI) end addEvent("Help_Panel", true) addEventHandler("Help_Panel", getRootElement(), binds) This works perfect, no problems in the code. But if you test this and remove the event "Help_Login" you will see my issue... It doesn't think a GUI is there, how can you keep a GUI closed for user but still bind it's window to a key? Link to comment
Simple0x47 Posted July 14, 2017 Share Posted July 14, 2017 (edited) So you're basically telling the bindKey is not made anymore so. addEvent( "Help_Login", true ) local guiElements = {} local screenW, screenH = guiGetScreenSize() function switchGUI() if ( guiElements[ 1 ] ) then showCursor( false ) for i = 1, #guiElements do local theElement = guiElements[ i ] destroyElement( theElement ) end else guiSetInputEnabled(false) showCursor(true) guiElements[ 1 ] = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(guiElements[ 1 ], false) guiSetAlpha(guiElements[ 1 ], 0.92) guiSetProperty(guiElements[ 1 ], "CaptionColour", "FFD7E21C") guiElements[ 2 ] = guiCreateLabel(230, 499, 196, 35, "F1 to close window", false, guiElements[ 1 ]) guiSetProperty(guiElements[ 2 ], "NormalTextColour", "FFFE0000") guiElements[ 3 ] = guiCreateTabPanel(9, 28, 572, 461, false, guiElements[ 1 ]) guiElements[ 4 ] = guiCreateTab("Tab1", guiElements[ 3 ]) guiElements[ 5 ] = guiCreateMemo(6, 32, 561, 399, "Line 1. \n\nLine 2.", false, guiElements[ 4 ] ) guiElements[ 6 ] = guiCreateLabel(13, 10, 544, 26, "Label", false, guiElements[ 4 ] ) guiLabelSetColor( guiElements[ 6 ], 255, 100, 25) guiElements[ 7 ] = guiCreateTab("Tab2", guiElements[ 3 ]) guiElements[ 8 ] = guiCreateMemo(5, 32, 561, 399, "Line 1 \n/Line 2", false, guiElements[ 7 ]) guiElements[ 9 ] = guiCreateLabel(15, 10, 544, 26, "Label", false, guiElements[ 7 ]) guiLabelSetColor( guiElements[ 9 ], 255, 100, 25) guiElements[ 10 ] = guiCreateTab("Tab3", guiElements[ 3 ]) guiElements[ 11 ] = guiCreateMemo(5, 32, 561, 399, "Line 1.\nLine2.", false, guiElements[ 10 ] ) end end bindKey( "f1", "down", switchGUI ) addEventHandler( "Help_Login", getRootElement(), switchGUI ) Edited July 14, 2017 by Uknown. Link to comment
kieran Posted July 14, 2017 Author Share Posted July 14, 2017 That permanently destroys the GUI when I press F1... WARNING:GUI\help.lua:10:Bad argument @ 'destroyElement' [Expected element at argument 1] That's my debugscript 3, I am not really experienced with stuff like for i = 1, #guiElements do local theElement = guiElements[ i ] destroyElement( theElement ) All I know is it basically groups it... Link to comment
Simple0x47 Posted July 14, 2017 Share Posted July 14, 2017 So you don't want to destroy it then no problem. addEvent( "Help_Login", true ) local guiElements = {} local screenW, screenH = guiGetScreenSize() function switchGUI() if ( guiElements[ 1 ] ) then if ( guiGetVisible( guiElements[ 1 ] ) then showCursor( false ) guiSetVisible( guiElements[ 1 ], false ) else guiSetInputEnabled(false) showCursor(true) guiSetVisible( guiElements[ 1 ], true ) end else guiSetInputEnabled(false) showCursor(true) guiElements[ 1 ] = guiCreateWindow((screenW - 591) / 2, (screenH - 534) / 2, 591, 534, "Information", false) guiWindowSetSizable(guiElements[ 1 ], false) guiSetAlpha(guiElements[ 1 ], 0.92) guiSetProperty(guiElements[ 1 ], "CaptionColour", "FFD7E21C") guiElements[ 2 ] = guiCreateLabel(230, 499, 196, 35, "F1 to close window", false, guiElements[ 1 ]) guiSetProperty(guiElements[ 2 ], "NormalTextColour", "FFFE0000") guiElements[ 3 ] = guiCreateTabPanel(9, 28, 572, 461, false, guiElements[ 1 ]) guiElements[ 4 ] = guiCreateTab("Tab1", guiElements[ 3 ]) guiElements[ 5 ] = guiCreateMemo(6, 32, 561, 399, "Line 1. \n\nLine 2.", false, guiElements[ 4 ] ) guiElements[ 6 ] = guiCreateLabel(13, 10, 544, 26, "Label", false, guiElements[ 4 ] ) guiLabelSetColor( guiElements[ 6 ], 255, 100, 25) guiElements[ 7 ] = guiCreateTab("Tab2", guiElements[ 3 ]) guiElements[ 8 ] = guiCreateMemo(5, 32, 561, 399, "Line 1 \n/Line 2", false, guiElements[ 7 ]) guiElements[ 9 ] = guiCreateLabel(15, 10, 544, 26, "Label", false, guiElements[ 7 ]) guiLabelSetColor( guiElements[ 9 ], 255, 100, 25) guiElements[ 10 ] = guiCreateTab("Tab3", guiElements[ 3 ]) guiElements[ 11 ] = guiCreateMemo(5, 32, 561, 399, "Line 1.\nLine2.", false, guiElements[ 10 ] ) end end bindKey( "f1", "down", switchGUI ) addEventHandler( "Help_Login", getRootElement(), switchGUI ) Link to comment
kieran Posted July 14, 2017 Author Share Posted July 14, 2017 OMG thank you @Uknown. it woked perfectly Link to comment
Simple0x47 Posted July 14, 2017 Share Posted July 14, 2017 8 minutes ago, kieran said: OMG thank you @Uknown. it woked perfectly No problem, if you want any more help contact me via, skype ( killer.68x ), email ( [email protected] ) or just by PM's 1 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