From 307a87210808b7965ffa1f0f1d61369ecfd31dad Mon Sep 17 00:00:00 2001 From: AlmTech Date: Wed, 11 Sep 2019 22:12:39 +0200 Subject: [PATCH] Added Inventory & more stuff to character system --- gamemode/engine/lib/server/sv_character.lua | 1 + gamemode/engine/lib/server/sv_inventory.lua | 42 +++++++++++++++++++++ gamemode/settings/sv_settings.lua | 6 +++ 3 files changed, 49 insertions(+) create mode 100644 gamemode/engine/lib/server/sv_inventory.lua diff --git a/gamemode/engine/lib/server/sv_character.lua b/gamemode/engine/lib/server/sv_character.lua index 3e535bd..69848d7 100644 --- a/gamemode/engine/lib/server/sv_character.lua +++ b/gamemode/engine/lib/server/sv_character.lua @@ -13,6 +13,7 @@ function Quantum.Server.Char.CreateCharTable( args ) name = args.name || "UNKNOWN", model = args.model || "models/player.mdl", money = args.money || Quantum.Server.Settings.StarterMoney, + inventory = args.inventory || {}, -- create new inventory jobs = args.jobs || { [1] = { title = "Hobo", level = -1 }, }, diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua new file mode 100644 index 0000000..6e1a988 --- /dev/null +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -0,0 +1,42 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Server.Inventory = {} + +function Quantum.Server.Inventory.Create( char ) + char.inventory = {} + + for i = 1, Quantum.Server.Settings.Inventory.Width do + char.inventory[i] = {} + end + + for h, v in pairs( char.inventory ) do + for w = 1, Quantum.Server.Settings.Inventory.Height do + char.inventory[h][w] = 0 + end + end + + return char.inventory +end + +local function isEquippable( item ) + return item.equipable || false +end + +function Quantum.Server.Inventory.SetSlotItem( char, x, y, item, amount ) + if( isEquippable( item ) ) then + amount = 1 + char.inventory[x][y] = { item } + else + amount = amount || 1 + char.inventory[x][y] = { item, amount } + end + Quantum.Debug( "Gave " .. char.name .. " " .. amount .. " [" .. item.name .. "]" ) + return +end + +function Quantum.Server.Inventory.GetSlotItem( char, x, y ) return char.inventory[x][y] end \ No newline at end of file diff --git a/gamemode/settings/sv_settings.lua b/gamemode/settings/sv_settings.lua index 39b7dee..b4abe0c 100644 --- a/gamemode/settings/sv_settings.lua +++ b/gamemode/settings/sv_settings.lua @@ -11,6 +11,12 @@ Quantum.Server.Settings.VoiceChatRange = 400 Quantum.Server.Settings.StarterMoney = 0 +Quantum.Server.Settings.Inventory = { + Height = 5, + Width = 5 +} + +--- Features to be added --- Quantum.Server.Settings.MaxJobLevel = 250 Quantum.Server.Settings.MaxJobSlots = 2 Quantum.Server.Settings.MaxSkillLevel = 100