diff --git a/entities/entities/q_item/init.lua b/entities/entities/q_item/init.lua index 35bb4e9..3b918fc 100644 --- a/entities/entities/q_item/init.lua +++ b/entities/entities/q_item/init.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 diff --git a/gamemode/engine/core/client/cl_fonts.lua b/gamemode/engine/core/client/cl_fonts.lua index 69cab84..104ff96 100644 --- a/gamemode/engine/core/client/cl_fonts.lua +++ b/gamemode/engine/core/client/cl_fonts.lua @@ -131,4 +131,22 @@ surface.CreateFont( "q_item_option_dropval", { font = "Cambria", 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 }) \ No newline at end of file diff --git a/gamemode/engine/core/client/cl_hud.lua b/gamemode/engine/core/client/cl_hud.lua index 306d4b0..0e089ec 100644 --- a/gamemode/engine/core/client/cl_hud.lua +++ b/gamemode/engine/core/client/cl_hud.lua @@ -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 diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index 0028e44..034bde8 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -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 diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index b2c2cef..365c3ba 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -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." ) diff --git a/gamemode/engine/lib/server/sv_networking.lua b/gamemode/engine/lib/server/sv_networking.lua index 30602a0..e23a102 100644 --- a/gamemode/engine/lib/server/sv_networking.lua +++ b/gamemode/engine/lib/server/sv_networking.lua @@ -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 \ No newline at end of file diff --git a/gamemode/engine/lib/sh_items.lua b/gamemode/engine/lib/sh_items.lua index 2111259..7f07c32 100644 --- a/gamemode/engine/lib/sh_items.lua +++ b/gamemode/engine/lib/sh_items.lua @@ -28,4 +28,34 @@ 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 \ No newline at end of file diff --git a/gamemode/settings/sh_settings.lua b/gamemode/settings/sh_settings.lua index 3ccaa25..f84fc8c 100644 --- a/gamemode/settings/sh_settings.lua +++ b/gamemode/settings/sh_settings.lua @@ -18,6 +18,9 @@ Quantum.Inventory = { MaxStackSize = 20 -- NOTE: MAX MaxStackSize=99 } +Quantum.ItemPickupTime = 0.5 -- seconds +Quantum.ItemInfoDisplayMaxDistance = 200 + Quantum.Money = { Prefix = "$", Surfix = "" diff --git a/gamemode/settings/sv_settings.lua b/gamemode/settings/sv_settings.lua index dcf7644..a1ff02b 100644 --- a/gamemode/settings/sv_settings.lua +++ b/gamemode/settings/sv_settings.lua @@ -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"