brocky Posted May 30, 2018 Share Posted May 30, 2018 Hey, I don't know whats wrong in this guy. any ideas? GUIEditor = { button = {}, window = {}, memo = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1]) button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1]) end ) function closeButton() if button1 == source then outputChatBox("Hey") end end addEventHandler("onClientGUIClick",button1,closeButton,false) Link to comment
Z4Zy Posted May 31, 2018 Share Posted May 31, 2018 (edited) Client Side :- GUIEditor = { button = {}, window = {}, memo = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1]) button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1]) end ) function closeButton() if source == button1 then outputChatBox("Hey") end end addEventHandler("onClientGUIClick", resourceRoot, closeButton) Or , Client Side :- GUIEditor = { button = {}, window = {}, memo = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1]) button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1]) addEventHandler("onClientGUIClick", button1, closeButton) end ) function closeButton() outputChatBox("Hey") end Edited May 31, 2018 by DeadthStrock Link to comment
AJXB Posted May 31, 2018 Share Posted May 31, 2018 1 hour ago, DeadthStrock said: Client Side :- GUIEditor = { button = {}, window = {}, memo = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1]) button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1]) end ) function closeButton() if source == button1 then outputChatBox("Hey") end end addEventHandler("onClientGUIClick", resourceRoot, closeButton) Or , Client Side :- GUIEditor = { button = {}, window = {}, memo = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1]) button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1]) addEventHandler("onClientGUIClick", button1, closeButton) end ) function closeButton() outputChatBox("Hey") end No, your first option is correct, not the second. Link to comment
Z4Zy Posted May 31, 2018 Share Posted May 31, 2018 1 hour ago, gSub said: No, your first option is correct, not the second. What is the reason ?? Link to comment
AJXB Posted May 31, 2018 Share Posted May 31, 2018 7 hours ago, DeadthStrock said: What is the reason ?? Compatibility issues if you put the GUI element in the event handler Link to comment
Z4Zy Posted May 31, 2018 Share Posted May 31, 2018 (edited) 9 minutes ago, gSub said: Compatibility issues if you put the GUI element in the event handler Quoted :- https://wiki.multitheftauto.com/wiki/GuiCreateButton --create our button button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) --Create an edit box and define it as "editBox". editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true ) -- and attach our button to the outputEditBox function addEventHandler ( "onClientGUIClick", editBox, outputEditBox ) guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this --setup our function to output the message to the chatbox function outputEditBox () local text = guiGetText ( editBox )--get the text from the edit box outputChatBox ( text ) --output that text end addEventHandler ( "onClientGUIClick", button, outputEditBox ) MTA:Wiki also guide that...!! Well Well as you said Compatibility may issues if we put the GUI element in the event handler. Edited May 31, 2018 by DeadthStrock Link to comment
AJXB Posted May 31, 2018 Share Posted May 31, 2018 4 minutes ago, DeadthStrock said: Quoted :- https://wiki.multitheftauto.com/wiki/GuiCreateButton --create our button button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) --Create an edit box and define it as "editBox". editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true ) -- and attach our button to the outputEditBox function addEventHandler ( "onClientGUIClick", editBox, outputEditBox ) guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this --setup our function to output the message to the chatbox function outputEditBox () local text = guiGetText ( editBox )--get the text from the edit box outputChatBox ( text ) --output that text end addEventHandler ( "onClientGUIClick", button, outputEditBox ) MTA:Wiki also guide that...!! Well Well as you said Compatibility may issues if we put the GUI element in the event handler. Yep, and I still stand by word. the GUI sometimes calculates the actual button element a bit larger than the actual displayed unit, or since it's attached to the GUI window, it sometimes confuses that as well. So that means when you click outside of a button, it triggers the button. Feel free to use any method you like, but what I use to avoid any type of issue is the first solution. 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