I want to trace an area and see if there are any npcs. How do I do that?
4 replies, posted
Basically what the title says. I just want to trace an area and do something if there are any npcs, but idk how to make it so it finds them. I also want to make it so it doesn't finds any friendlys npcs.
How do I do that?
Thanks a lot and sorry for my bad english.
You can use ents.FindInSphere, ents.FindInBox, etc.
[QUOTE=zzaacckk;44416165]You can use ents.FindInSphere, ents.FindInBox, etc.[/QUOTE]
I'm used to work with this kind of tracers:
[CODE]
tracedata={}
tracedata.start = ply:EyePos() + (ply:GetRight() * 1)
tracedata.endpos = ply:EyePos() + (ply:GetRight() * 32)
tracedata.filter = ply[/CODE]
Is there any way that to use those?
BTW, I just searched for the friendly npcs and I found ents.findbyclass, but how do I use it?
[B]EDIT:[/B] The same with the ents.findinbox, how do I use it? Could you give me an example?
Thanks
[QUOTE=shadowsaints;44416907]I'm used to work with this kind of tracers:
[CODE]
tracedata={}
tracedata.start = ply:EyePos() + (ply:GetRight() * 1)
tracedata.endpos = ply:EyePos() + (ply:GetRight() * 32)
tracedata.filter = ply[/CODE]
Is there any way that to use those?
BTW, I just searched for the friendly npcs and I found ents.findbyclass, but how do I use it?
[B]EDIT:[/B] The same with the ents.findinbox, how do I use it? Could you give me an example?
Thanks[/QUOTE]
if I rmember correclty it should return a table of entities. Meaning you need to loop through the information like this:
[lua]
--FindInSphere EXAMPLE
local vec = Vector(0,0,0)
--THis is setting the location of where it needs to search. 0,0,0, being the orgin of the map.
local junk = ents.FindInSphere( vec, 128 )
--this returns a table and sets the information to the junk variable
-- the for loop below searches though each value in the table and checks to see if it is a npc
for k,v in pairs(junk) do
if v:IsNpc() then
print("Hello I am a npc ^.^")
end
end
--FindInBox EXAMPLE
local vec_start = Vector(-32,-32,-32)
local vec_end = Vector(32,32,32)
--I have not messed with this much but from my understanding it is basically determining how large the box is depending on what area you are in.
local junky = ents.FindInBox(vec_start, vec_end )
--this returns a table and sets the information to the junky variable
-- the for loop below searches though each value in the table and checks to see if it is a npc
for k,v in pairs(junk) do
if v:IsNpc() then
print("Hello I am a npc ^.^")
end
end
[/lua]
[QUOTE=bran92don;44417076]if I rmember correclty it should return a table of entities. Meaning you need to loop through the information like this:
[lua]
--FindInSphere EXAMPLE
local vec = Vector(0,0,0)
--THis is setting the location of where it needs to search. 0,0,0, being the orgin of the map.
local junk = ents.FindInSphere( vec, 128 )
--this returns a table and sets the information to the junk variable
-- the for loop below searches though each value in the table and checks to see if it is a npc
for k,v in pairs(junk) do
if v:IsNpc() then
print("Hello I am a npc ^.^")
end
end
--FindInBox EXAMPLE
local vec_start = Vector(-32,-32,-32)
local vec_end = Vector(32,32,32)
--I have not messed with this much but from my understanding it is basically determining how large the box is depending on what area you are in.
local junky = ents.FindInBox(vec_start, vec_end )
--this returns a table and sets the information to the junky variable
-- the for loop below searches though each value in the table and checks to see if it is a npc
for k,v in pairs(junk) do
if v:IsNpc() then
print("Hello I am a npc ^.^")
end
end
[/lua][/QUOTE]
Thank you a LOT! I'm going to try that out!
Sorry, you need to Log In to post a reply to this thread.