diff --git a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua index e546435..bb0b74e 100644 --- a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua +++ b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua @@ -163,7 +163,7 @@ function iteminfo.giveoptions( p, page ) ypos = ypos + op.title.h + yspacing -- do the spacing thing - if( item.equipable ) then -- Equip + if( item.equipslot != nil ) then -- Equip op.equip = vgui.Create( "DButton", options ) op.equip:SetText( "Equip" ) diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index c3d7032..45f3e0b 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -11,18 +11,42 @@ Quantum.Inventory.Size = Quantum.Inventory.Width * Quantum.Inventory.Height function Quantum.Server.Inventory.Create( char ) char.inventory = {} + char.equiped = { + [Quantum.EquipSlots.Head] = -1, -- -1 means that it is empty + [Quantum.EquipSlots.Chest] = -1, + [Quantum.EquipSlots.Legs] = -1, + [Quantum.EquipSlots.Boots] = -1, + [Quantum.EquipSlots.Weapon] = -1 + } + char.effects = {} return char.inventory end local function isEquippable( item ) - return item.equipable || false + return item.equipslot != nil end local function isStackable( item ) return item.stack || false end +function Quantum.Server.Inventory.SetEquipSlotItem( pl, slot, itemindex ) + local char = Quantum.Server.Char.GetCurrentCharacter( pl ) + local slotitem = Quantum.Server.Inventory.GetSlotItem( char, index ) + local itemTbl = Quantum.Item.Get( slotitem[1] ) + + local equipslot = itemTbl.equipslot + + if( equipslot == nil ) then + Quantum.Error( tostring(pl) .. " tried to equip an non-equipable item (" .. tostring(itemTbl[1]) .. ")" ) + return + else + Quantum.Debug( "Commin' soon." ) + -- add effects here and equip it to the slot but check before + end +end + function Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, amount ) local setItemTbl = {} if( amount < 1 ) then diff --git a/gamemode/engine/lib/sh_effects.lua b/gamemode/engine/lib/sh_effects.lua new file mode 100644 index 0000000..13d77a7 --- /dev/null +++ b/gamemode/engine/lib/sh_effects.lua @@ -0,0 +1,97 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Effect = {} -- lib + +Quantum.Effects = {} -- container for all of the effects + +function Quantum.Effect.Create( effectid, tbl ) + local effect = { + id = effectid, + icon = tbl.icon, + rarity = tbl.rarity || Quantum.Rarity.Common, + duration = tbl.duration || -1 + func = { + start = tbl.startfunc || Quantum.EmptyFunction, + runtime = tbl.runtimefunc || Quantum.EmptyFunction, + stop = tbl.stopfunc || Quantum.EmptyFunction + } + } + Quantum.Effects[effectid] = effect + return effect +end + +function Quantum.Effect.Get( effectid ) return Quantum.Effects[effectid] end + +if SERVER then -- server only functions + + function Quantum.Effect.AddRuntimeFunction( pl, effectid ) + pl.effecthooks = pl.effecthooks || {} + local effectTbl = Quantum.Effect.Get( effectid ) + + if( effectTbl != nil ) then + + local hookID = "Quantum_Effects_RunTime_" .. tostring(pl) .. "_" .. tostring(effectid) + pl.effecthooks[ #pl.effecthooks + 1 ] = hookID + + Quantum.Debug( "Adding runtime effect hook: " .. hookID ) + + hook.Add( "Think", hookID, function() + effectTbl.func.runtime( pl ) + end) + + end + + end + + function Quantum.Effect.RemoveRuntimeFunction( pl, effectid ) + local hookID = "Quantum_Effects_RunTime_" .. tostring(pl) .. "_" .. tostring(effectid) + Quantum.Debug( "Removing runtime effect hook: " .. hookID ) + hook.Remove( "Think", hookID ) + end + + function Quantum.Effect.RemoveAllRuntimeFunctions( pl ) + if( pl.effecthooks != nil ) then + Quantum.Debug( "Removing all runtime hooks for " .. tostring(pl) .. "." ) + for n, hookid in pairs( pl.effecthooks ) do + Quantum.Effect.RemoveRuntimeFunction( pl, hookid ) + end + end + end + + function Quantum.Effect.Remove( pl, effectid ) + local effectTbl = Quantum.Effect.Get( effectid ) + local char = Quantum.Server.Char.GetCurrentCharacter( pl ) + + if( effectTbl != nil ) then + Quantum.Effect.RemoveRuntimeFunction( pl, effectid ) + pl.effects[effectid] = nil + effectTbl.func.stop( pl ) -- run the end function + end + end + + function Quantum.Effect.Give( pl, effectid ) + local effectTbl = Quantum.Effect.Get( effectid ) + local char = Quantum.Server.Char.GetCurrentCharacter( pl ) + + if( effectTbl != nil ) then + if( effectTbl.func.start != nil && effectTbl.func.start != Quantum.EmptyFunction ) + effectTbl.func.start( pl ) + end + + if( effectTbl.func.runtime != nil && effectTbl.func.runtime != Quantum.EmptyFunction ) then + Quantum.Effect.AddRuntimeFunction( pl, effectid ) + end + + if( effectTbl.duration > 0 ) then + timer.Simple( effectTbl.duration, function() + Quantum.Effect.Remove( pl, effectid ) -- remove the effect from the player after its duration is over + end) + end + end + end +end \ No newline at end of file diff --git a/gamemode/engine/lib/sh_items.lua b/gamemode/engine/lib/sh_items.lua index 3b0ab5f..a9e466a 100644 --- a/gamemode/engine/lib/sh_items.lua +++ b/gamemode/engine/lib/sh_items.lua @@ -16,12 +16,14 @@ function Quantum.Item.Create( itemid, args ) model = args.model || "models/props_phx/gears/bevel12.mdl", -- items model stack = args.stack || 1, -- items max stack size soulbound = args.soulbound, -- if item could be dropped/traded to other players - equipable = args.equipable, -- equipable or not + equipslot = args.equipslot, -- slot for the equipable + equipeffect = args.equipeffect, -- equip buff like in other MMO RPG games rarity = args.rarity || Quantum.Rarity.Trash, -- rarity of the item usefunction = args.usefunction, -- use function consumefunction = args.consumefunction --consume function } item.stack = math.Clamp( item.stack, 1, Quantum.Inventory.MaxStackSize ) -- clamp it so it does not go over the max size + if( item.equipslot != nil ) then item.stack = 1 end -- make the stack size to 1 if equipable Quantum.Items[itemid] = item return item end diff --git a/gamemode/settings/sh_items.lua b/gamemode/settings/sh_items.lua index 5a4f81d..ea06960 100644 --- a/gamemode/settings/sh_items.lua +++ b/gamemode/settings/sh_items.lua @@ -10,7 +10,6 @@ Quantum.Item.Create( "test", { desc = "This is a test item!\nDoes not stack.", model = "models/props_phx/gears/bevel12.mdl", soulbound = true, - equipable = false, rarity = Quantum.Rarity.Rare, usefunction = function() print( "Test!" ) end, consumefunction = function() print( "Test 2!" ) end @@ -22,7 +21,6 @@ Quantum.Item.Create( "test2", { model = "models/props_phx/gears/bevel12.mdl", stack = 10, soulbound = false, - equipable = false, rarity = Quantum.Rarity.Trash, consumefunction = function( user ) Quantum.Notify.Info( user, "You consumed trash and therefore died!" ) @@ -36,7 +34,6 @@ Quantum.Item.Create( "bomb", { model = "models/props_phx/ww2bomb.mdl", stack = 2, soulbound = false, - equipable = false, rarity = Quantum.Rarity.Epic } ) @@ -46,7 +43,6 @@ Quantum.Item.Create( "potatoe", { model = "models/props_phx/misc/potato.mdl", stack = 1, soulbound = false, - equipable = false, rarity = Quantum.Rarity.Legendary, consumefunction = function( user ) Quantum.Notify.Info( user, "You consumed a legendary potatoe! You now have 1000 health for 10 seconds!" ) diff --git a/gamemode/settings/sh_settings.lua b/gamemode/settings/sh_settings.lua index 00adc37..b899f1e 100644 --- a/gamemode/settings/sh_settings.lua +++ b/gamemode/settings/sh_settings.lua @@ -19,10 +19,11 @@ Quantum.Inventory = { } Quantum.EquipSlots = { - Head = "", - Chest = "", - Legs = "", - Boots = "" + Head = 0, + Chest = 1, + Legs = 2, + Boots = 3, + Weapon = 4 } Quantum.InventoryOpenDelay = 0.35