I'm trying to make NPC's spawn only on a certain map in my gamemode. Here's what I have:
[CODE]function SpawnShopsOnMap()
if game.GetMap() == "mememap1" then
function SpawnEntities()
if SERVER then
local npc = ents.Create("ent_scrapmerchant")
npc:SetPos(Vector(-165.836380,1001.145874,64))
npc:SetAngles(Angle(0,0,0))
npc:Spawn()
end
end
hook.Add( "InitPostEntity", "SpawnEntities", SpawnEntities)
else return false
end
end[/CODE]
It's placed into init.lua. The "SpawnEntities" function works if it's not in the "SpawnShopsOnMap". Any help is appreciated.
Have you actually RUN the SpawnShopsOnMap function?
[QUOTE=MPan1;50966436]Have you actually RUN the SpawnShopsOnMap function?[/QUOTE]
Yeah, he hasn't hooked SpawnShopsOnMap, and it isn't a valid function on the Gmod Lua Wiki, so maybes he needs to localise it aswell, just to be safe with any conflictions.
[QUOTE=jacobcooper18;50966442]it isn't a valid function on the Gmod Lua Wiki[/QUOTE]
Just because it's not on the wiki doesn't mean it's not a valid function... if it didn't work or wasn't a function it wouldn't be a valid function
I know what you mean though :p
And you could make a timer, like:
[CODE] function Initialize()
hook.Call( "SpawnShopsOnMap" )
end
hook.Add( "Initialize", "Initialize", Initialize )
local function SpawnShopsOnMap()
if game.GetMap() == "mememap1" then
function SpawnEntities()
if SERVER then
local npc = ents.Create("ent_scrapmerchant")
npc:SetPos(Vector(-165.836380,1001.145874,64))
npc:SetAngles(Angle(0,0,0))
npc:Spawn()
end
end
hook.Add( "InitPostEntity", "SpawnEntities", SpawnEntities)
else return false
end
end
hook.Add( "SpawnShopsOnMap", "Spawn Shops", SpawnShopsOnMap )
[/CODE]
[editline]29th August 2016[/editline]
[QUOTE=MPan1;50966455]Just because it's not on the wiki doesn't mean it's not a valid function... if it didn't work or wasn't a function it wouldn't be a valid function
I know what you mean though :p[/QUOTE]
Yeah :P
[editline]29th August 2016[/editline]
Would this work by any chance? Untested.
[QUOTE=jacobcooper18;50966467]And you could make a timer, like:
[CODE] function Initialize()
hook.Call( "SpawnShopsOnMap" )
end
hook.Add( "Initialize", "Initialize", Initialize )
local function SpawnShopsOnMap()
if game.GetMap() == "mememap1" then
function SpawnEntities()
if SERVER then
local npc = ents.Create("ent_scrapmerchant")
npc:SetPos(Vector(-165.836380,1001.145874,64))
npc:SetAngles(Angle(0,0,0))
npc:Spawn()
end
end
hook.Add( "InitPostEntity", "SpawnEntities", SpawnEntities)
else return false
end
end
hook.Add( "SpawnShopsOnMap", "Spawn Shops", SpawnShopsOnMap )
[/CODE]
[editline]29th August 2016[/editline]
Yeah :P
[editline]29th August 2016[/editline]
Would this work by any chance? Untested.[/QUOTE]
Yep, worked perfectly. Thanks for the help :smile:
Sorry, you need to Log In to post a reply to this thread.