Two questions

I’ve recently been working on a gamemode, for the experience and learning. I’ve got a few questions.

I’ve got a SENT which is basically a crate for storing items. Let’s say the items are stored within self.Items. But then I want it so when the client presses E on the crate, it draws a GUI with all the items. What would be a good way to send the item table to the client? I tried SetNetworkedVar() but that does not take tables. Is datastream the way to do it?

So far, when an entity is stored in the crate, I store it’s name, model and the classname. I’d obviously prefer to just store the classname and then retrieve the printname and model when needed (drawing the GUI). I played around with weapons.Get(), weapons.GetList() and weapons.GetStored() but failed.

All help appreciated, thanks.

Yes you could do datastream, then have a ds hook on the client that would draw what it got from the table you sent.

For your second, weapons.Get(<classname>) should work. Here is an example of what you can get with that function (I used it with weapon_zs_battleaxe on a zs server):

Okay, datastream it is then.

Ahh, I just realised why weapons.Get() wasn’t working. It only retrieves SWEPs which means it won’t work for weapon_pistol which is what I was testing it with. Any way to retrieve the weapon table, or at least the Printname and world model from any weapon (including HL2 weapons)?

Unfortunately my gmod isn’t working for me to equip an hl2 weapon. Try doing this in the console when you have an hl2 weapon equipped:

lua_run_cl PrintTable(LocalPlayer():GetActiveWeapon():GetTable())

Nothing useful unfortunately.

function ENT:UpdateItems( handle, id, encoded, decoded )
	self.Items = decoded
datastream.Hook( "CrateItems", self.Entity:UpdateItems )

I give up. Returns entities\crate/cl_init.lua:44: function arguments expected near ‘)’
Can’t get it to callback. >_<

Any ideas?

self.Entity:UpdateItems is expecting you to do self.Entity:UpdateItems(handle, id, encoded, decoded) however this would still do the wrong thing.
Your datastream would have to send which entity is getting its items updated as well as the items. You’d have to change how the data is sent, instead of just the Items have the Items as a subtable and the Entity which is getting updated another value in the table.
–[[ table should look something like this
Entity = Entity,
Items = {
I don’t know how you’ve done this but your items go in here
local function UpdateItems(handle, id, encoded, decoded)
function ENT:UpdateItems( Items )
self.Items = Items
datastream.Hook( “CrateItems”, UpdateItems )
Also self.Entity is equivalent to just self but less efficient. I think self.Entity is a relic of an older version of GMod.

Ahh, I understand. Thanks a lot!