Inventory networking & added item config stuff

master
AlmTech Software 5 years ago
parent da067dedfe
commit 8d56602a80
  1. 9
      gamemode/cl_init.lua
  2. 2
      gamemode/engine/core/sh_player_binds.lua
  3. 18
      gamemode/engine/derma/menus/menu_charinfo.lua
  4. 4
      gamemode/engine/lib/server/sv_character.lua
  5. 16
      gamemode/engine/lib/server/sv_inventory.lua
  6. 12
      gamemode/engine/lib/sh_items.lua
  7. 8
      gamemode/init.lua
  8. 12
      gamemode/settings/sh_items.lua
  9. 11
      gamemode/settings/sh_settings.lua

@ -7,7 +7,6 @@
if CLIENT then if CLIENT then
include( "shared.lua" ) include( "shared.lua" )
--local gmfolder = GAMEMODE.FolderName || GM.FolderName
Quantum.Client = {} Quantum.Client = {}
Quantum.Client.Cache = {} Quantum.Client.Cache = {}
Quantum.Client.ResolutionScale = ScrH() / 1080 Quantum.Client.ResolutionScale = ScrH() / 1080
@ -47,6 +46,10 @@ if CLIENT then
include( fol .. "cl_menu.lua" ) include( fol .. "cl_menu.lua" )
end end
local function loadAllItems()
include( "settings/sh_items.lua" )
end
function Quantum.Client.Load() function Quantum.Client.Load()
local fol = GM.FolderName .. "/gamemode/engine/core/" local fol = GM.FolderName .. "/gamemode/engine/core/"
@ -55,6 +58,10 @@ if CLIENT then
loadAllDermaMenus() loadAllDermaMenus()
Quantum.Debug( "Loaded all files." ) Quantum.Debug( "Loaded all files." )
-- add all of the items
loadAllItems()
Quantum.Debug( "Loaded all items." )
end end
Quantum.Client.Load() Quantum.Client.Load()

@ -18,7 +18,7 @@ if SERVER then
name = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).name, name = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).name,
money = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).money money = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).money
}, items = {} } ) }, items = { [1] = {"test", 1} } })
end end
} }

@ -19,7 +19,7 @@ local errorMdl = "models/player.mdl"
function menu.open( dt ) function menu.open( dt )
local items = dt.cont.items local items = dt.cont.items
PrintTable(dt)
if( !f ) then if( !f ) then
Quantum.Client.IsInMenu = true Quantum.Client.IsInMenu = true
@ -111,6 +111,10 @@ function menu.open( dt )
if( ii != 1 ) then count = count + 1 end if( ii != 1 ) then count = count + 1 end
itempanels[ii] = vgui.Create( "DPanel", itemframe ) 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 ) itempanels[ii]:SetSize( itemWidth, itemHeight )
if( count >= maxW ) then if( count >= maxW ) then
ypos = ypos + yintervall ypos = ypos + yintervall
@ -127,9 +131,19 @@ function menu.open( dt )
itempanels[ii]:SetPos( xpos, ypos ) itempanels[ii]:SetPos( xpos, ypos )
itempanels[ii].x, itempanels[ii].y = itempanels[ii]:GetPos() 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 ) itempanels[ii].Paint = function( self )
theme.itempanel( self, Quantum.Rarity.Rare.color ) theme.itempanel( self, self.itemcolor )
end end
end end
-- get the width and height of all of the items -- get the width and height of all of the items

@ -113,3 +113,7 @@ function Quantum.Server.Char.GetPlayerChars_cl( pl )
end end
return chars return chars
end end
function Quantum.Server.Char.GetInventory( char )
return char.inventory
end

@ -10,16 +10,6 @@ Quantum.Server.Inventory = {}
function Quantum.Server.Inventory.Create( char ) function Quantum.Server.Inventory.Create( char )
char.inventory = {} 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 return char.inventory
end end
@ -27,13 +17,13 @@ local function isEquippable( item )
return item.equipable || false return item.equipable || false
end end
function Quantum.Server.Inventory.SetSlotItem( char, x, y, item, amount ) function Quantum.Server.Inventory.SetSlotItem( char, pos, item, amount )
if( isEquippable( item ) ) then if( isEquippable( item ) ) then
amount = 1 amount = 1
char.inventory[x][y] = { item } char.inventory[pos] = { item }
else else
amount = amount || 1 amount = amount || 1
char.inventory[x][y] = { item, amount } char.inventory[pos] = { item, amount }
end end
Quantum.Debug( "Gave " .. char.name .. " " .. amount .. " [" .. item.name .. "]" ) Quantum.Debug( "Gave " .. char.name .. " " .. amount .. " [" .. item.name .. "]" )
return return

@ -12,12 +12,18 @@ function Quantum.Item.Create( id, args )
local item = { local item = {
name = args.name || "ERROR", -- items name name = args.name || "ERROR", -- items name
desc = args.desc || "ERROR: Some idiot forgot to give this item a description.", -- items description 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 stack = args.stack || false, -- items max stack size
soulbound = args.soulbound || true, -- if item could be dropped/traded to other players 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 rarity = args.rarity || Quantum.Rarity.Trash, -- rarity of the item
usefunction = args.usefunction, -- use function usefunction = args.usefunction, -- use function
consumefunction = args.consumefunction, --consume function consumefunction = args.consumefunction --consume function
equipfunction = args.equipfunction -- equip function
} }
Quantum.Items[id] = item
return item
end
function Quantum.Item.Get( id )
return Quantum.Items[id]
end end

@ -8,6 +8,7 @@
if SERVER then if SERVER then
AddCSLuaFile( "engine/sh_debug.lua" ) AddCSLuaFile( "engine/sh_debug.lua" )
AddCSLuaFile( "settings/sh_settings.lua" ) AddCSLuaFile( "settings/sh_settings.lua" )
AddCSLuaFile( "settings/sh_items.lua" )
AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "shared.lua" )
@ -100,11 +101,18 @@ if SERVER then
end end
local function loadAllItems()
include( "settings/sh_items.lua" )
end
function Quantum.Server.Load() function Quantum.Server.Load()
-- Add all of the base files -- Add all of the base files
loadCoreFiles() loadCoreFiles()
loadLibFiles() loadLibFiles()
addAllDermaMenus() addAllDermaMenus()
-- Creation of stuff
loadAllItems() -- load the items
end end
Quantum.Server.Load() Quantum.Server.Load()

@ -4,3 +4,15 @@
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > -- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
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,
} )

@ -23,11 +23,12 @@ Quantum.Money = {
} }
Quantum.Rarity = { Quantum.Rarity = {
Trash = { txt = "Trash", color = Color( 100, 100, 100, 100 ) }, None = { txt = "gnomerd the mvp", color = Color( 0, 0, 0, 120 ) },
Common = { txt = "Common", color = Color( 250, 250, 250, 100 ) }, Trash = { txt = "Trash", color = Color( 100, 100, 100, 40 ) },
Rare = { txt = "Rare", color = Color( 48, 163, 230, 100 ) }, Common = { txt = "Common", color = Color( 250, 250, 250, 40 ) },
Epic = { txt = "Epic", color = Color( 220, 90, 90, 100 ) }, Rare = { txt = "Rare", color = Color( 48, 163, 230, 40 ) },
Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 100 ) } Epic = { txt = "Epic", color = Color( 220, 90, 90, 40 ) },
Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) }
} }
Quantum.Models = { Quantum.Models = {

Loading…
Cancel
Save