I’m trying to send a boolean from init to cl_init using Umsg.
Part of init.lua code
function ENT:Break()
umsg.Start("PrinterState")
umsg.Bool(true)
umsg.End()
printTimeStart = 1000
printTimeEnd = 2000
GAMEMODE:Notify(self.dt.owning_ent, 0, 4, "Your basic money printer has clogged up.")
if math.random(1, 11) == 3 then
self:BurstIntoFlames()
end
end
cl_init.lua code
include("shared.lua")
function ENT:Initialize()
end
function my_message_hook( um )
isBroken = um:ReadBool();
end
function ENT:Draw()
self.Entity:DrawModel()
local Pos = self:GetPos()
local Ang = self:GetAngles()
local owner = self.dt.owning_ent
owner = (ValidEntity(owner) and owner:Nick()) or "unknown"
surface.SetFont("HUDNumber5")
local TextWidth = surface.GetTextSize("Basic Money Printer");
local TextWidth2 = surface.GetTextSize(owner);
local TextWidth3 = surface.GetTextSize("Working");
Ang:RotateAroundAxis(Ang:Up(), 90)
cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
draw.WordBox(2, -TextWidth*0.5, -30, "Basic Money Printer", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
draw.WordBox(2, -TextWidth2*0.5, 18, owner, "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
if isBroken == false then
draw.WordBox(2, -TextWidth3*0.5, 56, "Working", "HUDNumber5", Color(140, 0, 0, 100), Color(0,255,0,255))
else
draw.WordBox(2, -TextWidth3*0.5, 56, "Broken", "HUDNumber5", Color(140, 0, 0, 100), Color(255,0,0,255))
end
cam.End3D2D()
end
function ENT:Think()
end
usermessage.Hook("PrinterState", my_message_hook)
The printer is constantly displaying broken, when it shouldn’t be. The Break function is rarely called, and it’s sending false everywhere else. It’s probably a simple mistake. I’m new to Lua and help would be appreciated, thank you :).