diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-07-10 17:04:29 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-07-10 17:04:29 -0400 |
| commit | 1de5f9ac6f038bfed2230cc1272b253794b2f41a (patch) | |
| tree | 15bc9d515f1f48c036522afb7cc71f60243849a9 /gamemode/shared/loaditems.lua | |
| download | artery-1de5f9ac6f038bfed2230cc1272b253794b2f41a.tar.gz artery-1de5f9ac6f038bfed2230cc1272b253794b2f41a.tar.bz2 artery-1de5f9ac6f038bfed2230cc1272b253794b2f41a.zip | |
Initial commit
Diffstat (limited to 'gamemode/shared/loaditems.lua')
| -rw-r--r-- | gamemode/shared/loaditems.lua | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gamemode/shared/loaditems.lua b/gamemode/shared/loaditems.lua new file mode 100644 index 0000000..18260f2 --- /dev/null +++ b/gamemode/shared/loaditems.lua @@ -0,0 +1,55 @@ +--[[ + This file loads in all the items +]] +local concmd = include("concommands.lua") +--local autolua = include("../autolua.lua") +print("Hello from LoadItems.lua!") +ART.Items = {} +local requiredfields = { + "Name", +} +local defaultfields = { + ["Serialize"] = function(self) return "" end, + ["DeSerialize"] = function(self,string) return self end, + ["Shape"] = {{true}}, +} +function ART.RegisterItem(tbl) + print("Registering item:" .. tbl.Name) + for k,v in pairs(requiredfields) do + assert(tbl[v] ~= nil, "Attempted to register an item without field:" .. v) + end + assert(ART.Items[tbl.Name] == nil, "Attempted to register 2 items with the same name!") + for k,v in pairs(defaultfields) do + if tbl[k] == nil then + tbl[k] = v + end + end + ART.Items[tbl.Name] = tbl + print("Art is now:") + PrintTable(ART) +end + +--autolua.AddLuaSHFolder("/shared/itemsystem") + +function ART.GiveItem(player,name) + assert(ART.Items[name] ~= nil, "Attempted to give a nil item!") + player:GiveItem(ART.Items[name]) + player:SynchronizeInventory() +end + +function ART.GetItemByName(name) + assert(ART.Items[name] ~= nil,"Attempted to get a nil item:" .. name) + return ART.Items[name] +end + +concommand.Add("artery_printitems",function(ply,cmd,args) + if not ply:IsAdmin() then return end + print("Items table:") + PrintTable(ART.Items) +end) + +concommand.Add("artery_giveitem",function(ply,cmd,args) + if not ply:IsAdmin() then return end + print("Trying to give an item:" .. args[1]) + ART.GiveItem(ply,args[1]) +end, concmd.AutocompleteFunction(table.GetKeys(ART.Items)), "Give an item to the specified player, or yourself if no player is specified.") |
