Jump to content

Problem with a chat script (GUI)


FSXTim

Recommended Posts

Hello,

I created an edit in my GUI. The player can put a text in it and he can also sent it to all the players.

clientside:

function sendenButton (state) 
    if state == "left" then 
        if source == senden_button then 
            local localp = getLocalPlayer() 
            local memoText = guiGetText(edit_memo) 
            if memoText ~= "" then 
                triggerServerEvent("userpanelText", getLocalPlayer(), localp, memoText) 
                guiSetText(edit_memo, "")  
            else 
                outoutChatBox("Du hast keinen Text eingegeben!", 255, 48, 48)  
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), sendenButton)  

serverside:

function userpanelText (localp, memoText) 
    local name = getPlayerName(localp) 
    outputChatBox("#FF0000"..name.."#FFFFFF: "..memoText.."", getRootElement(), 255, 255, 255, true) 
end 
addEvent ( "userpanelText", true ) 
addEventHandler ( "userpanelText", getRootElement(), userpanelText ) 

Problem:

When I put a text in the edit and press the button 'Senden', everything is working, example: "FSXTim: Hello!"

But when I do only press on the button 'Senden" and when I don't put a text in the edit, the chatbox sais that: "Tim:"

But it has to tell the local player: "Du hast keinen Text eingegeben!":

            if memoText ~= "" then 
                triggerServerEvent("userpanelText", getLocalPlayer(), localp, memoText) 
                guiSetText(edit_memo, "")  
            else 
                outoutChatBox("Du hast keinen Text eingegeben!", 255, 48, 48)  

Greets

Link to comment
function sendenButton (state) 
    if state == "left" then 
        if source == senden_button then 
            local localp = getLocalPlayer() 
            local memoText = guiGetText(edit_memo) 
            if memoText ~= "" then 
                triggerServerEvent("userpanelText", getLocalPlayer(), localp, memoText) 
                guiSetText(edit_memo, "")  
            elseif memoText ~= nil then 
                outputChatBox("Du hast keinen Text eingegeben!", 255, 48, 48)  
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), sendenButton)  

Link to comment
function sendenButton (state) 
    if state == "left" then 
        if source == senden_button then 
            local localp = getLocalPlayer() 
            local memoText = guiGetText(edit_memo) 
            if memoText ~= "" then 
                triggerServerEvent("userpanelText", getLocalPlayer(), localp, memoText) 
                guiSetText(edit_memo, "")  
            elseif memoText ~= nil then 
                outputChatBox("Du hast keinen Text eingegeben!", 255, 48, 48)  
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), sendenButton)  

Thanks, but still not working.

When I don't put a text in the edit, the chatbox sais: "Tim:"

Link to comment

Maybe try:

function sendenButton (state) 
    if state == "left" then 
        if source == senden_button then 
            local localp = getLocalPlayer() 
            local memoText = guiGetText(edit_memo) 
            if memoText ~= "" and memoText:len() > 1 then 
                triggerServerEvent("userpanelText", getLocalPlayer(), localp, memoText) 
                guiSetText(edit_memo, "") 
            else 
                outoutChatBox("Du hast keinen Text eingegeben!", 255, 48, 48) 
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), sendenButton)  

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