Entity in area detection

Kinda new Lua coder here, help developing gamemode.

How would I designate an area, which would then be used to detect whether a certain entity ( in this case a weapon the player is holding ) entered the area? - Identical to the same method you might use to create a form of CTF mechanic.

I’m guessing an ( X, Y, Z ) area would be possible to create and define, and I know you could get pos of the player weapon entity and act whenever it is equal to another entity ( the capture point ), but that would be slightly ridiculous relying on them equaling exactly the same pos.

I just can’t find/know how I would do this. Any help? Any specific resources anyone could point me to?
Written code would be appreciate.

Thanks,

Google the function ‘ents.FindInSphere’. It’s probably what you want.

First and foremost, that^. Second, if specifically a weapon needs to be detected, I would do something along the lines of this

[lua]
local targets = ents.FindInSphere(YourRadius, YourEntity’sPos)
for k,v in pairs(targets) do
if v:IsPlayer() and v:GetActiveWeapon() == YourWeapon then
–stuff
end
end
[/lua]

To do this you can make a custom brush entity that mappers can place. Use the ENT:Touch function.