On Use (e) Derma popup => Entity

Hey guys.

I want to make an entity. If you press E on it (use key) a derma pops up. It’s basically an inventory, but not as GUI in a HUD format, it’s a GUI in an entity format. At least thats what I want it to be.

I set up the entity how Mr. Cosmic Seagul explained in his video. I got his version of it working, however, I dont want the entity to kill myself if I press E.

This is my Code, but it’s not working. (No errors, just not working)

cruiserentity.lua


AddCSLuaFile()

ENT.Type	= "anim"
ENT.Base	= "base_gmodentity"

ENT.PrintName	= "Storage"
ENT.Author		= "Pakos"
ENT.Purpose		= "Press E to open."
ENT.Instructions 	= "Press E to use it"

ENT.Spawnable	= false
ENT.AdminSpawnable	= false

function ENT:Initialize()
	self:SetHealth( 1000000 )
	self:SetModel( "models/breen.mdl" )
	self:SetSolid( 2 )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	
	local phys = self:GetPhysicsObject()
	if ( phys:IsValid() ) then
	
		phys:Wake()
	
	end
end

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

function ENT:Use( ply )
	if ( ply:IsPlayer() ) then		
		local base = vgui.Create( 'DFrame' )
			base:SetSize( 400, 200 )
			base:Center()
			base:SetTitle( '' )
			base:ShowCloseButton( true )
			base:SetDraggable( false )
			base:SetVisible( true )
			base:MakePopup()
			function base:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 255, 255, 255, 255 ) )
			end
--------------------------------------------------------------------------------------------
			local button = vgui.Create( 'DButton' )
			button:SetParent( base )
			button:Center()
			button:SetSize( 200, 40 )
			button:SetText( 'Test' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color(222, 222, 222, 120 ) )
			end
			
			function button:Paint( w, h )
				if In then
				surface.SetDrawColor(222, 222, 222, 60 )
				surface.DrawRect(0, 0, button:GetWide(), button:GetTall())
				end
			end
	end
end

item_basic folder:

init.lua


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

function ENT:Initialize()
	self.Entity:SetModel( getItems( self:GetNWString("itemName") ).model )
	
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	self.Entity:SetUseType(SIMPLE_USE)
	local phys = self.Entity:GetPhysicsObject()
	if phys and phys:IsValid() then phys:EnableGravity(true) phys:Wake() end
end

function ENT:SetItemName( name )
	self.itemName = name
end

function ENT:Use( activator, caller )
	getItems( self:GetNWString("itemName") ).use(activator, self)
end

function ENT:Touch( ent )
end

function ENT:OnRemove()
end

function ENT:Think()
end

cl_init.lua


include("shared.lua")

function ENT:Think()
end

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

shared.lua


ENT.Type = "anim"
ENT.Base = "base_entity"
ENT.PrintName = "item"
ENT.Author = "pakos"

What have I done wrong? (I’m new to lua, please don’t be too harsh on me <3)

[editline]3rd June 2014[/editline]

This error appears:


[ERROR] gamemodes/theopen/entities/entities/cruiserentity.lua:34: attempt to i
ex global 'vgui' (a nil value)
  1. unknown - gamemodes/theopen/entities/entities/cruiserentity.lua:34


[editline]3rd June 2014[/editline]

attempt to index*

You’re calling vgui in SERVER.

Make sure you use if ( CLIENT ) then… around client parts.