• Really bad problem
    7 replies, posted
I'm checking the distance of an entity and then setting a player variable if it's under 200, if it isn't then it will set it back off. The problem is, there's more then just one of those entities, so say if I got close to one entity but it still won't work because i'm not close enough to another. (SORRY for undescriptive title)
Tried using for loops?
I'm using them with the distance to get the entity, but it doesn't help (is that what you mean?)
How about hooking a function to your movement (something like OnPlayerStep) and put ents.FindInSphere() inside it ? And then perhaps make the variable auto-vanish after some time
The variable will disappear once the player is out of range of it. i don't know how i would do the onplayerstep
So you need to be within 200 units of all of these entities at the same time? If so, during a Think hook, loop through all of them and compare the distances to the player, if one of them is greater than 200 break the loop and ignore the rest.
will test and post back [editline]22nd April 2013[/editline] still won't work [highlight](User was banned for this post ("Making alts for a banned user" - Orkel))[/highlight]
-- Ninja'ed by mod .. but lets the post stand for others -- Sorry, but I didn't really catch what you're searching for. So I made both functions [lua]local entity_type = "ent_potato" local distance_to = 200 local Tab = ents.FindByClass( entity_type ) function UpdateEntites() // This will reduce the lag // If you call this each time the specific entity gets spawned or removed. Tab = ents.FindByClass( entity_type ) end meta = FindMetaTable( "Player" ) local function meta:IsWithin(n) // Returns true if a player is nearby the entity for _, v in pairs(Tab) do if v:GetPos():Distance(self:GetPos())<=n then return true end end return false end local function meta:IsWithinAll(n) // Returns true if a player is nearby all the entities on the map. if #Tab<1 then return false end // If there aren't any entities on the map. Just return false. for _, v in pairs(Tab) do if v:GetPos():Distance(self:GetPos())>n then return false end end return true end[/lua] ply:IsWithin(n) If the player is within n unites to just one entity (Aka the closest) ply:IsWithinAll(n) If the player is within x unities to all entites on the map
Sorry, you need to Log In to post a reply to this thread.