Added effects (Buffs) lib

master
AlmTech Software 5 years ago
parent 51b90fefe5
commit 32297ac03a
  1. 2
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  2. 26
      gamemode/engine/lib/server/sv_inventory.lua
  3. 97
      gamemode/engine/lib/sh_effects.lua
  4. 4
      gamemode/engine/lib/sh_items.lua
  5. 4
      gamemode/settings/sh_items.lua
  6. 9
      gamemode/settings/sh_settings.lua

@ -163,7 +163,7 @@ function iteminfo.giveoptions( p, page )
ypos = ypos + op.title.h + yspacing -- do the spacing thing 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 = vgui.Create( "DButton", options )
op.equip:SetText( "Equip" ) op.equip:SetText( "Equip" )

@ -11,18 +11,42 @@ Quantum.Inventory.Size = Quantum.Inventory.Width * Quantum.Inventory.Height
function Quantum.Server.Inventory.Create( char ) function Quantum.Server.Inventory.Create( char )
char.inventory = {} 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 return char.inventory
end end
local function isEquippable( item ) local function isEquippable( item )
return item.equipable || false return item.equipslot != nil
end end
local function isStackable( item ) local function isStackable( item )
return item.stack || false return item.stack || false
end 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 ) function Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, amount )
local setItemTbl = {} local setItemTbl = {}
if( amount < 1 ) then if( amount < 1 ) then

@ -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

@ -16,12 +16,14 @@ function Quantum.Item.Create( itemid, args )
model = args.model || "models/props_phx/gears/bevel12.mdl", -- items model model = args.model || "models/props_phx/gears/bevel12.mdl", -- items model
stack = args.stack || 1, -- items max stack size stack = args.stack || 1, -- items max stack size
soulbound = args.soulbound, -- if item could be dropped/traded to other players 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 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
} }
item.stack = math.Clamp( item.stack, 1, Quantum.Inventory.MaxStackSize ) -- clamp it so it does not go over the max size 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 Quantum.Items[itemid] = item
return item return item
end end

@ -10,7 +10,6 @@ Quantum.Item.Create( "test", {
desc = "This is a test item!\nDoes not stack.", desc = "This is a test item!\nDoes not stack.",
model = "models/props_phx/gears/bevel12.mdl", model = "models/props_phx/gears/bevel12.mdl",
soulbound = true, soulbound = true,
equipable = false,
rarity = Quantum.Rarity.Rare, rarity = Quantum.Rarity.Rare,
usefunction = function() print( "Test!" ) end, usefunction = function() print( "Test!" ) end,
consumefunction = function() print( "Test 2!" ) end consumefunction = function() print( "Test 2!" ) end
@ -22,7 +21,6 @@ Quantum.Item.Create( "test2", {
model = "models/props_phx/gears/bevel12.mdl", model = "models/props_phx/gears/bevel12.mdl",
stack = 10, stack = 10,
soulbound = false, soulbound = false,
equipable = false,
rarity = Quantum.Rarity.Trash, rarity = Quantum.Rarity.Trash,
consumefunction = function( user ) consumefunction = function( user )
Quantum.Notify.Info( user, "You consumed trash and therefore died!" ) Quantum.Notify.Info( user, "You consumed trash and therefore died!" )
@ -36,7 +34,6 @@ Quantum.Item.Create( "bomb", {
model = "models/props_phx/ww2bomb.mdl", model = "models/props_phx/ww2bomb.mdl",
stack = 2, stack = 2,
soulbound = false, soulbound = false,
equipable = false,
rarity = Quantum.Rarity.Epic rarity = Quantum.Rarity.Epic
} ) } )
@ -46,7 +43,6 @@ Quantum.Item.Create( "potatoe", {
model = "models/props_phx/misc/potato.mdl", model = "models/props_phx/misc/potato.mdl",
stack = 1, stack = 1,
soulbound = false, soulbound = false,
equipable = false,
rarity = Quantum.Rarity.Legendary, rarity = Quantum.Rarity.Legendary,
consumefunction = function( user ) consumefunction = function( user )
Quantum.Notify.Info( user, "You consumed a legendary potatoe! You now have 1000 health for 10 seconds!" ) Quantum.Notify.Info( user, "You consumed a legendary potatoe! You now have 1000 health for 10 seconds!" )

@ -19,10 +19,11 @@ Quantum.Inventory = {
} }
Quantum.EquipSlots = { Quantum.EquipSlots = {
Head = "", Head = 0,
Chest = "", Chest = 1,
Legs = "", Legs = 2,
Boots = "" Boots = 3,
Weapon = 4
} }
Quantum.InventoryOpenDelay = 0.35 Quantum.InventoryOpenDelay = 0.35

Loading…
Cancel
Save