Akimbo is looking reaaal SWEET

This commit is contained in:
Fesiug 2023-11-17 22:56:41 -05:00
parent 630a51915d
commit c6279b4b57
5 changed files with 125 additions and 18 deletions

View File

@ -73,10 +73,13 @@ function SWEP:BDeploy( hand, id )
self:D_SetID( hand, id ) self:D_SetID( hand, id )
self:D_SetMagID( hand, "" ) self:D_SetMagID( hand, "" )
self:D_SetClip( hand, 0 ) self:D_SetClip( hand, 0 )
if item.Loaded then if item.Loaded and item.Loaded != "" then
local mid = item.Loaded local mid = item.Loaded
local midi = inv[ mid ] local midi = inv[ mid ]
assert( midi, "Deploy: Magazine doesn't exist in the inventory!! " .. tostring(item.Loaded) ) if !midi then
item.Loaded = ""
error( "Deploy: Magazine doesn't exist in the inventory!! " .. tostring(mid) .. " item.Loaded removed." )
end
self:D_SetMagID( hand, mid ) self:D_SetMagID( hand, mid )
self:D_SetClip( hand, midi.Ammo ) self:D_SetClip( hand, midi.Ammo )
end end

View File

@ -130,7 +130,25 @@ function SWEP:Reload()
wep_table.Loaded = "" wep_table.Loaded = ""
else else
local maglist = p:INV_FindMag( "mag_" .. wep_table.Class ) local maglist = p:INV_FindMag( "mag_" .. wep_table.Class )
local mag = maglist[1] local mag
local usedlist = {}
for _id, mrow in pairs( inv ) do
if mrow.Loaded and mrow.Loaded != "" then
usedlist[mrow.Loaded] = true
-- print( mrow.Loaded .. " Added to Mrowlist" )
end
end
for num, mid in ipairs( maglist ) do
if usedlist[mid] then
-- print( "oh No we can't use " .. mid )
else
mag = mid
break
end
end
if mag then if mag then
self:D_SetMagID( hand, mag ) self:D_SetMagID( hand, mag )
self:D_SetClip( hand, inv[mag].Ammo ) self:D_SetClip( hand, inv[mag].Ammo )

View File

@ -339,7 +339,10 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
draw.SimpleText( wep_class.Name, "Benny_16", p_x+ss(6), p_y+ss(5), scheme["bg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) draw.SimpleText( wep_class.Name, "Benny_16", p_x+ss(6), p_y+ss(5), scheme["bg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
draw.SimpleText( wep:D_GetID( hand ), "Benny_10", p_x+p_w-pb2, p_y+ss(7), scheme["bg"], TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) local identicallist = p:INV_Find( wep:BTable( hand ).Class )
identicallist = table.Flip( identicallist )
local numba = identicallist[ wep:D_GetID( hand ) ]
draw.SimpleText( "(" .. tostring(numba) .. ") - " .. wep:D_GetID( hand ), "Benny_10", p_x+p_w-pb2, p_y+ss(7), scheme["bg"], TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
if wep_class.Firemodes then -- Firemode if wep_class.Firemodes then -- Firemode
surface.SetDrawColor( scheme["fg"] ) surface.SetDrawColor( scheme["fg"] )
@ -385,12 +388,15 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
local b2 = ss( 2 ) local b2 = ss( 2 )
local b3 = ss( 3 ) local b3 = ss( 3 )
local b4 = ss( 4 ) local b4 = ss( 4 )
local maglist = p:INV_FindMag( "mag_" .. wep_table.Class, wep:D_GetMagID( hand ) ) local maglist = p:INV_FindMag( "mag_" .. wep_table.Class, { [wep:D_GetMagID( hand )] = true, [wep:D_GetMagID( !hand )] = true, } )
local newmaglist = {} local newmaglist = {}
if wep:D_GetMagID( hand ) != "" then if wep:D_GetMagID( hand ) != "" then
table.insert( newmaglist, wep:D_GetMagID( hand ) ) table.insert( newmaglist, wep:D_GetMagID( hand ) )
end end
if wep:D_GetMagID( !hand ) != "" then
table.insert( newmaglist, wep:D_GetMagID( !hand ) )
end
for i, v in ipairs( maglist ) do for i, v in ipairs( maglist ) do
table.insert( newmaglist, v ) table.insert( newmaglist, v )
end end
@ -406,19 +412,20 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
local perc = math.abs( math.cos( CurTime() ) ) local perc = math.abs( math.cos( CurTime() ) )
local s1 = (m_h - b2 - b2) local s1 = (m_h - b2 - b2)
local s2 = (m_h - b2 - b2) * ( inv[tag].Ammo / WEAPONS[inv[tag].Class].Ammo ) local s2 = (m_h - b2 - b2) * (inv[tag] and ( inv[tag].Ammo / WEAPONS[inv[tag].Class].Ammo ) or 8)
local s3 = math.floor( s2 - s1 ) local s3 = math.floor( s2 - s1 )
local m1, m2, m3, m4 = m_x + bb + bb - chunk, m_y + bb + bb - s3, m_w - b2 - b2, s2 local m1, m2, m3, m4 = m_x + bb + bb - chunk, m_y + bb + bb - s3, m_w - b2 - b2, s2
local active = tag == wep:D_GetMagID( hand ) local active = tag == wep:D_GetMagID( hand )
if active then local active2 = tag == wep:D_GetMagID( !hand )
draw.SimpleText( "x", "Benny_10", m_x + (m_w/2) - chunk, m_y + (m_h/2), scheme["fg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) if active or active2 then
draw.SimpleText( active2 and "|" or "x", "Benny_10", m_x + (m_w/2) - chunk, m_y + (m_h/2), scheme["fg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end end
surface.DrawRect( m1, m2, m3, m4 ) surface.DrawRect( m1, m2, m3, m4 )
if active then if active or active2 then
render.SetScissorRect( m1, m2, m1 + m3, m2 + m4, true ) render.SetScissorRect( m1, m2, m1 + m3, m2 + m4, true )
draw.SimpleText( "x", "Benny_10", m_x + (m_w/2) - chunk, m_y + (m_h/2), scheme["bg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) draw.SimpleText( active2 and "|" or "x", "Benny_10", m_x + (m_w/2) - chunk, m_y + (m_h/2), scheme["bg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
render.SetScissorRect( 0, 0, 0, 0, false ) render.SetScissorRect( 0, 0, 0, 0, false )
end end
end end
@ -808,7 +815,7 @@ do
end end
local function Wrap( ply, num ) local function Wrap( ply, num )
local buckets = ply:INV_Buckets() local buckets = ply:INV_Buckets()
local currsel = ply:GetActiveWeapon():GetWep1() local currsel = ply:GetActiveWeapon():D_GetID( ply:GetActiveWeapon():GetTempHandedness() )
local lb, li = Locate( ply, buckets, currsel ) local lb, li = Locate( ply, buckets, currsel )
if lb then if lb then

View File

@ -47,7 +47,43 @@ end, "arg 1: player ent index, arg 2: classname")
-- PROTO: Move this all into weapon code. -- PROTO: Move this all into weapon code.
concommand.Add("benny_inv_equip", function( ply, cmd, args ) concommand.Add("benny_inv_equip", function( ply, cmd, args )
local wep = ply:BennyCheck() local wep = ply:BennyCheck()
if wep then wep:BDeploy( wep:GetTempHandedness(), args[1] ) end if wep then
print(args[2])
local hand = args[2]!=nil and tobool(args[2]) or wep:GetTempHandedness()
print(hand)
local id = args[1]
local swap_or_replace = tobool(args[3])
local L, R = true, false
local curr_r = wep:D_GetID( false )
local curr_l = wep:D_GetID( true )
if hand == R then
if curr_r == id then
-- We already have this equipped
return
elseif swap_or_replace and curr_r != "" then
-- We already have something equipped here, move it to the offhand
wep:BDeploy( L, curr_r )
elseif curr_l == id then
-- You have the gun we want, snatched
wep:BHolster( L )
end
wep:BDeploy( R, id )
elseif hand == L then
if curr_l == id then
-- We already have this equipped
return
elseif swap_or_replace and curr_l != "" then
-- We already have something equipped here, move it to the offhand
wep:BDeploy( R, curr_l )
elseif curr_r == id then
-- You have the gun we want, snatched
wep:BHolster( R )
end
wep:BDeploy( L, id )
end
end
end, end,
function(cmd, args) function(cmd, args)
args = string.Trim(args:lower()) args = string.Trim(args:lower())
@ -238,24 +274,67 @@ if CLIENT then
end end
local function regen_items( itemlist ) local function regen_items( itemlist )
local ply = LocalPlayer() local ply = LocalPlayer()
local inv = ply:INV_Get()
local active = GetConVar("benny_hud_tempactive"):GetString() local active = GetConVar("benny_hud_tempactive"):GetString()
itemlist:Clear() itemlist:Clear()
for i, v in pairs( ply:INV_Get() ) do for i, v in pairs( ply:INV_ListFromBuckets() ) do
local button = vgui.Create( "DButton" ) local button = vgui.Create( "DButton" )
itemlist:AddItem( button ) itemlist:AddItem( button )
button:SetSize( 1, ss(36) ) button:SetSize( 1, ss(30) )
button:Dock( TOP ) button:Dock( TOP )
button:DockMargin( 0, 0, 0, ss(4) ) button:DockMargin( 0, 0, 0, ss(4) )
button.ID = i button.ID = v
local Class = WEAPONS[v.Class] local Class = WEAPONS[inv[v].Class]
button.Text_Name = Class.Name button.Text_Name = Class.Name
button.Text_Desc = Class.Description button.Text_Desc = Class.Description
-- PROTO: These functions don't need to be remade over and over like this. -- PROTO: These functions don't need to be remade over and over like this.
function button:DoClick() function button:DoClick()
RunConsoleCommand("benny_inv_equip", button.ID) local Menu = DermaMenu()
local opt0 = Menu:AddOption( "Equip", function()
RunConsoleCommand( "benny_inv_equip", button.ID )
end)
opt0:SetIcon( "icon16/control_play_blue.png" )
Menu:AddSpacer()
local opt1 = Menu:AddOption( "Equip Right", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "false" )
end)
opt1:SetIcon( "icon16/resultset_next.png" )
local opt2 = Menu:AddOption( "Equip Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true" )
end)
opt2:SetIcon( "icon16/resultset_previous.png" )
local opt3 = Menu:AddOption( "Swap Right", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "false", "true" )
end)
opt3:SetIcon( "icon16/resultset_first.png" )
local opt4 = Menu:AddOption( "Swap Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true", "true" )
end)
opt4:SetIcon( "icon16/resultset_last.png" )
Menu:AddSpacer()
local opt5 = Menu:AddOption( "Holster", function()
RunConsoleCommand( "benny_inv_holster", button.ID )
end)
opt5:SetIcon( "icon16/control_pause_blue.png" )
local opt6 = Menu:AddOption( "Discard", function()
RunConsoleCommand("benny_inv_discard", button.ID)
self:Remove()
end)
opt6:SetIcon( "icon16/bin.png" )
Menu:Open()
-- timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end ) -- timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end )
end end

View File

@ -93,7 +93,7 @@ function PT:INV_FindMag( class, exclude )
local inv = self:INV_Get() local inv = self:INV_Get()
local results = {} local results = {}
for i, v in pairs( inv ) do for i, v in pairs( inv ) do
if v.Class == class and i != (exclude or "") then if v.Class == class and (exclude and !exclude[i] or !exclude and true) then
table.insert( results, i ) table.insert( results, i )
end end
end end