Need inventory help, again...

Hey all, it’s been a lil’ while since I asked for the inventory and then I gave up afterwards, but this time I’m trying at it again and I just can’t seem to network it correctly, here’s what I have so far.
[lua]
local TranslateItem = {}
TranslateItem[“weapon_ak47”] = “models/weapons/w_rif_ak47.mdl”
TranslateItem[“weapon_m4”] = “models/weapons/w_rif_m4.mdl”
TranslateItem[“weapon_para”] = “models/weapons/w_mach_para.mdl”
TranslateItem[“weapon_fiveseven”] = “models/weapons/w_pist_fiveseven.mdl”
TranslateItem[“weapon_mac10”] = “models/weapons/w_smg_mac10.mdl”
TranslateItem[“weapon_mp5”] = “models/weapons/w_smg_mp5.mdl”
TranslateItem[“weapon_deagle”] = “models/weapons/w_pist_deagle.mdl”

usermessage.Hook(“sendItem”,function(i)
for k,v in pairs(TranslateItem) do
Inventory[i:ReadString()] = i:ReadLong()
if i:ReadString() == k then
Inventory[i:ReadString()].Model = v
end
end
print(“100%”)
end)

usermessage.Hook(“openInventory”,function()
local m = vgui.Create(“DFrame”)
m:SetPos(ScrW()/2-200,ScrH()/2-200)
m:SetSize(400,400)
m:MakePopup()
m:ShowCloseButton(true)
m.Paint = function()
local tex = surface.GetTextureID(“hpbarsd”)
surface.SetTexture(tex)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(0,0,m:GetWide(),m:GetTall())
end
local l = vgui.Create( “DPanelList”, m )
l:EnableVerticalScrollbar( true )
l:EnableHorizontal( true )
l:SetPadding( 4 )
l:SetPos(10,30)
l:SetSize(200, 160)
for k,v in pairs(Inventory) do
local i = vgui.Create( “SpawnIcon”, l )
if v > 0 then
i:SetModel( k.Model )
l:AddItem( i )
end
end
end)
[/lua]
The reason the translate table is there is so it can give me a valid model for the weapon I’m using. I’d appreciate any help, I’m on the edge of actually finishing a gamemode for once… :v;

What exactly is the issue

It’s not giving me the model, and on top of that it’s not adding an icon for each weapon in my inventory :v

Can we see the server-side code as well

Ah yes, uh here;
[lua]
local tbl = glon.decode(player:GetPData(“Inventory”))
if type(tbl) == “table” then
player.Inventory = tbl
else
player.Inventory = {}
end
[/lua]

And the meta functions if you need these;
[lua]
function Player:GiveItem(item,amt)
amt = amt or 1
amt = (self.Inventory[item] or 0) + amt
self.Inventory[item] = amt
umsg.Start(“sendItem”,self)
umsg.String(item)
umsg.Short(amt)
umsg.End()
self:SetPData(“Inventory”,glon.encode(self.Inventory))
end

function Player:HasItem(item,amt)
return self.Inventory[item]
end

function Player:TakeItem(item,amt)
amt = amt or 1
amt = math.Max(0,(self.Inventory[item] or 0) - amt)
if amt < 1 then
amt = nil
end
self.Inventory[item] = amt
umsg.Start(“sendItem”,self)
umsg.String(item)
umsg.Short(amt or 0)
umsg.End()
self:SetPData(“Inventory”,glon.encode(self.Inventory))
end

function Player:Use(item,amt)
if self:HasItem(item,amt) then
if self.Inventory[item] >= amt then
self:TakeItem(item,amt)
self:Give(item)
end
end
end
[/lua]

You are using ReadString twice in the sendItem hook but you are only sending one string

Well, that didn’t exactly fix anything currently but I’m sure if I were to, and hopefully will progress it would have broken something. But thanks, my codes like this now
[lua]
local item
local amt
usermessage.Hook(“sendItem”,function(i)
item = i:ReadString()
amt = i:ReadShort()
for k,v in pairs(TranslateItem) do
Inventory[item] = amt
if item == k then
Inventory[item].Model = v
end
end
print(“100%”)
end)
[/lua]
and now I get this error:




[gamemodes\showdown\gamemode\cl_init.lua:26] attempt to index field '?' (a number value)



Bump? :<

From what I see, you’re now trying to set index ‘Model’ of a string.



    amt = i:ReadShort() --Sets atm to a string
    for k,v in pairs(TranslateItem) do
        Inventory[item] = amt --Sets Inventory[item] to atm, which is a string
            if item == k then
                Inventory[item].Model = v --Thus here, you're basically doing atm.Model = v
            end


Well, it’s fixed, I did it, fuck yeah! Thanks for the help though King.

That wasn’t it :v, and you can override model functions and shit because it has nothing to do with a known entity or anything for that matter but what I did was this;
[lua]
usermessage.Hook(“sendItem”,function(i)
local item = i:ReadString() or “”
local amt = i:ReadShort() or nil
Inventory[item] = amt or 1
end)
[/lua]
And now it works, :D.