• Server Client table not saving
    15 replies, posted
Making a little inventory but for some reason when I try to use a item the server acts as if the items aren't there : [lua] function PlayerInitialSpawn( ply ) ply.inv = {} ply.inv.weight = 0 ply.inv.items = {} ply.inv.equipment = {} AddItem("Stick", 10, ply) AddItem("Skull", 5, ply) PrintTable(ply.inv.items) end hook.Add("PlayerInitialSpawn","initSpawn",PlayerInitialSpawn); [/lua] Prints it out as supposed to, the items are there. [lua] function UseItem( ply, command, arguments ) PrintTable(ply.inv.items) for k,v in pairs(ply.inv.items) do if(v[1] == arguments[1]) then AddItem(arguments[1],-1,ply) end end end concommand.Add( "UseItem", UseItem ) [/lua] The PrintTable function doesn't print anything, and I checked if its getting called by just adding a print in there. Could anyone help me out here ?
function AddItem()? Wheeereeee? Ohey I'm a fuckin NINJA :D
[QUOTE=iRzilla;26953485]Nope. You weren't viewing this thread when I posted that, you're just repeating what I said to try and seem clever.[/QUOTE] zing
Think I know it, i'm passing the player object from the client and the inventory is serverside so I probably need too look the player up in THE server. Can't check it now though at grandma for xmas
I am doing that, Its getting called but I mean its passing allong a player object from the client, and since the inventory is stored in the player serverside its not going to find a inventory in the clientside ply. [editline]25th December 2010[/editline] going to try it now, the additem function so you can take a look at it while I'm bussy : [lua] function AddItem( name, amount, ply ) local inItems = false if(Items[name] != nil) then for k,v in pairs(ply.inv.items) do if(v[1] == name) then inItems = true v.amount = amount + v.amount umsg.Start( "ChangeItem" ); umsg.String( name ); umsg.Short( v.amount ); umsg.End(); break end end if(!inItem) then table.insert(ply.inv.items, {name, amount}) umsg.Start( "AddItem" ); umsg.String( name ); umsg.Short( amount ); umsg.End(); end end end [/lua] clientside [lua] items = {} function AddItem( data ) item = {} item.Name = data:ReadString() item.amount = data:ReadShort() table.insert(items,item) end usermessage.Hook( "AddItem", AddItem ) [/lua] [editline]25th December 2010[/editline] OKe well nvm, somebody knows why it isn't working ?
Does PrintTable(items) show you the table? Also, fyi, you are sending the items to all players. Not sure if that is what you intended to do.
hahah lol no, didn't even notice, checking your question now. [editline]26th December 2010[/editline] [QUOTE=_nonSENSE;26962107]Does PrintTable(items) show you the table? Also, fyi, you are sending the items to all players. Not sure if that is what you intended to do.[/QUOTE] on the client or did you mean something like on the server like ply.items ? [editline]26th December 2010[/editline] Both work, on the server : ply.items and clientside: items, but ply.items just gives me the clientside inventory I need the serverside one.
Thought I'd bump this a bit case I replied to this yesterday night when no-one was online
Oke well, its been a few days (4) and I'm still stuck for fucks sake anybody has a clue why this won't work ?
First you have this [lua] local inItems = false [/lua] And then you have this further down the function [lua] if(!inItem) then [/lua] [b]s[/b]
Changed that but the result still stays the same
changed if(!inItem) to if(!inItems)
Sorry, you need to Log In to post a reply to this thread.