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.
[url]http://wiki.garrysmod.com/?title=ENT.Use[/url]
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" )
[QUOTE=spekki7;17774267]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" )[/QUOTE]
[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
[QUOTE=spekki7;17776305]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)[/QUOTE]
[url]http://wiki.garrysmod.com/?title=Clientside_Lua#vgui[/url]
[lua]local frame = vgui.Create("Frame")
frame:SetName("HelloWorldFrame")
[/lua]
You are using.
[url]http://wiki.garrysmod.com/?title=Derma_Controls#DFrame[/url]
Vgui
[url]http://wiki.garrysmod.com/?title=Lua:VGUI_Basics[/url]
Derma
[url]http://wiki.garrysmod.com/?title=Derma_VGUI_Example[/url]
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 :D
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
[QUOTE=*Fish*;17777013]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[/QUOTE]
Oh yeah i didn't see that he is trying to put it in to an entity.
[QUOTE=octogon;17781687]Oh yeah i didn't see that he is trying to put it in to an entity.[/QUOTE]
Dont act smart.
And yeah, you can only do it in an entity if you put: [lua] if CLIENT then drawhudshit end[/lua]
You can do derma menus in an enity just fine in its cl_init. I do it all the time. :s
Don't need to use if CLIENT (I assume in shared you mean) at all.
[QUOTE=Emz;17790820]You can do derma menus in an enity just fine in its cl_init. I do it all the time. :s
Don't need to use if CLIENT (I assume in shared you mean) at all.[/QUOTE]
Example or it didn't happen, and you and Jamie don't even know lua so its bad enough trying to help out and rating everyone dumb, it doesn't bother me though.
[quote=To Jamie932]stop trolling, and stop acting like you know lua.[/quote]
I haven't rated you dumb but I will now. Here's a free box.
Of course I know Lua, and so does Jamie from what I have seen elsewhere.
I've coded 3 years in C++ and 1 year in Lua.
Spekki if you still get any issues just PM me if you need to.
Yeah, I know Lua. Just I know a different aspect. I code Gamemodes, rather than entities.
So, sorry for getting it wrong. And octogon, behave yourself or Santa wont get you any presents this Christmas.
Sorry, you need to Log In to post a reply to this thread.