Added equip & unequip functions (SERVER SIDE)

master
AlmTech Software 5 years ago
parent bfed037a5d
commit df827d3b9e
  1. 24
      gamemode/engine/lib/server/sv_inventory.lua
  2. 4
      gamemode/engine/lib/sh_effects.lua

@ -11,7 +11,7 @@ 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 = { char.equipped = {
[Quantum.EquipSlots.Head] = -1, -- -1 means that it is empty [Quantum.EquipSlots.Head] = -1, -- -1 means that it is empty
[Quantum.EquipSlots.Chest] = -1, [Quantum.EquipSlots.Chest] = -1,
[Quantum.EquipSlots.Legs] = -1, [Quantum.EquipSlots.Legs] = -1,
@ -40,14 +40,19 @@ function Quantum.Server.Inventory.EquipItem( pl, itemindex )
local equipslot = itemTbl.equipslot local equipslot = itemTbl.equipslot
if( equipslot == nil ) then if( equipslot == nil ) then
Quantum.Error( tostring(pl) .. " tried to equip an non-equipable item: (" .. tostring(itemTbl[1]) .. ")" ) Quantum.Error( tostring(pl) .. " tried to equip an non-equippable item: (" .. tostring(itemTbl[1]) .. ")" )
return return
else else
if( Quantum.EquipSlots[equipslot] != nil ) then if( Quantum.EquipSlots[equipslot] != nil ) then
char.equiped[equipslot] = slotitem[1] -- set it in the table
char.equipped[equipslot] = slotitem[1] -- set it in the table
if( itemTbl.equipeffect != nil ) then if( itemTbl.equipeffect != nil ) then
Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect
end end
-- NETWORKING --
Quantum.Net.Inventory.Update( pl ) -- update the client
else else
Quantum.Error( tostring(pl) .. " tried to equip an item in a non-existent equip slot: (" .. tostring(equipslot) .. ")" ) Quantum.Error( tostring(pl) .. " tried to equip an item in a non-existent equip slot: (" .. tostring(equipslot) .. ")" )
return return
@ -56,6 +61,19 @@ function Quantum.Server.Inventory.EquipItem( pl, itemindex )
end end
end end
function Quantum.Server.Inventory.UnEquipItem( pl, equipslot )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
if( char.equipped[equipslot] != nil && char.equipped[equipslot] != -1 ) then
local itemTbl = Quantum.Item.Get( char.equipped[equipslot] )
if( itemTbl.equipeffect != nil ) then -- remove the items effect
Quantum.Effect.Remove( pl, itemTbl.equipeffect )
end
char.equipped[equipslot] = nil
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

@ -79,7 +79,7 @@ if SERVER then -- server only functions
end end
end end
function Quantum.Effects.RemoveAll( pl ) function Quantum.Effect.RemoveAll( pl )
local char = Quantum.Server.Char.GetCurrentCharacter( pl ) local char = Quantum.Server.Char.GetCurrentCharacter( pl )
if( char.effects != nil ) then if( char.effects != nil ) then
Quantum.Debug( "Removing all " .. tostring(pl) .. " effects." ) Quantum.Debug( "Removing all " .. tostring(pl) .. " effects." )
@ -113,7 +113,7 @@ if SERVER then -- server only functions
end end
hook.Add( "PlayerDeath", "Quantum_Effects_LooseOnDeath", function( ply ) hook.Add( "PlayerDeath", "Quantum_Effects_LooseOnDeath", function( ply )
Quantum.Effects.RemoveAll( ply ) -- remove all effects Quantum.Effect.RemoveAll( ply ) -- remove all effects
end) end)
end end
Loading…
Cancel
Save