Added item consuming, using etc

master
AlmTech Software 5 years ago
parent 69f5916dcc
commit fca3ad0654
  1. 34
      gamemode/engine/core/client/cl_character_net.lua
  2. 38
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  3. 15
      gamemode/engine/derma/menus/menu_charinfo.lua
  4. 30
      gamemode/engine/lib/server/sv_inventory.lua
  5. 8
      gamemode/engine/lib/server/sv_networking.lua
  6. 7
      gamemode/engine/lib/server/sv_notify.lua
  7. 9
      gamemode/settings/sh_items.lua
  8. 2
      gamemode/settings/sv_settings.lua

@ -49,3 +49,37 @@ function Quantum.Client.InventoryNet.DropItem( itemid, index, amount )
net.WriteInt( amount, Quantum.calculateNeededBits( Quantum.Inventory.MaxStackSize ) )
net.SendToServer()
end
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
Quantum.Client.InventoryNet.SetItem( index, item[1], item[2] - 1 ) -- remove one from the inventory on the client
net.Start( "quantum_item_action" )
Quantum.WriteIntcode( Quantum.IntCode.USE_ITEM )
net.WriteInt( index, Quantum.calculateNeededBits( Quantum.Inventory.Size ) )
net.SendToServer()
end
end
end
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
Quantum.Client.InventoryNet.SetItem( index, item[1], item[2] - 1 ) -- remove one from the inventory on the client
net.Start( "quantum_item_action" )
Quantum.WriteIntcode( Quantum.IntCode.EAT_ITEM )
net.WriteInt( index, Quantum.calculateNeededBits( Quantum.Inventory.Size ) )
net.SendToServer()
end
end
end

@ -182,8 +182,10 @@ function iteminfo.giveoptions( p, page )
---- EQUIP NET HERE ----
end
ypos = ypos + op.equip.h + yspacing
end
elseif( item.usefunction != nil ) then
if( item.usefunction != nil ) then -- USE
op.use = vgui.Create( "DButton", options )
op.use:SetText( "Use Item" )
@ -198,15 +200,42 @@ function iteminfo.giveoptions( p, page )
op.use.DoClick = function( self )
surface.PlaySound( "UI/buttonclick.wav" )
p:GetParent().RemoveItem()
p:GetParent().SetItemAmount( amount - 1 )
options.Close()
---- USE NET HERE ----
---- USE NET ----
Quantum.Client.InventoryNet.UseItem( index )
end
ypos = ypos + op.use.h + yspacing
end
if( item.consumefunction ) then -- EAT
op.eat = vgui.Create( "DButton", options )
op.eat:SetText( "Consume" )
op.eat:SetFont( "q_item_option_button" )
op.eat:SizeToContents()
op.eat.w, op.eat.h = op.eat:GetSize()
op.eat:SetPos( xbasepos, ypos )
op.eat.x, op.eat.y = op.eat:GetPos()
op.eat.Paint = function( self )
theme.iteminfobutton( self )
end
op.eat.DoClick = function( self )
surface.PlaySound( "UI/buttonclick.wav" )
elseif( !item.soulbound ) then -- Drop
p:GetParent().SetItemAmount( amount - 1 )
options.Close()
---- EAT NET ----
Quantum.Client.InventoryNet.EatItem( index )
end
ypos = ypos + op.eat.h + yspacing
end
if( !item.soulbound ) then -- Drop
op.drop = vgui.Create( "DButton", options )
op.drop:SetText( "Drop" )
op.drop:SetFont( "q_item_option_button" )
@ -231,7 +260,6 @@ function iteminfo.giveoptions( p, page )
end
end
ypos = ypos + op.drop.h + yspacing
end
op.close = vgui.Create( "DButton", options )

@ -200,6 +200,10 @@ function menu.open( dt )
end
end
itempanels[ii].GetItemAmount = function()
return itempanels[ii].item.amount
end
---- Create the model icon for the item panel ----
if( itempanels[ii].item != nil && itempanels[ii].item.model != nil ) then
itempanels[ii].icon = vgui.Create( "DModelPanel", itempanels[ii] )
@ -283,17 +287,6 @@ function menu.open( dt )
end
hook.Add("ScoreboardShow", "Quantum_Menu_CharInfo_Open", function()
-- if( InventoryStartTime == nil ) then
-- InventoryStartTime = CurTime()
-- end
-- if( InventoryStartTime + 1 <= CurTime() ) then
-- menu.open()
-- InventoryStartTime = nil
-- end -- open the menu
-- menu.open()
return false
end)

@ -224,4 +224,34 @@ function Quantum.Server.Inventory.DropItem( pl, index, amount ) -- Quantum.Serve
else
Quantum.Error( "Player " .. tostring( pl ) .. " tried to drop a something from index=" .. tostring(index) .. " where there exists no item." )
end
end
function Quantum.Server.Inventory.UseItem( pl, index )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
local inv = Quantum.Server.Char.GetInventory( char )
local item = inv[index]
if( item != nil || #item > 0 ) then
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl.usefunction != nil ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, index, item[1], item[2] - 1 )
itemTbl.usefunction(pl) -- call the function
end
end
end
function Quantum.Server.Inventory.EatItem( pl, index )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
local inv = Quantum.Server.Char.GetInventory( char )
local item = inv[index]
if( item != nil || #item > 0 ) then
local itemTbl = Quantum.Item.Get( item[1] )
if( itemTbl.consumefunction != nil ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, index, item[1], item[2] - 1 )
itemTbl.consumefunction( pl )
end
end
end

@ -150,13 +150,19 @@ local intcodeFunctions = {
end,
[Quantum.IntCode.DROP_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.DropItem( pl, index, amount )
end,
[Quantum.IntCode.USE_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.UseItem( pl, index )
end,
[Quantum.IntCode.EAT_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.EatItem( pl, index )
end
}
net.Receive( "quantum_item_action", function( len, pl )
local intcode = net.ReadInt( Quantum.IntCode.BIT_SIZE )
local index = net.ReadInt( Quantum.calculateNeededBits( Quantum.Inventory.Size ) )
local itemid = net.ReadString()
local itemid = net.ReadString()
local amount = net.ReadInt( Quantum.calculateNeededBits( Quantum.Inventory.MaxStackSize ) )
intcodeFunctions[intcode]( pl, index, itemid, amount )

@ -31,5 +31,12 @@ function Quantum.Notify.Deny( pl, text )
local luaArgs = makeColorAString( Color( 245, 20, 20 ) ) .. ",'" .. tostring( text ) .. "'"
local luaFunc = "chat.AddText(" .. luaArgs .. ")"
pl:SendLua( luaFunc )
end
function Quantum.Notify.Info( pl, text )
local luaArgs = makeColorAString( Color( 245, 245, 245 ) ) .. ",'" .. tostring( text ) .. "'"
local luaFunc = "chat.AddText(" .. luaArgs .. ")"
pl:SendLua( luaFunc )
end

@ -25,8 +25,8 @@ Quantum.Item.Create( "test2", {
equipable = false,
rarity = Quantum.Rarity.Trash,
consumefunction = function( user )
Quantum.Notify.Info( user, "You consumed trash and therefore died!" )
user:Kill()
user:PrintChat( "You consumed trash and died!" )
end
} )
@ -47,5 +47,10 @@ Quantum.Item.Create( "potatoe", {
stack = 1,
soulbound = false,
equipable = false,
rarity = Quantum.Rarity.Legendary
rarity = Quantum.Rarity.Legendary,
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
} )

@ -15,7 +15,7 @@ Quantum.Server.Settings.MaxHealth = 100
Quantum.Server.Settings.StarterMoney = 0
Quantum.Server.Settings.ItemDespawnTimer = 3000
Quantum.Server.Settings.ItemDespawnTimer = 300
Quantum.Server.Settings.ItemPickupSound = "physics/cardboard/cardboard_box_impact_hard2.wav"

Loading…
Cancel
Save