• Proximity Detection
    2 replies, posted
So basically, I'm creating some sort of creeper and I need a way to detect how close the player is to the Entity. Once it detects the player close enough, I've got creeper sounds and an env_explosion and removing itself to top it all off.
Two ways: [lua] for k, v in pairs(ents.GetAll()) do if v:GetPos():Distance(self:GetPos()) <= 50 then if v:IsValid() and v:IsPlayer() or v:IsNPC() then --Explode shit here end end end [/lua] Or [lua] for k, v in pairs(ents.FindInSphere(self:GetPos(), 50) do if v:IsValid() and v:IsPlayer() or v:IsNPC() then --Explode shit here end end [/lua] Something like that. May have to tweak them to fit your needs exactly but those are the two basic ways.
[QUOTE=Feihc;31486993]Two ways: [lua] for k, v in pairs(ents.GetAll()) do if v:GetPos():Distance(self:GetPos()) <= 50 then if v:IsValid() and v:IsPlayer() or v:IsNPC() then --Explode shit here end end end [/lua] Or [lua] for k, v in pairs(ents.FindInSphere(self:GetPos(), 50) do if v:IsValid() and v:IsPlayer() or v:IsNPC() then --Explode shit here end end [/lua] Something like that. May have to tweak them to fit your needs exactly but those are the two basic ways.[/QUOTE] Wonderful Thanks!
Sorry, you need to Log In to post a reply to this thread.