• How does ents.FindInBox work?
    5 replies, posted
I'm just attempting to get a basic understanding of how the function works. I wrote a simple code: function removeweps()         for _, v in pairs ( ents.FindInBox(Vector(-3615.137939, -4352.076172, 277.606934),Vector(517.774475, -7289.652344, -128.356369)) ) do         if v:IsWeapon() then print("hello world!")         end     end end and it isn't printing anything. My assumption on how it works is you take one point of a map and another point of the map and gmod draws an invisible box and then checks that box for entities. I'm putting a weapon in the middle of the two points and it isn't doing anything. What do I not understand?
If I didn't miss anything, FindInBox still requires vectors to be as minimum and maximum. That means FindBox can be interpreted as Vector1 - Vector2. so if Vector1 is higher than Vector2 that will fail. You need to move all minimums and maximums to different vectors. Example: Vector(4,-2,10) Vector(7,-40,6) In FindInBox you should move values to have this: ents.FindInBox(Vector(4,-40,6),Vector(7,-2,10)) Try doing the same with your vectors
If I understood correctly: function removeweps()         for k, v in pairs(ents.FindInBox(Vector(-3615.137939, -7289.652344, -128.356369),Vector(517.774475, -4352.076172, 277.606934)) ) do         if v:IsWeapon() then print("hello world!")         end     end end It still prints nothing. if I reduce it down to just PrintTable(ents.FindInBox(Vector(-3615.137939, -7289.652344, -128.356369),Vector(517.774475, -4352.076172, 277.606934)) ) then everything prints just fine. I'm going to try function removeweps()         for k, v in pairs(ents.FindInBox(Vector(-3615.137939, -7289.652344, -128.356369),Vector(517.774475, -4352.076172, 277.606934)) ) do         if v:GetClass("spawned_weapon") then print("hello world!")         end     end end I will reply with results
This is false, the function orders the vectors for you.
Then why he had a problem?
Because IsWeapon() returns false for non weapons, and the box had only non-weapons? (spawned_weapon and spawned_shipment) Their first stop in debugging should've been to remove the IsWeapon() check.
Sorry, you need to Log In to post a reply to this thread.