Need help with ents.FindInSphere with two same entities

Two same entities, cant find solution how to find only second entity
[LUA]
for k, v in pairs (ents.FindInSphere(self:GetPos(), 0.5)) do
if self ~= v then
if v:GetClass() == “my_ent” then
return
end
end
end
[/LUA]

Please any suggestions

Something like this should do the trick

[lua]
local Count = 0
for k, v in pairs (ents.FindInSphere(self:GetPos(), 0.5)) do
if self ~= v then
if v:GetClass() == “my_ent” then
Count = Count+1
if Count > 1 then
return
end
end
end
end
[/lua]

Yea, already tried this, not working

You will need to give me more than it’s not working…

0.5 it’s TOO tiny, try 8 or 16
Tested it on one of my sents and this worked

If i put down two barrels this check doesn’t work for me.

[LUA]
function ENT:StartTouch( ent )
local count = 0
for k, v in pairs (ents.FindInSphere(self:GetPos(), 8)) do
if self ~= v then
if v:GetClass() == “barrel” then
count = count + 1
print(“Work!”)
return
end
end
end
ent:Remove()
end
[/LUA]

All your code is doing is incrementing count but don’t doing anything with the value, this means that print will be called for every ent called barrel it finds

Sorry, i’m mistaken with code, but it doesn’t work anyway
[LUA]
for k, v in pairs (ents.FindInSphere(self:GetPos(), 8)) do
if self ~= v then
if v:GetClass() == “barrel” then
count = count + 1
if count > 1 then
print(“Work!”)
return
end
end
end
end
[/LUA]

[editline]26th August 2014[/editline]

Seems this not a right way, because ents are the same
[LUA]
if self ~= v then
[/LUA]

[editline]26th August 2014[/editline]

Doesn’t find the second one
[LUA]
ents.FindInSphere
[/LUA]

Are you spawning regular source barrels?

Please…Tell us that your entity it’s not a blue prop_physics barrel and you’re trying to get that prop class as “barrel”

I trying to get ent class barrel not a prop

Use its EntIndex perhaps?

Add print( v:GetClass() ) before checking if the class is ‘barrel’

If there’s no ‘barrel’ entry, try using this to see what class your ‘barrel’ is:
[lua]
concommand.Add( “checkClass”, function( ply )
if not IsValid( ply ) then return end

print( ply:GetEyeTrace().Entity:GetClass() )

end )
[/lua]

If i place two same ents, it find only one second is invisible for ents.FindInSphere