Holdtype and WM bullshit

This commit is contained in:
Fesiug 2023-10-22 00:39:24 -04:00
parent 6ff235bba8
commit 13330ccc2c
1 changed files with 167 additions and 3 deletions

View File

@ -29,6 +29,7 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Int", 1, "Wep2Clip" )
self:NetworkVar( "Int", 2, "Wep1Burst" )
self:NetworkVar( "Int", 3, "Wep2Burst" )
self:NetworkVar( "Bool", 0, "UserAim" )
end
function SWEP:PrimaryAttack()
@ -56,7 +57,7 @@ function SWEP:PrimaryAttack()
if CLIENT and IsFirstTimePredicted() then
local tr = self:GetOwner():GetEyeTrace()
do
local vStart = self:GetAttachment( 1 ).Pos
local vStart = self.CWM:GetAttachment( 1 ).Pos
local vPoint = tr.HitPos
local effectdata = EffectData()
effectdata:SetStart( vStart )
@ -159,10 +160,19 @@ function SWEP:Reload()
return true
end
CreateClientConVar( "benny_toggleaim", 0, true, true )
function SWEP:Think()
local p = self:GetOwner()
self:SetAim( math.Approach( self:GetAim(), p:KeyDown(IN_ATTACK2) and 1 or 0, FrameTime()/0.05 ) )
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
self:SetAim( math.Approach( self:GetAim(), self:GetUserAim() and 1 or 0, FrameTime()/0.2 ) )
if !p:KeyDown( IN_ATTACK ) then
self:SetWep1Burst( 0 )
@ -170,7 +180,9 @@ function SWEP:Think()
local ht = "normal"
if self:GetAim() > 0 then
ht = "revolver"
if self:BClass( false ) then
ht = self:BClass( false ).HoldType or "revolver"
end
end
self:SetWeaponHoldType(ht)
@ -185,4 +197,156 @@ end
function SWEP:Holster()
return true
end
if CLIENT then
function SWEP:DrawWorldModel()
local p = self:GetOwner()
local wm = self.CWM
local class = self:BClass( false )
if class then
if !IsValid(wm) then
wm = ClientsideModel( class.WModel )
self.CWM = wm
end
wm:SetModel( class.WModel )
wm:SetNoDraw( true )
wm:AddEffects( EF_BONEMERGE )
wm:SetParent( p )
-- if IsValid(p) then
-- -- Specify a good position
-- local offsetVec = Vector(12.8, -1.4, 2.6)
-- local offsetAng = Angle(180 - 10, 180, 0)
--
-- local boneid = p:LookupBone("ValveBiped.Bip01_R_Hand") -- Right Hand
-- if !boneid then return end
-- local matrix = p:GetBoneMatrix(boneid)
-- if !matrix then return end
-- local newPos, newAng = LocalToWorld(offsetVec, offsetAng, matrix:GetTranslation(), matrix:GetAngles())
-- wm:SetPos(newPos)
-- wm:SetAngles(newAng)
-- wm:SetupBones()
-- else
-- wm:SetPos(self:GetPos())
-- wm:SetAngles(self:GetAngles())
-- wm:SetupBones()
-- end
wm:DrawModel()
end
end
end
-- Holdtype thingys
do
local ActIndex = {
[ "pistol" ] = ACT_HL2MP_IDLE_PISTOL,
[ "smg" ] = ACT_HL2MP_IDLE_SMG1,
[ "grenade" ] = ACT_HL2MP_IDLE_GRENADE,
[ "ar2" ] = ACT_HL2MP_IDLE_AR2,
[ "shotgun" ] = ACT_HL2MP_IDLE_SHOTGUN,
[ "rpg" ] = ACT_HL2MP_IDLE_RPG,
[ "physgun" ] = ACT_HL2MP_IDLE_PHYSGUN,
[ "crossbow" ] = ACT_HL2MP_IDLE_CROSSBOW,
[ "melee" ] = ACT_HL2MP_IDLE_MELEE,
[ "slam" ] = ACT_HL2MP_IDLE_SLAM,
[ "normal" ] = ACT_HL2MP_IDLE,
[ "fist" ] = ACT_HL2MP_IDLE_FIST,
[ "melee2" ] = ACT_HL2MP_IDLE_MELEE2,
[ "passive" ] = ACT_HL2MP_IDLE_PASSIVE,
[ "knife" ] = ACT_HL2MP_IDLE_KNIFE,
[ "duel" ] = ACT_HL2MP_IDLE_DUEL,
[ "camera" ] = ACT_HL2MP_IDLE_CAMERA,
[ "magic" ] = ACT_HL2MP_IDLE_MAGIC,
[ "revolver" ] = ACT_HL2MP_IDLE_REVOLVER,
[ "suitcase" ] = ACT_HL2MP_IDLE,
[ "melee_angry" ] = ACT_HL2MP_IDLE_MELEE_ANGRY,
[ "angry" ] = ACT_HL2MP_IDLE_ANGRY,
[ "scared" ] = ACT_HL2MP_IDLE_SCARED,
[ "zombie" ] = ACT_HL2MP_IDLE_ZOMBIE,
[ "cower" ] = ACT_HL2MP_IDLE_COWER,
}
--[[---------------------------------------------------------
Name: SetWeaponHoldType
Desc: Sets up the translation table, to translate from normal
standing idle pose, to holding weapon pose.
-----------------------------------------------------------]]
function SWEP:SetWeaponHoldType( t )
t = string.lower( t )
local index = ActIndex[ t ]
if ( index == nil ) then
Msg( "SWEP:SetWeaponHoldType - ActIndex[ \"" .. t .. "\" ] isn't set! (defaulting to normal)\n" )
t = "normal"
index = ActIndex[ t ]
end
self.ActivityTranslate = {}
self.ActivityTranslate[ ACT_MP_STAND_IDLE ] = index
self.ActivityTranslate[ ACT_MP_WALK ] = index + 1
self.ActivityTranslate[ ACT_MP_RUN ] = index + 2
self.ActivityTranslate[ ACT_MP_CROUCH_IDLE ] = index + 3
self.ActivityTranslate[ ACT_MP_CROUCHWALK ] = index + 4
self.ActivityTranslate[ ACT_MP_ATTACK_STAND_PRIMARYFIRE ] = index + 5
self.ActivityTranslate[ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index + 5
self.ActivityTranslate[ ACT_MP_RELOAD_STAND ] = index + 6
self.ActivityTranslate[ ACT_MP_RELOAD_CROUCH ] = index + 6
self.ActivityTranslate[ ACT_MP_JUMP ] = index + 7
self.ActivityTranslate[ ACT_RANGE_ATTACK1 ] = index + 8
self.ActivityTranslate[ ACT_MP_SWIM ] = index + 9
-- "normal" jump animation doesn't exist
if ( t == "normal" ) then
self.ActivityTranslate[ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
end
if ( t == "suitcase" ) then
self.ActivityTranslate[ ACT_MP_STAND_IDLE ] = ACT_HL2MP_IDLE_SUITCASE
self.ActivityTranslate[ ACT_MP_WALK ] = ACT_HL2MP_WALK_SUITCASE
self.ActivityTranslate[ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
end
if ( t == "rpg" ) then
self.ActivityTranslate[ ACT_MP_CROUCH_IDLE ] = ACT_HL2MP_IDLE_CROUCH_AR2
self.ActivityTranslate[ ACT_MP_CROUCHWALK ] = ACT_HL2MP_WALK_CROUCH_AR2
end
--self:SetupWeaponHoldTypeForAI( t )
end
-- Default hold pos is the pistol
SWEP:SetWeaponHoldType( "pistol" )
--[[---------------------------------------------------------
Name: weapon:TranslateActivity()
Desc: Translate a player's Activity into a weapon's activity
So for example, ACT_HL2MP_RUN becomes ACT_HL2MP_RUN_PISTOL
Depending on how you want the player to be holding the weapon
-----------------------------------------------------------]]
function SWEP:TranslateActivity( act )
if ( self.Owner:IsNPC() ) then
if ( self.ActivityTranslateAI[ act ] ) then
return self.ActivityTranslateAI[ act ]
end
return -1
end
if ( self.ActivityTranslate[ act ] != nil ) then
return self.ActivityTranslate[ act ]
end
return -1
end
end