Jump to content

onClientGUIClick issue


StefanAlmighty

Recommended Posts

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

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

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