I currently have this but I want to make it so it will spawn 5 of the same npc in random locations I have set in a vector positions table.
local NPCListInvasion = {"npc_zombie", "npc_fastzombie"}
local NPCListInvasionPositions = {}
NPCListInvasionPositions[1] = Vector(117, -315, -12223)
NPCListInvasionPositions[2] = Vector(-35, -528, -12223)
timer.Create("npcinvasiontimer", math.max(5, 10), 0, function(ply)
local npcinvasion = ents.Create(table.Random(NPCListInvasion))
npcinvasion:SetPos(NPCListInvasionPositions[math.random(1,2)])
npcinvasion:SetEnemy(ply)
npcinvasion:SetSchedule(SCHED_COMBAT_PATROL)
npcinvasion:Spawn()
end)
Timer has third argument called repetitions.
Also, for amount of small post in one day like this, I encourage you to ask in Offical GLua Discord
You can make a function with a simple for loop in it.
function spawnthenpcs(amount, table_pos) -- nake a function so we can call it later, for example in a hook
if amount < 1 then return end -- failsafe ( nothing will happen if it is lower than 1 and we dont wanna waste process time )
for i=1, amount do -- a for statement, which will loop x times ( x being the "amount" variable )
local pos = table.Random(table_pos) -- create a variable for it so you can use it in the "entity:SetPos( pos )"
-- and then your code here with the entity spawning etc
end
end
How we could use the function:
local enemyspawns = {
[1] = Vector( 0,0,0 ),
[2] = Vector( 49, -239, 3999 )
}
timer.Create( "enemyspawnstimer", 120, 0, spawnthenpcs(11, enemyspawns) ) -- this will create a timer which will spawn 11 enemys at random locations
-- It is a 50/50 chance
You can read more about for loops here: https://www.lua.org/pil/4.3.4.html
What's the point of learning and trying if you're going to create a dozen of posts every week
Sorry, you need to Log In to post a reply to this thread.