Npc Shop

Hi all,

I was thinking of an npc shop but there is one problem i don’t know how to do the use function.
Let me explain.
When i press E(Use) On the scripted npc it needs to open an derma menu.

Then you want to make it run a console command or use a usermessage

I got that but but i cant get the derma to work

function ENT:Use( activator, caller )
if ( activator:IsPlayer() ) then
concommand.Run(“Food”)
end
end

function Food()

DermaFrame = vgui.Create( “DFrame” )
DermaFrame:SetPos( 50, 50 )
DermaFrame:SetSize( 500, 350 )
DermaFrame:SetTitle( “Guten tag” )
DermaFrame:SetVisible( true )
DermaFrame:SetDraggable( true )
DermaFrame:ShowCloseButton( true )
DermaFrame:MakePopup()
concommand.Remove(“Food”)
end

concommand.Add( “Food” , Food )

are you getting any error’s and use [lua] [/lua] tags

Ok i tryed something news.

function ENT:AcceptInput( input, activator, caller )
if input == “Use” and activator:IsPlayer() and activator:KeyPressed( 32 ) then
activator:Food()
end
end

function Food()
local DermaFrame = vgui.Create( “DFrame” )
DermaFrame:SetPos( 50, 50 )
DermaFrame:SetSize( 500, 350 )
DermaFrame:SetTitle( “Guten tag” )
DermaFrame:SetVisible( true )
DermaFrame:SetDraggable( true )
DermaFrame:ShowCloseButton( true )
DermaFrame:MakePopup()
end

Error:entities/foodseller/init.lua:41: attempt to call method ‘Food’ (a nil value)

Line 41:activator:Food()

Without activator the error is: entities/foodseller/init.lua:48: attempt to index global ‘vgui’ (a nil value)

line48:local DermaFrame = vgui.Create( “DFrame” )

[lua]

function ENT:AcceptInput( input, activator, caller )
if input == “Use” and activator:IsPlayer() and activator:KeyPressed( 32 ) then
RunConsoleCommand(“food”)
end
end

function Food()
local DermaFrame = vgui.Create( “DFrame” )
DermaFrame:SetPos( 50, 50 )
DermaFrame:SetSize( 500, 350 )
DermaFrame:SetTitle( “Guten tag” )
DermaFrame:SetVisible( true )
DermaFrame:SetDraggable( true )
DermaFrame:ShowCloseButton( true )
DermaFrame:MakePopup()
end
concommand.Add(“food”, Food)
[/lua]

are you running the code server side or client side

Client-Side. It is in cl_init.lua

Octogon,
I tryed that but i get this error:
entities\foodseller\cl_init.lua:54: attempt to index global ‘vgui’ (a nil value)

Line 54: local DermaFrame = vgui.Create( “DFrame” )

replace the frame with
[lua]
local panel = vgui.Create(“DFrame”);
panel:SetSize( 512, 512 );
panel:MakePopup();
panel:Center();
[/lua]
and see if it opens

entities\foodseller\cl_init.lua:54: attempt to index global ‘vgui’ (a nil value)

function ENT:AcceptInput( input, activator, caller )
if input == “Use” and activator:IsPlayer() and activator:KeyPressed( 32 ) then
RunConsoleCommand(“food”)
end
end

function Food()
local panel = vgui.Create(“DFrame”);
panel:SetSize( 512, 512 );
panel:MakePopup();
panel:Center();
end
concommand.Add(“food”, Food)

Hmm so its not anything to do with frame

I don’t know it anymore xD i tryed everything

[lua]local frame = vgui.Create(“Frame”)
frame:SetName(“HelloWorldFrame”)
[/lua]

You are using.

Vgui

Derma

entities\foodseller\cl_init.lua:54: attempt to index global ‘vgui’ (a nil value)

function ENT:AcceptInput( input, activator, caller )
if input == “Use” and activator:IsPlayer() and activator:KeyPressed( 32 ) then
RunConsoleCommand(“food”)
end
end

function Food()
local frame = vgui.Create(“Frame”)
frame:SetName(“HelloWorldFrame”)
end
concommand.Add(“food”, Food)

[editline]06:02PM[/editline]

Shall i do the whole Init.lua and cl_init.lua?

are you sure your not running it server side?

Nope it is in cl_init.lua
Map: gamemodes\Test\Entities\entities\Foodseller\

why are you making derma inside an entity?

Read title:
NPC SHOP :smiley:

ye but VGUI is nil because you cant make it like that

put
[lua]
function Food()

DermaFrame = vgui.Create( “DFrame” )
DermaFrame:SetPos( 50, 50 )
DermaFrame:SetSize( 500, 350 )
DermaFrame:SetTitle( “Guten tag” )
DermaFrame:SetVisible( true )
DermaFrame:SetDraggable( true )
DermaFrame:ShowCloseButton( true )
DermaFrame:MakePopup()
concommand.Remove(“Food”)
end

concommand.Add( “Food” , Food )
[/lua]

in gamemodes\Test\cl_init.lua

Oh yeah i didn’t see that he is trying to put it in to an entity.