Storage Items

I’m currently trying to create a Sent that stores items touching it.

What I’m trying to figure out is,

How do I get a vgui to pop only for the player who calls ENT:Use on it. Currently I have it pop up for all players and that’s where I’m stuck.

How do I store items per entity? An example, I walk up to someones storage unit and it contains other items than my own.

You don’t need to post exact code. I just need a plan to follow.

How do I get a vgui to pop only for the player who calls ENT:Use on it. Currently I have it pop up for all players and that’s where I’m stuck.
– then you are obviously doing something wrong. REALLY wrong. the function only passes in 1 player… not all of them. Use usermessages and send it to the activator.

How do I store items per entity? An example, I walk up to someones storage unit and it contains other items than my own.
A table on the entity.

Here’s the init.lua umsg part
[lua]
function ENT:Use()
self:SetUseType(SIMPLE_USE)
umsg.Start(“popup”)
umsg.End()
end
[/lua]

Here’s cl_init.lua
[lua]

include( “shared.lua” )
function ENT:Draw()
self.Entity:DrawModel()
end
local function showfood()
local DFrame1

DFrame1 = vgui.Create('DFrame')
DFrame1:SetSize(449, 326)
DFrame1:Center()
DFrame1:SetTitle('Food')
DFrame1:SetSizable(false)
DFrame1:MakePopup()

end
usermessage.Hook(“popup”, showfood)
[/lua]

First of all… That’s not where you set the use type…

Second… Ok? You have the base… now display its inventory via usermessages…

Also, you arent filtering your usermessage.

Alright I moved the SetUseType out of the ENT:Use.

So I would use RecipientFilter() to send to the correct client?
How does this look
[lua]
function ENT:Use(ply)
local filter = RecipientFilter()
filter:AddPlayer(ply)

umsg.Start("popup", filter)
umsg.End()

end
[/lua]

could just use



umsg.Start("popup", ply)


You are fine on that end… Now just send the content.

I’m completely stuck on the content part. I’m quite new to sending table data through umsgs. How would I do this?

Well I have no idea what you are trying to send, so I have no clue how to help you without you telling me how your table is stored.

Read this page: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd325.html

I’ve made a very basic spawning system. However, Once again it shows up for everyone once I send it. I do not know how I can get it show up for just the person putting it into the entity.
Here’s the sending code once the entity is put into it.
[lua]
function ENT:StartTouch(toucher)
if (toucher:GetClass()) == “food” then
umsg.Start(“sendfood”)
umsg.End()
toucher:Remove()
end
end
[/lua]

I don’t know how to get a ply value into this function.

Here’s the clientside version
[lua]
local function makebutton()
foodstorage = {}
foodstorage[1] = “food”

for k,v in pairs(foodstorage) do
	if v == "food" then
		local DButton1 = vgui.Create('DButton')
		DButton1:Center()
		DButton1:SetText("Spawn")
		DButton1.DoClick = function()
			RunConsoleCommand("fridge_drop")
			DButton1:Remove()
		end
	end
end

end
usermessage.Hook(“popup”, showfood)
usermessage.Hook(“sendfood”, makebutton)
[/lua]

Do you have two items for example:
A fridge and an orange?

I’ve been making something like yours to see if I could create it and so far it works for me I just need someone else on the server.

Updated: Currently it runs off the owner of the fridge so if someone like an admin places the orange inside of it. It will place the orange on the owner of the fridges table.

I create the fridge and when the entity food touches it (from the darkrp microwave ) it sends the usermessage sendfood and makes the button. When another player does this after I do it, it spawns the button for me as well.

Updated: Currently it runs off the owner of the fridge so if someone like an admin places the orange inside of it. It will place the orange on the owner of the fridges table. But no one else can use it.

So how did you make it work so that each player has a different inventory in their fridge? I can’t wrap my head around it.

I’ll give you this as a reference:
Fridge:

cl_init:
[lua]
include(‘shared.lua’) --Include shared.lua

function ENT:Initialize()
end

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

function ShowFood(data)
local DMain = vgui.Create(“DFrame”)
DMain:SetSize(250, 300)
DMain:SetTitle(“Fridge”)
DMain:SetVisible(true)
DMain:ShowCloseButton(true)
DMain:MakePopup()
DMain:Center()
local DList = vgui.Create(“DPanelList”, DMain)
DList:SetPos(5, 31)
DList:SetSize(240, 300-36)
DList:SetSpacing(5)
DList:EnableHorizontal(true)
DList:EnableVerticalScrollbar(true)
local Items = data:ReadShort()
for i = 1, Items do
local name = data:ReadString()
local model = data:ReadString()
local Icon = vgui.Create(“SpawnIcon”)
Icon:SetModel(model)
Icon.OnMousePressed = function()
local option = DermaMenu()
option:AddOption(“Drop Banana”, function()
RunConsoleCommand(“drop_food”, name)
Icon:Remove()
end)
option:Open()
end
Icon:SetToolTip(name)
DList:AddItem(Icon)
end
end
usermessage.Hook(“ShowFood”, ShowFood)
[/lua]

Init:
[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
include(“shared.lua”)

function ENT:Initialize()
self:SetModel(“models/props_c17/FurnitureFridge001a.mdl”)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
end

function ENT:SpawnFunction( ply, tr )
ply.food = {}
if (!tr.Hit) then return end

local SpawnPos = tr.HitPos + tr.HitNormal * 36

local ent = ents.Create("fridge")
ent:SetPos(SpawnPos)
ent:Spawn()
ent:Activate()
return ent

end

function ENT:Touch(enthit)
if (ValidEntity(enthit) and enthit:IsValid() and enthit:GetClass() == “banana”) then
self.Owner.food[enthit:GetClass()] = enthit:GetModel()
enthit:Remove()
end
end

function ENT:Use(activator, ent)
PrintTable(activator.food)
if(activator != self.Owner) then
activator:ChatPrint(“You cannot use this!”)
return
end
umsg.Start(“ShowFood”, activator)
umsg.Short(table.Count(activator.food))
for k,v in pairs(activator.food) do
umsg.String(k)
umsg.String(v)
end
umsg.End()
end

concommand.Add(“drop_food”, function(ply,cmd,args)
local tof = args[1]
if not tof then
print(“Invalid arguements!”)
return
end
for k,v in pairs(ply.food) do
if (tof == k) then
local food = ents.Create(tof)
food:SetPos(ply:GetPos()+Vector(0,0,120))
food:Spawn()
food:Activate()
ply.food[tof] = nil – not using number indexes
end
end
end)
[/lua]

shared:
[lua]
ENT.Type = “anim”
ENT.Base = “base_gmodentity”
ENT.Category = “Inferno’s Fridge Items”

ENT.PrintName = “Fridge”
ENT.Author = “Inferno, Eh?”
ENT.Contact = “N/A”

ENT.Spawnable = true
ENT.AdminSpawnable = false
[/lua]

banana:

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

function ENT:Initialize()
end

function ENT:Draw()
self:DrawModel()
end
[/lua]

init:
[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
include(“shared.lua”)

function ENT:Initialize()

self:SetModel("models/props/cs_italy/bananna.mdl") 
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
	phys:Wake()
end

end

function ENT:SpawnFunction( ply, tr )
if (!tr.Hit) then return end

local SpawnPos = tr.HitPos + tr.HitNormal * 36

local ent = ents.Create("banana")
ent:SetPos(SpawnPos)
ent:Spawn()
ent:SetUnFreezable(!ent:GetUnFreezable())
ent:Activate()
return ent

end
[/lua]

shared:
[lua]
ENT.Type = “anim”
ENT.Base = “base_gmodentity”
ENT.Category = “Inferno’s Fridge Items”

ENT.PrintName = “Banana”
ENT.Author = “Inferno, Eh?”
ENT.Contact = “N/A”

ENT.Spawnable = true
ENT.AdminSpawnable = false
[/lua]