ents.FindByClass("info_node") does not appear to find any nodes even though I just made a map and placed nodes, verified by ai_show_conect in-game.
ents.FindByClass() cannot search 'info_node' s? :(
My code works when I replace info_node with info_player_start so I'm thinking it does not allow searching for info_nodes?
Serverside? Clientside?
Serverside, sir!
Node entities are removed on mapspawn.
Is there a way I could save all the positions to a table before they are removed?
EDIT:
Is there a function/hook I can use to have access to the nodes before or as they are deleted(so I can save their positions to a table)? ;)
[QUOTE=kklouzal23;39885690]Is there a way I could save all the positions to a table before they are removed?[/QUOTE]
I wrote a script a while ago which you can use to get access to a map's nodegraph:
[url]http://pastebin.com/7u96CfsS[/url]
Just throw it into 'lua/autorun/'.
Then you can just use:
[LUA]
local _R = debug.getregistry()
local nodegraph = _R.Nodegraph.Read()
for _,node in pairs(nodegraph:GetNodes()) do
local pos = node.pos
[...]
end
[/LUA]
Thank you very much Silverlan that is a powerful script you wrote! I'm thinking I should wait for Garry to release Next Bot since it appears to bypass the nodes and use its own way to compute paths.
I was going to use the info_nodes as spawn points for npc's but maybe I should take a different route..
--
I wanted to make it spawn an npc within a variable range around the player but I couldn't think of a way to keep them from getting stuck inside things as they were spawned which is where the idea of using info_nodes as spawn points came about.
Does anyone have any advice as to how I could pick a random coordinate around the player to spawn an NPC without getting the NPC stuck in walls, props, the player etc? :)
Trace a hull out from the player randomly 20 times, pick the farthest away that is on the floor?
Something like this should do the trick:
[LUA]local function SpawnNPC(class,pl)
local ent = ents.Create(class)
if(!ent:IsValid()) then return NULL end
ent:Spawn()
ent:Activate()
local min,max = ent:GetCollisionBounds()
local pos = pl:GetPos() +pl:OBBCenter()
local ang = Angle(0,0,0)
local filter = {pl,ent}
local trBest
local fractionBest = 0.25
local yStart = math.Rand(0,360)
for y = yStart,yStart +315,45 do
ang.y = y
local tr = util.TraceHull({
start = pos,
endpos = pos +ang:Forward() *512,
filter = filter,
mask = MASK_NPCSOLID,
mins = min,
maxs = max
})
if(!tr.Hit) then
local posSpawn = tr.HitPos -tr.Normal *max.x +Vector(0,0,25)
local angSpawn = (pos -posSpawn):Angle()
angSpawn.p = 0
angSpawn.r = 0
ent:SetPos(posSpawn)
ent:SetAngles(angSpawn)
ent:DropToFloor()
return ent
elseif(tr.Fraction > fractionBest) then
fractionBest = tr.Fraction
trBest = tr
end
end
if(!trBest) then -- No proper spawnposition found
ent:Remove()
return NULL
end
local posSpawn = tr.HitPos -tr.Normal *max.x +Vector(0,0,25)
local angSpawn = (pos -posSpawn):Angle()
angSpawn.p = 0
angSpawn.r = 0
ent:SetPos(posSpawn)
ent:SetAngles(angSpawn)
ent:DropToFloor()
return ent
end[/LUA]
Untested.
Holy shitballs Silverlan it worked, you are a true Lua King, today/tomorrow after I wake up I will decipher how this works exactly and implement it into my gamemode, it was the last missing puzzle piece I needed to get the ball rolling! Thank you all for your help!! <3
Sorry, you need to Log In to post a reply to this thread.