• Why won't this ENT:Think() work?
    1 replies, posted
What i'm trying to do is to constantly add velocity to props around an entity. For example, a black hole device of some sort. function ENT:Think() if (SERVER) then if !IsValid() then return end local pos = self:GetPos() local dmg = DamageInfo() dmg:SetDamage(self.DamageAmount) dmg:SetDamageType(self.DamageType) dmg:SetAttacker(self.GBOWNER) self.Bursts = self.Bursts + 1 if (self.Bursts >= self.Lifetime) then print("self.removed") self:Remove() elseif (self.Exploded) then print("elseif (self.Exploded) then") for k, v in pairs(ents.FindInSphere(pos,self.SpecialRadius)) do if IsValid(v) then --local phys = v:GetPhysicsObject() local i = 0 while i < v:GetPhysicsObjectCount() do print("WHILE") phys = v:GetPhysicsObjectNum(i) if (IsValid(phys)) then local mass = phys:GetMass() local F_ang = self.PhysForce local dist = (pos - v:GetPos()):Length() local relation = math.Clamp((self.SpecialRadius - dist) / self.SpecialRadius, 0,1) local F_dir = (v:GetPos() - pos):GetNormal() * self.PhysForce if(GetConVar("gb_unfreeze"):GetInt() >= 1) then phys:Wake() phys:EnableMotion(true) end phys:AddAngleVelocity(Vector(F_ang, F_ang, F_ang) * relation) phys:AddVelocity(F_dir) end i = i + 1 end end end end self:NextThink(CurTime() + self.DamageDelay) return true end end
There's your problem: if !IsValid() then return end For future, use [code] tags.
Sorry, you need to Log In to post a reply to this thread.