diff options
28 files changed, 231 insertions, 75 deletions
@@ -12,26 +12,34 @@ file = { } format = 'markdown' sort_modules = true -new_type("domain","Domain",false) new_type("concommand","Console commands", false) new_type("metamethod","Meta Methods", false) new_type("server","Server Modules", true) new_type("client","Client Modules", true) new_type("shared","Shared Modules", true) custom_tags = { - {'reqadmin', hidden=true}, - {'domain', hidden=true} + {'reqadmin', hidden=false}, } custom_display_name_handler = function(item,default_handeler) - if item.type == "function" then + if item.type == "concommand" then if item.tags.reqadmin then - return item.name .. "<strong>Requires Admin</strong>" - elseif item.tags.domain then - return item.name .. "Domain:" + return item.name .. " <em class=\"reqadmin\">Requires Admin</em> " + end + elseif item.type == "domain" then + if item.tags.domain == "server" then + return "<strong class=\"server\">[Server]</strong>" + elseif item.tags.domain == "client" then + return "<strong class=\"client\">[Client]</strong>" + elseif item.tags.domain == "shared" then + return "<strong class=\"shared\">[Shared]</strong>" end end return default_handeler(item) end readme = "README.md" + +examples = { + "doc/examples" +} diff --git a/doc/examples/babysfirstaddon.md b/doc/examples/babysfirstaddon.md new file mode 100644 index 0000000..595ad77 --- /dev/null +++ b/doc/examples/babysfirstaddon.md @@ -0,0 +1,29 @@ +# Tut 0x01 - Baby's First Addon + +A quick primer on addons for Garry's Mod, and Artery. + +You may have seen on the gmod wiki, instructions on running lua code. One way is to place files in your `garrysmod/lua/autorun` directory, and they will be run automatically when you enter single player. This can get messy though, another way to run lua is by making a folder in `garrysmod/addons/<addon_name>/lua/autorun`, and placing your scripts in that (i.e. so that `garrysmod/addons/my_first_addon/lua/autorun/hello.lua` is a valid file). As it turns out, all folders under `garrysmod/addons/<addon_name>` get reflected! This means that if you have a file `garrysmod/addons/data/pac3/my_pac.txt` it will appear in the pac editor and a pac you can load! + +This is the method used by addons for Artery. Since Garry's Mod loads addons's autorun BEFORE gamemodes, Artery uses the `data/artery/global/` folder to run scripts after the gamemode as loaded (and therefore has access to the nrequire() function, more on this later). + +## Lets get started + +Start by creating a new folder under `garrysmod/addons/` called `artery_rougelite`. We'll be using this folder for the rest of the tutorials to build a small rougelike gamemode to explore the different features artery provides. + +Now create another folder under the folder you just made `garrysmod/addons/artery_rougelite/data` + +Now another `garrysmod/addons/artery_rougelite/data/artery/` + +And another `garrysmod/addons/artery_rougelite/data/artery/global/` + +With the folder structure set up, we're ready to actually write some lua. + +Create a file `garrysmod/addons/artery_routelite/data/artery/global/helloworld.txt` + +and copy+paste the following code into it. + +``` +print("Hello, world!") +``` + +Now start up garrysmod with the Artery gamemode selected. Head into flatgrass or something. Open your console, you should see "Hello, world!" printed. diff --git a/doc/examples/setup.md b/doc/examples/setup.md new file mode 100644 index 0000000..2f9e0ce --- /dev/null +++ b/doc/examples/setup.md @@ -0,0 +1,22 @@ +# Tut 0x00 Setup & Installation + +This tutorial covers how to set up Artery so you can begin developing. + +First, you'll need to download the Artery gamemode base. This can be done for updates with [git](https://git-scm.com)(reccomended) or just downloaded as a zip and extracted + +## Git setup + +1. Download [git](https://git-scm.com) +2. Follow the setup instructions +3. Open command prompt and type in `git --version`, verify that version information is printed. +4. Use the `cd` command to go into your Garry's Mod directory. This is usuallly `C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod` (i.e. the command would be `cd "C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod"`). You can alternatively go to this location in your file browser, then click the file path at the top, and copy+paste it into your command prompt. +5. Use `cd` again to go into your `gamemodes` directory (i.e `cd gamemodes`) +6. Clone the repository `git clone http://cogarr.net/source/cgit.cgi/artery` +7. Go back and clone the artery_editor addon (`cd ../addons` then `git clone http://cogarr.net/source/cgit.cgi/artery_editor`) +8. Another one `git clone https://cogarr.net/source/cgit.cgi/zones` _*_ Please note that this is a fork of [bobleheadbob's original api](https://github.com/Luabee/Zones), all it does is put the files into an addon format. +9. Finally, be sure you are subscribed to PAC3 on the steam workshop +10. Boot up gmod, select the artery addon, and load into gm_flatgrass to make sure it works! You can skip the next section, and go on to the next tutorial. + +## Non-git setup + +You'll be doing almost the same thing, only downloading zips instead of using the `git clone` command diff --git a/doc/for_developers/structs/dropped_item.md b/doc/for_developers/structs/dropped_item.md deleted file mode 100644 index ffabfbd..0000000 --- a/doc/for_developers/structs/dropped_item.md +++ /dev/null @@ -1,14 +0,0 @@ -# Dropped item - -Droped items are represented as a name-data combo - - local i = <table_item> - local e = ents.Create("art_droppeditem") - e.Item = { - Name = i.Name - Data = i:Serialize() - } - -This structure is used in: -* gamemode/core/inventory/sv_invtracker.lua -* entities/entities/art_droppeditem/init.lua diff --git a/doc/for_developers/structs/inventories.md b/doc/for_developers/structs/inventories.md deleted file mode 100644 index d965597..0000000 --- a/doc/for_developers/structs/inventories.md +++ /dev/null @@ -1,5 +0,0 @@ -# Inventories - -A player starts off with 2 inventories, a equipment inventory, and a shaped inventory (5x5) - -the equipment inventory is in the first slot, the shaped inventory in the second. diff --git a/doc/for_developers/structs/player.md b/doc/for_developers/structs/player.md deleted file mode 100644 index 130927d..0000000 --- a/doc/for_developers/structs/player.md +++ /dev/null @@ -1,17 +0,0 @@ -# Player - -A player has the following fields - -`ply.data` - stores all data needed to save & create a player - -# Data - -A players data consists of the following - -`data.inventories :: array` the inventories a player posesses, remember that all inventories must have a :serialize() method - -`data.skills :: table` the skills a player has picked up - -`data.quests :: table` the quests a player knows about - -`data.prayers :: tabe` the prayers that a player can do diff --git a/doc/structs/dropped_item.md b/doc/structs/dropped_item.md deleted file mode 100644 index ffabfbd..0000000 --- a/doc/structs/dropped_item.md +++ /dev/null @@ -1,14 +0,0 @@ -# Dropped item - -Droped items are represented as a name-data combo - - local i = <table_item> - local e = ents.Create("art_droppeditem") - e.Item = { - Name = i.Name - Data = i:Serialize() - } - -This structure is used in: -* gamemode/core/inventory/sv_invtracker.lua -* entities/entities/art_droppeditem/init.lua diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index 2c1e693..1fe53b0 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -1,6 +1,7 @@ ---Functions for hiding and showing inventory panels. -- Deals with most the the things needed for inventory panels --@client cl_inventory.lua +--@alias inv --[[ Reserved inventory id's diff --git a/gamemode/core/clienteffects/cl_effects.lua b/gamemode/core/clienteffects/cl_effects.lua index 60b71c1..5ae0a31 100644 --- a/gamemode/core/clienteffects/cl_effects.lua +++ b/gamemode/core/clienteffects/cl_effects.lua @@ -1,6 +1,7 @@ ---A registry of client-side effects. -- Use this to register effects to be called with sv_effects.lua --@client cl_effects.lua +--@alias er local log = nrequire("log.lua") local er = {} --master table of effects diff --git a/gamemode/core/clienteffects/sv_effects.lua b/gamemode/core/clienteffects/sv_effects.lua index 9859b95..40ae1b1 100644 --- a/gamemode/core/clienteffects/sv_effects.lua +++ b/gamemode/core/clienteffects/sv_effects.lua @@ -1,6 +1,7 @@ ---A way to apply effects on players. -- Also see cl_effects.lua --@server sv_effects.lua +--@alias ed local ed = {} diff --git a/gamemode/core/combat/cl_weaponswing.lua b/gamemode/core/combat/cl_weaponswing.lua index 61c31b0..968ff9e 100644 --- a/gamemode/core/combat/cl_weaponswing.lua +++ b/gamemode/core/combat/cl_weaponswing.lua @@ -80,9 +80,10 @@ net.Receive("artery_doanimation",function() end) ---Force the player to do an animation. --- The animation must have been already registered to animbonelib  +-- The animation must have been already registered to animbonelib --@usage artery_startanimation <animation name> --@concommand artery_startanimation +--@reqadmin concommand.Add("artery_startanimation",function(ply,cmd,args) if not ply:IsAdmin() then return end swingtbl = {} diff --git a/gamemode/core/combat/sv_weaponswing.lua b/gamemode/core/combat/sv_weaponswing.lua index 1970007..7cac43a 100644 --- a/gamemode/core/combat/sv_weaponswing.lua +++ b/gamemode/core/combat/sv_weaponswing.lua @@ -1,6 +1,7 @@ ---Automatically re-calculates swing arcs for weapons. -- This files helps you create mele weapons that need to be swung --@server sv_weaponswing.lua +--@alias ws --[[ This file tells you what weapons need their swings recalculated diff --git a/gamemode/core/database/sv_queries.lua b/gamemode/core/database/sv_queries.lua index f6f8c9f..96908d4 100644 --- a/gamemode/core/database/sv_queries.lua +++ b/gamemode/core/database/sv_queries.lua @@ -1,6 +1,7 @@ ---Helper functions for saveing and loading players. -- Defines functions for saveing/loading the player --@server sv_queries.lua +--@alias q local fn = nrequire("utility/fn.lua") local track = nrequire("core/inventory/sv_invtracker.lua") diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua index 2fd0d42..dd2332d 100644 --- a/gamemode/core/database/sv_setup.lua +++ b/gamemode/core/database/sv_setup.lua @@ -1,6 +1,7 @@ ---Functions for working the the mysqlite module. -- Helps load players into their correct instance --@server sv_setup.lua +--@alias sql --Adds the MySQLite global nrequire("sv_mysqlite.lua") diff --git a/gamemode/core/dataloader/sv_loadglobals.lua b/gamemode/core/dataloader/sv_loadglobals.lua index 5a24996..84212e6 100644 --- a/gamemode/core/dataloader/sv_loadglobals.lua +++ b/gamemode/core/dataloader/sv_loadglobals.lua @@ -123,8 +123,9 @@ concommand.Add("artery_reloadglobals_cs",function(ply,cmd,args) end) ---Reloads all global/ files on all clients. --- Tells all clients to reload their client-side files, and reloads server-side files.  +-- Tells all clients to reload their client-side files, and reloads server-side files. --@concommand artery_reloadglobals +--@reqadmin concommand.Add("artery_reloadglobals",function(ply,cmd,args) if not ply:IsAdmin() then return end loadglobals() diff --git a/gamemode/core/inventory/cl_invtracker.lua b/gamemode/core/inventory/cl_invtracker.lua index fdf5be3..e808627 100644 --- a/gamemode/core/inventory/cl_invtracker.lua +++ b/gamemode/core/inventory/cl_invtracker.lua @@ -1,6 +1,7 @@ ---[[ - One of the tabs in the inventory -]] +---Keeps track of inventories on the client side. +--@client cl_invtracker.lua +--@alias q + local inv = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") nrequire("cl_loadglobals.lua") @@ -11,6 +12,9 @@ local q = {} local known_inventories = {} local inventory_frames = {} local invsheet + +---An array of all the known inventories. +--@export q.known_inventories = known_inventories local drawfloatinginventory = function(id, inventory) diff --git a/gamemode/core/inventory/common/items.lua b/gamemode/core/inventory/common/items.lua index 4b52a97..0a32f27 100644 --- a/gamemode/core/inventory/common/items.lua +++ b/gamemode/core/inventory/common/items.lua @@ -1,6 +1,7 @@ ---Some common functions for working with items. -- Just one function for now --@shared items.lua +--@alias items local items = {} diff --git a/gamemode/core/inventory/common/weapons.lua b/gamemode/core/inventory/common/weapons.lua index 065d1a6..9067981 100644 --- a/gamemode/core/inventory/common/weapons.lua +++ b/gamemode/core/inventory/common/weapons.lua @@ -1,6 +1,7 @@ ---Common functionality used in a lot of weapons. -- Bits an peices that most weapons need --@shared weapons.lua +--@alias com local com = {} @@ -62,7 +63,7 @@ function com.swingarc(player,times,positions,onhit) end) end ----Creates a new attack table +---Creates a new attack table. -- Creates a table of ["forward|backward|left|right"] = function() -- This is done before hand so that table is not re-generated on the fly each time a player attacks --@tparam attacktbl tbl_attackdata The attack data to use diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua index 1290519..ea1d33e 100644 --- a/gamemode/core/inventory/inventory.lua +++ b/gamemode/core/inventory/inventory.lua @@ -1,6 +1,7 @@ ---The main file needed to register create new inventory types. -- Helps you register inventories that work with the rest of artery --@shared inventory.lua +--@alias inv --[[ Public functions: diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua index 9a6a293..79f9ad5 100644 --- a/gamemode/core/inventory/item.lua +++ b/gamemode/core/inventory/item.lua @@ -1,6 +1,8 @@ ---The main module to use when createing new items. -- Registers items that will work with the inventory system --@shared item.lua +--@alias itm + --[[ An itemsystem public functions: @@ -18,7 +20,6 @@ item:DeSerialize(string_data) ::nil Recreate an item. If this item has any instance specific data, it should return a table.Copy(self) with the appropriate fields set. The above must be defined for every item - Items may also have methods from one or more interfaces registered with RegisterInterface ]] local log = nrequire("log.lua") @@ -31,8 +32,7 @@ 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 +--@tparam itemtbl 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)) @@ -50,7 +50,7 @@ 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 +--@treturn itemtbl 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"))) @@ -67,6 +67,7 @@ end -- 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 +--@treturn itemtbl The item that was deserialized 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) @@ -101,6 +102,9 @@ end hook.Call("artery_include_items") -concommand.Add("art_printitems",printitems) +---Prints a list of all items the client/server knows about +--@concommand artery_printitems +--@usage artery_printitems +concommand.Add("artery_printitems",printitems) return itm diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua index e009828..88de42e 100644 --- a/gamemode/core/inventory/sv_invtracker.lua +++ b/gamemode/core/inventory/sv_invtracker.lua @@ -1,8 +1,7 @@ ---Utilities to help deal with inventories. -- Helps you display, manage, and manipulate inventories --@server sv_invtracker.lua - ---@domain Server +--@alias track --[[ some accessability functions @@ -65,7 +64,7 @@ end) ---Drops an item at the position. -- Creates a droped item at the given position, gives the player that walks over it the item. ---@tparam itmtbl item The item to drop +--@tparam itemtbl item The item to drop --@tparam vector3 pos The position to drop the item function track.DropItem(item,pos) local e = ents.Create("art_droppeditem") @@ -287,7 +286,6 @@ end ---Prints a player's inventory to the console. --@concommand artery_ShowMyInventories ---@reqadmin concommand.Add("artery_ShowMyInventories", function(ply,cmd,args) @@ -298,6 +296,7 @@ end) -- Gives a new inventory to a player  --@usage artery_AddInventory <inventory name> --@concommand artery_AddInventory +--@reqadmin concommand.Add("artery_AddInventory",function(ply,cmd,args) if not ply:IsAdmin() then return end track.GiveInventoryTo(ply,args[1]) @@ -307,6 +306,7 @@ end) -- Gives a new item to the player  --@usage artery_GiveItem <item name> --@concommand artery_GiveItem +--@reqadmin concommand.Add("artery_GiveItem",function(ply,cmd,args) if not ply:IsAdmin() then return end xpcall(function() diff --git a/gamemode/core/mapstich/sv_mapstich.lua b/gamemode/core/mapstich/sv_mapstich.lua index f8e79cd..3c5da66 100644 --- a/gamemode/core/mapstich/sv_mapstich.lua +++ b/gamemode/core/mapstich/sv_mapstich.lua @@ -45,6 +45,7 @@ end ---Saves the player. -- Saves the player as if they had disconnected, or transfered to another level --@concommand artery_saveplayer +--@usage artery_saveplayer concommand.Add("artery_saveplayer",function(ply,cmd,args) SavePlayerData(ply) end) diff --git a/gamemode/core/npc/sv_huntingspawner.lua b/gamemode/core/npc/sv_huntingspawner.lua index 99ed754..a9bc64c 100644 --- a/gamemode/core/npc/sv_huntingspawner.lua +++ b/gamemode/core/npc/sv_huntingspawner.lua @@ -1,6 +1,7 @@ ---Lets huntable monsters drop loot. -- Register what monsters drop what loot --@server sv_huntingspawner.lua +--@alias o --[[ This file spawns the huntable npc's in their zones. diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua index 0916d28..d376d6d 100644 --- a/gamemode/core/npc/sv_npcsystem.lua +++ b/gamemode/core/npc/sv_npcsystem.lua @@ -1,6 +1,7 @@ ---Various functions for npcs. -- Helps you spawn monsters, townies, and shopkeepers --@server sv_npcsystem.lua +--@alias n local f = nrequire("concommands.lua") local n = {} diff --git a/gamemode/core/npc/sv_shop.lua b/gamemode/core/npc/sv_shop.lua index fd98eb8..17d222c 100644 --- a/gamemode/core/npc/sv_shop.lua +++ b/gamemode/core/npc/sv_shop.lua @@ -1,5 +1,6 @@ ---Some more logic related to shop npc's --@server sv_shop.lua +--@alias shop local itm = nrequire("core/inventory/item.lua") diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua index a4d2c00..916430c 100644 --- a/gamemode/core/pac/sv_pac.lua +++ b/gamemode/core/pac/sv_pac.lua @@ -2,6 +2,7 @@ --PAC3 outfits are not downloaded until they are needed, we can keep the inital download to join the server pretty small this way. -- The downside is that the game might lag a little when someone wears something that is rare/new and everyone has to download it. --@server sv_pac.lua +--@alias p3 --[[ Console Commands: diff --git a/gamemode/inventorysystem/exampleinventory.lua b/gamemode/inventorysystem/exampleinventory.lua new file mode 100644 index 0000000..b8c539f --- /dev/null +++ b/gamemode/inventorysystem/exampleinventory.lua @@ -0,0 +1,111 @@ +---An example inventory. +-- An inventory that can hold any kind of item. Inventories in Artery are pretty flexible, when you get started, decide on how you want to represent items in your inventory. Inventories use a "position table" to talk about where items are in the inventory. What the position table's structure is can be different for each type of inventory, but each inventory should not use more than one kind of position table. If you find yourself needing more than 1 position table, consider making 2 different inventories. +--@classmod invtbl + +local inv = {} + +---Inventory name. +-- All inventories must have a name, names must be unique per TYPE of inventory. +inv.Name = "Example Inventory" + +inv.items = {} + +---Finds a spot for an item. +-- Finds a place in this inventory to place an item. Returns nil if the item cannot fit. +--@tparam invtbl self The instace we want to put the item into +--@tparam itemtbl itemtbl The item we want to put into the inventory +--@treturn table|nil Returns a position table if the item can fit, or nil if it cannot. +function inv.FindPlaceFor(self,itemtbl) + return {#self.items + 1} +end + +---Check if the item can fit in the given position. +-- Finds if an item can be placed at a given position in this inventory +--@tparam invtbl self The instance to put the item into +--@tparam table position The position to put the item into +--@tparam itemtbl item The item to try to put in +--@treturn boolean True if the item can fit, false if it cannot +function inv.CanFitIn(self,position,item) + return self.items[position[1]] == nil +end + +---Puts an item into the inventory. +-- Puts an item into the inventory at a given position +--@tparam invtbl self The inventory instance +--@tparam table position The position to put the item into +--@tparam itemtbl item The item to put into the inventory +function inv.Put(self,position,item) + self.items[position[1]] = item +end + +---Checks if this inventory has an item. +-- This method checks if an inventory has an item, this can be passed EITHER a string, item name, OR a function that takes a itemtbl as it's single parameter and returns True if the item is what is being looked for or false if it is not. +--@tparam invtbl self The instance to look at +--@tparam string|function ptr The string or compare function to look for +--@treturn table|nil Returns the position of the item if the item was found, or nil if it was not +function inv.Has(self,ptr) + for k,v in pairs(self.items) do + if type(ptr) == "function" then + if ptr(v) then + return {k} + end + elseif type(ptr) == "string" then + if v.Name == ptr then + return {k} + end + else + error("Passed a " .. type(ptr) .. " to example inventory's Has() function") + end + end +end + +---Removes an item from the inventory. +-- Removes an item by position, returns the item that was removed +--@tparam invtbl self The inventory instance to remove from +--@tparam table position The position to remove the item from +--@treturn itemtbl The item that was removed +--@raises error May error if the given position does not contain an item. +function inv.Remove(self,position) + local item = self.items[position[1]] + self.items[position[1]] = nil + return item +end + +---Gets the item at a given position. +-- Returns the item at a given position in the inventory. May error if the given position does not have an item. +--@tparam invtbl self The instance to get from +--@tparam table position The position to look in +--@treturn itemtbl The item at the given position +--@raises error May error if the given position does not contain an item +function inv.Get(self,position) + return self.items[position[1]] +end + +---Serailizes the inventory. +-- Returns a string that the inventory can be rebuilt from. This should include all items currently in the inventory. Take advantage of the fact that items must also have a Serailize() method. +--@tparam invtbl self The instance of the inventory to serialize +--@treturn string The string representation of this inventory +function inv.Serailize(self) + local items = {} + for k,v in pairs(self.items) do + items[k] = {v.Name,v:Serialize()} + end + return util.TableToJSON(items) +end + +---Deserializes an inventory. +-- Takes the string returned by the Serialize() function and returns the inventory re-made +--@tparam invtbl self The prototype table, you probably want to make a table.Copy() of this +--@tparam string data The string returned by Serialize() +--@treturn invtbl The table after it has been deserialized +function inv.DeSerialize(self,str) + local cpy = table.Copy(self) + local json = util.JSONToTable(str) + for k,v in pairs(json) do + local item = itm.GetItemFromData(v[1],v[2]) + cpy.items[k] = item + end + return cpy +end + +RegisterInventory(inv) diff --git a/gamemode/itemsystem/exampleitem.lua b/gamemode/itemsystem/exampleitem.lua index 269e2d6..196db20 100644 --- a/gamemode/itemsystem/exampleitem.lua +++ b/gamemode/itemsystem/exampleitem.lua @@ -1,3 +1,7 @@ +---An example item. +-- An item you can create a copy of as a starting point. This is the minimum needed for an item. Different inventories usually also require different fields and functions. +--@classmod itemtbl + --[[ An example item ]] @@ -6,19 +10,27 @@ local item = {} --Make sure we identify ourselves as a prayer item.isprayer = true ---Required, a name, all item names must be unique +---A name. +-- All items must have a .Name, which gives a string, an item should give the same string each time. You can generate an item's name from it's data by leaving this blank, and giving the item a metatable with a __index method that does the right thing item.Name = "Test item" --Optional, a tooltip to display when hovered over item.Tooltip = "An example item. Copy this file\nand edit it to make your own items!" ---Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network +---Create a string representation of this item. +-- Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network. +--@tparam itemtbl self The item we need to serialize +--@treturn string The string representation of this item (can be length 0) item.Serialize = function(self) print("Trying to serailize!") return "" end ---Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set. +---Recreates an item from data. +-- Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set. +--@tparam itemtbl self The prototype table we want to deserialize from +--@tparam string string The data given by a Serailize() method +--@treturn itemtbl The fully deserialized item item.DeSerialize = function(self,string) print("Trying to deserialize!") return self |
