Spawning Entities Doesn't Work in timer.Create() loop
0 replies, posted
The title says all. Here is my GM:InitPostEntity() function I am having a problem with, including helpful comments. The last timer in this bunch works.
[CODE]
function GM:InitPostEntity()
timer.Create( "my_timer", 2, 0, function() -- Every 2 seconds
local ent = ents.Create("npc_zombie")
ent:SetPos( Vector(0,0,40) ) -- Higher than headcrabs because I don't want them stuck in turf
ent:Spawn()
ent:SetVelocity( Vector(0,50,50) )
end)
timer.Create( "my_timer", 8, 0, function() -- Every 8 seconds
local ent = ents.Create("npc_poisonzombie")
ent:SetPos( Vector(0,0,40) )
ent:Spawn()
ent:SetVelocity( Vector(0,50,50) )
end)
timer.Create( "my_timer", 14, 0, function() -- Every 14 seconds
local ent = ents.Create("npc_fastzombie")
ent:SetPos( Vector(0,0,40) )
ent:Spawn()
ent:SetVelocity( Vector(0,50,50) )
end)
timer.Create( "my_timer", 18, 0, function() -- Every 18 seconds
local ent = ents.Create("npc_headcrab_fast")
-- This is the only one that actually works...
-- Weird Right?
ent:SetPos( Vector(0,0,20) )
ent:Spawn()
ent:SetVelocity( Vector(0,50,50) )
end)
end
--More than this, too.
[/CODE]
[editline]9th June 2017[/editline]
[QUOTE=Lavacoal123;52333762]
~Snip
[/QUOTE]
It seems I need a [URL="https://wiki.garrysmod.com/page/timer/Create"]different identifier[/URL] for each of these timers... I'll fix that real quick and brb.
[editline]9th June 2017[/editline]
And it's good. Sorry guys!
Sorry, you need to Log In to post a reply to this thread.