diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua index ffa75fd..47e1428 100644 --- a/gamemode/cl_init.lua +++ b/gamemode/cl_init.lua @@ -7,7 +7,6 @@ if CLIENT then include( "shared.lua" ) - --local gmfolder = GAMEMODE.FolderName || GM.FolderName Quantum.Client = {} Quantum.Client.Cache = {} Quantum.Client.ResolutionScale = ScrH() / 1080 @@ -47,6 +46,10 @@ if CLIENT then include( fol .. "cl_menu.lua" ) end + local function loadAllItems() + include( "settings/sh_items.lua" ) + end + function Quantum.Client.Load() local fol = GM.FolderName .. "/gamemode/engine/core/" @@ -55,6 +58,10 @@ if CLIENT then loadAllDermaMenus() Quantum.Debug( "Loaded all files." ) + + -- add all of the items + loadAllItems() + Quantum.Debug( "Loaded all items." ) end Quantum.Client.Load() diff --git a/gamemode/engine/core/sh_player_binds.lua b/gamemode/engine/core/sh_player_binds.lua index bdf4d53..600956f 100644 --- a/gamemode/engine/core/sh_player_binds.lua +++ b/gamemode/engine/core/sh_player_binds.lua @@ -18,7 +18,7 @@ if SERVER then name = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).name, money = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).money - }, items = {} } ) + }, items = { [1] = {"test", 1} } }) end } diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index 6e29a28..ffee61d 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -19,7 +19,7 @@ local errorMdl = "models/player.mdl" function menu.open( dt ) local items = dt.cont.items - PrintTable(dt) + if( !f ) then Quantum.Client.IsInMenu = true @@ -111,6 +111,10 @@ function menu.open( dt ) if( ii != 1 ) then count = count + 1 end itempanels[ii] = vgui.Create( "DPanel", itemframe ) + + itempanels[ii].index = ii -- set the vars + if( items[ii] ) then itempanels[ii].item = Quantum.Item.Get( items[ii][1] ) end -- get the items info through its id + itempanels[ii]:SetSize( itemWidth, itemHeight ) if( count >= maxW ) then ypos = ypos + yintervall @@ -127,9 +131,19 @@ function menu.open( dt ) itempanels[ii]:SetPos( xpos, ypos ) itempanels[ii].x, itempanels[ii].y = itempanels[ii]:GetPos() + if( itempanels[ii].item == nil ) then -- get the items rarity color + itempanels[ii].itemcolor = Quantum.Rarity.None.color + print( ii, "is nil", itemcolor ) + else + itempanels[ii].itemcolor = itempanels[ii].item.rarity.color + print( ii, "is an item", itemcolor ) + end + itempanels[ii].Paint = function( self ) - theme.itempanel( self, Quantum.Rarity.Rare.color ) + theme.itempanel( self, self.itemcolor ) end + + end -- get the width and height of all of the items diff --git a/gamemode/engine/lib/server/sv_character.lua b/gamemode/engine/lib/server/sv_character.lua index 274d821..543ea48 100644 --- a/gamemode/engine/lib/server/sv_character.lua +++ b/gamemode/engine/lib/server/sv_character.lua @@ -112,4 +112,8 @@ function Quantum.Server.Char.GetPlayerChars_cl( pl ) chars[count] = Quantum.Server.Char.getBasicCharInfo( char ) end return chars +end + +function Quantum.Server.Char.GetInventory( char ) + return char.inventory end \ No newline at end of file diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index 20e55b8..ec05253 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -10,16 +10,6 @@ Quantum.Server.Inventory = {} function Quantum.Server.Inventory.Create( char ) char.inventory = {} - for i = 1, Quantum.Inventory.Width do - char.inventory[i] = {} - end - - for h, v in pairs( char.inventory ) do - for w = 1, Quantum.Inventory.Height do - char.inventory[h][w] = 0 - end - end - return char.inventory end @@ -27,13 +17,13 @@ local function isEquippable( item ) return item.equipable || false end -function Quantum.Server.Inventory.SetSlotItem( char, x, y, item, amount ) +function Quantum.Server.Inventory.SetSlotItem( char, pos, item, amount ) if( isEquippable( item ) ) then amount = 1 - char.inventory[x][y] = { item } + char.inventory[pos] = { item } else amount = amount || 1 - char.inventory[x][y] = { item, amount } + char.inventory[pos] = { item, amount } end Quantum.Debug( "Gave " .. char.name .. " " .. amount .. " [" .. item.name .. "]" ) return diff --git a/gamemode/engine/lib/sh_items.lua b/gamemode/engine/lib/sh_items.lua index 30b179d..0730a9b 100644 --- a/gamemode/engine/lib/sh_items.lua +++ b/gamemode/engine/lib/sh_items.lua @@ -12,12 +12,18 @@ function Quantum.Item.Create( id, args ) local item = { name = args.name || "ERROR", -- items name desc = args.desc || "ERROR: Some idiot forgot to give this item a description.", -- items description - icon = args.icon, -- items icon + model = args.model || "models/props_phx/gears/bevel12.mdl", -- items model stack = args.stack || false, -- items max stack size soulbound = args.soulbound || true, -- if item could be dropped/traded to other players + equipable = args.equipable || false, -- equipable or not rarity = args.rarity || Quantum.Rarity.Trash, -- rarity of the item usefunction = args.usefunction, -- use function - consumefunction = args.consumefunction, --consume function - equipfunction = args.equipfunction -- equip function + consumefunction = args.consumefunction --consume function } + Quantum.Items[id] = item + return item +end + +function Quantum.Item.Get( id ) + return Quantum.Items[id] end \ No newline at end of file diff --git a/gamemode/init.lua b/gamemode/init.lua index d17307f..292eab5 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -8,6 +8,7 @@ if SERVER then AddCSLuaFile( "engine/sh_debug.lua" ) AddCSLuaFile( "settings/sh_settings.lua" ) + AddCSLuaFile( "settings/sh_items.lua" ) AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) @@ -99,12 +100,19 @@ if SERVER then end end + + local function loadAllItems() + include( "settings/sh_items.lua" ) + end function Quantum.Server.Load() -- Add all of the base files loadCoreFiles() loadLibFiles() addAllDermaMenus() + + -- Creation of stuff + loadAllItems() -- load the items end Quantum.Server.Load() diff --git a/gamemode/settings/sh_items.lua b/gamemode/settings/sh_items.lua index 77fd27b..9394a77 100644 --- a/gamemode/settings/sh_items.lua +++ b/gamemode/settings/sh_items.lua @@ -3,4 +3,16 @@ -- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ -- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / --- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ \ No newline at end of file +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Item.Create( "test", { + name = "Test Item", + desc = "This is a test item!", + model = "models/props_phx/gears/bevel12.mdl", + stack = false, + soulbound = true, + equipable = false, + rarity = Quantum.Rarity.Legendary, + usefunction = function() print( "Test!" ) end, + consumefunction = function() print( "Test 2!" ) end, +} ) \ No newline at end of file diff --git a/gamemode/settings/sh_settings.lua b/gamemode/settings/sh_settings.lua index 9d3dc2c..83d4a65 100644 --- a/gamemode/settings/sh_settings.lua +++ b/gamemode/settings/sh_settings.lua @@ -23,11 +23,12 @@ Quantum.Money = { } Quantum.Rarity = { - Trash = { txt = "Trash", color = Color( 100, 100, 100, 100 ) }, - Common = { txt = "Common", color = Color( 250, 250, 250, 100 ) }, - Rare = { txt = "Rare", color = Color( 48, 163, 230, 100 ) }, - Epic = { txt = "Epic", color = Color( 220, 90, 90, 100 ) }, - Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 100 ) } + None = { txt = "gnomerd the mvp", color = Color( 0, 0, 0, 120 ) }, + Trash = { txt = "Trash", color = Color( 100, 100, 100, 40 ) }, + Common = { txt = "Common", color = Color( 250, 250, 250, 40 ) }, + Rare = { txt = "Rare", color = Color( 48, 163, 230, 40 ) }, + Epic = { txt = "Epic", color = Color( 220, 90, 90, 40 ) }, + Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) } } Quantum.Models = {