-
Notifications
You must be signed in to change notification settings - Fork 77
Inventory
rebel1324 edited this page Dec 25, 2014
·
13 revisions
The Inventory object is pretty important object in the NutScript framework. Not only character's inventory, it can be used on many entity/stuffs in the gamemode.
Having Inventory as Object has following advantages:
- Good Extensibility
- Good Adaptability
- Easy to Manage Items
To use Inventory Object to other, All you need to do is just create the inventory and assign the inventory on the entity/object.
id
- This is the numeric key for the inventory in the database. This is unique for each item and is shared.
slots
- This is the table for the inventory in the database. This table contains List of Item Objects that inventory contains.
-
w
h
- This is the numeric value for the inventory in the database. This is the size of the inventory, which means the amount of items that the inventory object can hold.
inventory:getSize()
- Returns the size of the inventory object.
inventory:print(printPos?)
- Prints the simple information of the inventory object.
inventory:findError()
- Find and Prints the error of the inventory object.
inventory:printAll()
- Prints the all content of the inventory object.
inventory:setOwner(client)
- Sets the owner of the inventory object.
inventory:canItemFit(x, y, w, h, item2)
- Returns whether the provided item size on the providied position can fit on current inventory or not.
inventory:findEmptySlot(w, h, onlyMain)
- Returns the x and y slot poistion for the provided size of the item.
inventory:getItemAt(x, y)
- Returns the item object at the provided position.
inventory:remove()
- Removes certain class of the item in the inventory.
inventory:getReceiver()
- Get the networking recipicient filter of the inventory.
inventory:getItemByID(itemClass)
- Searches the inventory slots with the provided item class and returns the found item object.
inventory:getItems(onlyMain)
- Gets all items in the inventory (If there is another inventory object in the inventory, includes their contents in the result if the recursive search is not supressed.)
inventory:getBags()
- Gets all other inventory objects in the current inventory object's slots.
inventory:hasItem(itemClass, itemData)
- Returns whether current inventory object has the item or not.
inventory:sendSlot(x, y, item)
- Sends an item to current/another inventory slot.
inventory:add(itemClass, quantity, itemData, x, y, noReplication)
- Adds new/existing item on the current inventory object.1
inventory:sync()
- Synchronizes the inventory's information to the receiver. If the receiver is nil, then everyone will receive the inventory's information. If a player is provided, only that player will receive the information. If the receiver is any other value, then only public variables are sent.
local inventories = nut.item.inventories[id]
local items = self:getInv():getItems(true)
for k, v in pairs(items) do
if (v.isWeapon) then
if (v.isMelee) then
v:setData("broken", false)
elseif (v.isFirearm) then
v:setData("jammed", false)
end
v:setData("quality", 100)
end
end
print("Repaired all Items in Inventory ID: ".. id)
function META:getBags()
local invs = {}
for k, v in pairs(self.slots) do
for k2, v2 in pairs(v) do
local isBag = v2.data.id
if (!table.HasValue(invs, isBag)) then
if (isBag and isBag != self:getID()) then
table.insert(invs, isBag)
end
end
end
end
return invs
end