Converted item functions to effects & bug fixes

master
AlmTech Software 5 years ago
parent 1c72d96e28
commit 503cb4a9a9
  1. 7
      gamemode/cl_init.lua
  2. 4
      gamemode/engine/core/client/cl_character_net.lua
  3. 70
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  4. 8
      gamemode/engine/lib/server/sv_inventory.lua
  5. 19
      gamemode/engine/lib/sh_effects.lua
  6. 4
      gamemode/engine/lib/sh_items.lua
  7. 6
      gamemode/init.lua
  8. 29
      gamemode/settings/sh_effects.lua
  9. 13
      gamemode/settings/sh_items.lua

@ -46,8 +46,9 @@ if CLIENT then
include( fol .. "cl_menu.lua" )
end
local function loadAllItems()
local function loadAllItemsAndEffects()
include( "settings/sh_items.lua" )
include( "settings/sh_effects.lua" )
end
function Quantum.Client.Load()
@ -60,8 +61,8 @@ if CLIENT then
Quantum.Debug( "Loaded all files." )
-- add all of the items
loadAllItems()
Quantum.Debug( "Loaded all items." )
loadAllItemsAndEffects()
Quantum.Debug( "Loaded all items & effects." )
end
Quantum.Client.Load()

@ -55,7 +55,7 @@ function Quantum.Client.InventoryNet.UseItem( index )
local item = Quantum.Client.Inventory[index]
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl != nil && item[2] > 0 ) then
if( itemTbl.usefunction != nil ) then
if( itemTbl.useeffect != nil ) then
Quantum.Client.InventoryNet.SetItem( index, item[1], item[2] - 1 ) -- remove one from the inventory on the client
@ -72,7 +72,7 @@ function Quantum.Client.InventoryNet.EatItem( index )
local item = Quantum.Client.Inventory[index]
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl != nil && item[2] > 0 ) then
if( itemTbl.consumefunction != nil ) then
if( itemTbl.consumeeffect != nil ) then
Quantum.Client.InventoryNet.SetItem( index, item[1], item[2] - 1 ) -- remove one from the inventory on the client

@ -188,7 +188,7 @@ function iteminfo.giveoptions( p, page )
end
if( item.usefunction != nil ) then -- USE
if( item.useeffect != nil ) then -- USE
op.use = vgui.Create( "DButton", options )
op.use:SetText( "Use Item" )
@ -213,7 +213,7 @@ function iteminfo.giveoptions( p, page )
ypos = ypos + op.use.h + yspacing
end
if( item.consumefunction ) then -- EAT
if( item.consumeeffect != nil ) then -- EAT
op.eat = vgui.Create( "DButton", options )
op.eat:SetText( "Consume" )
@ -335,14 +335,17 @@ function iteminfo.givetooltip( p, page )
rare:SetPos( title.x, title.y + title.h + padding_s )
rare.x, rare.y = rare:GetPos()
local equip = vgui.Create( "DLabel", self )
equip:SetText( Quantum.EquipSlotsNames[self.item.equipslot] || "ERROR EQUIPTYPE" )
equip:SetFont( "q_tooltip_equiptype" )
equip:SetTextColor( Color( 255, 255, 255, 255 ) )
equip:SizeToContents()
equip.w, equip.h = equip:GetSize()
equip:SetPos( title.x, rare.y + rare.h + padding_s )
equip.x, equip.y = equip:GetPos()
local equip
if( Quantum.EquipSlotsNames[self.item.equipslot] != nil ) then
equip = vgui.Create( "DLabel", self )
equip:SetText( Quantum.EquipSlotsNames[self.item.equipslot] || "ERROR EQUIPTYPE" )
equip:SetFont( "q_tooltip_equiptype" )
equip:SetTextColor( Color( 255, 255, 255, 255 ) )
equip:SizeToContents()
equip.w, equip.h = equip:GetSize()
equip:SetPos( title.x, rare.y + rare.h + padding_s )
equip.x, equip.y = equip:GetPos()
end
local desc = vgui.Create( "DLabel", self )
desc:SetText( self.item.desc || "ERROR DESC" )
@ -350,9 +353,52 @@ function iteminfo.givetooltip( p, page )
desc:SetTextColor( Color( 205, 205, 205, 255 ) )
desc:SizeToContents()
desc.w, desc.h = desc:GetSize()
desc:SetPos( title.x, equip.y + equip.h + padding_s )
if( IsValid(equip) ) then
desc:SetPos( title.x, equip.y + equip.h + padding_s )
else
desc:SetPos( title.x, rare.y + rare.h + padding_s )
end
desc.x, desc.y = desc:GetPos()
local yposBase = desc.y + desc.h + padding_s
if( self.item.useeffect != nil ) then
local effectTbl = Quantum.Effect.Get( self.item.useeffect )
if( effectTbl.desc != nil ) then
local use = vgui.Create( "DLabel", self )
use:SetText( "Use: " .. effectTbl.desc || "ERROR DESC USE" )
use:SetFont( "q_tooltip_desc" )
use:SetTextColor( Color( 18, 224, 66, 255 ) )
use:SizeToContents()
use.w, use.h = use:GetSize()
use:SetPos( title.x, yposBase )
use.x, use.y = use:GetPos()
yposBase = yposBase + use.y + padding_s
end
end
if( self.item.consumeeffect != nil ) then
local effectTbl = Quantum.Effect.Get( self.item.consumeeffect )
if( effectTbl.desc != nil ) then
local eat = vgui.Create( "DLabel", self )
eat:SetText( "Consume: " .. effectTbl.desc || "ERROR DESC EAT" )
eat:SetFont( "q_tooltip_desc" )
eat:SetTextColor( Color( 18, 224, 66, 255 ) )
eat:SizeToContents()
eat.w, eat.h = eat:GetSize()
eat:SetPos( title.x, yposBase )
eat.x, eat.y = eat:GetPos()
yposBase = yposBase + eat.y + padding_s
end
end
if( self.item.soulbound == true ) then
local sb = vgui.Create( "DLabel", self )
sb:SetText( "Soulbound" )
@ -360,7 +406,7 @@ function iteminfo.givetooltip( p, page )
sb:SetTextColor( Color( 235, 64, 52, 255 ) )
sb:SizeToContents()
sb.w, sb.h = sb:GetSize()
sb:SetPos( title.x, desc.y + desc.h + padding_s )
sb:SetPos( title.x, yposBase )
end
-- Correct the tooltips size so its content fits inside of it

@ -283,9 +283,9 @@ function Quantum.Server.Inventory.UseItem( pl, index )
if( item != nil || #item > 0 ) then
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl.usefunction != nil ) then
if( itemTbl.useeffect != nil ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, index, item[1], item[2] - 1 )
itemTbl.usefunction(pl) -- call the function
Quantum.Effect.Give( pl, itemTbl.useeffect ) -- call the function
end
end
end
@ -298,9 +298,9 @@ function Quantum.Server.Inventory.EatItem( pl, index )
if( item != nil || #item > 0 ) then
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl.consumefunction != nil ) then
if( itemTbl.consumeeffect != nil ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, index, item[1], item[2] - 1 )
itemTbl.consumefunction( pl )
Quantum.Effect.Give( pl, itemTbl.consumeeffect )
end
end
end

@ -12,9 +12,10 @@ Quantum.Effects = {} -- container for all of the effects
function Quantum.Effect.Create( effectid, tbl )
local effect = {
id = effectid,
icon = tbl.icon,
title = tbl.title || "Unknown Effect",
desc = tbl.desc || "An effect that does stuff.",
rarity = tbl.rarity || Quantum.Rarity.Common,
duration = tbl.duration || -1,
duration = tbl.duration,
func = {
start = tbl.startfunc || Quantum.EmptyFunction,
runtime = tbl.runtimefunc || Quantum.EmptyFunction,
@ -35,7 +36,7 @@ if SERVER then -- server only functions
if( effectTbl != nil ) then
local hookID = "Quantum_Effects_RunTime_" .. tostring(pl) .. "_" .. tostring(effectid)
local hookID = "Quantum_Effects_RunTime_" .. tostring(pl:SteamID64()) .. "_" .. tostring(effectid)
pl.effecthooks[ #pl.effecthooks + 1 ] = hookID
Quantum.Debug( "Adding runtime effect hook: " .. hookID )
@ -48,8 +49,8 @@ if SERVER then -- server only functions
end
function Quantum.Effect.RemoveRuntimeFunction( pl, effectid )
local hookID = "Quantum_Effects_RunTime_" .. tostring(pl) .. "_" .. tostring(effectid)
function Quantum.Effect.RemoveRuntimeFunction( pl, effectid, hookID )
hookID = hookID || "Quantum_Effects_RunTime_" .. tostring(pl:SteamID64()) .. "_" .. tostring(effectid)
Quantum.Debug( "Removing runtime effect hook: " .. hookID )
hook.Remove( "Think", hookID )
end
@ -58,7 +59,7 @@ if SERVER then -- server only functions
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 )
Quantum.Effect.RemoveRuntimeFunction( pl, nil, hookid )
end
end
end
@ -86,6 +87,7 @@ if SERVER then -- server only functions
for i, effect in pairs( char.effects ) do
Quantum.Effect.Remove( pl, effect, char ) -- remove the effect
end
Quantum.Effect.RemoveAllRuntimeFunctions( pl )
end
end
@ -94,6 +96,9 @@ if SERVER then -- server only functions
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
if( effectTbl != nil ) then
Quantum.Debug( "Giving " .. tostring(pl) .. " the '" .. tostring(effectid) .. "' effect." )
if( effectTbl.func.start != nil && effectTbl.func.start != Quantum.EmptyFunction ) then
effectTbl.func.start( pl )
end
@ -102,7 +107,7 @@ if SERVER then -- server only functions
Quantum.Effect.AddRuntimeFunction( pl, effectid )
end
if( effectTbl.duration > 0 ) then
if( effectTbl.duration != nil ) then
timer.Simple( effectTbl.duration, function()
Quantum.Effect.Remove( pl, effectid ) -- remove the effect from the player after its duration is over
end)

@ -19,8 +19,8 @@ function Quantum.Item.Create( itemid, args )
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
useeffect = args.useeffect, -- use effect
consumeeffect = args.consumeeffect --consume effect
}
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

@ -13,6 +13,7 @@ if SERVER then
AddCSLuaFile( "settings/sh_settings.lua" )
AddCSLuaFile( "settings/sh_items.lua" )
AddCSLuaFile( "settings/sh_effects.lua" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
@ -110,8 +111,9 @@ if SERVER then
end
local function loadAllItems()
local function loadAllItemsAndEffects()
include( "settings/sh_items.lua" )
include( "settings/sh_effects.lua" )
end
function Quantum.Server.Load()
@ -121,7 +123,7 @@ if SERVER then
addAllDermaMenus()
-- Creation of stuff
loadAllItems() -- load the items
loadAllItemsAndEffects()
end
Quantum.Server.Load()

@ -0,0 +1,29 @@
-- __ _ _______ _ __
-- / / /\ | | |__ __| | | \ \
-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
Quantum.Effect.Create( "eat_potatoe", {
title = "Potatoe Powers",
desc = "Gives you 1000 health for 10 seconds.",
rarity = Quantum.Rarity.Legendary,
duration = 10,
startfunc = function( pl )
pl:SetHealth( 1000 )
end,
stopfunc = function( pl )
pl:SetHealth( pl:GetMaxHealth() )
end
} )
Quantum.Effect.Create( "eat_trash", {
title = "Bad Health",
desc = "You die.",
rarity = Quantum.Rarity.Trash,
startfunc = function( pl )
pl:Kill()
end
} )

@ -11,8 +11,6 @@ Quantum.Item.Create( "test", {
model = "models/props_phx/gears/bevel12.mdl",
soulbound = true,
rarity = Quantum.Rarity.Rare,
usefunction = function() print( "Test!" ) end,
consumefunction = function() print( "Test 2!" ) end
} )
Quantum.Item.Create( "test2", {
@ -22,10 +20,7 @@ Quantum.Item.Create( "test2", {
stack = 10,
soulbound = false,
rarity = Quantum.Rarity.Trash,
consumefunction = function( user )
Quantum.Notify.Info( user, "You consumed trash and therefore died!" )
user:Kill()
end
consumeeffect = "eat_trash"
} )
Quantum.Item.Create( "bomb", {
@ -45,9 +40,5 @@ Quantum.Item.Create( "potatoe", {
soulbound = false,
rarity = Quantum.Rarity.Legendary,
equipslot = Quantum.EquipSlots.Head,
consumefunction = function( user )
Quantum.Notify.Info( user, "You consumed a legendary potatoe! You now have 1000 health for 10 seconds!" )
user:SetHealth( 1000 )
timer.Simple( 10, function() user:SetHealth( user:GetMaxHealth() ) end)
end
consumeeffect = "eat_potatoe"
} )
Loading…
Cancel
Save