Random NPC spawns

I’ve been trying to get my gamemode to spawn NPCs at certain places on specified maps at random intervals, and i really have no idea how to do it, i tried doing this

function SpawnBandit()  
    local spawn = table.Random(BanditSpawns)
    local pos = spawn:GetPos()  
    local angles = spawn:GetAngles()
    local bandit = ents.Create("npc_banditenemy")  

I have no idea where i got that from though, any help?

You need to create a table with a list of positions.

Then create a timer, with that function in, but when you do *local pos *it should be this

[lua]local pos = table.Random(“NameOfTable”)[/lua]


local pos = table.Random(NameOfTable)

A table is table not a string :keke:

Crap, how could I forget :<

Also, why are you using PHP tags?

idk but il start using it :quagmire:

Ok, i ditched that and made my own way for NPCs to spawn at random positions at certain intervals.
But unless it is a creature NPC it cannot attack because it has no weapon, how do i specify it to spawn with a weapon, for example SMG1.

the console command for it is

npc_create_equipment weapon_<NAMEHERE>

Except we’re in the lua section and this wouldn’t do anything anyway. It’s for use with npc_create.

[lua]npc:SetKeyValue(“additionalequipment”, “weapon_ar2”)[/lua]



Thanks, any way to make them not drop the weapon though?
Would this work?
-snip The code does not work-