Added text above dropped item & inventory optimizations & bug fixes

master
AlmTech Software 5 years ago
parent 7667e9ed9e
commit a916c3fb78
  1. 18
      entities/entities/q_item/init.lua
  2. 18
      gamemode/engine/core/client/cl_fonts.lua
  3. 100
      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,14 +22,22 @@ function ENT:Initialize()
end
local useStartTime
local useDelay = Quantum.ItemPickupTime
function ENT:Use( activator, caller )
if( activator:IsPlayer() ) then
if( self.itemid != nil && self.amount != nil ) then
self:Remove()
-- add item to players inventory
Quantum.Server.Inventory.GiveItem( activator, self.itemid, self.amount )
Quantum.Notify.ItemPickup( activator, Quantum.Item.Get( self.itemid ), self.amount ) -- notify the player
self:EmitSound( Quantum.Server.Settings.ItemPickupSound ) -- make a pickup sound
useStartTime = useStartTime || CurTime()
if( CurTime() - useStartTime >= useDelay ) then
useStartTime = nil
self:Remove()
-- add item to players inventory
Quantum.Server.Inventory.GiveItem( activator, self.itemid, self.amount )
Quantum.Notify.ItemPickup( activator, Quantum.Item.Get( self.itemid ), self.amount ) -- notify the player
self:EmitSound( Quantum.Server.Settings.ItemPickupSound ) -- make a pickup sound
end
end
end
end

@ -132,3 +132,21 @@ surface.CreateFont( "q_item_option_dropval", {
size = 40 * Quantum.Client.ResolutionScale,
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,38 +20,82 @@ local radius = 1.05 * scale
local padding = 5 * scale
local sw, sh = ScrW(), ScrH()
local client = LocalPlayer()
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 maxhp = client:GetMaxHealth()
-- Health border
surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH )
-- Health bar
surface.SetDrawColor( 168, 62, 50, 255 )
surface.DrawRect( ( sw/2 - barW/2 ) + padding/2, (sh*0.9) + padding/2, math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ), barH - padding )
-- Health Text
surface.SetFont( "q_HUD" )
surface.SetTextColor( 255, 255, 255, 255 )
local hptxt = tostring( 100 * (hp/maxhp) .. "%" )
local txtW, txtH = surface.GetTextSize( hptxt )
surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) )
surface.DrawText( hptxt )
-- Crosshair
if( Quantum.Client.ShowCrosshair ) then
surface.SetDrawColor( 255, 255, 255, 200 )
surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 )
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
local hp = LocalPlayer():Health()
local lasthp = hp
local maxhp = LocalPlayer():GetMaxHealth()
if( !client:Alive() ) then
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawRect( 0, 0, sw, sh )
end
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
surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH )
-- Health bar
surface.SetDrawColor( 168, 62, 50, 255 )
surface.DrawRect( ( sw/2 - barW/2 ) + padding/2, (sh*0.9) + padding/2, math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ), barH - padding )
-- Health Text
surface.SetFont( "q_HUD" )
surface.SetTextColor( 255, 255, 255, 255 )
local hptxt = tostring( 100 * (hp/maxhp) .. "%" )
local txtW, txtH = surface.GetTextSize( hptxt )
surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) )
surface.DrawText( hptxt )
-- Crosshair
if( Quantum.Client.ShowCrosshair ) then
surface.SetDrawColor( 255, 255, 255, 200 )
surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 )
end
if( client:Alive() ) then
renderStatHUD()
renderItemInfoHUD()
end
end
end

@ -31,6 +31,12 @@ end
function menu.open( dt )
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
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 )
-- spawn the item infront of the player
local itemEnt = ents.Create( "q_item" )
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
Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount )
end
else
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
if( !Quantum.Server.Settings.DeveloperMode ) then
if( Quantum.Server.Settings.DeveloperMode == false ) then
UpdateAllPlayers() -- Update the players on auto-refresh / lua-refresh
end

@ -29,3 +29,33 @@ end
function Quantum.Item.Get( id )
return Quantum.Items[id]
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
}
Quantum.ItemPickupTime = 0.5 -- seconds
Quantum.ItemInfoDisplayMaxDistance = 200
Quantum.Money = {
Prefix = "$",
Surfix = ""

@ -15,7 +15,7 @@ Quantum.Server.Settings.MaxHealth = 100
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"

Loading…
Cancel
Save