• 2 Entities Colliding = new ent.Create??
    11 replies, posted
I'm hoping to make two entities touch eachother to create a new entity on their position when they collide. Example: seed + pot = plant How do I detect collision to make an output of ent.Create ? A mixture system, in that style. Thank you in advance for any help! I appreciate it.
isnt it like a [LUA]function ENT:Touch() t -- CODE end [/LUA]
[lua]-- Pot code, init function ENT:Touch(hitEntity) -- Code -- Example hitEntity:GetClass() == "seed" then self.Entity:SetModel("something_else.mdl") end end [/lua]
[QUOTE=ms333;39580761][lua]-- Pot code, init function ENT:Touch(hitEntity) -- Code -- Example hitEntity:GetClass() == "seed" then self.Entity:SetModel("something_else.mdl") end end [/lua][/QUOTE] Will this not just replace the model? I want it to create a totally different entity. For example: [lua]-- Pot code, init function ENT:Touch(hitEntity) -- Code -- Example hitEntity:GetClass() == "seed" then ent.Create("plant") end end [/lua] Is this possible?
YOu can specify to remove the one entity and spawn a new one, simple as that
Ok, so here's my update [lua]Craft = 0 function ENT.Touch(self, hitEnt) if (CurTime() >= Craft) and hitEnt:GetClass() == "meth" then Craft = CurTime() + 1 hitEnt:Remove() self:Remove() local product = ents.Create("printer_lvlone") product:SetPos( self:GetPos() + Vector(0,0,20) ) end end[/lua] There aren't any lua errors now, both of the existing entities remove but the new one doesn't spawn. Any ideas?
Using the right model ? or ent name ? and self:GetPos() is invalid since it was romoved before that, so stoe the pos some where in like a "local pos = self:GetPos()" at the top
[QUOTE=MICKMAC;39581400]Ok, so here's my update [lua]Craft = 0 function ENT.Touch(self, hitEnt) if (CurTime() >= Craft) and hitEnt:GetClass() == "meth" then Craft = CurTime() + 1 hitEnt:Remove() self:Remove() local product = ents.Create("printer_lvlone") product:SetPos( self:GetPos() + Vector(0,0,20) ) end end[/lua] There aren't any lua errors now, both of the existing entities remove but the new one doesn't spawn. Any ideas?[/QUOTE] Spawn the new ent first, since your removing the old one and then getting a pos from the old one (When it doesn't exist) and trying to spawn a new one. If that makes any sense.
[QUOTE=Sudoxe;39581492]Spawn the new ent first, since your removing the old one and then getting a pos from the old one (When it doesn't exist) and trying to spawn a new one. If that makes any sense.[/QUOTE] Yeah that makes sense. Updated to: [lua]Craft = 0 function ENT.Touch(self, hitEnt) if (CurTime() >= Craft) and hitEnt:GetClass() == "meth" then Craft = CurTime() + 1 local product = ents.Create("weed_plant") product:SetPos( self:GetPos() + Vector(0,0,20) ) hitEnt:Remove() self:Remove() end end[/lua] This doesn't work, exact same problem. No entity is created, but the existing entities are still removed.
Is the entity your creating valid ?
Oh wow, I fixed it. missed this: product:Spawn() [b] LINE 8 [/b] Fixed code: [lua]Craft = 0 function ENT.Touch(self, hitEnt) if (CurTime() >= Craft) and hitEnt:GetClass() == "meth" then Craft = CurTime() + 1 local product = ents.Create("printer_lvlone") product:SetPos( self:GetPos() + Vector(0,0,20) ) product:Spawn() hitEnt:Remove() self:Remove() end end[/lua] [editline]14th February 2013[/editline] Is there a way to make the entity spawned set the owner to whoever forces the entities to collide? Last part of this and I'm done on this project.
I would use ENT:StartTouch() instead @Edit: Also point of note, have you been to CheesecakeRP ? Because I got the same thing on my server, I made upgradable printers.
Sorry, you need to Log In to post a reply to this thread.