Mr.unpredictable. Posted June 25, 2014 Share Posted June 25, 2014 few days ago i created a script in which when i do /getnrg i get nrg and when i do /getfcr i get fcr then i though of creating a gui pic of the gui http://i.imgur.com/tr2aKBy.png code: GUIEditor = { button = {}, window = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1]) end ) my problem is that how do i link those command to those buttons? like when i click on get nrg button the server automatically does /getnrg and give me nrg Link to comment
Castillo Posted June 25, 2014 Share Posted June 25, 2014 You can use the function executeCommandHandler Use onClientGUIClick to link the button to a function. Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 You can use the function executeCommandHandler Use onClientGUIClick to link the button to a function. can you give me a example you mean should i menstion button name in onclient gui click ? Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 (edited) i got another problem can anyone help ?? my bind key is not working for the gui here is my code GUIEditor = { button = {}, window = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1]) end ) bindKey("F2","down", function () guiSetText(GUIEditor.label[1],tostring(getElementData(localPlayer,"window[1]"))) if visbWndw then guiSetVisible(GUIEditor.window[1],false) showCursor(false) else guiSetVisible(GUIEditor.window[1],true) showCursor(true) end visbWndw = not visbWndw end) end ) can any find why it's not working ? Edited April 9, 2015 by Guest Link to comment
Castillo Posted June 25, 2014 Share Posted June 25, 2014 addEvent('startdraw',true) addEvent('stopdraw',true) local screenx,screeny = guiGetScreenSize() GUIEditor = { button = {}, window = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1]) end ) bindKey ( "F2", "down", function ( ) local state = ( not guiGetVisible ( GUIEditor.window[1] ) ) guiSetVisible ( GUIEditor.window[1], state ) showCursor ( state ) end ) Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 thanks bind key is working Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 can you fix this i just made for linking the button to the command, sorry if i'm asking too many question , i am not that good lua scripter. addEventHandler ( "onClientGUIClick", GUIEditor.button[1], getnrggui, false ) function getnrggui () executeCommandHandler("getnrg",playersource) end the commands are in server side so not sure if it will work Link to comment
Castillo Posted June 25, 2014 Share Posted June 25, 2014 You can't execute server-side commands from the client side. Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 You can't execute server-side commands from the client side. then how do link those buttons? Link to comment
Castillo Posted June 25, 2014 Share Posted June 25, 2014 You can use triggerServerEvent and execute the command server-side. Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 addEventHandler ( "onClientGUIClick", GUIEditor.button[1], getnrggui, false ) function getnrggui () triggerServerEvent ( "getbike", localPlayer ) end is this correct Link to comment
Castillo Posted June 25, 2014 Share Posted June 25, 2014 The addEventHandler has to go inside the function where you create the GUI. Link to comment
Mr.unpredictable. Posted June 25, 2014 Author Share Posted June 25, 2014 new code addEvent('startdraw',true) addEvent('stopdraw',true) local screenx,screeny = guiGetScreenSize() GUIEditor = { button = {}, window = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1]) end addEventHandler ( "onClientGUIClick", GUIEditor.button[1], getnrggui, false ) end ) bindKey ( "F2", "down", function ( ) local state = ( not guiGetVisible ( GUIEditor.window[1] ) ) guiSetVisible ( GUIEditor.window[1], state ) showCursor ( state ) end ) function getnrggui () triggerServerEvent ( "getbike", localPlayer ) end) not working Link to comment
Castillo Posted June 25, 2014 Share Posted June 25, 2014 You got 1 extra end before addEventHandler, remove it. Link to comment
Mr.unpredictable. Posted June 26, 2014 Author Share Posted June 26, 2014 it's not working can i use this function to link server side command to client side gui button ? callServerFunction Link to comment
Castillo Posted June 26, 2014 Share Posted June 26, 2014 Maybe you can, but I'm not sure how good is it. 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