Added item halos & item pickup delay & bug fixes

master
AlmTech Software 5 years ago
parent a916c3fb78
commit 307972ea61
  1. 89
      gamemode/engine/core/client/cl_hud.lua
  2. 21
      gamemode/engine/derma/menus/menu_charinfo.lua
  3. 2
      gamemode/engine/lib/sh_items.lua
  4. 10
      gamemode/settings/sh_items.lua
  5. 5
      gamemode/settings/sh_settings.lua

@ -20,16 +20,14 @@ local radius = 1.05 * scale
local padding = 5 * scale local padding = 5 * scale
local sw, sh = ScrW(), ScrH() local sw, sh = ScrW(), ScrH()
local client = LocalPlayer()
local function SetAlpha( color, alpha ) local function SetAlpha( color, alpha )
return Color( color.r, color.g, color.b, alpha ) return Color( color.r, color.g, color.b, alpha )
end end
local function renderStatHUD() local function renderStatHUD()
local hp = client:Health() local hp = LocalPlayer():Health()
local lasthp = hp local lasthp = hp
local maxhp = client:GetMaxHealth() local maxhp = LocalPlayer():GetMaxHealth()
-- Health border -- Health border
surface.SetDrawColor( 0, 0, 0, 200 ) surface.SetDrawColor( 0, 0, 0, 200 )
@ -55,47 +53,76 @@ local function renderStatHUD()
end end
local function renderItemInfoHUD() local function renderItemInfoHUD()
local trace = client:GetEyeTraceNoCursor() local trace = LocalPlayer():GetEyeTraceNoCursor()
if( trace.Entity:GetClass() == "q_item" ) then local entsNear = ents.FindInSphere( LocalPlayer():GetPos(), Quantum.ItemInfoDisplayMaxDistance )
local distance = client:GetPos():Distance( trace.Entity:GetPos() )
local distFrac = Lerp( distance/Quantum.ItemInfoDisplayMaxDistance, 1, 0 ) for i, ent in pairs( entsNear ) do
if( ent:GetClass() == "q_item" ) then
local distance = LocalPlayer():GetPos():Distance( ent:GetPos() )
local distFrac = Lerp( distance/Quantum.ItemInfoDisplayMaxDistance, 1, 0 )
if( distance <= Quantum.ItemInfoDisplayMaxDistance ) then if( distance <= Quantum.ItemInfoDisplayMaxDistance ) then
local item = Quantum.Item.Get( trace.Entity:GetNWString( "q_item_id" ) ) || { name="ERROR" } local item = Quantum.Item.Get( ent:GetNWString( "q_item_id" ) ) || { name = "", rarity = { txt = "", color = Color( 0, 0, 0, 0 ) } }
local amount = trace.Entity:GetNWInt( "q_item_amount" ) || 1 local amount = ent:GetNWInt( "q_item_amount" ) || 1
local pos = trace.Entity:GetPos() local pos = ent:GetPos()
pos.z = pos.z + 20 pos.z = pos.z + 20
local screenPos = pos:ToScreen() local screenPos = pos:ToScreen()
local txtPadding = 20 * scale local txtPadding = 20 * scale
local itemAmountTxt = "" local itemAmountTxt = ""
if( amount > 1 ) then itemAmountTxt = amount .. "x " end if( amount > 1 ) then itemAmountTxt = amount .. "x " end
local alphaFrac = distFrac 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( 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 ) 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 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 ) 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 end
end end
end end
function GM:HUDPaint() local showRarities = {
if( !Quantum.Client.IsInMenu ) then [Quantum.Rarity.Rare] = true,
if( !client:Alive() ) then [Quantum.Rarity.Epic] = true,
surface.SetDrawColor( 0, 0, 0, 255 ) [Quantum.Rarity.Legendary] = true
surface.DrawRect( 0, 0, sw, sh ) }
local function renderHaloAroundItems()
for i, item in pairs( ents.FindByClass( "q_item" ) ) do
local itemid = item:GetNWString( "q_item_id" )
local itemTbl = Quantum.Item.Get(itemid) || { rarity = Quantum.Rarity.Rare }
if( itemTbl != nil ) then
if( showRarities[itemTbl.rarity] ) then
halo.Add( { item }, SetAlpha( itemTbl.rarity.color, 255 ), 0, 0, 2, true, false )
end
end end
end
end
hook.Add( "PreDrawHalos", "Quantum_Item_Halos", function()
renderHaloAroundItems()
end)
function GM:HUDPaint()
if( LocalPlayer():IsValid() ) then
if( !Quantum.Client.IsInMenu ) then
if( !LocalPlayer():Alive() ) then
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawRect( 0, 0, sw, sh )
end
if( Quantum.Client.Config.EnableHUD ) then if( Quantum.Client.Config.EnableHUD ) then
if( client:Alive() ) then if( LocalPlayer():Alive() ) then
renderStatHUD() renderStatHUD()
renderItemInfoHUD() renderItemInfoHUD()
end
end end
end end
end end

@ -145,7 +145,7 @@ function menu.open( dt )
itempanels[ii].index = ii -- set the vars itempanels[ii].index = ii -- set the vars
if( items[ii] ) then if( items[ii] ) then
itempanels[ii].item = Quantum.Item.Get( items[ii][1]) -- get the items info through its id itempanels[ii].item = Quantum.Item.Get( items[ii][1] ) -- get the items info through its id
itempanels[ii].item.amount = items[ii][2] || 1 -- get the amount itempanels[ii].item.amount = items[ii][2] || 1 -- get the amount
end end
@ -292,10 +292,27 @@ hook.Add("ScoreboardShow", "Quantum_Menu_CharInfo_Open", function()
-- InventoryStartTime = nil -- InventoryStartTime = nil
-- end -- open the menu -- end -- open the menu
menu.open() -- menu.open()
return false return false
end) end)
local startTime
hook.Add( "Think", "Quantum_Menu_CharInfo_Think", function()
if( !Quantum.Client.IsInMenu ) then
if( input.IsButtonDown( Quantum.Bind.OpenInventory ) ) then
startTime = startTime || CurTime()
if( CurTime() - startTime >= Quantum.InventoryOpenDelay ) then
startTime = nil
menu.open()
end
else
startTime = nil
end
end
end)
return menu return menu

@ -55,7 +55,7 @@ if SERVER then
end end
end end
function Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount ) -- function Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount ) -- Quantum.Server.Item.SpawnItemAtPlayer( Entity(1), "test2", 5 )
Quantum.Server.Item.SpawnItem( pl:GetPos() + ( pl:GetForward() * 40 ) + Vector( 0, 0, 40 ), itemid, amount ) Quantum.Server.Item.SpawnItem( pl:GetPos() + ( pl:GetForward() * 40 ) + Vector( 0, 0, 40 ), itemid, amount )
end end
end end

@ -39,3 +39,13 @@ Quantum.Item.Create( "bomb", {
equipable = false, equipable = false,
rarity = Quantum.Rarity.Epic rarity = Quantum.Rarity.Epic
} ) } )
Quantum.Item.Create( "potatoe", {
name = "Legendary Potatoe",
desc = "The most legendary potatoe in existance. Don't eat it!",
model = "models/props_phx/misc/potato.mdl",
stack = 1,
soulbound = false,
equipable = false,
rarity = Quantum.Rarity.Legendary
} )

@ -18,6 +18,7 @@ Quantum.Inventory = {
MaxStackSize = 20 -- NOTE: MAX MaxStackSize=99 MaxStackSize = 20 -- NOTE: MAX MaxStackSize=99
} }
Quantum.InventoryOpenDelay = 0.35
Quantum.ItemPickupTime = 0.5 -- seconds Quantum.ItemPickupTime = 0.5 -- seconds
Quantum.ItemInfoDisplayMaxDistance = 200 Quantum.ItemInfoDisplayMaxDistance = 200
@ -35,6 +36,10 @@ Quantum.Rarity = {
Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) } Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) }
} }
Quantum.Bind = {
OpenInventory = KEY_TAB
}
Quantum.Models = { Quantum.Models = {
NPC = {}, NPC = {},
Player = { Player = {

Loading…
Cancel
Save