New reloading logic.

This commit is contained in:
Fesiug 2023-12-10 03:00:05 -05:00
parent 4ab6312ab1
commit fe3584376b
9 changed files with 272 additions and 129 deletions

View File

@ -1,67 +1,103 @@
-- Weapon ID
function SWEP:D_GetID( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2() or (hand == false) and self:GetWep1()
end
function SWEP:D_SetID( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2( value ) or (hand == false) and self:SetWep1( value )
end
-- Wep. Clip ID
function SWEP:D_GetMagID( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_Clip() or (hand == false) and self:GetWep1_Clip()
end
function SWEP:D_SetMagID( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_Clip( value ) or (hand == false) and self:SetWep1_Clip( value )
end
-- Weapon Firemode
function SWEP:D_GetFiremode( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_Firemode() or (hand == false) and self:GetWep1_Firemode()
end
function SWEP:D_SetFiremode( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_Firemode( value ) or (hand == false) and self:SetWep1_Firemode( value )
end
-- Weapon Burst
function SWEP:D_GetBurst( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_Burst() or (hand == false) and self:GetWep1_Burst()
end
function SWEP:D_SetBurst( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_Burst( value ) or (hand == false) and self:SetWep1_Burst( value )
end
-- Weapon Spread
function SWEP:D_GetSpread( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_Spread() or (hand == false) and self:GetWep1_Spread()
end
function SWEP:D_SetSpread( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_Spread( value ) or (hand == false) and self:SetWep1_Spread( value )
end
-- Weapon Spread
function SWEP:D_GetShotTime( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_ShotTime() or (hand == false) and self:GetWep1_ShotTime()
end
function SWEP:D_SetShotTime( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_ShotTime( value ) or (hand == false) and self:SetWep1_ShotTime( value )
end
-- Weapon Holstering Time
function SWEP:D_GetHolstering( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_Holstering() or (hand == false) and self:GetWep1_Holstering()
end
function SWEP:D_SetHolstering( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_Holstering( value ) or (hand == false) and self:SetWep1_Holstering( value )
end
-- Weapon Reloading Time
function SWEP:D_GetReloading( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_Reloading() or (hand == false) and self:GetWep1_Reloading()
end
function SWEP:D_SetReloading( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_Reloading( value ) or (hand == false) and self:SetWep1_Reloading( value )
end
-- Weapon Reload Type
function SWEP:D_GetReloadType( hand )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:GetWep2_ReloadType() or (hand == false) and self:GetWep1_ReloadType()
end
function SWEP:D_SetReloadType( hand, value )
assert( hand!=nil, "Missing hand argument" )
return (hand == true) and self:SetWep2_ReloadType( value ) or (hand == false) and self:SetWep1_ReloadType( value )
end
-- Weapon Player Requesting ID
function SWEP:D_GetReqID( hand )
local p = self:GetOwner()

View File

@ -0,0 +1,104 @@
-- Reload logic
SWEP.GEN_MagOut = 0
SWEP.GEN_MagIn = 0.8
SWEP.GEN_MagIn_BonusStart = 0.2
SWEP.GEN_MagIn_BonusEnd = 0.25
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()
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 rt = self:D_GetReloading( hand )
if rt > 0 then
if self.GEN_MagIn_BonusStart <= rt and rt < self.GEN_MagIn_BonusEnd then
self:D_SetReloading( hand, 0 )
return true
else
B_Sound( self, "Common.ReloadFail" )
self:D_SetReloading( hand, 1 )
return false
end
end
local curmag = self:D_GetMagID( hand )
if curmag != "" then
-- self:D_SetReloading( hand, wep_class.Reload_MagOut or self.GEN_MagOut )
-- self:D_SetReloadType( hand, 2 )
self:Reload_MagOut( hand, self:D_GetMagID( hand ), inv )
else
self:D_SetReloading( hand, wep_class.Reload_MagIn or self.GEN_MagIn )
self:D_SetReloadType( hand, 1 )
end
self:TPReload( hand )
end
return true
end
function SWEP:Reload_MagOut( hand, curmag, optinv, optwep_table, optwep_class )
local p = self:GetOwner()
local inv = optinv or p:INV_Get()
local wep_table = optwep_table or self:BTable( hand )
local wep_class = optwep_class or self:BClass( hand )
if !inv[curmag] then
ErrorNoHalt( "Mag isn't a valid item" )
self:D_SetMagID( hand, "" )
wep_table.Loaded = ""
elseif inv[curmag].Ammo == 0 then
if SERVER or (CLIENT and IsFirstTimePredicted()) then
p:INV_Discard( curmag )
end
end
self:D_SetMagID( hand, "" )
self:D_SetClip( hand, 0 )
B_Sound( self, wep_class.Sound_MagOut )
wep_table.Loaded = ""
end
function SWEP:Reload_MagIn( hand, curmag, optinv, optwep_table, optwep_class )
local p = self:GetOwner()
local inv = optinv or p:INV_Get()
local wep_table = optwep_table or self:BTable( hand )
local wep_class = optwep_class or self:BClass( hand )
local maglist = p:INV_FindMag( 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

View File

@ -27,6 +27,8 @@ AddCSLuaFile( "sh_inv.lua" )
include ( "sh_inv.lua" )
AddCSLuaFile( "sh_holdtypes.lua" )
include ( "sh_holdtypes.lua" )
AddCSLuaFile( "sh_reload.lua" )
include ( "sh_reload.lua" )
AddCSLuaFile( "cl_wm.lua" )
if CLIENT then
@ -44,6 +46,8 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Float", 7, "Wep2_ShotTime" )
self:NetworkVar( "Float", 8, "Wep1_Holstering" )
self:NetworkVar( "Float", 9, "Wep2_Holstering" )
self:NetworkVar( "Float", 10, "Wep1_Reloading" )
self:NetworkVar( "Float", 11, "Wep2_Reloading" )
self:NetworkVar( "String", 0, "Wep1" )
self:NetworkVar( "String", 1, "Wep2" )
self:NetworkVar( "String", 2, "Wep1_Clip" )
@ -52,11 +56,19 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Int", 1, "Wep2_Burst" )
self:NetworkVar( "Int", 2, "Wep1_Firemode" )
self:NetworkVar( "Int", 3, "Wep2_Firemode" )
self:NetworkVar( "Int", 4, "Wep1_ReloadType" )
self:NetworkVar( "Int", 5, "Wep2_ReloadType" )
self:NetworkVar( "Bool", 0, "UserAim" )
self:NetworkVar( "Bool", 1, "GrenadeDown" )
self:SetWep1_Firemode( 1 )
self:SetWep2_Firemode( 1 )
self:SetWep1_Holstering( -1 )
self:SetWep2_Holstering( -1 )
self:SetWep1_Reloading( -1 )
self:SetWep2_Reloading( -1 )
end
-- BENNY shit
@ -96,73 +108,6 @@ function SWEP:B_FiremodeName( alt )
end
end
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()
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] then
ErrorNoHalt( "Mag isn't a valid item" )
self:D_SetMagID( hand, "" )
wep_table.Loaded = ""
elseif 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( 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
end
self:TPReload( hand )
end
return true
end
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_TempForAim", function( ply, button )
local wep = ply:BennyCheck()
if wep then
@ -200,15 +145,17 @@ function SWEP:BStartHolster( hand )
if self:D_GetHolstering( hand ) == -1 then
B_Sound( self, "Common.Holster" )
-- print( "Holstering the " .. (hand and "LEFT" or "RIGHT") )
self:D_SetHolstering( hand, 1 )
self:D_SetHolstering( hand, 0 )
self:D_SetReloading( hand, -1 )
self:D_SetReloadType( hand, 0 )
end
end
function SWEP:BThinkHolster( hand )
if self:D_GetHolstering( hand ) > 0 then
self:D_SetHolstering( hand, math.Approach( self:D_GetHolstering( hand ), 0, FrameTime() / 0.35 ) )
if self:D_GetHolstering( hand ) >= 0 then
self:D_SetHolstering( hand, math.Approach( self:D_GetHolstering( hand ), 1, FrameTime() / 0.35 ) )
end
if self:D_GetHolstering( hand ) == 0 then
if self:D_GetHolstering( hand ) == 1 then
self:D_SetHolstering( hand, -1 )
self:BHolster( hand )
local p = self:GetOwner()
@ -224,6 +171,11 @@ function SWEP:Think()
local p = self:GetOwner()
local inv = p:INV_Get()
local wep1 = self:BTable( false )
local wep1c = self:BClass( false )
local wep2 = self:BTable( true )
local wep2c = self:BClass( true )
if self:D_GetReqID( false ) != "" and self:D_GetReqID( true ) != "" and self:D_GetReqID( false ) == self:D_GetReqID( true ) then
self:D_SetReqID( false, "" )
self:D_SetReqID( true, "" )
@ -257,13 +209,26 @@ function SWEP:Think()
end
self:BThinkHolster( hand )
-- print( self:D_GetReqID( hand ), self:D_GetID( hand ) )
end
local wep1 = self:BTable( false )
local wep1c = self:BClass( false )
local wep2 = self:BTable( true )
local wep2c = self:BClass( true )
do -- Reload logic
if self:D_GetReloading( hand ) != -1 then
self:D_SetReloading( hand, math.Approach( self:D_GetReloading( hand ), 0, FrameTime() ) )
if self:D_GetReloading( hand ) == 0 then
local rlt = self:D_GetReloadType( hand )
if rlt == 1 then
if SERVER or (CLIENT and IsFirstTimePredicted() ) then
self:Reload_MagIn( hand, self:D_GetMagID( hand ), inv )
end
elseif rlt == 2 then
--self:Reload_MagOut( hand, self:D_GetMagID( hand ), inv )
end
self:D_SetReloading( hand, -1 )
self:D_SetReloadType( hand, 0 )
-- Do reload stuff.
end
end
end
end
self:SetAim( math.Approach( self:GetAim(), self:GetUserAim() and 1 or 0, FrameTime()/0.2 ) )

View File

@ -75,5 +75,6 @@ AddSound( "Common.Deploy", "benny/weapons/common/06-07.ogg", 70, 100, 0.2, CHAN_
AddSound( "Common.Holster", "benny/weapons/common/06-09.ogg", 70, 100, 0.2, CHAN_STATIC )
RegisterCaption("Common.Deploy", "DEBUG", color_white, "[deploy]", 0.1, 0.5, false, true )
RegisterCaption("Common.Holster", "DEBUG", color_white, "[holster]", 0.1, 0.5, false, true )
RegisterCaption("Common.ReloadFail", "DEBUG", color_white, "[fail]", 0.1, 0.5, false, true )
CAPTIONS = CAPTIONS["en-us"]

View File

@ -71,15 +71,15 @@ local mewer = {
end,
-- "How much damage the weapon can output over a long period of time.\nDoes not consider armor penetration.\nAffected by Damage, RPM, Capacity and Reload Time."
},
{
Name = "Range",
Size = 12,
Font = "Benny_10",
Stat = function( class )
return 0
end,
-- "How well the weapon gains or loses damage over long distances.\nAffected by Minimum Range, Maximum Range, and damage falloff."
},
--
-- Name = "Range",
-- Size = 12,
-- Font = "Benny_10",
-- Stat = function( class )
-- return 0
-- end,
-- -- "How well the weapon gains or loses damage over long distances.\nAffected by Minimum Range, Maximum Range, and damage falloff."
-- },
{
Name = "Precision",
Size = 12,
@ -98,24 +98,24 @@ local mewer = {
end,
-- "How managable the weapon's recoil and spread is under sustained fire.\nAffected by RPM and various Recoil stats."
},
{
Name = "Handling",
Size = 12,
Font = "Benny_10",
Stat = function( class )
return 0
end,
-- "How quickly this weapon readies from sprinting, aiming and deploying.\nAffected by Aim Down Sights Time, Sprint To Fire Time, and Deploy Time."
},
{
Name = "Maneuvering",
Size = 12,
Font = "Benny_10",
Stat = function( class )
return 0
end,
-- "How accurate the weapon is while not aiming.\nAffected by Hipfire Spread, Mid-air Spread, Sway, and Free Aim Angle."
},
-- {
-- Name = "Handling",
-- Size = 12,
-- Font = "Benny_10",
-- Stat = function( class )
-- return 0
-- end,
-- -- "How quickly this weapon readies from sprinting, aiming and deploying.\nAffected by Aim Down Sights Time, Sprint To Fire Time, and Deploy Time."
-- },
-- {
-- Name = "Maneuvering",
-- Size = 12,
-- Font = "Benny_10",
-- Stat = function( class )
-- return 0
-- end,
-- -- "How accurate the weapon is while not aiming.\nAffected by Hipfire Spread, Mid-air Spread, Sway, and Free Aim Angle."
-- },
{
Name = "Mobility",
Size = 12,

View File

@ -612,8 +612,8 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.DrawTexturedRectRotated( poosx + s(spacer_long) + gap, poosy, s(16), s(16), 0 )
surface.SetMaterial( mat2 )
surface.DrawTexturedRectRotated( poosx, poosy - gap - s(spacer), s(32), s(32), 0 )
surface.DrawTexturedRectRotated( poosx, poosy + gap + s(spacer), s(32), s(32), 0 )
surface.DrawTexturedRectRotated( poosx, poosy - gap - s(spacer), s(24), s(24), 0 )
surface.DrawTexturedRectRotated( poosx, poosy + gap + s(spacer), s(24), s(24), 0 )
elseif typ == "shotgun" or typ == "smg" or typ == "machinegun" then
local smg = typ == "smg"
local lmg = typ == "machinegun"
@ -630,12 +630,12 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end
elseif typ == "pistol" then -- pistol
surface.SetMaterial( mat2 )
surface.DrawTexturedRectRotated( poosx - gap - s(spacer), poosy, s(32), s(32), 0 )
surface.DrawTexturedRectRotated( poosx + gap + s(spacer), poosy, s(32), s(32), 0 )
surface.DrawTexturedRectRotated( poosx - gap - s(spacer), poosy, s(24), s(24), 0 )
surface.DrawTexturedRectRotated( poosx + gap + s(spacer), poosy, s(24), s(24), 0 )
surface.SetMaterial( mat2 )
surface.DrawTexturedRectRotated( poosx, poosy - gap - s(spacer), s(32), s(32), 0 )
surface.DrawTexturedRectRotated( poosx, poosy + gap + s(spacer), s(32), s(32), 0 )
surface.DrawTexturedRectRotated( poosx, poosy - gap - s(spacer), s(24), s(24), 0 )
surface.DrawTexturedRectRotated( poosx, poosy + gap + s(spacer), s(24), s(24), 0 )
elseif typ == "grenade" then -- grenade
surface.SetMaterial( mat2 )
surface.DrawTexturedRectRotated( poosx, poosy, s(32), s(32), 0 )
@ -895,11 +895,44 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end
end
if false and wep then
surface.SetDrawColor( color_white )
surface.DrawRect( sw/2 - ss(400)/2, sh/2 - ss(8)/2, ss(400*wep:GetWep1_Holstering()), ss(8) )
if true and wep then
for i=1, 2 do
local hand = i==2
local boost = ss(44)
if hand then boost = -boost end
surface.DrawOutlinedRect( sw/2 - ss(400+2)/2, sh/2 - ss(8+2)/2, ss(400+2), ss(8+2), ss(0.5) )
local wr = wep:D_GetReloading( hand )
if wr > 0 then
local translate = 1
if wep:D_GetReloadType( hand ) == 2 then
wr = math.TimeFraction( 0, wep.GEN_MagOut, wr )
else
wr = math.TimeFraction( 0, wep.GEN_MagIn, wr )
end
translate = wr/wep:D_GetReloading( hand )
wr = 1-wr
-- PROTO: Get interp values
local interpr = GetConVarNumber( "cl_interp_ratio" )/GetConVarNumber( "cl_cmdrate" )
local interp = GetConVarNumber( "cl_interp" )
print( interpr, interp )
wr = wr - math.max( interpr, interp )
local r_w, r_h = ss(8), ss(72)
local r_x, r_y = sw/2 - r_w/2 + boost, sh/2 - r_h/2
surface.SetDrawColor( schema("bg") )
surface.DrawRect( r_x, r_y, r_w, r_h )
surface.SetDrawColor( schema("fg") )
surface.DrawOutlinedRect( r_x + ss(1), r_y + ss(1), r_w - ss(2), r_h - ss(2), ss(0.5) )
surface.DrawRect( r_x + ss(2), r_y + ss(2) + (r_h-ss(4))-math.Round( (r_h-ss(4)) * wr ), r_w - ss(4), math.Round((r_h - ss(4)) * wr) )
surface.SetDrawColor( 255, 100, 100 )
surface.DrawRect( r_x + ss(2), r_y + ss(2) + (r_h+ss(4))*(translate*wep.GEN_MagIn_BonusStart), r_w - ss(4), ss(1) )
surface.DrawRect( r_x + ss(2), r_y + ss(2) + (r_h+ss(4))*(translate*wep.GEN_MagIn_BonusEnd), r_w - ss(4), ss(1) )
end
end
end
end )

View File

@ -76,21 +76,23 @@ if CLIENT then
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Dev", function( ply, button )
local wep = ply:BennyCheck()
if button == KEY_F1 then
OpenSettingsMenu()
elseif button == KEY_F2 then
OpenDebugInv()
elseif button == KEY_F3 then
OpenSMenu()
elseif button == KEY_F4 then
OpenDeadeye()
elseif button == KEY_F5 then
elseif button == KEY_F6 then
elseif button == KEY_F7 then
elseif button == KEY_F8 then
elseif button == KEY_F9 then
elseif button == KEY_F11 then
elseif button == KEY_F12 then
if IsFirstTimePredicted() then
if button == KEY_F1 then
OpenSettingsMenu()
elseif button == KEY_F2 then
OpenDebugInv()
elseif button == KEY_F3 then
OpenSMenu()
elseif button == KEY_F4 then
OpenDeadeye()
elseif button == KEY_F5 then
elseif button == KEY_F6 then
elseif button == KEY_F7 then
elseif button == KEY_F8 then
elseif button == KEY_F9 then
elseif button == KEY_F11 then
elseif button == KEY_F12 then
end
end
end)
end

View File

@ -22,6 +22,7 @@ local function beatup( ply, num )
local hand = ply:KeyDown(IN_ZOOM)
local invid = 0
if CLIENT and !IsFirstTimePredicted() then return end
for _, item in pairs( weighted ) do
local class = WeaponGet(item.Class)
local id = iflip[item]

View File

@ -149,6 +149,7 @@ do -- Sound definitions
AddSound( "Common.Dryfire.Pistol", "benny/weapons/common/06-13.ogg", 70, 100, 0.5, CHAN_STATIC )
AddSound( "Common.Dryfire.Rifle", "benny/weapons/common/06-12.ogg", 70, 100, 0.5, CHAN_STATIC )
AddSound( "Common.NoAmmo", "benny/weapons/noammo.ogg", 70, 100, 0.5, CHAN_STATIC )
AddSound( "Common.ReloadFail", "benny/hud/reloadfail.ogg", 70, 100, 0.5, CHAN_STATIC )
end