Need help with ents.FindInSphere with two same entities
13 replies, posted
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]
[QUOTE=King Penisless;45793151]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][/QUOTE]
Yea, already tried this, not working
[QUOTE=lua_error;45793407]Yea, already tried this, not working[/QUOTE]
You will need to give me more than it's not working..
[QUOTE=lua_error;45793407]Yea, already tried this, not working[/QUOTE]
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"
[QUOTE=gonzalolog;45806491]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"[/QUOTE]
I trying to get ent class barrel not a prop
Use its EntIndex perhaps?
[QUOTE=lua_error;45814104]I trying to get ent class barrel not a prop[/QUOTE]
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]
[QUOTE=HumbleTH;45815018]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][/QUOTE]
If i place two same ents, it find only one second is invisible for ents.FindInSphere
Sorry, you need to Log In to post a reply to this thread.