get rid of temphandedness

This commit is contained in:
Fesiug 2023-11-29 02:45:36 -05:00
parent d377c50739
commit c2864c5ca8
5 changed files with 120 additions and 116 deletions

View File

@ -1,12 +1,22 @@
function SWEP:PrimaryAttack()
self:BFire( false )-- self:GetTempHandedness() )
local dual = self:BTable( false ) and self:BTable( true )
if dual then
self:BFire( true )
else
self:BFire( false )
end
return true
end
function SWEP:SecondaryAttack()
self:BFire( true )-- self:GetTempHandedness() )
local dual = self:BTable( false ) and self:BTable( true )
if dual then
self:BFire( false )
else
self:BFire( true )
end
return true
end
@ -34,7 +44,7 @@ function SWEP:BFire( hand )
self:B_Ammo( hand, self:D_GetClip( hand ) - 1 )
B_Sound( self, wep_class.Sound_Fire )
self:TPFire( self:GetTempHandedness() )
self:TPFire( hand )
self:CallFire( hand )
self:D_SetDelay( hand, CurTime() + wep_class.Delay )
@ -67,8 +77,8 @@ function SWEP:CallFire( hand )
for i=1, class.Pellets or 1 do
local dir = self:GetOwner():EyeAngles()
local radius = util.SharedRandom("benny_distance", 0, 1, i )
local circ = util.SharedRandom("benny_radius", 0, math.rad(360), i )
local radius = util.SharedRandom("benny_distance_"..tostring(hand), 0, 1, i )
local circ = util.SharedRandom("benny_radius_"..tostring(hand), 0, math.rad(360), i )
dir:RotateAroundAxis( dir:Right(), spread * radius * math.sin( circ ) )
dir:RotateAroundAxis( dir:Up(), spread * radius * math.cos( circ ) )

View File

@ -48,7 +48,6 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Int", 3, "Wep2_Firemode" )
self:NetworkVar( "Bool", 0, "UserAim" )
self:NetworkVar( "Bool", 1, "GrenadeDown" )
self:NetworkVar( "Bool", 2, "TempHandedness" )
self:SetWep1_Firemode( 1 )
self:SetWep2_Firemode( 1 )
@ -91,67 +90,65 @@ function SWEP:B_FiremodeName( alt )
end
end
function SWEP:Reload()
function SWEP:Reload( hand )
if hand == nil then return end -- Needs to be called from the custom ones
local p = self:GetOwner()
local inv = p:INV_Get()
if p:KeyPressed( IN_RELOAD ) then
local hand = self:GetTempHandedness()
local wep_table = self:BTable( hand )
local wep_class = self:BClass( hand )
if wep_table then
if wep_class.Custom_Reload then
if wep_class.Custom_Reload( self, wep_table ) then return end
end
if self:D_GetDelay( hand ) > CurTime() then
return false
end
local wep_table = self:BTable( hand )
local wep_class = self:BClass( hand )
if wep_table then
if wep_class.Custom_Reload then
if wep_class.Custom_Reload( self, wep_table ) then return end
end
if self:D_GetDelay( hand ) > CurTime() then
return false
end
local mid = self:D_GetMagID( hand )
if SERVER or (CLIENT and IsFirstTimePredicted()) then
if mid != "" then
if inv[mid].Ammo == 0 then
if SERVER or (CLIENT and IsFirstTimePredicted()) then
p:INV_Discard( mid )
end
end
self:D_SetMagID( hand, "" )
self:D_SetClip( hand, 0 )
B_Sound( self, wep_class.Sound_MagOut )
wep_table.Loaded = ""
else
local maglist = p:INV_FindMag( "mag_" .. wep_table.Class )
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
self:D_SetMagID( hand, mag )
self:D_SetClip( hand, inv[mag].Ammo )
wep_table.Loaded = mag
B_Sound( self, wep_class.Sound_MagIn )
else
B_Sound( self, "Common.NoAmmo" )
local mid = self:D_GetMagID( hand )
if SERVER or (CLIENT and IsFirstTimePredicted()) then
if mid != "" then
if inv[mid].Ammo == 0 then
if SERVER or (CLIENT and IsFirstTimePredicted()) then
p:INV_Discard( mid )
end
end
self:D_SetMagID( hand, "" )
self:D_SetClip( hand, 0 )
B_Sound( self, wep_class.Sound_MagOut )
wep_table.Loaded = ""
else
local maglist = p:INV_FindMag( "mag_" .. wep_table.Class )
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
self:D_SetMagID( hand, mag )
self:D_SetClip( hand, inv[mag].Ammo )
wep_table.Loaded = mag
B_Sound( self, wep_class.Sound_MagIn )
else
B_Sound( self, "Common.NoAmmo" )
end
end
self:TPReload( self:GetTempHandedness() )
end
self:TPReload( hand )
end
return true
end
@ -168,6 +165,15 @@ hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_TempForAim", function( ply
wep:SetUserAim( true )
end
end
local dual = wep:BTable( false ) and wep:BTable( true )
if button == KEY_R then
if dual then wep:Reload( true ) else wep:Reload( false ) end
end
if button == KEY_T then
if dual then wep:Reload( false ) else wep:Reload( true ) end
end
end)
hook.Add( "PlayerButtonUp", "Benny_PlayerButtonUp_TempForAim", function( ply, button )
@ -183,18 +189,6 @@ end)
function SWEP:Think()
local p = self:GetOwner()
--if tobool(p:GetInfoNum("benny_toggleaim", 0)) then
-- if p:KeyPressed( IN_ATTACK2 ) then
-- self:SetUserAim( !self:GetUserAim() )
-- end
--else
-- self:SetUserAim( p:KeyDown( IN_ATTACK2 ) )
--end
if p:KeyPressed( IN_ZOOM ) and (SERVER or (CLIENT and IsFirstTimePredicted())) then
self:SetTempHandedness( !self:GetTempHandedness() )
end
self:SetAim( math.Approach( self:GetAim(), self:GetUserAim() and 1 or 0, FrameTime()/0.2 ) )
if !p:KeyDown( IN_ATTACK ) then
@ -214,14 +208,17 @@ function SWEP:Think()
end
if ht == "normal" and self:GetHoldType() != "normal" then
self:TPHolster( self:GetTempHandedness() )
self:TPHolster( false )
elseif ht != "normal" and self:GetHoldType() == "normal" then
self:TPDraw( self:GetTempHandedness() )
self:TPDraw( false )
end
if self:BClass( false ) then
if self:BClass( false ).Custom_Think then
self:BClass( false ).Custom_Think( self, self:BTable( false ) )
for i=1, 2 do
local hand = i==2
if self:BClass( hand ) then
if self:BClass( hand ).Custom_Think then
self:BClass( hand ).Custom_Think( self, self:BTable( hand ) )
end
end
end

View File

@ -291,14 +291,6 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end
end
if wep and wep:GetTempHandedness() then
local t_w, t_h = ss( 90 ), ss( 14 )
local t_x, t_y = sw/2 - t_w/2, sh - Hb - t_h
surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( t_x, t_y, t_w, t_h )
draw.SimpleText( "LEFT-HANDED MODE", "Benny_12", t_x + t_w/2, t_y + t_h/2 + ss(1), scheme["fg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
do -- Vaulting
if vaultsave then
local tex = "[SPACE] VAULT OVER"
@ -621,7 +613,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end
end
if wep then -- Quickinv
if false then -- Quickinv
local inv = p:INV_Get()
local gap = ss(1)
local size_textx = ss(96)
@ -641,12 +633,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
-- PROTO: Maybe check this every 10hz instead
do
-- local flipped = table.Flip( Entity(1):INV_ListFromBuckets() )
-- local id = flipped[ Entity(1):GetActiveWeapon():D_GetID( false ) ]
for n, bucket in ipairs( inventorylist ) do
for i, v in ipairs( bucket ) do
if v == wep:D_GetID( wep:GetTempHandedness() ) then
if v == wep:D_GetID( false ) then
bucket_selected = n
item_selected = i
end
@ -684,7 +673,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
else
for d, item in ipairs( bucket ) do
local idata = WEAPONS[inv[item].Class]
local sel = item==wep:D_GetID( wep:GetTempHandedness() )--d==item_selected
local sel = item==wep:D_GetID( false )--d==item_selected
surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( bump + Wb, (item_start+ybump) + Hb, size_textx, (sel and size_texty_sel or size_texty) )
if sel then
@ -927,8 +916,9 @@ do
return false
end
local function Wrap( ply, num )
do return end
local buckets = ply:INV_Buckets()
local currsel = ply:GetActiveWeapon():D_GetID( ply:GetActiveWeapon():GetTempHandedness() )
local currsel = ply:GetActiveWeapon():D_GetID( false )
local lb, li = Locate( ply, buckets, currsel )
if lb then
@ -955,9 +945,10 @@ do
end
local qt = {
["invnext"] = function( ply )
do return end
if !ply:BennyCheck() then return end
local buckets = ply:INV_Buckets()
local currsel = ply:GetActiveWeapon():D_GetID( ply:GetActiveWeapon():GetTempHandedness() )
local currsel = ply:GetActiveWeapon():D_GetID( false )
local lb, li = Locate( ply, buckets, currsel )
if lb then
@ -980,8 +971,9 @@ do
end
end,
["invprev"] = function( ply )
do return end
local buckets = ply:INV_Buckets()
local currsel = ply:GetActiveWeapon():D_GetID( ply:GetActiveWeapon():GetTempHandedness() )
local currsel = ply:GetActiveWeapon():D_GetID( false )
local lb, li = Locate( ply, buckets, currsel )
if lb then

View File

@ -97,7 +97,13 @@ end, "arg 1: item id, arg 2 does offhand")
-- PROTO: Move this all into weapon code.
concommand.Add("benny_inv_holster", function( ply, cmd, args )
local wep = ply:BennyCheck()
if wep then wep:BHolster( wep:GetTempHandedness() ) end
if wep then
if wep:D_GetID( false ) == args[1] then
wep:BHolster( false )
elseif wep:D_GetID( true ) == args[1] then
wep:BHolster( true )
end
end
end)
concommand.Add("benny_inv_sync", function( ply, cmd, args )
@ -335,27 +341,22 @@ if CLIENT then
function button:DoClick()
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" )
Menu:AddSpacer()
local opt2 = Menu:AddOption( "Equip Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true" )
end)
opt2:SetIcon( "icon16/resultset_previous.png" )
local opt4 = Menu:AddOption( "Swap Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true", "true" )
@ -379,7 +380,10 @@ if CLIENT then
-- timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end )
end
button.DoRightClick = button.DoClick
button.DoRightClick = function( self )
RunConsoleCommand("benny_inv_discard", button.ID)
self:Remove()
end
function button:Paint( w, h )
surface.SetDrawColor( schemes[active]["fg"] )

View File

@ -911,26 +911,27 @@ do -- Grenades, nothing here is guaranteed.
-- TEMP: Do this right!
if !class.GrenadeCharge then self:SetGrenadeDownStart( CurTime() ) end
--
self:TPFire( self:GetTempHandedness() )
local hand = (self:BTable( true ) and self:BTable( true ).Class == data.Class) or false
self:TPFire( hand )
if SERVER then GrenadeCreate( self, data ) end
local id = self:D_GetID( false )
self:BHolster( false )
local id = self:D_GetID( hand )
self:BHolster( hand )
if SERVER or (CLIENT and IsFirstTimePredicted()) then
p:INV_Discard( id )
end
local subsequent = p:INV_Find( data.Class )[1]
if subsequent then
self:BDeploy( false, subsequent )
end
-- local subsequent = p:INV_Find( data.Class )[1]
-- if subsequent then
-- self:BDeploy( hand, subsequent )
-- end
end
local function GrenadeThink( self, data )
local p = self:GetOwner()
local class = WEAPONS[data.Class]
if self:GetGrenadeDown() then
if !p:KeyDown( IN_ATTACK ) or ( CurTime() >= (self:GetGrenadeDownStart() + class.GrenadeFuse) ) then
if true or ( CurTime() >= (self:GetGrenadeDownStart() + class.GrenadeFuse) ) then
GrenadeThrow( self, data )
end
end