Added text above dropped item & inventory optimizations & bug fixes

master
AlmTech Software 5 years ago
parent 7667e9ed9e
commit a916c3fb78
  1. 8
      entities/entities/q_item/init.lua
  2. 18
      gamemode/engine/core/client/cl_fonts.lua
  3. 62
      gamemode/engine/core/client/cl_hud.lua
  4. 6
      gamemode/engine/derma/menus/menu_charinfo.lua
  5. 16
      gamemode/engine/lib/server/sv_inventory.lua
  6. 2
      gamemode/engine/lib/server/sv_networking.lua
  7. 30
      gamemode/engine/lib/sh_items.lua
  8. 3
      gamemode/settings/sh_settings.lua
  9. 2
      gamemode/settings/sv_settings.lua

@ -22,9 +22,16 @@ function ENT:Initialize()
end end
local useStartTime
local useDelay = Quantum.ItemPickupTime
function ENT:Use( activator, caller ) function ENT:Use( activator, caller )
if( activator:IsPlayer() ) then if( activator:IsPlayer() ) then
if( self.itemid != nil && self.amount != nil ) then if( self.itemid != nil && self.amount != nil ) then
useStartTime = useStartTime || CurTime()
if( CurTime() - useStartTime >= useDelay ) then
useStartTime = nil
self:Remove() self:Remove()
-- add item to players inventory -- add item to players inventory
Quantum.Server.Inventory.GiveItem( activator, self.itemid, self.amount ) Quantum.Server.Inventory.GiveItem( activator, self.itemid, self.amount )
@ -32,6 +39,7 @@ function ENT:Use( activator, caller )
self:EmitSound( Quantum.Server.Settings.ItemPickupSound ) -- make a pickup sound self:EmitSound( Quantum.Server.Settings.ItemPickupSound ) -- make a pickup sound
end end
end end
end
end end
function ENT:InitializeItem( itemid, amount ) function ENT:InitializeItem( itemid, amount )

@ -132,3 +132,21 @@ surface.CreateFont( "q_item_option_dropval", {
size = 40 * Quantum.Client.ResolutionScale, size = 40 * Quantum.Client.ResolutionScale,
antialias = true antialias = true
}) })
surface.CreateFont( "q_item_hud_title", {
font = "Cambria",
size = 28 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_item_hud_rarity", {
font = "Cambria",
size = 21 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_item_hud_soulbound", {
font = "Cambria",
size = 20 * Quantum.Client.ResolutionScale,
antialias = true
})

@ -20,17 +20,17 @@ local radius = 1.05 * scale
local padding = 5 * scale local padding = 5 * scale
local sw, sh = ScrW(), ScrH() local sw, sh = ScrW(), ScrH()
function GM:HUDPaint() local client = LocalPlayer()
if( !Quantum.Client.IsInMenu ) then
local hp = LocalPlayer():Health() local function SetAlpha( color, alpha )
return Color( color.r, color.g, color.b, alpha )
end
local function renderStatHUD()
local hp = client:Health()
local lasthp = hp local lasthp = hp
local maxhp = LocalPlayer():GetMaxHealth() local maxhp = client:GetMaxHealth()
if( Quantum.Client.Config.EnableHUD ) then
if( !LocalPlayer():Alive() ) then
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawRect( 0, 0, sw, sh )
else
-- Health border -- Health border
surface.SetDrawColor( 0, 0, 0, 200 ) surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH ) surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH )
@ -52,6 +52,50 @@ function GM:HUDPaint()
surface.SetDrawColor( 255, 255, 255, 200 ) surface.SetDrawColor( 255, 255, 255, 200 )
surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 )
end end
end
local function renderItemInfoHUD()
local trace = client:GetEyeTraceNoCursor()
if( trace.Entity:GetClass() == "q_item" ) then
local distance = client:GetPos():Distance( trace.Entity:GetPos() )
local distFrac = Lerp( distance/Quantum.ItemInfoDisplayMaxDistance, 1, 0 )
if( distance <= Quantum.ItemInfoDisplayMaxDistance ) then
local item = Quantum.Item.Get( trace.Entity:GetNWString( "q_item_id" ) ) || { name="ERROR" }
local amount = trace.Entity:GetNWInt( "q_item_amount" ) || 1
local pos = trace.Entity:GetPos()
pos.z = pos.z + 20
local screenPos = pos:ToScreen()
local txtPadding = 20 * scale
local itemAmountTxt = ""
if( amount > 1 ) then itemAmountTxt = amount .. "x " end
local alphaFrac = distFrac
draw.SimpleText( itemAmountTxt .. item.name, "q_item_hud_title", screenPos.x, screenPos.y, SetAlpha( item.rarity.color, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
draw.SimpleText( "Rarity: " .. item.rarity.txt, "q_item_hud_rarity", screenPos.x, screenPos.y + txtPadding, SetAlpha( item.rarity.color, 255 *alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
if( item.soulbound ) then
draw.SimpleText( "Soulbound", "q_item_hud_soulbound", screenPos.x, screenPos.y + txtPadding*2, Color( 235, 64, 52, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
end
end
end
function GM:HUDPaint()
if( !Quantum.Client.IsInMenu ) then
if( !client:Alive() ) then
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawRect( 0, 0, sw, sh )
end
if( Quantum.Client.Config.EnableHUD ) then
if( client:Alive() ) then
renderStatHUD()
renderItemInfoHUD()
end end
end end
end end

@ -31,6 +31,12 @@ end
function menu.open( dt ) function menu.open( dt )
local items = Quantum.Client.Inventory local items = Quantum.Client.Inventory
if( Quantum.Client.Character == nil ) then
chat.AddText( Color( 255, 25, 25 ), "[Quantum] - [ERROR] Check console for details.\n" )
Quantum.Error( "\nCharacter could not be found. Can not open inventory!\nGive this message to someone important: Quantum.Client.Character=nil\nTry rejoining the server and this should be fixed." )
return
end
if( !f ) then if( !f ) then
Quantum.Client.IsInMenu = true Quantum.Client.IsInMenu = true

@ -219,21 +219,7 @@ function Quantum.Server.Inventory.DropItem( pl, index, amount ) -- Quantum.Serve
Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, am_diff ) Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, am_diff )
-- spawn the item infront of the player -- spawn the item infront of the player
local itemEnt = ents.Create( "q_item" ) Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount )
if( IsValid( itemEnt ) ) then
itemEnt:SetPos( pl:GetPos() + ( pl:GetForward() * 40 ) + Vector( 0, 0, 40 ) )
itemEnt:InitializeItem( itemid, amount )
itemEnt:Spawn()
timer.Simple( math.Clamp( Quantum.Server.Settings.ItemDespawnTimer, 1, 600 ), function()
if( IsValid( itemEnt ) ) then
Quantum.Debug( "Despawned item " .. tostring(itemEnt) .. " [" .. itemEnt.itemid .. "]" )
itemEnt:Remove()
end
end)
end
end end
else else
Quantum.Error( "Player " .. tostring( pl ) .. " tried to drop a something from index=" .. tostring(index) .. " where there exists no item." ) Quantum.Error( "Player " .. tostring( pl ) .. " tried to drop a something from index=" .. tostring(index) .. " where there exists no item." )

@ -169,6 +169,6 @@ local function UpdateAllPlayers()
end end
end end
if( !Quantum.Server.Settings.DeveloperMode ) then if( Quantum.Server.Settings.DeveloperMode == false ) then
UpdateAllPlayers() -- Update the players on auto-refresh / lua-refresh UpdateAllPlayers() -- Update the players on auto-refresh / lua-refresh
end end

@ -29,3 +29,33 @@ end
function Quantum.Item.Get( id ) function Quantum.Item.Get( id )
return Quantum.Items[id] return Quantum.Items[id]
end end
if SERVER then
Quantum.Server.Item = {}
function Quantum.Server.Item.SpawnItem( pos, itemid, amount )
if( pos == nil || itemid == nil || amount == nil ) then return end
if( Quantum.Item.Get( itemid ) != nil ) then
local itemEnt = ents.Create( "q_item" )
if( IsValid( itemEnt ) ) then
itemEnt:SetPos( pos )
itemEnt:InitializeItem( itemid, amount )
itemEnt:Spawn()
timer.Simple( math.Clamp( Quantum.Server.Settings.ItemDespawnTimer, 1, 600 ), function()
if( IsValid( itemEnt ) ) then
Quantum.Debug( "Despawned item " .. tostring(itemEnt) .. " [" .. itemEnt.itemid .. "]" )
itemEnt:Remove()
end
end)
end
end
end
function Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount ) --
Quantum.Server.Item.SpawnItem( pl:GetPos() + ( pl:GetForward() * 40 ) + Vector( 0, 0, 40 ), itemid, amount )
end
end

@ -18,6 +18,9 @@ Quantum.Inventory = {
MaxStackSize = 20 -- NOTE: MAX MaxStackSize=99 MaxStackSize = 20 -- NOTE: MAX MaxStackSize=99
} }
Quantum.ItemPickupTime = 0.5 -- seconds
Quantum.ItemInfoDisplayMaxDistance = 200
Quantum.Money = { Quantum.Money = {
Prefix = "$", Prefix = "$",
Surfix = "" Surfix = ""

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

Loading…
Cancel
Save