ents.FindInSphere returns nothing

Hello all,

As I was coding my Sent the other day i wrote:




function GetOBBCenterPos(Ent)
  return Ent:LocalToWorld(Ent:GetPhysicsObject():OBBCenter())
end

  local SearchRad
  local wSearchRad
  
  if(WireLib) then
    wSearchRad     =  self.Inputs["nSearchRad"].Value
  end

  if(wSearchRad and wSearchRad > 0) then
    SearchRad = wSearchRad
  else
    SearchRad = self:GetSearchRadius()  ---- Metod for my ENT 
    --  Made using
    --  self:NetworkVar( "Float",  1, "SearchRadius" ); in SetupDataTables
    --
  end

  local MineCentre = GetOBBCenterPos(self)
  local MineSouth  = self:GetSouthPosOrigin(MineCentre)
  local MineNorth  = self:GetNorthPosOrigin(MineCentre)

    if(SearchRad > 0) then --true
      local Others = ents.FindInSphere(MineCentre, SearchRad)
      if(Others) then  --false
        ---- Do something with the found ents
      end
    end



print MineCentre, print SearchRad and print Others

just to get sure, its the ents.FindInSphere function that works for me

I will provide info ASAIGH

Your function has not a single vector of position. Just use self:GetPos() for the first argument.



  local MineCentre = GetOBBCenterPos(self)
  local MineSouth  = self:GetSouthPosOrigin(MineCentre)
  local MineNorth  = self:GetNorthPosOrigin(MineCentre)


Verify the search radius, it sounds like it’s nil or too low.

Made it work, it does wonderful job, just need to make it dupe at last…

The fileds of my ENT from init.lua are:




ENT.Strength = 0
ENT.SearRad  = 0
ENT.Length   = 0
ENT.PoleDirX = 0
ENT.PoleDirY = 0
ENT.PoleDirZ = 0
ENT.On       = false



Taken from my Stool:




if SERVER then
  cleanup.Register( "magnetdipoles" )
  
  CreateConVar('sbox_maxmagnetdipoles', 10, FCVAR_NOTIFY)

  local function onMagnetDipoleRemove(self, KeyOn)
    numpad.Remove(KeyOn);
  end

  function MakeMagnetDipole(ply      ,
                            pos      ,
                            ang      ,
                            key      ,
                            model    ,
                            strength ,
                            searchrad,
                            length   ,
                            offx     ,
                            offy     ,
                            offz     ,
                            advise   ,
                            property)

    if (not ply:CheckLimit("magnetdipoles")) then
      return false;
    end
    if(util.IsValidModel(model)) then -- <-- You never know .. ^_^
      local eMag = ents.Create( "gmod_magnetdipole" )
      if(eMag and eMag:IsValid()) then
        eMag:SetCollisionGroup(COLLISION_GROUP_NONE );
        eMag:SetSolid( SOLID_VPHYSICS );
        eMag:SetMoveType( MOVETYPE_VPHYSICS )
        eMag:SetModel(model)
        eMag:SetNotSolid( false );
        eMag:SetPos( pos )
        eMag:SetAngles( ang )
        eMag:Setup(strength ,
                   searchrad,
                   length   ,
                   offx     ,
                   offy     ,
                   offz     ,
                   advise   ,
                   property)
        eMag:Spawn()
        eMag:Activate()
        eMag:SetColor( Color( 255, 255, 255, 255 ) )
        eMag:SetRenderMode( RENDERMODE_TRANSALPHA )
        eMag:CallOnRemove("MagnetDipoleNumpadCleanup", onMagnetDipoleRemove,
        numpad.OnDown(ply, key, "MagnetDipole_On", eMag ) )
        eMag:DrawShadow( true )
        eMag:PhysWake()
        local oPhys = eMag:GetPhysicsObject()
          if(oPhys and oPhys:IsValid()) then
            ply:AddCount("magnetdipoles", eMag)
            return eMag
          end
        eMag:Remove()
        print("MagnetDipole Phys invalid !")
        return false
      end
      return false
    end
    return false
  end

  duplicator.RegisterEntityClass( "gmod_magnetdipole", MakeMagnetDipole, "Pos", "Ang",
                                  "NumpadKey", "Model", "Strength",
                                  "SearRad", "Length", "PoleDirX", "PoleDirY", "PoleDirZ")
end



Just wander how the "advise " and “property” should get parsed, coz there is no such field on the ENT, but instead SetNWFloat / SetNWBool

It says here that “RegisterEntityClass” Takes data from the entity’s table

I think it calls the “Make” function with the data in the set fields in the ENT, and the strings are just where the data shold be placed when calling the Maker …
The table should be taken like that I guess:

[editline]5th November 2014[/editline]

It was actually nil :slight_smile: When i printed it, the PB was in my Get method.