Items dropped which are equipped now gets unequipped (SERVER & CLIENT)

master
AlmTech Software 5 years ago
parent d27a24ef08
commit a39cf80eae
  1. 34
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  2. 6
      gamemode/engine/derma/menus/menu_charinfo.lua
  3. 1
      gamemode/engine/derma/menus/menu_main.lua
  4. 53
      gamemode/engine/lib/server/sv_inventory.lua
  5. 3
      gamemode/engine/lib/server/sv_networking.lua
  6. 1
      gamemode/engine/vars/sh_vars.lua

@ -21,6 +21,31 @@ local function resizePanel( p )
return p.w, p.h
end
local function getEquippedItems()
local returnTbl = {}
for equipType, equipSlot in pairs( Quantum.Client.Equipped ) do
returnTbl[ #returnTbl + 1 ] = { type = equipType, slot = equipSlot }
end
return returnTbl
end
local function checkIfItemIsEquippedAndRemove( page, index )
local equipItems = getEquippedItems()
for ie, ii in pairs( equipItems ) do
print( ie, ii )
if( ii.slot == index ) then
if( page.equippanels[ii.type] != nil ) then
page.equippanels[ii.type].SetItem( nil ) -- remove it
else
Quantum.Error( "Func 'checkIfItemIsEquippedAndRemove': type is not valid! type=" .. tostring(ii.type) )
end
end
end
end
function iteminfo.dropamount( p, page, itemPanel )
local index = p.index
local item = p.item
@ -207,6 +232,10 @@ function iteminfo.giveoptions( p, page )
options.Close()
if( amount - 1 <= 0 ) then
checkIfItemIsEquippedAndRemove( page, index )
end
---- USE NET ----
Quantum.Client.InventoryNet.UseItem( index )
end
@ -232,6 +261,10 @@ function iteminfo.giveoptions( p, page )
options.Close()
if( amount - 1 <= 0 ) then
checkIfItemIsEquippedAndRemove( page, index )
end
---- EAT NET ----
Quantum.Client.InventoryNet.EatItem( index )
end
@ -257,6 +290,7 @@ function iteminfo.giveoptions( p, page )
iteminfo.dropamount( options, page, itemPanel )
else
p:GetParent().RemoveItem()
checkIfItemIsEquippedAndRemove( page, index )
---- DROP NET HERE ----
Quantum.Client.InventoryNet.DropItem( item.id, index, amount )

@ -74,7 +74,6 @@ local function createEquipSlotPanel( equiptype, x, y, scale, parent )
p.icon:SetModel( itemTbl.model )
configureCamLookPos( p.icon )
else
print( "REMOVE" )
p.icon:SetVisible( false ) -- hide it if there is no item
if( IsValid( p.icon.tooltip ) ) then
p.icon.tooltip:Remove()
@ -109,7 +108,11 @@ end
local function getItemInSlot( pos )
local inv = Quantum.Client.Inventory || {}
if( inv[pos] != nil ) then
return inv[pos][1]
else
return
end
end
function menu.open( dt )
@ -205,7 +208,6 @@ function menu.open( dt )
f.equippanels[Quantum.EquipSlots.Head] = createEquipSlotPanel( Quantum.EquipSlots.Head, slotXpos, char.y + char.h/5, slotScale, f ) -- create the panel
f.equippanels[Quantum.EquipSlots.Head].SetItem( getItemInSlot(equipped[ Quantum.EquipSlots.Head ]) ) -- give its current item
print( "EQUIPED: ", getItemInSlot(equipped[ Quantum.EquipSlots.Head ]) )
---- Inventory panel ----
local inv = vgui.Create( "DPanel", f ) -- section for all of the item panels

@ -156,7 +156,6 @@ function main.open(dt)
play.w, play.h = play:GetSize()
play.y = play.y + play.h + padding*2
print( play.y )
end
play:SetTextColor( buttonTextColor )

@ -55,11 +55,12 @@ function Quantum.Server.Inventory.EquipItem( pl, itemindex )
end
end
function Quantum.Server.Inventory.UnEquipItem( pl, equipslot )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char )
char = char || Quantum.Server.Char.GetCurrentCharacter( pl )
if( char.equipped[equipslot] != nil ) then
local slotItem = Quantum.Server.Inventory.GetSlotItem( char, char.equipped[equipslot] )
local itemTbl = Quantum.Item.Get( slotItem )
local itemTbl = Quantum.Item.Get( slotItem[1] )
if( itemTbl.equipeffect != nil ) then -- remove the items effect
Quantum.Effect.Remove( pl, itemTbl.equipeffect )
@ -72,9 +73,27 @@ function Quantum.Server.Inventory.UnEquipItem( pl, equipslot )
end
end
function Quantum.Server.Inventory.GetEquippedItems( pl, char )
char = char || Quantum.Server.Char.GetCurrentCharacter( pl )
local returnTbl = {}
for equipType, equipSlot in pairs( char.equipped ) do
returnTbl[ #returnTbl + 1 ] = { type = equipType, slot = equipSlot }
end
return returnTbl
end
function Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, amount )
local setItemTbl = {}
if( amount < 1 ) then
local equippedItems = Quantum.Server.Inventory.GetEquippedItems( pl, char )
for ei, slotTbl in pairs( equippedItems ) do
if( slotTbl.slot == pos ) then
Quantum.Server.Inventory.UnEquipItem( pl, slotTbl.type ) -- unequipp the item if it was removed
end
end
setItemTbl = nil
else
local item = Quantum.Item.Get( itemid )
@ -93,6 +112,27 @@ function Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, amount )
Quantum.Net.Inventory.SetItem( pl, pos, itemid, amount )
end
function Quantum.Server.Inventory.RemoveSlotItem( pl, char, pos, amount )
local slotItem = Quantum.Server.Inventory.GetSlotItem( char, pos )
local itemid = slotItem[1]
if( slotItem == nil ) then return end
if( amount <= 0 ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, 0 )
return 0
else
local am_diff = slotItem[2] - amount
if( am_diff <= 0 ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, 0 )
return 0
else
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, am_diff )
return am_diff
end
end
end
function Quantum.Server.Inventory.GetSlotItem( char, pos ) return char.inventory[pos] end
function Quantum.Server.Inventory.FindStackable( char, item )
@ -268,7 +308,8 @@ function Quantum.Server.Inventory.DropItem( pl, index, amount ) -- Quantum.Serve
if( am_diff >= 0 ) then -- drop the item from the players inv
-- remove the items am_diff from its stack
Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, am_diff )
--Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, am_diff )
Quantum.Server.Inventory.RemoveSlotItem( pl, char, index, amount )
-- spawn the item infront of the player
Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount )
@ -287,7 +328,7 @@ function Quantum.Server.Inventory.UseItem( pl, index )
if( item != nil || #item > 0 ) then
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl.useeffect != nil ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, index, item[1], item[2] - 1 )
Quantum.Server.Inventory.RemoveSlotItem( pl, char, index, 1 )
Quantum.Effect.Give( pl, itemTbl.useeffect ) -- call the function
end
end
@ -302,7 +343,7 @@ function Quantum.Server.Inventory.EatItem( pl, index )
if( item != nil || #item > 0 ) then
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl.consumeeffect != nil ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, index, item[1], item[2] - 1 )
Quantum.Server.Inventory.RemoveSlotItem( pl, char, index, 1 )
Quantum.Effect.Give( pl, itemTbl.consumeeffect )
end
end

@ -147,7 +147,7 @@ end
local intcodeFunctions = {
[Quantum.IntCode.SET_ITEM] = function( pl, index, itemid, amount ) -- if the client is trying to set an item then kick the player
Quantum.Warn( "Player [" .. pl:Nick() .. " | " .. pl:SteamID() .. "] tried to use a blacklisted Intcode function called from the client!" )
--pl:Kick( "[Quantum Security] Tried to use a invalid Intcode function. Nice try." )
pl:Kick( "[Quantum Security] Tried to use a invalid Intcode function. Nice try." )
end,
[Quantum.IntCode.DROP_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.DropItem( pl, index, amount )
@ -169,7 +169,6 @@ net.Receive( "quantum_item_action", function( len, pl )
local itemid = net.ReadString()
local amount = net.ReadInt( Quantum.calculateNeededBits( Quantum.Inventory.MaxStackSize ) )
print( "####", intcode, index, itemid, amount )
intcodeFunctions[intcode]( pl, index, itemid, amount )
end)

@ -48,6 +48,5 @@ Quantum.IntCode = {
function Quantum.calculateNeededBits( n ) return math.ceil( math.log( n, 2 ) ) end
function Quantum.WriteIntcode( intcode )
print( intcode )
net.WriteInt( intcode, Quantum.IntCode.BIT_SIZE )
end
Loading…
Cancel
Save