diff options
Diffstat (limited to 'gamemode/core/inventory/item.lua')
| -rw-r--r-- | gamemode/core/inventory/item.lua | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua index 2eb2fb3..1e6a0cf 100644 --- a/gamemode/core/inventory/item.lua +++ b/gamemode/core/inventory/item.lua @@ -1,3 +1,6 @@ +---The main module to use when createing new items. +-- Registers items that will work with the inventory system +--@module item.lua --[[ An itemsystem public functions: @@ -25,6 +28,11 @@ local required_fields = { } local items = items or {} --Master table of all item prototypes + +---Registers an item. +-- Registers an item that can be gotten later. It usually dosn't make sense for only parts of the level to have an item (the player probably can travel between all the parts of your world with the item in their inventory), therefore you should make sure items are loaded globally. +--@see itemtbl +--@tparam table tbl The table to register for the item prototype function itm.RegisterItem(tbl) for k,v in pairs(required_fields) do assert(tbl[v] ~= nil, string.format("Attempted to register item without field %q",v)) @@ -39,6 +47,10 @@ function itm.RegisterItem(tbl) --print("Registered item: " .. tbl.Name) end +---Gets an instance of an item. +-- Gets an instanced copy of an item registered with RegisterItem() +--@tparam string name The name of the item +--@treturn itemtbl item The item function itm.GetItemByName(name) assert(type(name) == "string",string.format("Attempted to get an item by name with a %s.",type(name))) assert(items[name] ~= nil,string.format("Attempted to get item with invalid name %q Valid item names are:\n\t%s",name,table.concat(table.GetKeys(items),"\n\t"))) @@ -51,6 +63,10 @@ function itm.GetItemByName(name) return item end +---Gets an item, with data. +-- Just gets the item, then calls DeSerialize(), returning whatever deserialize returned +--@tparam string name The name of the item +--@tparam string data The data to instantiate the item with function itm.GetItemFromData(name,data) assert(items[name] ~= nil,string.format("Attempted to get item with invalid name %q",name)) return items[name]:DeSerialize(data) @@ -64,7 +80,7 @@ local function printitems() print(table.concat(tbl,"\n")) end ---Must be called in a coroutine. +---To be depriciated. function itm.DeriveItem(tbl,name) print("Attempting to derive item",name) while items[name] == nil do |
