Spawning Entities on info_nodes

Title says it all, I’m looking to get all the nodes in the map and spawning NPCs on them. When I check the map to see if there are nodes, it returns 0…

Any help is much appreciated.

are you checking for nodes clientside or serverside, ents.GetAll() clientside wont show some entities like spawnpoints.

Nodes are removed when the map is done loading, so you will have to set up a list of positions, and fill it progressively using the EntityKeyValue hook. (which is active before the map loads, and therefore will be called even for static entities such as nodes and lights)

Couldn’t you also run it in GM:Initialize()?

Okay, thanks for the info on the map entities. I think I have it figured out, but it doesn’t seem to be generating a table of all the Node Position coordinates.

[lua]
nodepos = {}

function GM:Initialize()

for k,v in pairs(ents.FindByClass( “info_node” ) do
table.insert( nodepos, v:GetPos() )
end
end
[/lua]

Also, Kilburn… Not quite sure how to do it with the EntityKeyValue hook, I’ve never used this before, if you could enlighten me on that, that would be great. :slight_smile:

Thanks,

Edit: Just tried:

[lua]
function GM:EntityKeyValue( entity )
for k,v in pairs(ents.FindByClass(“info_node”)) do

table.insert( NodePos, v:GetPos() )

end
end
[/lua]

It generates a table!

But…

[lua]

1 = 0.0000 0.0000 0.0000
2 = -1120.0000 160.0000 65.0000
3 = -1120.0000 160.0000 65.0000
4 = -1120.0000 160.0000 65.0000
5 = -1120.0000 160.0000 65.0000
6 = 0.0000 0.0000 0.0000
7 = -1120.0000 480.0000 65.0000
8 = -1120.0000 480.0000 65.0000
9 = -1120.0000 480.0000 65.0000
10 = -1120.0000 480.0000 65.0000
11 = 0.0000 0.0000 0.0000
12 = -1120.0000 928.0000 65.0000
13 = -1120.0000 928.0000 65.0000
14 = -1120.0000 928.0000 65.0000
15 = -1120.0000 928.0000 65.0000
[/lua]

It gets the same node 4 times, and every fifth entry, it gives a vector of 0, 0, 0.

Any clues?

[lua]
function GM:EntityKeyValue()
local nodes = {}
table.Empty(nodes)
for k,v in pairs(ents.FindByClass(“info_node”)) do
table.insert( nodes, v:GetPos() )
end
end
[/lua]
Try that

[lua]
Nodes = {}
function GM:EntityKeyValue(ent)
if ent:GetClass() == “info_node” then
if Nodes[ent:EntIndex()] == nil then
Nodes[ent:EntIndex()] = ent:GetPos()
end
end
end
[/lua]

:eng101:

EDIT: I updated it

Mkay, getting [lua]
includes/extensions/table.lua:177: bad argument #2 to ‘random’ (interval is empty)
[/lua]

And this is what the table looks like:[lua]

0 = 0.0000 0.0000 0.0000
[/lua]

Population code:

[lua]
function Populate()
local currentnpc = table.Random( NPCList )
local currentnode = Vector(tonumber(table.Random( nodes ))) + Vector( 0, 0, 200 )
print(currentnode)
print(currentnpc)
if #ents.FindByClass( currentnpc ) <= MaxNPCs then

	npc = ents.Create( currentnpc )
	npc:SetPos( currentnode )
	npc:Spawn()
	npc:DropToFloor()
	npc:Activate()

end

end
timer.Create( “Population”, 45, 0, Populate() )
[/lua]

Edit: Updated the table with Gbps updated code.
Edit: [lua]
ERROR: GAMEMODE:‘EntityKeyValue’ Failed: Payback/gamemode/init.lua:18: attempt to call method ‘GetClass’ (a nil value)
[/lua] Using gamemode.Call(“EntityKeyValue”, “info_node”) now in GM:Initialize. Still getting the above error as well.

How should I call GM:EntityKeyValue, by the way?

  1. It calls it automatically

  2. I guess the hook is happening before the info_node is spawned, meaning that GetClass() would be nil.

  3. Put this code in the init.lua, not with the hook.

[lua]
Nodes = {}
for k,v in pairs(ents.FindByClass(“info_node”)) do
if Nodes[ent:EntIndex()] == nil then
Nodes[ent:EntIndex()] = ent:GetPos()
end
end
[/lua]

Entered the code, removed the old code. The table, nodes, has not been generated.

Does anyone know any Gamemodes or scripts that might do something similar to this? A piece of code that runs at load time to get map entities before they are removed?

Thanks for your help so far Gbps. :slight_smile:

So close to finishing this gamemode! Anyone know how to do this? Is it even possible, cause I’ve tried in so many different ways!