• VGUI Menu Not Properly Refreshing
    0 replies, posted
This is a basic item container entity I've been writing, the items are transferring and everything is working fine except for when I attempt to repopulate the player inventory panel. For some context the inventory object of the player is a table that get entries from a MySQL database inserted into it on player load, giveitem and removeitem update this table and sync it to a MySQL database, the refresh function is RefreshContainerMenu(). There are no errors serverside or clientside. I'd really appreciate some help on this. [CODE] AddCSLuaFile(); ENT.Base = "base_anim"; ENT.Type = "anim"; ENT.PrintName = "Item Container"; ENT.Author = ""; ENT.Contact = ""; ENT.Purpose = ""; ENT.Instructions = ""; ENT.Category = "testing"; ENT.Spawnable = true; ENT.AdminSpawnable = true; ENT.AutomaticFrameAdvance = true; function ENT:PostEntityPaste( ply, ent, tab ) GAMEMODE:LogSecurity( ply:SteamID(), "n/a", ply:VisibleRPName(), "Tried to duplicate " .. ent:GetClass() .. "!" ); ent:Remove(); end function ENT:Initialize() self:SetModel( "models/props_junk/wood_crate001a.mdl" ); if( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ); self:SetMoveType( MOVETYPE_VPHYSICS ); self:SetSolid( SOLID_VPHYSICS ); local phys = self:GetPhysicsObject(); if( phys and phys:IsValid() ) then phys:EnableMotion( false ); end self:SetUseType( SIMPLE_USE ); end inventory = { }; end function ENT:Use( ply ) if( SERVER ) then net.Start( "nContainer" ); net.Send( ply ); end end if( CLIENT ) then function nContainer( len ) CCP.Container = vgui.Create( "DFrame" ) CCP.Container:SetSize( 500, 500 ) CCP.Container:SetTitle( "Object Container" ) CCP.Container:MakePopup() CCP.Container:Center() CCP.ContainerInventory = vgui.Create( "DListView", CCP.Container ) CCP.ContainerInventory:SetMultiSelect( false ) CCP.ContainerInventory:SetSize( 225, 480 ) CCP.ContainerInventory:SetPos( 0, 20 ) CCP.ContainerInventory:AddColumn( "Item" ) CCP.ContainerInventory:AddColumn( "Weight" ) for k, v in pairs ( inventory ) do local i = GAMEMODE:GetItemByID( v ) local w = i.Weight CCP.ContainerInventory:AddLine( v, w ) end CCP.PlayerInventory = vgui.Create( "DListView", CCP.Container ) CCP.PlayerInventory:SetMultiSelect( false ) CCP.PlayerInventory:SetSize( 225, 480 ) CCP.PlayerInventory:SetPos( 275, 20 ) CCP.PlayerInventory:AddColumn( "Item" ) CCP.PlayerInventory:AddColumn( "Weight" ) for k, v in pairs( LocalPlayer().Inventory ) do local i = GAMEMODE:GetItemByID( v ); if( i ) then local item = v; local ID = k; local weight = i.Weight CCP.PlayerInventory:AddLine( v, i.Weight ) end end CCP.MoveOutBut = vgui.Create( "DButton", CCP.Container ) CCP.MoveOutBut:SetText( ">" ) CCP.MoveOutBut:SetPos( 235, 400 ) CCP.MoveOutBut:SetSize( 30, 25 ) CCP.MoveOutBut.DoClick = function() local i = CCP.ContainerInventory:GetSelectedLine(); if( !LocalPlayer():CanTakeItem( inventory[i] ) ) then GAMEMODE:AddChat( Color( 200, 0, 0, 255 ), "CombineControl.ChatNormal", "That's too heavy for you to carry.", { CB_ALL, CB_IC } ); return; end net.Start( "nTakeItem" ) net.WriteString( inventory[i] ) net.SendToServer() table.remove( inventory, i ) RefreshContainerMenu() end CCP.MoveInBut = vgui.Create( "DButton", CCP.Container ) CCP.MoveInBut:SetText( "<" ) CCP.MoveInBut:SetPos( 235, 450 ) CCP.MoveInBut:SetSize( 30, 25 ) CCP.MoveInBut.DoClick = function() local s = CCP.PlayerInventory:GetSelectedLine(); local i = LocalPlayer().Inventory[s] net.Start( "nStoreItem" ) net.WriteString( i ) net.SendToServer() table.insert( inventory, i ) RefreshContainerMenu() end end net.Receive( "nContainer", nContainer ); else function nTakeItem( len, ply ) local item = net.ReadString(); if( table.HasValue( inventory, item ) ) then ply:GiveItem( item, 1 ) end end net.Receive( "nTakeItem", nTakeItem ) function nStoreItem( len, ply ) local item = net.ReadString() if( table.HasValue( ply.Inventory, item ) ) then ply:RemoveItem( ply:GetInventoryItem( item ) ) end end net.Receive( "nStoreItem", nStoreItem ) end function RefreshContainerMenu() CCP.ContainerInventory:Clear() CCP.PlayerInventory:Clear() for k, v in pairs ( inventory ) do local i = GAMEMODE:GetItemByID( v ) local w = i.Weight CCP.ContainerInventory:AddLine( v, w ) end for k, v in pairs( LocalPlayer().Inventory ) do local i = GAMEMODE:GetItemByID( v ); if( i ) then local item = v; local ID = k; local weight = i.Weight CCP.PlayerInventory:AddLine( v, i.Weight ) end end end function ENT:CanPhysgun() return true; end [/CODE]
Sorry, you need to Log In to post a reply to this thread.