aboutsummaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/client/cl_inventory.lua1
-rw-r--r--gamemode/core/clienteffects/cl_effects.lua1
-rw-r--r--gamemode/core/clienteffects/sv_effects.lua1
-rw-r--r--gamemode/core/combat/cl_weaponswing.lua3
-rw-r--r--gamemode/core/combat/sv_weaponswing.lua1
-rw-r--r--gamemode/core/database/sv_queries.lua1
-rw-r--r--gamemode/core/database/sv_setup.lua1
-rw-r--r--gamemode/core/dataloader/sv_loadglobals.lua3
-rw-r--r--gamemode/core/inventory/cl_invtracker.lua10
-rw-r--r--gamemode/core/inventory/common/items.lua1
-rw-r--r--gamemode/core/inventory/common/weapons.lua3
-rw-r--r--gamemode/core/inventory/inventory.lua1
-rw-r--r--gamemode/core/inventory/item.lua14
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua8
-rw-r--r--gamemode/core/mapstich/sv_mapstich.lua1
-rw-r--r--gamemode/core/npc/sv_huntingspawner.lua1
-rw-r--r--gamemode/core/npc/sv_npcsystem.lua1
-rw-r--r--gamemode/core/npc/sv_shop.lua1
-rw-r--r--gamemode/core/pac/sv_pac.lua1
-rw-r--r--gamemode/inventorysystem/exampleinventory.lua111
-rw-r--r--gamemode/itemsystem/exampleitem.lua18
21 files changed, 165 insertions, 18 deletions
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 ![Requires admin](./req_admin)
+-- 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. ![Requires admin](./req_admin)
+-- 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 ![Requires admin](./req_admin)
--@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 ![Requires admin](./req_admin)
--@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