• Entity respawn
    4 replies, posted
Im trying to make an entity get removed after you press e and after this new entities will spawn. it code works but deleting entities after they spawn. help me please . sorry for my english function ENT:Use(pl) if ((self.nextUse or 0) >= CurTime()) then return end self.lastComp1 = ent1 self.lastComp2 = ent2 self:EmitSound("ambient/levels/canals/toxic_slime_sizzle3.wav", 70, 100, 0.2); self.nextUse = CurTime() + 2 timer.Create( "Deleteiflongtime", 180, 1, function() self.lastComp1:Remove() self.lastComp2:Remove() end ) self.lastComp1:Remove()  self.lastComp2:Remove() local ent2 = ents.Create("eml_comp2") ent2:SetPos( self.poscomp2 ) ent2:Spawn() local ent1 = ents.Create("eml_comp1") ent1:SetPos( self.poscomp1 ) ent1:Spawn() end
Do the eml_comp entities happen to have a Use() function in them, and are they within use range when they spawn? Also your timer name is not unique and will keep overriding itself, use EntIndex somewhere in the identifier.
function ENT:Use(pl) if ((self.nextUse or 0) >= CurTime()) then return end local ent1 = ents.Create("eml_comp1") ent1:SetPos( self.poscomp1 ) ent1:Spawn() self.lastComp1 = ent1 local ent2 = ents.Create("eml_comp2") ent2:SetPos( self.poscomp2 ) ent2:Spawn() self.lastComp2 = ent2 self:EmitSound("ambient/levels/canals/toxic_slime_sizzle3.wav", 70, 100, 0.2); self.nextUse = CurTime() + 2       self.lastComp1:Remove() self.lastComp2:Remove() end the timer doesn't matter , I'll remove it. Need to old components were removed, and new spawn. in the current code, they are spawned and deleted. this is the code of the entity which will spawn components and such entities may be many and each must delete and spawn his components.
Wat? [code] function ENT:Initialize() self.nextUse = CurTime() + 1 end function ENT:Use() if self.nextUse > CurTime() then return end -- here ur code end [/code]
In the code you just provided, you're removing them right after spawning them, if you want to remove the previous two and spawn two new you need to move the Remove() calls to be before assign the new entities as the lastComp variables. If I understand you correctly, this should be what you want. https://gist.github.com/idubs/b7edf75e38d79eafa0ebc7701adcb740
Sorry, you need to Log In to post a reply to this thread.