• For k,v loop not accurately doing its job
    5 replies, posted
Hey all i recently made a post in regards to my entity. its drawing correctly however, the same method doing the calculation of render.DrawSphere for the size isn't working accurately in my entity. [lua] function ENT:Initialize() self.Size=50 self.Growing=true self:SetModel("models/hunter/blocks/cube025x025x025.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_NONE) self:SetSolid(SOLID_VPHYSICS) self.Name = "sphere" local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end end function ENT:Use( activator, caller ) return end function ENT:Think() local d=FrameTime() if self.Growing==true then self.Size=math.Clamp(self.Size+350*d, 0, 1800) else self.Size=math.Clamp(self.Size-1300*d, 50, 1800) end if self.Size==1800 then self.Growing=false end if self.Size==50 then self.Growing=true end for k,v in pairs(ents.FindInSphere(self:GetPos(),self.Size)) do if v:IsPlayer() or v:IsNPC() or v:Alive() then local d = DamageInfo() d:SetDamageType(DMG_DISSOLVE) d:SetDamage(v:Health()) d:SetAttacker(self) v:TakeDamageInfo(d) end end timer.Simple(4, function() self:Remove() end) end [/lua] The value for render.DrawSphere size is 1500 is max size. Here i've set it to 1800 in hopes of it actually killing the player when the sphere touches them. However i can be inside the entity and unless i'm right next to the prop model that spawns with it i don't die immediately. Also sometimes if im near the outside edge of the render.DrawSphere i don't die at all, however i SHOULD be dieing because i've sent the ents.FindinSphere to size 1800 so the kill range should extend past what i'm seeing on the client. Heres what i am trying to do: Make it so that if i am a player and i go inside the sphere or it touches me i die automatically, i also want the ents.FindinSphere to adjust based on what i am drawing clientside hence me using the same calculation for the size. I appreciate any and all help :)
Not sure why it's not killing the player, but you're creating a large amount of timers without checking if self is even valid. Create one, then check if the entity is valid. Also, you should be doing [code]if (v:IsPlayer() or v:IsNPC()) and v:Alive() then[/code]
[QUOTE=code_gs;51591880]Not sure why it's not killing the player, but you're creating a large amount of timers without checking if self is even valid. Create one, then check if the entity is valid. Also, you should be doing [code]if (v:IsPlayer() or v:IsNPC()) and v:Alive() then[/code][/QUOTE] Okay i added [lua] timer.Simple(4, function() if !IsValid(self) then return end self:Remove() end) [/lua]
[QUOTE=Keosan;51591914]Okay i added [lua] timer.Simple(4, function() if !IsValid(self) then return end self:Remove() end) [/lua][/QUOTE] Did you move it out of the think function?
[QUOTE=code_gs;51591934]Did you move it out of the think function?[/QUOTE] Yeah i put it into ENT:Initialize function so when it spawns 4 seconds later if it spawned in it removes itself :) Still having the size issue though. When i had a specific set size before it was an immediate kill. Now i get lucky if it kills someone less than 250 radius despite the set radius ranging from 50 to 1500.
Still havent solved this issue. It seems using the above format, the size never changes from when it was set on ENT:In... I had a simple if then code that i try out next and respond with later.
Sorry, you need to Log In to post a reply to this thread.