• Help with Entity and Net Library
    2 replies, posted
Alright, so i'm fairly new to lua and i've been trying to make a basic weed growing addon, but i've ran into a few hitches with the Net Library. Now I may just be retarded and can't see the obvious error(s). I'm trying to get the message "Growing..." appear of the 3D2D panel when a seed is put into the pot. If it's not obvious this is the first time i've used the net messages :v: [B]init.lua (Serverside)[/B] [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") util.AddNetworkString("GrowingMsg") function ENT:Initialize() self:SetModel("models/nater/weedplant_pot_dirt.mdl") self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end self.isGrowing = false self.finishGrowing = 0 end function ENT:StartTouch(ent) if ent:GetClass() == "seed" and self.isGrowing == false then ent:Remove() self.isGrowing = true self.finishGrowing = CurTime() + 5 // This is set to 5 for testing end end function ENT:Think() if self.isGrowing == true then self:SetColor(Color(0,255,0)) self:SetModel("models/nater/weedplant_pot_growing1.mdl") net.Start("GrowingMsg") net.Send() else self:SetColor(Color(255,0,0)) end if self.isGrowing == true then if self.finishGrowing <= CurTime() then self:SetModel("models/nater/weedplant_pot_dirt.mdl") self.isGrowing = false local weed = ents.Create("weed") weed:SetPos(self:GetPos() + Vector(0,0,30)) weed:Spawn() end end end[/CODE] [B]cl_init.lua (Clientside)[/B] [CODE]include("shared.lua") surface.CreateFont( "PlantFont", { font = "Arial", extended = false, size = 40, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } ) function ENT:Draw() self:DrawModel() local ang = self:GetAngles() ang:RotateAroundAxis(self:GetAngles():Up(),90) ang:RotateAroundAxis(self:GetAngles():Right(),-90) cam.Start3D2D(self:GetPos(), ang, 0.1) draw.RoundedBox(10,-110,-300,200,100,Color(0,0,0,200)) local function growingFunc() draw.SimpleText("Growing...", "PlantFont", 75,-280,Color(120,120,255),2,2) end net.Receive("GrowingMsg", growingFunc); cam.End3D2D() end[/CODE]
Your net.Receive cannot be inside of any other function. Place it outside of ENT.Draw and have it maybe set a variable to true. If that variable is true then draw that text and box inside of ENT.Draw. [editline]16th May 2017[/editline] Also be careful using net messages in a Think hook. If self.IsGrowing is true for more than one time you will be sending net messages way too often. What you should do instead is send a net message when the growing starts to display the text, then send a message when the growing stops to remove the text. An even better solution would be a NetworkVar.
net.Send() doesn't have a receiver (Missing first argument). Use net.Broadcast() if you want to send a net message to all players.
Sorry, you need to Log In to post a reply to this thread.