+ Reply to Thread
Results 1 to 8 of 8

Thread: Getting all players outside ents.FindInBox()

  1. #1
    Wiremod Helper Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden
    Posts
    1,661

    Default Getting all players outside ents.FindInBox()

    How can i filter all players inside a ents.FindInBox to all players on the server, so i get all players that is OUTSIDE that box? Im talking about Lua ofc. Im working with loops and such but really, it shouldent be this hard, could anyone help me?
    Get out. Seriously, do it.

  2. #2
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: Getting all players outside ents.FindInBox()

    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  3. #3
    Wiremod Helper Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden
    Posts
    1,661

    Default Re: Getting all players outside ents.FindInBox()

    Clever answer, but lets say i want to split up those guys that is inside and those that is outside into 2 tables. I have been lurking with loops and stuff for hours, i still dont find it out :<

    Also, your uses ApplyClip function which i have no idea how it works.
    Get out. Seriously, do it.

  4. #4
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: Getting all players outside ents.FindInBox()

    Here you go!
    Note: untested.

    Code:
    -- handy inrange function
    local function inrange( vec, min, max )
    	if (vec.x < min.x) then return false end
    	if (vec.y < min.y) then return false end
    	if (vec.z < min.z) then return false end
    	if (vec.x > max.x) then return false end
    	if (vec.y > max.y) then return false end
    	if (vec.z > max.z) then return false end
    	return true
    end
    
    local function Find( classname, min, max )
    	-- if it's players you're after, it's simple:
    	-- local targets = player.GetAll()
            -- and then you can remove the "classname" argument as well
    	
    	-- if it's not just players...
    	local targets = ents.FindByClass(classname)
    	
    	-- set up tables
    	local inbox = {}
    	local notinbox = {}
    	
    	-- loop time!
    	for _, e in pairs( targets ) do
    		-- check using our handy function
    		if (inrange( e:GetPos(), min, max )) then -- if it's inside the box
    			table.insert( inbox, e )
    		else -- if it isn't
    			table.insert( notinbox, e )
    		end
    	end
    	
    	-- maybe you want to send it somewhere?
    	return inbox, notinbox
    end
    Last edited by Divran; 03-16-2010 at 04:38 PM.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  5. #5
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: Getting all players outside ents.FindInBox()

    Quote Originally Posted by Divran View Post
    -snip- This post sucked. making a better one
    NINJAD

    You can find inside the box, to array, and then outside the box, to other array.

    Or find by class, loop it, using inrange you check if a player is inside the box, if so, delete from first array and put into second.

  6. #6
    Wiremod Helper Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden
    Posts
    1,661

    Default Re: Getting all players outside ents.FindInBox()

    Your code seems to work Divran, but how does it remove players that have changed from inside to outside the box, or players that have left the server?
    By reseting the Table as i seen you do, wouldent that be quite a pain, couse it needs to fill it back up all the time?
    Get out. Seriously, do it.

  7. #7
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: Getting all players outside ents.FindInBox()

    Quote Originally Posted by Donkie View Post
    Your code seems to work Divran, but how does it remove players that have changed from inside to outside the box, or players that have left the server?
    By reseting the Table as i seen you do, wouldent that be quite a pain, couse it needs to fill it back up all the time?
    No, I think that's the easiest way to do it.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  8. #8
    Wiremod Helper Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden
    Posts
    1,661

    Default Re: Getting all players outside ents.FindInBox()

    Anyways, i shall try it out, Thanks alot :3

    Edit: It works perfectly. You sure will get credits when this is done
    Last edited by Donkie; 03-17-2010 at 06:27 AM.
    Get out. Seriously, do it.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots