Unhandled Usermessage

I had them in an add-on, but it wouldn’t automatically run when I joined a single player game. I put the scripts in the Lua folder and manually ran them to see if I could get them to work, but when I type the !war command, the “Warning: Unhandled usermessage ‘wgui_open’” pops up in the console. Am I doing something wrong? Should I use something other than usermessages, and if so, what should I use? Any help is appreciated. Let me know if you need more info and sorry if this message is in the wrong place or has been posted before. I couldn’t find anything, and the GMod Wiki was no help. Thanks!

Here’s my client script:


usermessage.Hook("wgui_open",function()
    local BG = vgui.Create("DFrame")
    BG:SetPos(ScrW()/5,ScrW()/5)
    BG:SetSize(ScrW()/5,ScrH()/3)
    BG:SetTitle( "War Voting GUI" )
    BG:SetVisible(true)
    BG:SetDraggable(true)
    BG:ShowCloseButton(true)
    BG:MakePopup()
    
    local vforb = vgui.Create("DButton",BG)
    vforb:SetSize(BG:GetWide()-20,(BG:GetTall()/2)-40)
    vforb:SetText("Vote for war")
    vforb:SetPos(10,30)
    vforb.DoClick = function()
        RunConsoleCommand("war_vote","1")
    end
    
    local vendb = vgui.Create("DButton",BG)
    vendb:SetSize(BG:GetWide()-20,(BG:GetTall()/2)-40)
    vendb:SetText("Vote against war")
    vendb:SetPos(10,(BG:GetTall()/2)+30)
    vendb.DoClick = function()
        RunConsoleCommand("war_vote","0")
    end
end)

And here’s my server code:


local function wguiOpen()
    umsg.Start("wgui_open");
    umsg.End();
end

function onPlayerSay(ply,txt,_)
	if txt=="!war" then
        if can_vote == 1 then
            wguiOpen()
        else
            ply:PrintMessage(HUD_PRINTTALK,"You need to wait longer before theres another vote.")
            return ""
        end
	end
end

AddCSLuaFile("autorun/client/wgui_cl.lua")
hook.Add("PlayerSay", "wgui_chat", onPlayerSay)

--[[------------------------]]--

war_on = 0
voting = 0
can_vote = 1
voted = {}
votes = 0

function vote(ply,_,args)
    if voting == 0 then
        if args[1] == "1" then
            voted[1] = ply
            votes = votes + 1
        elseif args[1] == "0" then
            voted[1] = ply
            votes = votes - 1
        end
        PrintMessage(HUD_PRINTCENTER,ply:GetName().." has statred a war vote!")
        PrintMessage(HUD_PRINTTALK,"The vote will end in 60 seconds.")
        ply:PrintMessage(HUD_PRINTTALK,"Your vote has been counted.")
        wguiOpen()
        timer.Create("vote_end",30,1,endVote)
        timer.Create("vote_allowed",300,1,function()
            can_vote = 1
        end)
        voting = 1
    elseif voting == 1 then
        for i=0,MaxPlayers() do
            if voted* == nil then
                voted* = ply
                if args[1] == "1" then
                    votes = votes + 1
                elseif args[1] == "0" then
                    votes = votes - 1
                end
                ply:PrintMessage(HUD_PRINTTALK,"Your vote has been counted.")
                break
            elseif voted* == ply then
                ply:PrintMessage(HUD_PRINTTALK,"You already voted!")
                break
            end
        end
    end
end

concommand.Add("war_vote",vote)

function grav(ply,_,arg)
    RunConsoleCommand("sv_gravity "..arg[1])
end

concommand.Add("zombie_grav",grav)

function endVote()
    if votes > 0 then
        PrintMessage(HUD_PRINTTALK,"More people have voted for war, noclip and godmode are off.")
        war_on = 1
    else
        PrintMessage(HUD_PRINTTALK,"More people have voted against war, noclip and godmode are on.")
        war_on = 0
    end
    voting = 0
    table.Empty(votesF)
    table.Empty(votesA)
    table.Empty(players)
end

hook.Add("Think","war_var",function()
    if war_on == 1 then
        RunConsoleCommand("sbox_noclip","0")
        RunConsoleCommand("sbox_godmode","0")
        RunConsoleCommand("say","!noclip * 0")
    else
        RunConsoleCommand("sbox_noclip","1")
        RunConsoleCommand("sbox_godmode","1")
    end
end)

it means your clientside script isn’t being sent to clients

Wouldn’t AddCSLuaFile(“autorun/client/wgui_cl.lua”) send it to the client? I have the name and directory correct, I just double checked that.

check for lua errors

I didn’t get any Lua errors when I ran them. The only error I got at all was the usermessage error. :confused:

try changing the usermessages name to something else.

It may work, this is happened to me before.

I changed it several times, but I will try again to see if it has an effect.

[editline]12th June 2012[/editline]

Interesting… switching the usermessage identifier from ‘wgui_open’ to ‘open_wgui’ seems to have worked. Not sure if that was it though, I also renamed the files and changed some variables. But I guess something did it. And for all I know, it wouldn’t have happened without all of you, so thanks everyone! :slight_smile: