Npc not spawning

I’ve been having a problem with this NPC. The problem is I can’t seem to have the NPC spawn in the location I set. Another weird thing is that there is no Error in console. Does this mean it’s not reading the file’s?

This is cl_init.lua:

[LUA]include(‘shared.lua’)

function NPCShopMenu()

local pShop = vgui.Create('DFrame')
pShop:SetSize(334, 63)
pShop:SetPos(ScrW()*0.5, ScrH()*0.5)
pShop:SetTitle('test')
pShop:SetSizable(true)
pShop:SetDeleteOnClose(false)
pShop:MakePopup()

end

usermessage.Hook(“ShopNPCUsed”, NPCShopMenu) [/LUA]

This is init.lua:

[LUA]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

function ENT:Initialize( )
print(“IT’S WORKING!”)
self:SetModel( “models/humans/group01/female_02.mdl” )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal( )
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX )
self:CapabilitiesAdd( CAP_ANIMATEDFACE, CAP_TURN_HEAD )
self:SetUseType( SIMPLE_USE )
self:DropToFloor()

self:SetMaxYawSpeed( 90 )

end

function ENT:AcceptInput( Name, Activator, Caller )

if Name == "Use" and Caller:IsPlayer() then
	
	umsg.Start("ShopNPCUsed", Caller)
	umsg.End() 
	
end

end

function ENT:OnTakeDamage()
return false
end

function NPCSpawn()
local ent = ents.Create(“npc_shop”)
local spot = Vector(-557.401428, 22.703876, -12095.832031)
ent:SetPos(spot)
ent:Spawn()
end
hook.Add(“InitPostEntity”,“NPCSpawn”,NPCSpawn)[/LUA]

This is shared.lua:

[LUA]ENT.Base = “base_ai”
ENT.Type = “ai”

ENT.PrintName = “”
ENT.Author = “”
ENT.Contact = “”
ENT.Purpose = “”
ENT.Instructions = “”

ENT.AutomaticFrameAdvance = true

function ENT:SetAutomaticFrameAdvance( bUsingAnim )
self.AutomaticFrameAdvance = bUsingAnim
end[/LUA]

Any help will be greatly appreciated.

I tried using InitPostEntity, however it only worked when I spawned anything via Q menu.
You can temporary make a separate script with hook “Initialize” and timer set to 10 seconds.
After that time you can set it to spawn npc.

InitPostEntity was never working for me. My solution was something along the lines of this:



hook.Add( "PlayerInitialSpawn", "SpawnNPCs", function() 
	--[[
		NPC spawning code
	]]

	hook.Remove("PlayerInitialSpawn","SpawnNPCs")
end)


I’m spawning NPCs just fine with the InitPostEntity hook.

For darkrp/other gamemodes…
go in to init.lua and put this in.



function SpawnNpc()
	if SERVER then
		local npc = ents.Create("npcshop1")
		npc:SetPos(Vector( x, y, z )) -- Find the place for the npc, stand there, and type getpos in console...
		npc:SetAngles(Angle(0,0,0))
		npc:Spawn()
	end
end
hook.Add("InitPostEntity", "SpawnNpc", SpawnNpc)
concommand.Add("SpawnNpc", SpawnNpc)


PROFIT!!! :slight_smile:

Make the function local when you only use it in that script…

Thank you everyone for all your support.