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

View File

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

View File

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