Hey, I'm developing an inventory addon for DarkRP, and I'm trying to communicate changes with the player's inventory (server adds/removes/changes inventory -> hook run -> hook sends data to client), but for some reason whenever I set the player's inventory to another table, it refuses to actually record the item's string ID.
Here's the code snippet that appears to be causing problems:
for k,v in ipairs(emptyslots) do
if(!amount || self:slotSpacesFull()) then break end
local newSlot, remainder = meta.slot:create(item, amount)
amount = remainder
self.slots[v] = newSlot
print(self.slots[v].item)
print(self.slots[v].amount)
end
hook.Run("rpginv_invUpdated", self)
Apologies about not putting in the code format... it keeps squishing the code together for some reason.
Anyways, "self" in this context is the inventory (which is a metatable), and inventory.slots is what contains the actual items (a slot is simply a container for an item ID, and an amount; think minecraft style)
Regardless, as you can see I create a new slot and then assign it to self.slots[v] (v is an index). I have no clue what the problem is, because after the hook is run at the very bottom, I print the table inside of the hook, like so:
hook.Add("rpginv_invUpdated", "updatePlayerInv", function(inv, updateTbl)
PrintTable(inv)
if(inv.owner:IsPlayer()) then
RPGINV.Util:sendInventoryUpdate(inv.owner, updateTbl)
end
end)
And here is the result in the console:
1:
amount = 1
That might not seem like a problem, but it is supposed to look like this:
1:
item = "item_debug"
amount = 1
So there. I have no clue what the problem is, and I've been stuck on this for a couple days now. I'm currently thinking that it has something to do with the way I handle deleting slots in the table, but I'm not sure that's the case considering when I need to delete an item all I do is use a function that calls table.remove()
Any help is appreciated. Thank you very much!
Sorry, you need to Log In to post a reply to this thread.