• Spawning ENT once
    2 replies, posted
In my init.lua I have net.Receive("spawn", function()     local recipe = net.ReadString()     local ent = net.ReadEntity()     local spawned     if(recipe == "Bread") then         ent:SetItemOne("")         ent:SetItemTwo("")         local bread = ents.Create("bread")         --print("spawning bread")         --bread:SetModel("models/foodnhouseholditems/bread-3.mdl")         bread:SetPos(ent:GetPos()+Vector(0,0,50))         bread:Spawn()     end end) which spawns my ENT, but I only want it to do it once, the net send is in my cl_init.lua and looks like function ENT:Draw() if(recipe == "Bread") then net.Start("spawn") net.WriteString("Bread") net.WriteEntity(self) net.SendToServer() end end ENT:Draw() is called constantly, but I only want the bread:Spawn() to happen once, how would I go about doing this? I tried cutting off the if(recipe == "Bread") but it is still too slow and spawns around 10 Thank you, Endus
Why are you doing net logic in Draw to begin with? You could do it in Think. Regardless, you need to keep track of whether or not you spawned the associated entity. function ENT:Think() if self.SpawnedRecipe then return end if (recipe == "Bread") then net.Start("spawn") net.WriteString(recipe) net.WriteEntity(self) net.SendToServer() self.SpawnedRecipe = true end end
I was doing it in Draw since I had 3D2D I was using alongside it
Sorry, you need to Log In to post a reply to this thread.