I need to know what is wrong with my code.

What is wrong with my npc_shop codes? I got everything, and when I go into my game server, nothing is there…(yes I have restarted that game server after editing or changing any of the files, so don’t tell me to try restarting the server)…

cl_init:



include('shared.lua')
 
ENT.RenderGroup = RENDERGROUP_BOTH


function ENT:Draw()
	self.Entity:DrawModel()
end

function ENT:DrawTranslucent()
end

function ENT:BuildBonePositions( NumBones, NumPhysBones )
end

function ENT:SetRagdollBones( bIn )
end

function ENT:DoRagdollBone( PhysBoneNum, BoneNum )
end

function NPCShopMenu()
	local DLabel3
	local DLabel2
	local DButton5
	local DButton6
	local DFrame2

	DFrame2 = vgui.Create('DFrame')
	DFrame2:SetSize(445, 267)
	DFrame2:Center()
	DFrame2:SetTitle('John's Jobs')
	DFrame2:SetDeleteOnClose(false)
	DFrame2:ShowCloseButton(false)
	DFrame2:MakePopup()

	DButton6 = vgui.Create('DButton')
	DButton6:SetParent(DFrame2)
	DButton6:SetSize(225, 50)
	DButton6:SetPos(107, 68)
	DButton6:SetText('Yes, I am.')
	DButton6.DoClick = function() menu2()

	DButton5 = vgui.Create('DButton')
	DButton5:SetParent(DFrame2)
	DButton5:SetSize(223, 50)
	DButton5:SetPos(107, 153)
	DButton5:SetText('No, I really do not know why I am here.')
	DButton5.DoClick = function() end

	DLabel2 = vgui.Create('DLabel')
	DLabel2:SetParent(DFrame2)
	DLabel2:SetPos(62, 28)
	DLabel2:SetText('Hey there! My name is John, and I own this fine establishment. ')
	DLabel2:SizeToContents()

	DLabel3 = vgui.Create('DLabel')
	DLabel3:SetParent(DFrame2)
	DLabel3:SetPos(62, 43)
	DLabel3:SetText('Can I interest you in a job?')
	DLabel3:SizeToContents()
end
usermessage.Hook("ShopNPCUsed", NPCShopMenu)

function menu2()
	local DLabel4
	local DLabel5
	local DButton8
	local DButton7
	local DFrame3

	DFrame3 = vgui.Create('DFrame')
	DFrame3:SetSize(445, 267)
	DFrame3:Center()
	DFrame3:SetTitle('John's Jobs')
	DFrame3:SetDeleteOnClose(false)
	DFrame3:ShowCloseButton(false)
	DFrame3:MakePopup()

	DButton7 = vgui.Create('DButton')
	DButton7:SetParent(DFrame3)
	DButton7:SetSize(225, 50)
	DButton7:SetPos(107, 68)
	DButton7:SetText('Yeah. Sure.')
	DButton7.DoClick = function() JobsTab()

	DButton8 = vgui.Create('DButton')
	DButton8:SetParent(DFrame3)
	DButton8:SetSize(223, 50)
	DButton8:SetPos(107, 153)
	DButton8:SetText('No, take me away from here.')
	DButton8.DoClick = function() end

	DLabel5 = vgui.Create('DLabel')
	DLabel5:SetParent(DFrame3)
	DLabel5:SetPos(62, 28)
	DLabel5:SetText('Well I am glad you are so enthusiastic.')
	DLabel5:SizeToContents()

	DLabel4 = vgui.Create('DLabel')
	DLabel4:SetParent(DFrame3)
	DLabel4:SetPos(62, 43)
	DLabel4:SetText('Would you like to see our selection of jobs?')
	DLabel4:SizeToContents()
end

function JobsTab()
	local hordiv = vgui.Create("DHorizontalDivider")
	hordiv:SetLeftWidth(370)
	function hordiv.m_DragBar:OnMousePressed() end
	hordiv.m_DragBar:SetCursor("none")
	local Panel
	local Information
	function hordiv:Update()
		if Panel and Panel:IsValid() then
			Panel:Remove()
		end
		Panel = vgui.Create( "DPanelList")
		Panel:SetSize(370, 540)
		Panel:SetSpacing(1)
		Panel:EnableHorizontal( true )
		Panel:EnableVerticalScrollbar( true )
		Panel:SetSkin("DarkRP")
		
		
		local Info = {}
		local model
		local modelpanel
		local function UpdateInfo(a)
			if Information and Information:IsValid() then
				Information:Remove()
			end
			Information = vgui.Create( "DPanelList" )
			Information:SetPos(378,0)
			Information:SetSize(370, 540)
			Information:SetSpacing(10)
			Information:EnableHorizontal( false )
			Information:EnableVerticalScrollbar( true )
			Information:SetSkin("DarkRP")
			function Information:Rebuild() -- YES IM OVERRIDING IT AND CHANGE ONLY ONE LINE BUT I HAVE A FUCKING GOOD REASON TO DO IT!
				local Offset = 0
				if ( self.Horizontal ) then
					local x, y = self.Padding, self.Padding;
					for k, panel in pairs( self.Items ) do
						local w = panel:GetWide()
						local h = panel:GetTall()
						if ( x + w  > self:GetWide() ) then
							x = self.Padding
							y = y + h + self.Spacing
						end
						panel:SetPos( x, y )
						x = x + w + self.Spacing
						Offset = y + h + self.Spacing
					end
				else
					for k, panel in pairs( self.Items ) do
						if not panel:IsValid() then return end
						panel:SetSize( self:GetCanvas():GetWide() - self.Padding * 2, panel:GetTall() )
						panel:SetPos( self.Padding, self.Padding + Offset )
						panel:InvalidateLayout( true )
						Offset = Offset + panel:GetTall() + self.Spacing
					end
					Offset = Offset + self.Padding	
				end
				self:GetCanvas():SetTall( Offset + (self.Padding) - self.Spacing ) 
			end
			
			if type(Info) == "table" and #Info > 0 then
				for k,v in ipairs(Info) do
					local label = vgui.Create("DLabel")
					label:SetText(v)
					label:SizeToContents()
					if label:IsValid() then
						Information:AddItem(label)
					end
				end
			end

			if model and type(model) == "string" and a ~= false then
				modelpanel = vgui.Create("DModelPanel")
				modelpanel:SetModel(model)
				modelpanel:SetSize(90,230)
				modelpanel:SetAnimated(true)
				modelpanel:SetFOV(90)
				modelpanel:SetAnimSpeed(1)
				if modelpanel:IsValid() then
					Information:AddItem(modelpanel)
				end
			end
			hordiv:SetLeft(Panel)
			hordiv:SetRight(Information)
		end
		UpdateInfo()
		
		local function AddIcon(Model, name, description, Weapons, command, special, specialcommand)
			local icon = vgui.Create("SpawnIcon")
			local IconModel = Model
			if type(Model) == "table" then
				IconModel = Model[math.random(#Model)]
			end
			icon:SetModel(IconModel)
			
			icon:SetIconSize(120)
			icon:SetToolTip()
			icon.OnCursorEntered = function()
				icon.PaintOverOld = icon.PaintOver 
				icon.PaintOver = icon.PaintOverHovered
				Info[1] = LANGUAGE.job_name .. name 
				Info[2] = LANGUAGE.job_description .. description
				Info[3] = LANGUAGE.job_weapons .. Weapons
				model = IconModel
				UpdateInfo()
			end
			icon.OnCursorExited = function()
				if ( icon.PaintOver == icon.PaintOverHovered ) then 
					icon.PaintOver = icon.PaintOverOld 
				end
				Info = {}
				if modelpanel and modelpanel:IsValid() and icon:IsValid() then
					modelpanel:Remove()
					UpdateInfo(false)
				end
			end
			
			icon.DoClick = function()
				local function DoChatCommand(frame)
					if special then
						local menu = DermaMenu()
						menu:AddOption("Vote", function() LocalPlayer():ConCommand("say "..command) frame:Close() end)
						menu:AddOption("Do not vote", function() LocalPlayer():ConCommand("say " .. specialcommand) frame:Close() end)
						menu:Open()
					else
						LocalPlayer():ConCommand("say " .. command)
						frame:Close()
					end
				end
				
				if type(Model) == "table" and #Model > 0 then
					hordiv:GetParent():GetParent():Close()
					local frame = vgui.Create( "DFrame" )
					frame:SetTitle( "Choose model" )
					frame:SetVisible(true)
					frame:MakePopup()
					
					local levels = 1
					local IconsPerLevel = math.floor(ScrW()/64)
					
					while #Model * (64/levels) > ScrW() do
						levels = levels + 1
					end
					frame:SetSize(math.Min(#Model * 64, IconsPerLevel*64), math.Min(90+(64*(levels-1)), ScrH()))
					frame:Center()
					
					local CurLevel = 1
					for k,v in pairs(Model) do
						local icon = vgui.Create("SpawnIcon", frame)
						if (k-IconsPerLevel*(CurLevel-1)) > IconsPerLevel then
							CurLevel = CurLevel + 1
						end
						icon:SetPos((k-1-(CurLevel-1)*IconsPerLevel) * 64, 25+(64*(CurLevel-1)))
						icon:SetModel(v)
						icon:SetIconSize(64)
						icon:SetToolTip()
						icon.DoClick = function()
							RunConsoleCommand("rp_playermodel", v)
							RunConsoleCommand("_rp_ChosenModel", v)
							DoChatCommand(frame)
						end
					end
				else
					DoChatCommand(hordiv:GetParent():GetParent())
				end
			end
			
			if icon:IsValid() then
				Panel:AddItem(icon)
			end
		end
		
		for k,v in ipairs(RPExtraTeams) do
			if LocalPlayer():Team() ~= k then
				local nodude = true
				if v.admin == 1 and not LocalPlayer():IsAdmin() then
					nodude = false
				end
				if v.admin > 1 and not LocalPlayer():IsSuperAdmin() then
					nodude = false
				end
				if (type(v.NeedToChangeFrom) == "number" and LocalPlayer():Team() ~= v.NeedToChangeFrom) or (type(v.NeedToChangeFrom) == "table" and not table.HasValue(v.NeedToChangeFrom, LocalPlayer():Team())) then
					nodude = false
				end
				
				if nodude then
					local weps = "no extra weapons"
					if #v.Weapons > 0 then
						weps = table.concat(v.Weapons, "
")
					end
					if v.Vote then
						local condition = ((v.admin == 0 and LocalPlayer():IsAdmin()) or (v.admin == 1 and LocalPlayer():IsSuperAdmin()) or LocalPlayer().DarkRPVars["Priv"..v.command])
						AddIcon(v.model, v.name, v.Des, weps, "/vote"..v.command, condition, "/"..v.command)
					else
						AddIcon(v.model, v.name, v.Des, weps, "/"..v.command)
					end
				end
			end
		end
	end
	hordiv:Update()
	return hordiv
end


init.lua:



AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
 
include('shared.lua')

function ENT:Initialize()
	self:SetModel( "models/Characters/hostage_03.mdl" ) 
 
	self:SetHullType( HULL_HUMAN );
	self:SetHullSizeNormal();
 
	self:SetSolid( SOLID_BBOX ) 
	self:SetMoveType( MOVETYPE_STEP )
 
	self:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD ) 
 
	self:SetMaxYawSpeed( 5000 )

	self:SetHealth(99999)
 
end
 
function ENT:AcceptInput( input, activator, caller )  
    if not timerforbox then
        timerforbox = true timer.Simple(1, function() timerforbox = false end)
         if input == "Use" and activator:IsPlayer() and then 
	    	    umsg.Start("NPCShopMenu", activator)
				umsg.End()
         end  
    end
end

function NpcShop()
local NPCShop = ents.Create("npc_shop")
NPCShop:SetPos(Vector( -6672, -9397, 136)) -- sets the position
NPCShop:SetAngles(Vector(0,0,0))
NPCShop:Spawn() -- spawns the npc_shop entity
end
hook.Add("InitPostEntity","shop",NpcShop)


shared.lua:



ENT.Base = "base_ai" 
ENT.Type = "ai"
 
ENT.PrintName		= ""
ENT.Author			= ""
ENT.Contact			= "" 
ENT.Purpose			= ""
ENT.Instructions	= ""
 
ENT.AutomaticFrameAdvance = true
 
function ENT:OnRemove()
end
 
function ENT:PhysicsCollide( data, physobj )
end

function ENT:PhysicsUpdate( physobj )
end

function ENT:SetAutomaticFrameAdvance( bUsingAnim )
	self.AutomaticFrameAdvance = bUsingAnim
end


What am I doing wrong with my code to the extent of where my NPC won’t spawn? Please help.

Is there any error in your console?

Well, there is a mass spam of: Too many vertex format changes in frame,whole world not rendered. But I don’t think this has anything to do with my shop NPC.

Are you actually spawning the NPC? If so, post the code.

Those are all the codes and the code to spawn the NPC is in the init.lua at the bottom:



function NpcShop()
local NPCShop = ents.Create("npc_shop")
NPCShop:SetPos(Vector( -6672, -9397, 136)) -- sets the position
NPCShop:SetAngles(Vector(0,0,0))
NPCShop:Spawn() -- spawns the npc_shop entity
end
hook.Add("InitPostEntity","shop",NpcShop)


Put that into your gamemode init.lua.

Thanks, I’ll try that

IT still does not work.
Someone else wanna test out my codes and see if they work?

Where’d you put the npc_shop folder?

gamemodes/darkrp/entites/entities/npc_shop

bump

Ok, explain what’s happening in detail. Are you spawning the entity? Are you able to see the menu? Explain what happens explicitly.

The entity itself does not spawn at all.

Try writing ent_create npc_shop in console and copy the error, if you get any.

After NPCShop:Spawn(), try putting a print function like print(“NPCShop:Spawn()”) just to see if the code was fully executed to that point. If you’re hosting it on SRCDS, check the dedicated server’s console. If it’s your copy of gmod hosting, then check your console. If you don’t see it, then NPCShop:Spawn() is not being called. You might want to write some print function as labels to check what functions are being called and which are not. This is one of the best ways to debug thus finding the issue in your code.

Could there be a way for me to call the NPC spawn way a little bit differently? Like instead of
[lua]
function NpcShop()
local NPCShop = ents.Create(“npc_shop”)
NPCShop:SetPos(Vector( -6672, -9397, 136)) – sets the position
NPCShop:SetAngles(Vector(0,0,0))
NPCShop:Spawn() – spawns the npc_shop entity
end
hook.Add(“InitPostEntity”,“shop”,NpcShop)
[/lua]
I could maybe do something like:
[lua]
function NpcShop()
local NPCShop = ents.Create(“npc_shop”)
NPCShop:SetPos(Vector( -6672, -9397, 136)) – sets the position
NPCShop:SetAngles(Vector(0,0,0))
NPCShop:Spawn(npc_shop) – spawns the npc_shop entity
end
hook.Add(“InitPostEntity”,“shop”,NpcShop)
[/lua]
Sorry if it doesn’t even make sense, as I am new to LUA.
Oh and doesn’t there have to be two == between local NPCShop and ents?

npc_shop isn’t declared so no.

The == operand means “if the right is equal to the left then return a true/1”
The = operand means “pass whatever value is on the right to the left”

Is your function NpcShop() being called though? Also you should keep the argument of Spawn( – this right here --) empty

Yes it is being called, it is just not spawning I guess.

Also you might want to change NPCShop:SetAngles(Vector(0,0,0)) to NPCShop:SetAngles(Angle(0,0,0))