Improved holstering and baseclass code

This commit is contained in:
Fesiug 2024-09-21 14:08:48 -04:00
parent e87245c419
commit 7fd2fba51e
Signed by: Fesiug
GPG Key ID: 374BFF45E1EEF243
4 changed files with 86 additions and 67 deletions

View File

@ -1,26 +0,0 @@
SWEP.Base = "weapon_base"
function SWEP:PrimaryAttack()
return true
end
function SWEP:SecondaryAttack()
return true
end
function SWEP:Reload()
return true
end
function SWEP:Think()
return true
end
function SWEP:Deploy()
return true
end
function SWEP:Holster()
return true
end

View File

@ -70,7 +70,7 @@ end
function SWEP:SetActive( ent ) function SWEP:SetActive( ent )
local p = self:GetOwner() local p = self:GetOwner()
if ent:GetOwner() != p then return false end if ent:GetOwner() != p then return false end
if self:GetActiveR():IsValid() then self:Deactive() end --if self:GetActiveR():IsValid() then self:Deactive() end
self:SetActiveR( ent ) self:SetActiveR( ent )
if self:ItemR() then if self:ItemR() then
self:ItemR( "Deploy" ) self:ItemR( "Deploy" )
@ -80,12 +80,6 @@ function SWEP:SetActive( ent )
end end
function SWEP:Deactive() function SWEP:Deactive()
local p = self:GetOwner()
if self:ItemR() then
self:ItemR( "Holster" )
self:ItemR():SetNoDraw( true )
end
self:SetActiveR( NULL )
end end
function SWEP:PrimaryAttack() function SWEP:PrimaryAttack()
@ -169,8 +163,7 @@ function SWEP:DropItem()
local ent = self:GetActiveR() local ent = self:GetActiveR()
if ent:IsValid() then if ent:IsValid() then
if CLIENT then print("DropItem called on CLIENT but certain things aren't finished yet.") return end if CLIENT then print("DropItem called on CLIENT but certain things aren't finished yet.") return end
self:Deactive()
self:SetDesireR( NULL ) self:SetDesireR( NULL )
ent:SetParent( NULL ) ent:SetParent( NULL )
@ -206,40 +199,44 @@ function SWEP:Think()
local p = self:GetOwner() local p = self:GetOwner()
if p:IsValid() then if p:IsValid() then
local DesireR = self:GetDesireR() local DesireR = self:GetDesireR()
local ActiveR = self:GetActiveR() local ActiveR = self:GetActiveR()
local DesireR_Valid = DesireR:IsValid() local DesireR_Valid = DesireR:IsValid()
local ActiveR_Valid = ActiveR:IsValid() local ActiveR_Valid = ActiveR:IsValid()
-- If we're holding the weapon we want... if DesireR != ActiveR then
if ActiveR == DesireR then print(DesireR, ActiveR)
-- Do nothing
-- If we want no weapon equipped
elseif !DesireR_Valid then
if ActiveR_Valid then if ActiveR_Valid then
self:Deactive() if ActiveR:GetHolsterIn() == 0 then
--self:Deactive()
print("hi?")
ActiveR.Class.Holster( ActiveR.Class, ActiveR, self )
else
-- wait
end
else else
-- We're holding nothing. Do nothing. if DesireR_Valid then
self:SetActive( DesireR )
end
end end
else
-- If we want a weapon equipped if ActiveR_Valid and ActiveR:GetHolsterIn() != 0 then
elseif DesireR_Valid then ActiveR.Class.UndoHolster( ActiveR.Class, ActiveR, self )
if ActiveR != DesireR then
self:Deactive()
end end
self:SetActive( DesireR )
end end
if p:KeyPressed(IN_WEAPON1) then if p:KeyPressed(IN_WEAPON1) then
if SERVER then if !self:ItemR() then
if !self:ItemR() then if SERVER then
local trace = self:ItemCheckTrace() local trace = self:ItemCheckTrace()
self:EquipItem( trace.Entity ) self:EquipItem( trace.Entity )
else end
else
ActiveR.Class.Drop( ActiveR.Class, ActiveR, self )
if SERVER then
self:DropItem() self:DropItem()
end end
self:SetActiveR( NULL )
end end
end end
if p:KeyPressed(IN_WEAPON2) then if p:KeyPressed(IN_WEAPON2) then
@ -247,7 +244,6 @@ function SWEP:Think()
if p:KeyPressed(IN_ALT1) then if p:KeyPressed(IN_ALT1) then
end end
if p:KeyPressed(IN_ALT2) then if p:KeyPressed(IN_ALT2) then
end end
if p:KeyPressed(IN_GRENADE1) then if p:KeyPressed(IN_GRENADE1) then
if self:ItemR() and self:ItemR().Class.Alt then if self:ItemR() and self:ItemR().Class.Alt then
@ -260,7 +256,6 @@ function SWEP:Think()
if self:ItemR() then if self:ItemR() then
self:ItemR("Think") self:ItemR("Think")
end end
--self:SetHoldType( self:ItemR() and (self:ItemR().Class.HoldType or "rpg") or "normal" )
else else
print( self, "Thinking without an owner." ) print( self, "Thinking without an owner." )
end end

View File

@ -199,7 +199,7 @@ end)
for i=0, 9 do for i=0, 9 do
local tent = {} local tent = {}
tent.Base = "goat" --tent.Base = "goat"
tent.Goat = i tent.Goat = i
weapons.Register( tent, "goat_" .. i ) weapons.Register( tent, "goat_" .. i )

View File

@ -38,6 +38,10 @@ function AddItem( itemname, item )
end end
end end
function BaseClassGet( item )
-- TODO
end
AddItem( "base", { AddItem( "base", {
PrintName = "Base Item", PrintName = "Base Item",
Description = "Beginning item base.", Description = "Beginning item base.",
@ -56,9 +60,23 @@ AddItem( "base", {
end, end,
["Deploy"] = function( class, ent, handler ) ["Deploy"] = function( class, ent, handler )
ent:SetNoDraw( false )
end,
["Drop"] = function( class, ent, handler )
end, end,
["Holster"] = function( class, ent, handler ) ["Holster"] = function( class, ent, handler )
ent:SetHolsterIn( CurTime() + 0.5 )
end,
["FinishHolster"] = function( class, ent, handler )
handler:SetActiveR( NULL )
ent:SetNoDraw( true )
end,
["UndoHolster"] = function( class, ent, handler )
ent:SetHolsterIn( 0 )
end, end,
["Attack"] = function( class, ent, handler ) ["Attack"] = function( class, ent, handler )
@ -67,7 +85,14 @@ AddItem( "base", {
["AttackAlt"] = function( class, ent, handler ) ["AttackAlt"] = function( class, ent, handler )
end, end,
["Alt"] = function( class, ent, handler )
end,
["Think"] = function( class, ent, handler ) ["Think"] = function( class, ent, handler )
if ent:GetHolsterIn() != 0 and ent:GetHolsterIn() <= CurTime() then
class:FinishHolster( ent, handler )
ent:SetHolsterIn( 0 )
end
end, end,
["Reload"] = function( class, ent, handler ) ["Reload"] = function( class, ent, handler )
@ -101,6 +126,7 @@ local AnimationLookup = {
}, },
} }
local BaseClass = ITEMS.base
AddItem( "base_firearm", { AddItem( "base_firearm", {
PrintName = "Base Firearm", PrintName = "Base Firearm",
Description = "Item base for firearms.", Description = "Item base for firearms.",
@ -145,7 +171,7 @@ AddItem( "base_firearm", {
BoltPullSound = "benny/weapons/fnc/cock.ogg", BoltPullSound = "benny/weapons/fnc/cock.ogg",
["Initialize"] = function( class, ent, handler ) ["Initialize"] = function( class, ent, handler )
ITEMS["base"].Initialize( class, ent, handler ) BaseClass.Initialize( class, ent, handler )
ent:SetClip( class.ClipSize ) ent:SetClip( class.ClipSize )
ent:SetLoaded(true) ent:SetLoaded(true)
@ -160,7 +186,7 @@ AddItem( "base_firearm", {
local BAuto = class.BurstAuto local BAuto = class.BurstAuto
local Firedown = handler:GetOwner():KeyDown( IN_ATTACK ) local Firedown = handler:GetOwner():KeyDown( IN_ATTACK )
if Runaway and InProcess and !Topped then if Runaway and InProcess and !Topped then
class["Attack"]( class, ent, handler ) class:Attack( ent, handler )
else else
if !Firedown then if !Firedown then
if !Topped and InProcess then if !Topped and InProcess then
@ -177,6 +203,7 @@ AddItem( "base_firearm", {
ent:SetClip( class.ClipSize ) ent:SetClip( class.ClipSize )
ent:SetRefillTime( 0 ) ent:SetRefillTime( 0 )
end end
BaseClass.Think( class, ent, handler )
end, end,
["Attack"] = function( class, ent, handler ) ["Attack"] = function( class, ent, handler )
@ -184,6 +211,7 @@ AddItem( "base_firearm", {
if ent:GetDelay() > CurTime() then return end if ent:GetDelay() > CurTime() then return end
if ent:GetDelayBurst() > CurTime() then return end if ent:GetDelayBurst() > CurTime() then return end
if ent:GetBurstCount() >= class.BurstCount then return end if ent:GetBurstCount() >= class.BurstCount then return end
if ent:GetHolsterIn() != 0 then return end
local Runaway = class.BurstRunaway local Runaway = class.BurstRunaway
local BAuto = class.BurstAuto local BAuto = class.BurstAuto
@ -210,6 +238,7 @@ AddItem( "base_firearm", {
Attacker = p, Attacker = p,
Damage = 1, Damage = 1,
Force = 1, Force = 1,
Tracer = 0,
Num = class.Pellets, Num = class.Pellets,
Dir = p:GetAimVector(), Dir = p:GetAimVector(),
Src = p:GetShootPos(), Src = p:GetShootPos(),
@ -226,11 +255,8 @@ AddItem( "base_firearm", {
end, end,
["Reload"] = function( class, ent, handler ) ["Reload"] = function( class, ent, handler )
--if ent:GetClip() >= class.ClipSize then return end
--handler:EmitSound( "weapons/m4a1/m4a1_boltpull.wav", 70, 125, 0.4, CHAN_STATIC )
--ent:SetRefillTime( CurTime() + 0.1 )
--handler:EmitSound( "benny/weapons/basic.ogg", 70, 100, 0.4, CHAN_STATIC )
if ent:GetDelay() > CurTime() then return end if ent:GetDelay() > CurTime() then return end
if ent:GetHolsterIn() != 0 then return end
local ply = handler:GetOwner() local ply = handler:GetOwner()
local time = 0.6 local time = 0.6
@ -266,20 +292,41 @@ AddItem( "base_firearm", {
ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["deploy"][class.HoldType] ), 0, true ) ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["deploy"][class.HoldType] ), 0, true )
end end
end, end,
["Drop"] = function( class, ent, handler )
ent:SetRefillTime( 0 )
BaseClass.Drop( class, ent, handler )
end,
["Holster"] = function( class, ent, handler ) ["Holster"] = function( class, ent, handler )
ent:SetRefillTime( 0 ) ent:SetRefillTime( 0 )
handler:EmitSound( "weapons/m4a1/m4a1_deploy.wav", 70, 125, 0.4, CHAN_STATIC ) handler:EmitSound( "weapons/elite/elite_deploy.wav", 70, 125, 0.4, CHAN_STATIC )
ent:SetDelay( CurTime() + 0.25 ) ent:SetDelay( CurTime() + 0.25 )
ent:SetHolsterIn( CurTime() + 0.25 )
local ply = handler:GetOwner() local ply = handler:GetOwner()
if SERVER or CLIENT and IsFirstTimePredicted() then if SERVER or CLIENT and IsFirstTimePredicted() then
ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["holster"][class.HoldType] ), 0, true ) ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["holster"][class.HoldType] ), 0, true )
end end
end, end,
["FinishHolster"] = function( class, ent, handler )
handler:EmitSound( "weapons/m4a1/m4a1_deploy.wav", 70, 125, 0.4, CHAN_STATIC )
BaseClass.FinishHolster( class, ent, handler )
end,
["UndoHolster"] = function( class, ent, handler )
BaseClass.UndoHolster( class, ent, handler )
handler:EmitSound( "weapons/elite/elite_deploy.wav", 70, 125, 0.4, CHAN_STATIC )
local ply = handler:GetOwner()
if SERVER or CLIENT and IsFirstTimePredicted() then
ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["deploy"][class.HoldType] ), 0, true )
end
end,
}) })
local BaseClass = ITEMS.base_firearm
AddItem( "base_firearm_ubgl", { AddItem( "base_firearm_ubgl", {
PrintName = "Base Firearm w/ UBGL", PrintName = "Base Firearm w/ UBGL",
Description = "Item base for firearms that include grenade launchers.", Description = "Item base for firearms that include grenade launchers.",
@ -303,7 +350,7 @@ AddItem( "base_firearm_ubgl", {
ClipSize2 = 4, ClipSize2 = 4,
["Initialize"] = function( class, ent, handler ) ["Initialize"] = function( class, ent, handler )
ITEMS["base_firearm"].Initialize( class, ent, handler ) BaseClass.Initialize( class, ent, handler )
ent:SetClip2( class.ClipSize2 ) ent:SetClip2( class.ClipSize2 )
end, end,
@ -312,7 +359,7 @@ AddItem( "base_firearm_ubgl", {
if ent:GetFiremode() == 1 then if ent:GetFiremode() == 1 then
class:Attack2( ent, handler ) class:Attack2( ent, handler )
else else
ITEMS["base_firearm"].Attack( class, ent, handler ) BaseClass.Attack( class, ent, handler )
end end
end, end,
@ -320,7 +367,7 @@ AddItem( "base_firearm_ubgl", {
if ent:GetFiremode() == 1 then if ent:GetFiremode() == 1 then
class:Reload2( ent, handler ) class:Reload2( ent, handler )
else else
ITEMS["base_firearm"].Reload( class, ent, handler ) BaseClass.Reload( class, ent, handler )
end end
end, end,
@ -329,7 +376,7 @@ AddItem( "base_firearm_ubgl", {
end, end,
["Think"] = function( class, ent, handler ) ["Think"] = function( class, ent, handler )
ITEMS["base_firearm"].Think( class, ent, handler ) BaseClass.Think( class, ent, handler )
if ent:GetRefillTime2() != 0 and ent:GetRefillTime2() <= CurTime() then if ent:GetRefillTime2() != 0 and ent:GetRefillTime2() <= CurTime() then
ent:SetClip2( class.ClipSize2 ) ent:SetClip2( class.ClipSize2 )
@ -357,6 +404,7 @@ AddItem( "base_firearm_ubgl", {
end, end,
}) })
local BaseClass = ITEMS.base
AddItem( "satchels", { AddItem( "satchels", {
PrintName = "#Item.satchels.Name", PrintName = "#Item.satchels.Name",
Description = "#Item.satchels.Description", Description = "#Item.satchels.Description",
@ -404,6 +452,7 @@ AddItem( "satchels", {
end, end,
}) })
local BaseClass = ITEMS.base
AddItem( "toolgun", { AddItem( "toolgun", {
PrintName = "#Item.toolgun.Name", PrintName = "#Item.toolgun.Name",
Description = "#Item.toolgun.Description", Description = "#Item.toolgun.Description",
@ -480,6 +529,7 @@ AddItem( "toolgun", {
end, end,
}) })
local BaseClass = ITEMS.base_firearm
do -- Handguns do -- Handguns
AddItem( "mk23", { AddItem( "mk23", {