• Unhandled usermessage - Building Achievement Addon
    5 replies, posted
I'm building an achievement addon for my deathrun gamemode, but every time I try to use a usermessage, it plainly doesn't work. Here's the order of operation: Nubcake.lua runs the function 'EarnedAch' on round end (no conditional statements for bug testing) - This works EarnedAch updates the players coins, and sends a usermessage - This works However, the clientside file (client_usermessage.lua) isn't picking up the usermessage, and Unhandled usermessage is returned. Below is the entire code (Yes, it's not much, but It's just been started). [b]Autorun.lua[/b] [LUA] if SERVER then AddCSLuaFile("client_usermessage.lua") include("ach/functions/earned.lua") for _, v in pairs( file.FindInLua( "ach/*.lua")) do include("ach/"..v) end end [/LUA] [b]ach/functions/earned.lua[/b] - Proven to work (to a degree?), Updates coins, sends usermessage. [LUA] function EarnedAch(ply, ach, coins) local coinsG = ply:GetNWInt("COINS") sql.Query("UPDATE player_info SET COINS = "..coinsG + tonumber(coins).." WHERE unique_id = '"..ply:SteamID().."'") umsg.Start("earn_ach") umsg.Entity(ply) umsg.String(ach) umsg.String(coins) umsg.End() end [/LUA] [b]ach/Nubcake.lua[/b] - Proven to work, sets Pdata, updates coins, and sends usermessage. [LUA] include("functions/earned.lua") Nubcake = {} Nubcake.NAME = "Nubcake" Nubcake.COINGAIN = "5" Nubcake.DESC = "Win one Round." Nubcake.TYPE = "Round Result" Nubcake.NEEDVALUE = true function GetNubCake() for k, ply in pairs(player.GetAll()) do EarnedAch(ply, "Nubcake", "5") ply:SetPData("Nubcake", "1") end end hook.Add("RoundEnded", "ach_nubcake", GetNubCake) [/LUA] [b]client_usermessage.lua[/b] [LUA] local ColourTable = {} ColourTable["ach"] = Color(255, 201, 0) ColourTable[3] = Color(40, 40, 200) ColourTable[2] = Color(200, 40, 40) ColourTable[1] = Color(40, 200, 40) ColourTable[0] = Color(255,255,255) usermessage.Hook("earn_ach", function(um) local PlayerEnt = um:ReadEntity() local achievement = um:ReadString() local coins = um:ReadString() chat.AddText(ColourTable[1], PlayerEnt:Name(), Color(255,255,255), " has earnt the achievement ", ColourTable["ach"], achievement) end) [/LUA] TL;DR Usermessages in my addon aren't working, tell me how to setup all the files, or where I spelt something wrong so it will.
You need to include it clientside.
Added to autorun.lua : If CLIENT then include("client_usermessage.lua") end Still nothing
on the server you need to put [lua] AddCSLuaFile("client_usermessage.lua") [/lua]
But I already have that in Autorun.lua Isn't that already correct?
if CLIENT then include("client_usermessage.lua") end
Sorry, you need to Log In to post a reply to this thread.