Jump to content

onClientGUIClick issue


StefanAlmighty

Recommended Posts

Posted

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?

Posted

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

Posted

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)  

Posted
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

Posted
  
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) 

Posted
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) 

Posted

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.

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