Hello everybody!
I am making a gmod server and I want specific enemies to be spawned at a specific time during the day (eg. 12:30PM), I'm still a noob with lua and the script works partially.
local function checkTime()
MsgC( Color( 128, 128, 0 ), "CheckedTime" )
if (os.date("%H") == "12") and tonumber(os.date("%M")) >= 20 and tonumber(os.date("%M")) <= 59 then-- Perform action
timer.Stop("830Timer")
timer.Create("RestartTimer", 5, 1, function() timer.Start("830Timer") end)
MsgC( Color( 128, 128, 0 ), "Spawned boss!" )
if SERVER then
local _ent = ents.Create("npc_vj_dmvj_giant_worm")
_ent:SetPos(Vector(4837.775879,-3985.372070,-26.258362))
_ent:Spawn()
end
end
end
hook.Add( "Initialize", "Start Timer", function() timer.Create( "830Timer", 60, 0, checkTime ) end)
Both of the messages print in the console but the entity doesn't get created, I don't even get an error in the console.
If anyone can help me set this up correctly I'd be grateful!
Is the code being run serverside?
The lua file is located inside an autorun folder (lua/autorun/boss_spawn.lua) <-- like that in the file explorer. How do I make it run serverside?
put it in lua/autorun/server
Thanks putting it into the server folder fixed it! Yeah I could change the code to fit yours, still new to the timers and all that stuff ^^
No problem!
Sorry, you need to Log In to post a reply to this thread.