NPC Shop

I’m experiencing a strange event when I try to use my NPC to call up a clientsided menu.

Whenever I try to hit E (I’ve also tried +use in console incase it’s an error with the binds) on my entity, no errors pop up, nor do my debug prints pop up.

This is all code for the entity:

Init.lua
[lua]

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

function ENT:Initialize( )

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:OnTakeDamage()
return false
end

function ENT:Use(activator, caller)

print("SV Activator:IsPlayer() : "..tostring(activator:IsPlayer()))
if activator:IsPlayer() then
	umsg.Start( "pmodelreset", activator )
	umsg.End()
	print("SV pmodelreset umsg has been sent")
	local pmodels = string.Explode("

“, file.Read(“gparty/pmodels.txt”))
local num = table.Count( pmodels )
local ownedm = string.Explode(”
“, file.Read(“gparty/pdata/”…activator:GetNWString(“txtid”)…”.txt"))
print(“SV pmodel, num, and ownedm variables have been established”)
for _,v in pairs(ownedm) do
umsg.Start( “ownedm” )
umsg.String( v )
umsg.End()
end
print(“SV The for look for ownedm usermessage has completed”)
umsg.Start( “pmodelcount”, activator )
umsg.Long( num )
umsg.End()
print(“SV pmodelcount usermessage has been sent”)
for _,v in pairs(pmodels) do
umsg.Start( “pmodel”, activator )
umsg.String( v )
umsg.End()
end
print(“SV pmodel usermessage has been sent”)
umsg.Start(“ShopNPCUsed”, activator)
umsg.End()
print(“SV ShopNPCUsed usermessage has been sent”)
end
end
[/lua]

cl_init.lua
[lua]
include(‘shared.lua’)

local pmodelc = 0
local function pmodelcounts( data )
pmodelc = data:ReadLong()
print(“CL pmodelcount has been set to”…tostring(pmodelc))
end
usermessage.Hook(“pmodelcount”, pmodelcounts)
local ownedm = {}
print(“CL ownedm table set”)
local pmodels = {}
print(“CL pmodels table set”)
local function pmodelreset()
pmodels = {}
print(“CL pmodels has been reset”)
ownedm = {}
print(“CL ownedm has been reset”)
end
usermessage.Hook(“pmodelreset”, pmodelreset)

local function pmodeladd( data )
pmodels[table.Count(pmodels)+1] = data:ReadString()
print(“CL pmodeladd umsg received”)
end
usermessage.Hook(“pmodel”, pmodeladd)

local function ownedmadd( data )
ownedm[table.Count(ownedm) + 1] = data:ReadString()
print(“CL ownedm umsg received”)
end
usermessage.Hook(“ownedm”, ownedmadd)
local function NPCShopMenu()

local BB = vgui.Create("DFrame")
BB:SetSize(700, 600)
BB:SetPos( ScrW()/2-BB:GetWide()/2, ScrH()/2-BB:GetTall()/2 )
BB:SetTitle( "Gshop - Playermodel Shop" )
BB:SetVisible( true )
BB:SetDraggable( false )
BB:ShowCloseButton( true )
BB:MakePopup()
BB.Paint = function()
	draw.RoundedBox(4, 0, 0, BB:GetWide(), BB:GetTall(), Color(76,76,76))
	draw.RoundedBox(2, 2, 2, BB:GetWide()-4, 21, Color(76,76,100))
end
print("CL BB:DFrame set")

local DermaListView = vgui.Create("DListView", BB)
DermaListView:SetPos(10, 20)
DermaListView:SetSize(BB:GetWide()-20, BB:GetTall()-30)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn("Player Model")
DermaListView:AddColumn("Owned")
DermaListView:AddColumn("Price")
print("CL DermaListView set")
for _,v in pairs(pmodels) do
	local owned = "Unowned"
	for _,b in pairs(ownedm) do
		if b == v then
			owned = "Owned"
			break
		end
	end
	DermaListView:AddLine(v, owned, "1000")
	print("CL DermaListView:AddLine("..v..", "..owned..", 1000)")
end

end

usermessage.Hook(“ShopNPCUsed”, NPCShopMenu)

[/lua]

shared.lua if it’s necessary
[lua]

ENT.Base = “base_ai”
ENT.Type = “ai”
ENT.AutomaticFrameAdvance = true

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

Instead of ENT:Use, use ENT:AcceptInput like so:


function ENT:AcceptInput( name, activator, caller )	
 if Name == "Use" and Caller:IsPlayer() then
		--your code
	end
end

Thank you