• Edit My Entity?
    7 replies, posted
Hey, im working on an ENT that takes three normal or mixed drugs, and bumps it up to One of its higher class. the problem is, is that it spawns a medium AND a super drugs, and if it manages to Touch it again, it spawns another set. So my question is, how can i get it to spawn JUST one? and how can i set it so that the drugs dont get sucked right back up after spawning? [lua] AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/props_lab/crematorcase.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys and phys:IsValid() then phys:Wake() end self.sparking = false self.damage = 100 end function ENT:OnTakeDamage(dmg) self.damage = self.damage - dmg:GetDamage() if (self.damage <= 0) then self:Remove() end end function ENT:Destruct() local vPoint = self:GetPos() local effectdata = EffectData() effectdata:SetStart(vPoint) effectdata:SetOrigin(vPoint) effectdata:SetScale(1) util.Effect("Explosion", effectdata) end local n = 0 -- Start count at zero local m = 0 function ENT:Touch( hitEnt ) if self.sparking then return end if (hitEnt:GetClass() == 'normaldrugs') then -- If the thing we want to touch it touches it hitEnt:Remove() -- Remove it n = n +1 -- Increment counter if (n == 3) then -- Hit target count -- Reset counter self.sparking = true n = 0 timer.Create( "n_timer", 30, 0, function() local ent = ents.Create('mixeddrugs') local phys = ent:GetPhysicsObject() ent:SetPos(self:GetPos()+Vector(0,0,100)) ent:Spawn() if phys and phys:IsValid() then phys:EnableMotion(false) end self.sparking = false end) end end if (hitEnt:GetClass() == 'mixeddrugs') then -- If the thing we want to touch it touches it hitEnt:Remove() -- Remove it m = m +1 -- Increment counter if (m == 3) then -- Hit target count -- Reset counter self.sparking = true m = 0 timer.Create( "m_timer", 30, 0, function() local ent = ents.Create('superdrugs') local phys = ent:GetPhysicsObject() ent:SetPos(self:GetPos()+Vector(0,0,100)) ent:Spawn() if phys and phys:IsValid() then phys:EnableMotion(false) end self.sparking = false end) end end end function ENT:Think() if self.sparking then local effectdata = EffectData() effectdata:SetOrigin(self:GetPos()) effectdata:SetMagnitude(1) effectdata:SetScale(1) effectdata:SetRadius(2) util.Effect("Sparks", effectdata) end end function ENT:OnRemove() self:Destruct() timer.Destroy(self) m = 0 n = 0 end [/lua] TIA
self:Remove() =S
im not trying to GET RID of the entity that is converting the others...
No, use self:Remove to get rid of one of the duplicates
Replace timer.Create( "n_timer", 30, 0, function() with timer.Simple(30, function() That would fix your problem, and use separate locals for ents like local entdrug and local entsuperdrug.
okay, one more Q. is there any way to set it so either only ONE face of the Converter entity (a stove in this case, most preferably the front) will suck up the Normal/mixed drugs, or is there any other way to make it so that this entity doesnt immediately suck up the Mixed drugs that it creates after creating them?
Im not great with entities, but if you want only the front I might create an entity when that entity is created, with the model of a phx panel and set it invisible. And make it change it's pos to the entity that created it. And use that panel for the collision. And if you don't want "suck up Mixed drugs that it creates after creating them", make it so it only does it if ent.Test is == 1, and then set it to 0, make a timer, then set it to 1. Rate me bad reading of necessary. I'm tired, so I don't quite understand what you want. xD
Can someone give me the EXACT code to put a PHX plate in front of this thing, give it a name, and make it so that the ENT.Touch only works with that?
Sorry, you need to Log In to post a reply to this thread.