StefanAlmighty Posted February 22, 2016 Share Posted February 22, 2016 Okay so I have the following event handler inside of a function: addEventHandler("onClientGUIClick", source, function() local statement = nil if source == cpCopyAccount then statement = guiGetText(cpInfoAccount2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpCopySerial then statement = guiGetText(cpInfoSerial2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpCopyIP then statement = guiGetText(cpInfoIP2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpBanReason then guiSetText(cpBanReason, "") elseif source == cpBanTime then guiSetText(cpBanTime, "") elseif source == cpJailReason then guiSetText(cpJailReason, "") elseif source == cpJailTime then guiSetText(cpJailTime, "") elseif source == cpWarnReason then guiSetText(cpWarnReason, "") end end) cpCopyAccount button should copy the players account name to the clipboard, and it does. However, if I open the menu and copy once it works fine. If I close the menu, open it again and click the button it copies it twice. If I close it again and open it, it copies it three times and so on. Could somebody please help? Link to comment
tosfera Posted February 22, 2016 Share Posted February 22, 2016 you're adding the event over and over again. You should move the function you've created inline into it's own function, and add/remove the onClientGUIClick handler on the open/close event from the menu. Link to comment
KariiiM Posted February 22, 2016 Share Posted February 22, 2016 Well, If I understood you well, this might work for you addEventHandler("onClientGUIClick", source, function() local statement = nil if source == cpCopyAccount then statement = guiGetText(cpInfoAccount2) local clip1 = setClipboard(statement) if clip1 then outputChatBox("Copied: " .. statement) end elseif source == cpCopySerial then statement = guiGetText(cpInfoSerial2) local clip2 = setClipboard(statement) if clip2 then outputChatBox("Copied: " .. statement) end elseif source == cpCopyIP then statement = guiGetText(cpInfoIP2) local clip3 = setClipboard(statement) if clip3 then outputChatBox("Copied: " .. statement) end elseif source == cpBanReason then guiSetText(cpBanReason, "") elseif source == cpBanTime then guiSetText(cpBanTime, "") elseif source == cpJailReason then guiSetText(cpJailReason, "") elseif source == cpJailTime then guiSetText(cpJailTime, "") elseif source == cpWarnReason then guiSetText(cpWarnReason, "") end end) Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 Is there a way to destroy/kill an event? Link to comment
KariiiM Posted February 22, 2016 Share Posted February 22, 2016 Is there a way to destroy/kill an event? yeah try removeEventHandler Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 removeEventHandler("onClientGUIClick", source, function) Gives me errors such as expected symbol (, but when I add it, it doesn't work. Seems like it doesn't recognise function. Link to comment
KariiiM Posted February 22, 2016 Share Posted February 22, 2016 The function must be defined to remove the event handler, like that you're just trying to remove an unknown event, which make no sense Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 When I replace 'function' with a name, it still doesn't work. Link to comment
KariiiM Posted February 22, 2016 Share Posted February 22, 2016 When I replace 'function' with a name, it still doesn't work. Post what you have tried, btw why are you attaching source to the event handler? it must be root or guiRoot Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 addEventHandler("onClientGUIClick", guiRoot, onClickButton() local statement = nil if source == cpCopyAccount then statement = guiGetText(cpInfoAccount2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpCopySerial then statement = guiGetText(cpInfoSerial2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpCopyIP then statement = guiGetText(cpInfoIP2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpBanReason then guiSetText(cpBanReason, "") elseif source == cpBanTime then guiSetText(cpBanTime, "") elseif source == cpJailReason then guiSetText(cpJailReason, "") elseif source == cpJailTime then guiSetText(cpJailTime, "") elseif source == cpWarnReason then guiSetText(cpWarnReason, "") end end) Later.. removeEventHandler("onClientGUIClick", source, onClickButton) Link to comment
KariiiM Posted February 22, 2016 Share Posted February 22, 2016 removeEventHandler("onClientGUIClick", guiRoot, onClickButton) EDIT: I just saw your main code wasn't fine, copy it function onClickButton() local statement = nil if source == cpCopyAccount then statement = guiGetText(cpInfoAccount2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpCopySerial then statement = guiGetText(cpInfoSerial2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpCopyIP then statement = guiGetText(cpInfoIP2) setClipboard(statement) outputChatBox("Copied: " .. statement) elseif source == cpBanReason then guiSetText(cpBanReason, "") elseif source == cpBanTime then guiSetText(cpBanTime, "") elseif source == cpJailReason then guiSetText(cpJailReason, "") elseif source == cpJailTime then guiSetText(cpJailTime, "") elseif source == cpWarnReason then guiSetText(cpWarnReason, "") end end addEventHandler("onClientGUIClick", guiRoot, onClickButton) Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 All working, thanks. Link to comment
KariiiM Posted February 22, 2016 Share Posted February 22, 2016 All working, thanks. You are welcome Stefan Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 One more thing, how do I make edit boxes have an invisible white background? I want to use an edit box for a custom login screen, but I only want to use the text part and remove the white background area. I've seen it done before. Link to comment
Bonus Posted February 22, 2016 Share Posted February 22, 2016 I think that's called Label. You can edit it with onClientKey. Link to comment
StefanAlmighty Posted February 22, 2016 Author Share Posted February 22, 2016 And how do I slide an image across the screen like a transition? 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