Advertisement
Guest User

Untitled

a guest
Dec 17th, 2016
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 101.11 KB | None | 0 0
  1. ACT_VM_FIDGET_EMPTY = ACT_VM_FIDGET_EMPTY or ACT_CROSSBOW_FIDGET_UNLOADED
  2. --[[BaseClass]]--
  3. --[[Define Modules]]--
  4. SWEP.SV_MODULES = {}
  5. SWEP.SH_MODULES = {"sh_bobcode.lua", "sh_anims.lua", "sh_bullet.lua", "sh_autodetection.lua", "sh_utilities.lua", "sh_effects.lua", "sh_attachments.lua", "sh_akimbo.lua"}
  6. SWEP.ClSIDE_MODULES = {"cl_viewbob.lua", "cl_effects.lua", "cl_hud.lua", "cl_mods.lua"}
  7. SWEP.CSMuzzleFlashes = false
  8. SWEP.CSMuzzleX = false
  9. SWEP.Category = "" --The category.  Please, just choose something generic or something I've already done if you plan on only doing like one swep.
  10. SWEP.Gun = "tfa_gun_base" --Make sure this is unique.
  11. SWEP.Manufacturer = nil --Gun Manufactrer (e.g. Hoeckler and Koch )
  12. SWEP.Author = "TheForgottenArchitect" --DO NOT CHANGE, CUZ ITS ME.
  13. SWEP.Contact = "theforgottenarchitect" --Contact me on steam.  Leave a comment first.
  14. SWEP.Purpose = "" --Why do you want this?   Not really necesary.
  15. SWEP.Instructions = "" --Instructions on how to use, lol.  Not really necessary.
  16. SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
  17. --SWEP.MuzzleAttachmentRaw = 1 --This will override whatever string you gave.  This is the raw attachment number.  This is overridden or created when a gun makes a muzzle event.
  18. SWEP.ShellAttachment = "2" -- Should be "2" for CSS models or "shell" for hl2 models
  19. SWEP.DrawCrosshair = true -- Draw the crosshair?
  20. SWEP.DrawCrosshairIS = false --Draw crosshair in ironsights
  21. SWEP.ViewModelFOV = 65 -- This controls how big the viewmodel looks.  Less is more.
  22. SWEP.CameraOffset = Angle(0, 0, 0)
  23. SWEP.ViewModelFlip = false -- Set this to true for CSS models, or false for everything else (with a righthanded viewmodel.)  Note that this breaks c_arms if you set it to true.
  24. SWEP.UseHands = false --Use c_hands a.k.a playermodel hands?  Disable for CS:S or HL2 direct ports, or anything containing v_arms.
  25. SWEP.VMPos = Vector(0, 0, 0) --The viewmodel positional offset, constantly.
  26. SWEP.VMAng = Vector(0, 0, 0) --The viewmodel angular offset, constantly.
  27. SWEP.AllowViewAttachment = true --Allow the view to sway based on weapon attachment while reloading or drawing, IF THE CLIENT HAS IT ENABLED IN THEIR CONVARS!!!!11111oneoneELEVEN
  28. SWEP.InspectPosDef = Vector(9.779, -11.658, -2.241)
  29. SWEP.InspectAngDef = Vector(24.622, 42.915, 15.477)
  30. --SWEP.InspectPos = Vector(0,0,0) --replace with a vector, in style of ironsights position, to be used for inspection
  31. --SWEP.InspectAng= Vector(0,0,0) --replace with a vector, in style of ironsights angle, to be used for inspection
  32. SWEP.FidgetLoop = true --Setting false will cancel inspection once the animation is done.  CS:GO style.
  33. SWEP.Spawnable = false --Can you, as a normal user, spawn this?
  34. SWEP.AdminSpawnable = false --Can an adminstrator spawn this?  Does not tie into your admin mod necessarily, unless its coded to allow for GMod's default ranks somewhere in its code.  Evolve and ULX should work, but try to use weapon restriction rather than these.
  35. SWEP.HoldType = "smg" -- This is how others view you carrying the weapon.
  36. SWEP.Primary.Sound = Sound("") -- This is the sound of the gun/bow, when you shoot.
  37. SWEP.Primary.Round = "" -- What kind of bullet does it shoot?
  38. SWEP.Primary.Cone = 0.2 -- This is the accuracy of NPCs.  Not necessary in almost all cases, since I don't even think this base is compatible with NPCs.
  39. SWEP.Primary.Recoil = 1 -- This is the recoil multiplier.  Really, you should keep this at 1 and change the KickUp, KickDown, and KickHorizontal variables.  However, you can change this as a multiplier too.
  40. SWEP.Primary.Damage = 0.01 -- Damage, in standard damage points.
  41. SWEP.Primary.DamageType = nil --See DMG enum.  This might be DMG_SHOCK, DMG_BURN, etc.
  42. SWEP.Primary.Spread = .01 --This is hip-fire acuracy.  Less is more (1 is horribly awful, .0001 is close to perfect)
  43. SWEP.FiresUnderwater = false
  44. --Attachments
  45. SWEP.Attachments = {}
  46. SWEP.Primary.SpreadMultiplierMax = nil --How far the spread can expand when you shoot.
  47. SWEP.Primary.SpreadIncrement = nil --What percentage of the modifier is added on, per shot.
  48. SWEP.Primary.SpreadRecovery = nil --How much the spread recovers, per second.
  49. SWEP.Primary.PenetrationMultiplier = 1
  50. SWEP.Primary.NumShots = 1 --The number of shots the gun/bow fires.
  51. SWEP.Primary.RPM = 600 -- This is in Rounds Per Minute / RPM
  52. SWEP.Primary.RPM_Semi = nil -- RPM for semi-automatic or burst fire.  This is in Rounds Per Minute / RPM
  53. SWEP.Primary.ClipSize = 0 -- This is the size of a clip
  54. SWEP.Primary.DefaultClip = 0 -- This is the number of bullets the gun gives you, counting a clip as defined directly above.
  55. SWEP.Primary.AmmoConsumption = 1 --Ammo consumed per shot
  56. SWEP.DisableChambering = nil --Disable round-in-the-chamber
  57. SWEP.Primary.KickUp = 0 -- This is the maximum upwards recoil (rise)
  58. SWEP.Primary.KickDown = 0 -- This is the maximum downwards recoil (skeet)
  59. SWEP.Primary.KickHorizontal = 0 -- This is the maximum sideways recoil (no real term)
  60. SWEP.Primary.StaticRecoilFactor = 0.5 --Amount of recoil to directly apply to EyeAngles.  Enter what fraction or percentage (in decimal form) you want.  This is also affected by a convar that defaults to 0.5.
  61. SWEP.Primary.Automatic = true -- Automatic/Semi Auto
  62. SWEP.Primary.Ammo = "none" -- What kind of ammo
  63. SWEP.Primary.Range = -1 -- The distance the bullet can travel in source units.  Set to -1 to autodetect based on damage/rpm.
  64. SWEP.Primary.RangeFalloff = -1 -- The percentage of the range the bullet damage starts to fall off at.  Set to 0.8, for example, to start falling off after 80% of the range.
  65. SWEP.Secondary.ClipSize = 0 -- Size of a clip
  66. SWEP.Secondary.DefaultClip = 0 -- Default number of bullets in a clip
  67. SWEP.Secondary.Automatic = false -- Automatic/Semi Auto
  68. SWEP.Secondary.Ammo = "none"
  69. SWEP.Secondary.IronFOV = 0 -- How much you 'zoom' in. Less is more!  Don't have this be <= 0
  70. SWEP.Secondary.AmmoConsumption = 1 --Ammo consumed per shot
  71. SWEP.SprintFOVOffset = 3.75 --Add this onto the FOV when we're sprinting.
  72. --Shell Eject
  73. SWEP.LuaShellEject = false
  74. SWEP.LuaShellEjectDelay = 0
  75. SWEP.LuaShellEffect = nil --Defaults to blowback
  76. --Scoped vars.
  77. SWEP.BoltAction = false --Unscope/sight after you shoot?
  78. SWEP.Scoped = false --Draw a scope overlay?
  79. SWEP.ScopeOverlayThreshold = 0.875 --Percentage you have to be sighted in to see the scope.
  80. SWEP.BoltTimerOffset = 0.25 --How long you stay sighted in after shooting, with a bolt action.
  81. --Revolver vars
  82. SWEP.Revolver = false
  83. --Shotgun Vars
  84. SWEP.Shotgun = false
  85. SWEP.KF2StyleShotgun = true --Allow empty reloads for shotguns?
  86. SWEP.ShellTime = .35 -- For shotguns.  How long it takes to insert a shell.
  87. --Penetration Code
  88. SWEP.MaxPenetrationCounter = 4 --The maximum number of ricochets.  To prevent stack overflows.
  89. -- Selective Fire Stuff
  90. SWEP.SelectiveFire = false --Allow selecting your firemode?
  91. SWEP.DisableBurstFire = false --Only bursting?
  92. SWEP.OnlyBurstFire = false --No auto, only burst?
  93. SWEP.DefaultFireMode = "" --Default to auto or whatev
  94. --Sighting Code
  95. SWEP.IronSightsAng = Vector(0, 0, 0)
  96. SWEP.IronSightsPos = Vector(0, 0, 0)
  97. SWEP.RunSightsAng = Vector(0, 0, 0)
  98. SWEP.RunSightsPos = Vector(0, 0, 0)
  99. SWEP.ProceduralHolsterPos = Vector(3, 0, -5)
  100. SWEP.ProceduralHolsterAng = Vector(-40, -30, 10)
  101. SWEP.IronSightsSensitivity = 1
  102. SWEP.CLNearWallProgress = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  103. SWEP.CLRunSightsProgress = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  104. SWEP.CLIronSightsProgress = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  105. SWEP.CLCrouchProgress = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  106. SWEP.CLJumpProgress = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  107. SWEP.ProceduralHolsterFactor = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  108. SWEP.CLInspectingProgress = 0
  109. SWEP.CLSpreadRatio = 1 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  110. SWEP.ShouldDrawAmmoHUD = false --THIS IS PROCEDURALLY CHANGED AND SHOULD NOT BE TWEAKED.  BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  111. SWEP.IronRecoilMultiplier = 0.5 --Multiply recoil by this factor when we're in ironsights.  This is proportional, not inversely.
  112. SWEP.CrouchRecoilMultiplier = 0.65 --Multiply recoil by this factor when we're crouching.  This is proportional, not inversely.
  113. SWEP.JumpRecoilMultiplier = 1.3 --Multiply recoil by this factor when we're crouching.  This is proportional, not inversely.
  114. SWEP.WallRecoilMultiplier = 1.1 --Multiply recoil by this factor when we're changing state e.g. not completely ironsighted.  This is proportional, not inversely.
  115. SWEP.ChangeStateRecoilMultiplier = 1.3 --Multiply recoil by this factor when we're crouching.  This is proportional, not inversely.
  116. SWEP.CrouchAccuracyMultiplier = 0.5 --Less is more.  Accuracy * 0.5 = Twice as accurate, Accuracy * 0.1 = Ten times as accurate
  117. SWEP.ChangeStateAccuracyMultiplier = 1.5 --Less is more.  A change of state is when we're in the progress of doing something, like crouching or ironsighting.  Accuracy * 2 = Half as accurate.  Accuracy * 5 = 1/5 as accurate
  118. SWEP.JumpAccuracyMultiplier = 2 --Less is more.  Accuracy * 2 = Half as accurate.  Accuracy * 5 = 1/5 as accurate
  119. SWEP.WalkAccuracyMultiplier = 1.35 --Less is more.  Accuracy * 2 = Half as accurate.  Accuracy * 5 = 1/5 as accurate
  120. SWEP.IronSightTime = 0.3 --The time to enter ironsights/exit it.
  121. SWEP.RunSightTime = nil --Time to enter sprint/exit it
  122. SWEP.NearWallTime = 0.3 --The time to pull up  your weapon or put it back down
  123. SWEP.NearWallAnimationTime = 0.4 --The time to pull up  your weapon or put it back down
  124. SWEP.ToCrouchTime = 0.05 --The time it takes to enter crouching state
  125. SWEP.WeaponLength = 40 --Almost 3 feet Feet.  This should be how far the weapon sticks out from the player.  This is used for calculating the nearwall trace.
  126. SWEP.DefaultFOV = 1 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  127. SWEP.MoveSpeed = 1 --Multiply the player's movespeed by this.
  128. SWEP.IronSightsMoveSpeed = 0.8 --Multiply the player's movespeed by this when sighting.
  129. --VAnimation Support
  130. SWEP.DoProceduralHolster = true
  131. SWEP.DoProceduralReload = false --Do we reload using lua instead of a .mdl animation
  132. SWEP.ProceduralReloadTime = 1 --Time to take when procedurally reloading, including transition in (but not out)
  133. SWEP.ShootWhileDraw = false --Can you shoot while draw anim plays?
  134. SWEP.AllowReloadWhileDraw = false --Can you reload while draw anim plays?
  135. SWEP.SightWhileDraw = false --Can we sight in while the weapon is drawing / the draw anim plays?
  136. SWEP.AllowReloadWhileHolster = true --Can we interrupt holstering for reloading?
  137. SWEP.ShootWhileHolster = true --Cam we interrupt holstering for shooting?
  138. SWEP.SightWhileHolster = false --Cancel out "iron"sights when we holster?
  139. SWEP.UnSightOnReload = true --Cancel out ironsights for reloading.
  140. SWEP.AllowReloadWhileSprinting = false --Can you reload when close to a wall and facing it?
  141. SWEP.AllowReloadWhileNearWall = false --Can you reload when close to a wall and facing it?
  142. SWEP.SprintBobMult = 1.5 -- More is more bobbing, proportionally.  This is multiplication, not addition.  You want to make this > 1 probably for sprinting.
  143. SWEP.IronBobMult = 0.0 -- More is more bobbing, proportionally.  This is multiplication, not addition.  You want to make this < 1 for sighting, 0 to outright disable.
  144. SWEP.IronBobMultWalk = 0.2 -- More is more bobbing, proportionally.  This is multiplication, not addition.  You want to make this < 1 for sighting, 0 to outright disable.
  145. SWEP.ProceduralHolsterTime = 0.4 --Time to procedurally holster if no animation.  Set to 0 to disable.
  146. --Advanced Projectile Support
  147. SWEP.ProjectileEntity = nil --Entity to shoot
  148. SWEP.ProjectileVelocity = 0 --Entity to shoot's velocity
  149. SWEP.ProjectileModel = nil --Entity to shoot's model
  150.  
  151. --These holdtypes are used in ironsights.  Syntax:  DefaultHoldType=NewHoldType
  152. SWEP.IronSightHoldTypes = {
  153.     pistol = "revolver",
  154.     smg = "rpg",
  155.     grenade = "melee",
  156.     ar2 = "rpg",
  157.     shotgun = "ar2",
  158.     rpg = "rpg",
  159.     physgun = "physgun",
  160.     crossbow = "ar2",
  161.     melee = "melee2",
  162.     slam = "camera",
  163.     normal = "fist",
  164.     melee2 = "magic",
  165.     knife = "fist",
  166.     duel = "duel",
  167.     camera = "camera",
  168.     magic = "magic",
  169.     revolver = "revolver"
  170. }
  171.  
  172. --These holdtypes are used while sprinting.  Syntax:  DefaultHoldType=NewHoldType
  173. SWEP.SprintHoldTypes = {
  174.     pistol = "normal",
  175.     smg = "passive",
  176.     grenade = "normal",
  177.     ar2 = "passive",
  178.     shotgun = "passive",
  179.     rpg = "passive",
  180.     physgun = "normal",
  181.     crossbow = "passive",
  182.     melee = "normal",
  183.     slam = "normal",
  184.     normal = "normal",
  185.     melee2 = "melee",
  186.     knife = "fist",
  187.     duel = "normal",
  188.     camera = "slam",
  189.     magic = "normal",
  190.     revolver = "normal"
  191. }
  192.  
  193. --These holdtypes are used in reloading.  Syntax:  DefaultHoldType=NewHoldType
  194. SWEP.ReloadHoldTypes = {
  195.     pistol = "pistol",
  196.     smg = "smg",
  197.     grenade = "melee",
  198.     ar2 = "ar2",
  199.     shotgun = "shotgun",
  200.     rpg = "ar2",
  201.     physgun = "physgun",
  202.     crossbow = "crossbow",
  203.     melee = "pistol",
  204.     slam = "smg",
  205.     normal = "pistol",
  206.     melee2 = "pistol",
  207.     knife = "pistol",
  208.     duel = "duel",
  209.     camera = "pistol",
  210.     magic = "pistol",
  211.     revolver = "revolver"
  212. }
  213.  
  214. --These holdtypes are used in reloading.  Syntax:  DefaultHoldType=NewHoldType
  215. SWEP.CrouchHoldTypes = {
  216.     ar2 = "ar2",
  217.     smg = "smg",
  218.     rpg = "ar2"
  219. }
  220.  
  221. SWEP.IronSightHoldTypeOverride = "" --This variable overrides the ironsights holdtype, choosing it instead of something from the above tables.  Change it to "" to disable.
  222. SWEP.SprintHoldTypeOverride = "" --This variable overrides the sprint holdtype, choosing it instead of something from the above tables.  Change it to "" to disable.
  223. SWEP.ReloadHoldTypeOverride = "" --This variable overrides the reload holdtype, choosing it instead of something from the above tables.  Change it to "" to disable.
  224. --Override allowed VAnimations.  Necessary for lazy modelers/animators.
  225. SWEP.ForceDryFireOff = true
  226. SWEP.DisableIdleAnimations = true
  227. SWEP.ForceEmptyFireOff = true
  228. --Allowed VAnimations.  These are autodetected, so not really needed except as an extra precaution.  Don't change these until you get to the next category.
  229. SWEP.CanDrawAnimate = true
  230. SWEP.CanDrawAnimateEmpty = false
  231. SWEP.CanDrawAnimateSilenced = false
  232. SWEP.CanHolsterAnimate = true
  233. SWEP.CanHolsterAnimateEmpty = false
  234. SWEP.CanIdleAnimate = true
  235. SWEP.CanIdleAnimateEmpty = false
  236. SWEP.CanIdleAnimateSilenced = false
  237. SWEP.CanShootAnimate = true
  238. SWEP.CanShootAnimateSilenced = false
  239. SWEP.CanReloadAnimate = true
  240. SWEP.CanReloadAnimateEmpty = false
  241. SWEP.CanReloadAnimateSilenced = false
  242. SWEP.CanDryFireAnimate = false
  243. SWEP.CanDryFireAnimateSilenced = false
  244. SWEP.CanSilencerAttachAnimate = false
  245. SWEP.CanSilencerDetachAnimate = false
  246. SWEP.actlist = {ACT_VM_DRAW, ACT_VM_DRAW_EMPTY, ACT_VM_DRAW_SILENCED, ACT_VM_IDLE, ACT_VM_IDLE_EMPTY, ACT_VM_IDLE_SILENCED, ACT_VM_PRIMARYATTACK, ACT_VM_PRIMARYATTACK_1, ACT_VM_PRIMARYATTACK_EMPTY, ACT_VM_PRIMARYATTACK_SILENCED, ACT_VM_SECONDARYATTACK, ACT_VM_RELOAD, ACT_VM_RELOAD_EMPTY, ACT_VM_RELOAD_SILENCED, ACT_VM_HOLSTER, ACT_VM_HOLSTER_EMPTY, ACT_VM_ATTACH_SILENCER, ACT_VM_DETACH_SILENCER, ACT_VM_FIDGET, ACT_VM_FIDGET_EMPTY, ACT_SHOTGUN_RELOAD_START, ACT_VM_RELEASE}
  247. --If you really want, you can remove things from SWEP.actlist and manually enable animations and set their lengths.
  248. SWEP.SequenceEnabled = {}
  249. SWEP.SequenceLength = {}
  250. SWEP.SequenceLengthOverride = {} --Override this if you want to change the length of a sequence but not the next idle
  251. --WAnim Support
  252. SWEP.ThirdPersonReloadDisable = false --Disable third person reload?  True disables.
  253.  
  254. --FX Stuff
  255. --These are particle effects, not PCF files, that are played when you shoot.
  256. SWEP.SmokeParticles = {
  257.     pistol = "smoke_trail_controlled",
  258.     smg = "smoke_trail_tfa",
  259.     grenade = "smoke_trail_tfa",
  260.     ar2 = "smoke_trail_tfa",
  261.     shotgun = "smoke_trail_wild",
  262.     rpg = "smoke_trail_tfa",
  263.     physgun = "smoke_trail_tfa",
  264.     crossbow = "smoke_trail_tfa",
  265.     melee = "smoke_trail_tfa",
  266.     slam = "smoke_trail_tfa",
  267.     normal = "smoke_trail_tfa",
  268.     melee2 = "smoke_trail_tfa",
  269.     knife = "smoke_trail_tfa",
  270.     duel = "smoke_trail_tfa",
  271.     camera = "smoke_trail_tfa",
  272.     magic = "smoke_trail_tfa",
  273.     revolver = "smoke_trail_tfa",
  274.     silenced = "smoke_trail_controlled"
  275. }
  276.  
  277. SWEP.DoMuzzleFlash = true --Do a muzzle flash?
  278. SWEP.CustomMuzzleFlash = true --Disable muzzle anim events and use our custom flashes?
  279. SWEP.AutoDetectMuzzleAttachment = false --For multi-barrel weapons, detect the proper attachment?
  280. SWEP.MuzzleFlashEffect = nil --Change to a string of your muzzle flash effect
  281. SWEP.Tracer = 0 --Bullet tracer.  TracerName overrides this.
  282. SWEP.TracerName = nil --Change to a string of your tracer name,or lua effect if chosen
  283. SWEP.TracerLua = false --Use lua effect, TFA Muzzle syntax
  284. SWEP.TracerCount = nil --0 disables, otherwise, 1 in X chance
  285. SWEP.TracerDelay = 0.01 --Delay for lua tracer effect
  286. SWEP.ImpactEffect = nil --Impact Effect
  287. --Event Table, used for custom events when a sequence is played
  288. SWEP.EventTable = {}
  289. --[[
  290. example:
  291. SWEP.EventTable = {
  292. [ACT_VM_RELOAD] = {
  293.         { ['time'] = 0.1, ['type'] = "lua", ['value'] = hifunc },
  294.         { ['time'] = 0.2, ['type'] = "sound", ['value'] = Sound("CryGauss.1") }
  295.     }
  296. }
  297. ]]--
  298. --RT Stuff
  299. SWEP.RTMaterialOverride = nil
  300. SWEP.RTOpaque = false
  301. SWEP.RTCode = function(self) return end
  302. --Callback system so that you can add onto base functions without copying
  303. SWEP.Callback = {}
  304. --Blowblack Function
  305. SWEP.BlowbackEnabled = false --Enable Blowback?
  306. SWEP.BlowbackVector = Vector(0, -1, 0) --Vector to move bone <or root> relative to bone <or view> orientation.
  307. SWEP.BlowbackCurrentRoot = 0 --Amount of blowback currently, for root
  308. SWEP.BlowbackCurrent = 0 --Amount of blowback currently, for bones
  309. SWEP.BlowbackBoneMods = nil --Viewmodel bone mods via SWEP Creation Kit
  310. SWEP.Blowback_Only_Iron = true --Only do blowback on ironsights
  311. SWEP.Blowback_PistolMode = false --Do we recover from blowback when empty?
  312.  
  313. ACT_VM_FIDGET_EMPTY = ACT_VM_FIDGET_EMPTY or ACT_CROSSBOW_FIDGET_UNLOADED
  314.  
  315. SWEP.Blowback_PistolMode_Disabled = {
  316.     [ACT_VM_RELOAD] = true,
  317.     [ACT_VM_RELOAD_EMPTY] = true,
  318.     [ACT_VM_DRAW_EMPTY] = true,
  319.     [ACT_VM_IDLE_EMPTY] = true,
  320.     [ACT_VM_HOLSTER_EMPTY] = true,
  321.     [ACT_VM_DRYFIRE] = true,
  322.     [ACT_VM_FIDGET] = true,
  323.     [ACT_VM_FIDGET_EMPTY] = true
  324. }
  325.  
  326. SWEP.Blowback_Shell_Enabled = true
  327. SWEP.Blowback_Shell_Effect = "ShellEject"
  328. --Stuff you shouldn't touch after this
  329. SWEP.EventTimer = 0 --Don't change this, base dependent and does nothing for users anyways.
  330. SWEP.PenetrationCounter = 0 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  331. SWEP.DrawTime = 1 --BASE DEPENDENT VALUE.  DO NOT CHANGE OR THINGS MAY BREAK.  NO USE TO YOU.
  332. SWEP.TextCol = Color(255, 255, 255, 255) --Primary text color
  333. SWEP.TextColContrast = Color(32, 32, 32, 255) --Secondary Text Color (used for shadow)
  334. SWEP.ScopeScale = 0.5
  335. SWEP.ReticleScale = 0.7
  336. SWEP.Akimbo = false
  337. SWEP.CustomBulletCallback = nil
  338. SWEP.AnimCycle = 0 -- Start on the right
  339. SWEP.IsTFAWeapon = true
  340.  
  341. for k, v in pairs(SWEP.SmokeParticles) do
  342.     PrecacheParticleSystem(v)
  343. end
  344.  
  345. SWEP.ConDamageMultiplier = 1
  346.  
  347. --[[ Localize Functions  ]]--
  348. local function l_Lerp(v, f, t)
  349.     return f + (t - f) * v
  350. end
  351.  
  352. local l_mathApproach = math.Approach
  353. local l_mathClamp = math.Clamp
  354. local l_CT = CurTime
  355. local l_FT = FrameTime
  356. local l_RT = RealTime
  357. --[[  Quadratic Interpolation Functions  ]]--
  358. local qerppower = 2
  359.  
  360. --[[
  361. Function Name:  Power
  362. Syntax: pow(number you want to take the power of, it's power)
  363. Returns:  The number to the power you specify
  364. Purpose:  Utility function
  365. ]]--
  366. local function pow(num, power)
  367.     return math.pow(num, power)
  368. end
  369.  
  370. --[[
  371. Function Name:  Qerp Inwards
  372. Syntax: QerpIn(progress, your starting value, how much it should change, across what period)
  373. Returns:  A number that you get when you quadratically fade into a value.  Kind of like a more advanced LERP.
  374. Purpose:  Utility function / Animation
  375. ]]--
  376. local function QerpIn(progress, startval, change, totaltime)
  377.     if not totaltime then
  378.         totaltime = 1
  379.     end
  380.  
  381.     return startval + change * pow(progress / totaltime, qerppower)
  382. end
  383.  
  384. --[[
  385. Function Name:  Qerp Outwards
  386. Syntax: QerpOut(progress, your starting value, how much it should change, across what period)
  387. Returns:  A number that you get when you quadratically fade out of a value.  Kind of like a more advanced LERP.
  388. Purpose:  Utility function / Animation
  389. ]]--
  390. local function QerpOut(progress, startval, change, totaltime)
  391.     if not totaltime then
  392.         totaltime = 1
  393.     end
  394.  
  395.     return startval - change * pow(progress / totaltime, qerppower)
  396. end
  397.  
  398. --[[
  399. Function Name:  Qerp
  400. Syntax: Qerp(progress, starting value, ending value, period)
  401. Note:  This is different syntax from QerpIn and QerpOut.  This uses a start and end value instead of a start value and change amount.
  402. Returns:  A number that you get when you quadratically fade out of and into a value.  Kind of like a more advanced LERP.
  403. Purpose:  Utility function / Animation
  404. ]]--
  405. local function Qerp(progress, startval, endval, totaltime)
  406.     change = endval - startval
  407.  
  408.     if not totaltime then
  409.         totaltime = 1
  410.     end
  411.  
  412.     if progress < totaltime / 2 then return QerpIn(progress, startval, change / 2, totaltime / 2) end
  413.  
  414.     return QerpOut(totaltime - progress, endval, change / 2, totaltime / 2)
  415. end
  416.  
  417. --[[
  418. Function Name:  QerpAngle
  419. Syntax: QerpAngle(progress, starting value, ending value, period)
  420. Returns:  The quadratically interpolated angle.
  421. Purpose:  Utility function / Animation
  422. ]]--
  423. local l_NormalizeAngle = math.NormalizeAngle
  424. local LerpAngle = LerpAngle
  425.  
  426. local function util_NormalizeAngles(a)
  427.     a.p = l_NormalizeAngle(a.p)
  428.     a.y = l_NormalizeAngle(a.y)
  429.     a.r = l_NormalizeAngle(a.r)
  430.  
  431.     return a
  432. end
  433.  
  434. local function QerpAngle(progress, startang, endang, totaltime)
  435. return util_NormalizeAngles(LerpAngle(Qerp(progress, 0, 1, totaltime), startang, endang))
  436. end
  437.  
  438. --[[
  439. Function Name:  QerpVector
  440. Syntax: QerpVector(progress, starting value, ending value, period)
  441. Returns:  The quadratically interpolated vector.
  442. Purpose:  Utility function / Animation
  443. ]]--
  444. local myqerpvec = Vector()
  445.  
  446. local function QerpVector(progress, startang, endang, totaltime)
  447. if not totaltime then
  448.     totaltime = 1
  449. end
  450.  
  451. local startx, starty, startz, endx, endy, endz
  452. startx = startang.x
  453. starty = startang.y
  454. startz = startang.z
  455. endx = endang.x
  456. endy = endang.y
  457. endz = endang.z
  458. myqerpvec.x = Qerp(progress, startx, endx, totaltime)
  459. myqerpvec.y = Qerp(progress, starty, endy, totaltime)
  460. myqerpvec.z = Qerp(progress, startz, endz, totaltime)
  461.  
  462. return myqerpvec
  463. end
  464.  
  465. --[[  Standard SWEP Functions  ]]--
  466. local host_timescale_cv, sv_cheats_cv, cl_vm_flip_cv, legacy_reloads_cv
  467. local is, isr, rs, rsr, insp, inspr, tsv, crouchr, jumpr, ftv, newratio, rel_proc
  468. local compensatedft, compensatedft_cr, compensatedft_sp
  469. local heldentindex, heldent
  470. legacy_reloads_cv = GetConVar("sv_tfa_reloads_legacy")
  471. host_timescale_cv = GetConVar("host_timescale")
  472. sv_cheats_cv = GetConVar("sv_cheats")
  473. local fps_max_cvar = GetConVar("fps_max")
  474. local dryfire_cvar = GetConVar("sv_tfa_allow_dryfire")
  475. local sensitivity_cvar, sensitivity_fov_cvar, sensitivity_speed_cvar
  476. local rtime, RealFrameTime
  477. local owent
  478. local ammo_fadein_cvar
  479. local isnumber
  480.  
  481. if CLIENT then
  482.     ammo_fadein_cvar = GetConVar("cl_tfa_hud_ammodata_fadein")
  483. end
  484.  
  485. local ironsights_toggle_cvar
  486.  
  487. if CLIENT then
  488.     ironsights_toggle_cvar = GetConVar("cl_tfa_ironsights_toggle")
  489. end
  490.  
  491. local ironsights_resight_cvar
  492.  
  493. if CLIENT then
  494.     ironsights_resight_cvar = GetConVar("cl_tfa_ironsights_resight")
  495. end
  496.  
  497. local seq
  498. local seqtime
  499. local dt
  500. local stwep
  501. local isreloading, isshooting, isdrawing, isholstering, issighting, issprinting, isbolttimer, isinspecting, isfidgeting, ct, is_old, spr_old, ft, rsnumber, bash, bts, bte, del, mb, fe
  502. local tonetwork_thresh = 0.001
  503. local ckeyvar
  504. local CurrentRecoil
  505. local CurrentCone
  506. local gunbob_intensity_cvar = GetConVar("cl_tfa_gunbob_intensity")
  507. local cl_tfa_viewmodel_offset_x = GetConVar("cl_tfa_viewmodel_offset_x")
  508. local cl_tfa_viewmodel_offset_y = GetConVar("cl_tfa_viewmodel_offset_y")
  509. local cl_tfa_viewmodel_offset_z = GetConVar("cl_tfa_viewmodel_offset_z")
  510. local gunswaycvar = GetConVar("cl_tfa_gunbob_intensity")
  511. local fovmod_add = GetConVar("cl_tfa_viewmodel_offset_fov")
  512. local fovmod_mult = GetConVar("cl_tfa_viewmodel_multiplier_fov")
  513. local mult_cvar = GetConVar("sv_tfa_spread_multiplier")
  514. local dynacc_cvar = GetConVar("sv_tfa_dynamicaccuracy")
  515. local tmp_nwsightsang
  516. local ang2 = Angle()
  517. local ang3 = Angle()
  518. local ang4 = Angle()
  519. local ang5 = Angle()
  520. local hidevec = Vector(0, 0, -10000)
  521. local mvfac
  522. local qerp_threshold = 0.01
  523. local isp
  524. local rsp
  525. local nwp
  526. local inspectrat
  527. local tmp_ispos
  528. local tmp_isa
  529. local tmp_rspos
  530. local tmp_rsa
  531. local vmfov
  532. local oldang = Angle()
  533. local anga = Angle()
  534. local angb = Angle()
  535. local angc = Angle()
  536. local posfac = 0.75
  537. if CLIENT then
  538.     sensitivity_cvar = GetConVar("cl_tfa_scope_sensitivity")
  539.     sensitivity_fov_cvar = GetConVar("cl_tfa_scope_sensitivity_autoscale")
  540.     sensitivity_speed_cvar = GetConVar("sv_tfa_scope_gun_speed_scale")
  541. end
  542. local resrat
  543. if CLIENT then
  544.     resrat = ScrW() / ScrH()
  545. end
  546. local hudhangtime_cvar
  547.  
  548. if CLIENT then
  549.     hudhangtime_cvar = GetConVar("cl_tfa_hud_hangtime")
  550. end
  551.  
  552. --[[
  553. Function Name:  ResetEvents
  554. Syntax: self:ResetEvents()
  555. Returns:  Nothing.
  556. Purpose:  Cleans up events table.
  557. ]]--
  558. function SWEP:ResetEvents()
  559.     if self.Callback.ResetEvents then
  560.         local val = self.Callback.ResetEvents(self)
  561.         if val then return val end
  562.     end
  563.  
  564.     if not self:OwnerIsValid() then return end
  565.  
  566.     if sp and not CLIENT and IsValid(self.Owner) then
  567.         self:CallOnClient("ResetEvents", "")
  568.     end
  569.  
  570.     self.EventTimer = l_CT()
  571.  
  572.     for k, v in pairs(self.EventTable) do
  573.         for l, b in pairs(v) do
  574.             b.called = false
  575.         end
  576.     end
  577. end
  578.  
  579. --[[
  580. Function Name:  SetupDataTables
  581. Syntax: Should not be manually called.
  582. Returns:  Nothing.  Simple sets up DTVars to be networked.
  583. Purpose:  Networking.
  584. ]]--
  585. function SWEP:SetupDataTables()
  586.     if self.Callback.SetupDataTables then
  587.         local val = self.Callback.SetupDataTables(self)
  588.         if val then return val end
  589.     end
  590.  
  591.     self:NetworkVar("Bool", 0, "IronSights")
  592.     self:NetworkVar("Bool", 1, "IronSightsRaw")
  593.     self:NetworkVar("Bool", 2, "Holstering")
  594.     self:NetworkVar("Bool", 3, "Sprinting")
  595.     self:NetworkVar("Bool", 4, "Drawing")
  596.     self:NetworkVar("Bool", 5, "Reloading")
  597.     self:NetworkVar("Bool", 6, "Shooting")
  598.     self:NetworkVar("Bool", 7, "NearWall")
  599.     self:NetworkVar("Bool", 8, "Silenced")
  600.     self:NetworkVar("Bool", 9, "Bursting")
  601.     self:NetworkVar("Bool", 10, "ChangingSilence")
  602.     self:NetworkVar("Bool", 11, "FireModeChanging")
  603.     self:NetworkVar("Bool", 13, "ShotgunInsertingShell")
  604.     self:NetworkVar("Bool", 14, "ShotgunPumping")
  605.     self:NetworkVar("Bool", 15, "ShotgunNeedsPump")
  606.     self:NetworkVar("Bool", 16, "ShotgunCancel")
  607.     self:NetworkVar("Bool", 17, "BoltTimer")
  608.     self:NetworkVar("Bool", 18, "CanHolster")
  609.     self:NetworkVar("Bool", 19, "Inspecting")
  610.     self:NetworkVar("Bool", 20, "Fidgeting")
  611.     self:NetworkVar("Float", 0, "DrawingEnd")
  612.     self:NetworkVar("Float", 1, "HolsteringEnd")
  613.     self:NetworkVar("Float", 2, "ReloadingEnd")
  614.     self:NetworkVar("Float", 3, "ShootingEnd")
  615.     self:NetworkVar("Float", 4, "NextIdleAnim")
  616.     self:NetworkVar("Float", 5, "NextBurst")
  617.     self:NetworkVar("Float", 6, "NextSilenceChange")
  618.     self:NetworkVar("Float", 7, "FireModeChangeEnd")
  619.     self:NetworkVar("Float", 9, "BoltTimerStart")
  620.     self:NetworkVar("Float", 10, "BoltTimerEnd")
  621.     self:NetworkVar("Float", 11, "FidgetingEnd")
  622.     self:NetworkVar("Float", 12, "IronSightsRatio")
  623.     self:NetworkVar("Float", 13, "RunSightsRatio")
  624.     self:NetworkVar("Float", 14, "CrouchingRatio")
  625.     self:NetworkVar("Float", 15, "JumpingRatio")
  626.     self:NetworkVar("Float", 16, "NearWallRatio")
  627.     self:NetworkVar("Float", 17, "SpreadRatio")
  628.     self:NetworkVar("Float", 18, "InspectingRatio")
  629.     self:NetworkVar("Int", 0, "FireMode")
  630.     self:NetworkVar("Int", 1, "BurstCount")
  631.     self:NetworkVar("Int", 2, "LastActivity")
  632.     self:NetworkVar("Entity", 0, "SwapTarget")
  633. end
  634.  
  635. --[[
  636. Function Name:  Precache
  637. Syntax: Should not be normally called.
  638. Returns:  Nothing.  Simply precaches models/sound.
  639. Purpose:  Standard SWEP Function
  640. ]]--
  641. function SWEP:Precache()
  642.     if self.Callback.Precache then
  643.         local val = self.Callback.Precache(self)
  644.         if val then return val end
  645.     end
  646.  
  647.     if self.Primary.Sound then
  648.         util.PrecacheSound(self.Primary.Sound)
  649.     end
  650.  
  651.     util.PrecacheModel(self.ViewModel)
  652.     util.PrecacheModel(self.WorldModel)
  653. end
  654.  
  655. --[[
  656. Function Name:  Initialize
  657. Syntax: Should not be normally called.
  658. Notes:   Called after actual SWEP code, but before deploy, and only once.
  659. Returns:  Nothing.  Sets the intial values for the SWEP when it's created.
  660. Purpose:  Standard SWEP Function
  661. ]]--
  662. sp = game.SinglePlayer()
  663.  
  664. function SWEP:Initialize()
  665.  
  666.     self.HasRunInitialize = true
  667.  
  668.     if self.Callback.Initialize then
  669.         local val = self.Callback.Initialize(self)
  670.         if val then return val end
  671.     end
  672.  
  673.     if (not self.Primary.Damage) or (self.Primary.Damage <= 0.01) then
  674.         self:AutoDetectDamage()
  675.     end
  676.  
  677.     if not self.Primary.IronAccuracy then
  678.         self.Primary.IronAccuracy = (self.Primary.Accuracy or self.Primary.Spread or 0) * 0.2
  679.     end
  680.  
  681.     if self.MuzzleAttachment == "1" then
  682.         self.CSMuzzleFlashes = true
  683.     end
  684.  
  685.     self:CreateFireModes()
  686.     self:AutoDetectMuzzle()
  687.     self:AutoDetectRange()
  688.     self:AutoDetectDamageType()
  689.     self:AutoDetectForce()
  690.     self:AutoDetectKnockback()
  691.     self.DefaultHoldType = self.HoldType
  692.     self.ViewModelFOVDefault = self.ViewModelFOV
  693.     self.DrawCrosshairDefault = self.DrawCrosshair
  694.     self:SetUpSpread()
  695.  
  696.     if CLIENT then
  697.         self:InitMods()
  698.         self:IconFix()
  699.     end
  700.  
  701.     self.drawcount = 0
  702.     self.drawcount2 = 0
  703.     self.canholster = false
  704.     self:SetDeploySpeed(10)
  705.     self:ResetEvents()
  706.     self:DoBodyGroups()
  707.     self:InitAttachments()
  708.     self.IsHolding = false
  709.     self.ViewModelFlipDefault = self.ViewModelFlip
  710.     self:SetDrawing(true)
  711.     self:ProcessHoldType()
  712.     sp = game.SinglePlayer()
  713.  
  714.     if self.Akimbo then
  715.         self:InitializeAkimbo()
  716.     end
  717. end
  718.  
  719. --[[
  720. Function Name:  Deploy
  721. Syntax: self:Deploy()
  722. Notes:  Called after self:Initialize().  Called each time you draw the gun.  This is also essential to clearing out old networked vars and resetting them.
  723. Returns:  True/False to allow quickswitch.  Why not?  You should really return true.
  724. Purpose:  Standard SWEP Function
  725. ]]--
  726.  
  727. function SWEP:Deploy()
  728.  
  729.     if not IsValid(self.OwnerViewModel) then
  730.         self.OwnerViewModel = self.Owner:GetViewModel()
  731.     end
  732.     if self.Callback.Deploy then
  733.         local val = self.Callback.Deploy(self)
  734.         if val then return val end
  735.     end
  736.  
  737.     if not self.HasRunInitialize then
  738.         self:Initialize()
  739.     end
  740.  
  741.     self.ViewModelFOVDefault = self.ViewModelFOV
  742.     self.DefaultFOV = TFADUSKFOV or ( IsValid(self.Owner) and self.Owner:GetFOV() or 90 )
  743.     self:CorrectScopeFOV(self.DefaultFOV)
  744.     self:ResetSightsProgress()
  745.  
  746.     if not self.HasDetectedValidAnimations then
  747.         self:DetectValidAnimations()
  748.         timer.Simple(0,function()
  749.             if IsValid(self) then
  750.                 self:DetectValidAnimations()
  751.             end
  752.         end)
  753.     end
  754.  
  755.     success, anim = self:ChooseDrawAnim()
  756.  
  757.     self:SetHoldType(self.DefaultHoldType or self.HoldType)
  758.     self.OldIronsights = false
  759.     self:SetIronSights(false)
  760.     self:SetIronSightsRaw(false)
  761.     self.OldSprinting = false
  762.     self.OldSafety = false
  763.     self:SetSprinting(false)
  764.     self:SetShooting(false)
  765.     self:SetChangingSilence(false)
  766.     self:SetCanHolster(false)
  767.     self:SetReloading(false)
  768.     self:SetShotgunInsertingShell(false)
  769.     self:SetShotgunCancel(false)
  770.     self:SetShotgunPumping(false)
  771.     self:SetShotgunNeedsPump(false)
  772.     self:SetFireModeChanging(false)
  773.     self:SetBoltTimer(false)
  774.     self:SetDrawing(true)
  775.     self:SetHolstering(false)
  776.     self:SetUnpredictedHolstering(false)
  777.     self:SetInspecting(false)
  778.  
  779.     if self:GetSilenced() == nil then
  780.         if self.Silenced == nil then
  781.             self.Silenced = false
  782.         end
  783.         self:SetSilenced( self.Silenced )
  784.     end
  785.  
  786.     self:SetSpreadRatio(0)
  787.     self:SetBurstCount(0)
  788.     self:SetBursting(false)
  789.     self.PenetrationCounter = 0
  790.  
  791.     self.CLSpreadRatio = 1
  792.     self.CLIronSightsProgress = 0
  793.     self.CLRunSightsProgress = 0
  794.     self.CLCrouchProgress = 0
  795.     self.CLInspectingProgress = 0
  796.     self.CLNearWallProgressProgress = 0
  797.  
  798.     seqtime = self.OwnerViewModel:SequenceDuration()
  799.     dt = l_CT() + (self.SequenceLengthOverride[anim] or seqtime)
  800.  
  801.     if self.ShootWhileDraw == false then
  802.         self:SetNextPrimaryFire(dt)
  803.     end
  804.  
  805.     self:SetDrawingEnd(dt)
  806.     self:SetNextIdleAnim(l_CT() + seqtime)
  807.  
  808.     self.customboboffset.x = 0
  809.     self.customboboffset.y = 0
  810.     self.customboboffset.z = 0
  811.     self:ResetEvents()
  812.  
  813.     if SERVER and self:OwnerIsValid() then
  814.         self:CallOnClient("ResetEvents", "")
  815.         self:CallOnClient("SelfSetHolding", "")
  816.     end
  817.  
  818.     self:UpdateConDamage()
  819.     self.LastSys = SysTime()
  820.     self.ProceduralHolsterFactor = 0
  821.     self:StopClientHolstering()
  822.     self:SetFidgeting(false)
  823.     self.IsHolding = false
  824.  
  825.     if self.Akimbo then
  826.         self:DeployAkimbo()
  827.     end
  828.  
  829.     return true
  830. end
  831.  
  832. --[[
  833. Function Name:  OnRemove
  834. Syntax: self:OnRemove()
  835. Notes:  Resets bone mods and cleans up.
  836. Returns:  Nil.
  837. Purpose:  Standard SWEP Function
  838. ]]--
  839. function SWEP:OnRemove()
  840.     if self.Callback.OnRemove then
  841.         local val = self.Callback.OnRemove(self)
  842.         if val then return val end
  843.     end
  844.  
  845.     if CLIENT then
  846.         self:CleanModels(self.VElements) -- create viewmodels
  847.         self:CleanModels(self.WElements) -- create worldmodels
  848.     end
  849. end
  850.  
  851. --[[
  852. Function Name:  OnDrop
  853. Syntax: self:OnDrop()
  854. Notes:  Resets bone mods and cleans up.
  855. Returns:  Nil.
  856. Purpose:  Standard SWEP Function
  857. ]]--
  858. function SWEP:OnDrop()
  859.     if self.Callback.OnDrop then
  860.         local val = self.Callback.OnDrop(self)
  861.         if val then return val end
  862.     end
  863.  
  864.     if self.Callback.OnDrop then
  865.         self.Callback.OnDrop(self)
  866.     end
  867.  
  868.     if CLIENT then
  869.         self:CleanModels(self.VElements) -- create viewmodels
  870.         self:CleanModels(self.WElements) -- create worldmodels
  871.     end
  872. end
  873.  
  874. --[[
  875. Function Name:  CanPickup
  876. Syntax: self:CanPickup( to pick up)
  877. Notes:  For picking up props.
  878. Returns:  True/False
  879. Purpose:  Self explanitory
  880. ]]--
  881. local objectMass
  882. local itspos
  883. local dist
  884. local ang1
  885. local angdif
  886.  
  887. function SWEP:CanPickup(ent)
  888.     local massLimit = 35
  889.     local sizeLimit = 128
  890.  
  891.     --Must be valid
  892.     if not IsValid(ent) then
  893.         print("noent")
  894.  
  895.         return false
  896.     end
  897.  
  898.     local count = ent:GetPhysicsObjectCount()
  899.  
  900.     --Must have a physics object
  901.     if (not count) then
  902.         print("no count")
  903.  
  904.         return false
  905.     end
  906.  
  907.     objectMass = 0
  908.  
  909.     if count > 0 then
  910.         for i = 0, count - 1 do
  911.             local phys = ent:GetPhysicsObjectNum(i)
  912.  
  913.             if IsValid(phys) then
  914.                 objectMass = objectMass + phys:GetMass()
  915.  
  916.                 if (not phys:IsMoveable()) then
  917.                     print(phys)
  918.  
  919.                     return false
  920.                 end
  921.             end
  922.         end
  923.     else
  924.         local phys = ent:GetPhysicsObject()
  925.  
  926.         if IsValid(phys) then
  927.             objectMass = objectMass + phys:GetMass()
  928.  
  929.             if (not phys:IsMoveable()) then
  930.                 print(phys)
  931.  
  932.                 return false
  933.             end
  934.         end
  935.     end
  936.  
  937.     if (massLimit > 0 and objectMass > massLimit) then
  938.         print("toomass")
  939.  
  940.         return false
  941.     end
  942.  
  943.     if (sizeLimit > 0) then
  944.         local size = ent:OBBMaxs() - ent:OBBMins()
  945.  
  946.         if (size.x > sizeLimit or size.y > sizeLimit or size.z > sizeLimit) then
  947.             print("toobig")
  948.  
  949.             return false
  950.         end
  951.     end
  952.  
  953.     itspos = ent:GetPos() + ent:OBBCenter()
  954.     dist = itspos:Distance(self.Owner:GetShootPos())
  955.     ang1 = self.Owner:EyeAngles()
  956.     ang2 = (itspos - self.Owner:GetShootPos()):Angle()
  957.     angdif = ang1 - ang2
  958.     if dist > 100 then return false end
  959.     if math.abs(math.NormalizeAngle(angdif.p)) > 90 - dist / 4 or math.abs(math.NormalizeAngle(angdif.y)) > 90 - dist / 4 then return false end
  960.  
  961.     return hook.Call("PlayerCanPickupItem", GAMEMODE, self.Owner, ent)
  962. end
  963.  
  964. function SWEP:SelfSetHolding(arg)
  965.     if arg == "true" then
  966.         self.IsHolding = true
  967.     else
  968.         self.IsHolding = false
  969.     end
  970. end
  971.  
  972. --[[
  973. Function Name:  Holster
  974. Syntax: self:Holster( weapon entity to switch to )
  975. Notes:  This is kind of broken.  I had to manually select the new weapon using ply:ConCommand.  Returning true is simply not enough.  This is also essential to clearing out old networked vars and resetting them.
  976. Returns:  True/False to allow holster.  Useful for animations.
  977. Purpose:  Standard SWEP Function
  978. ]]--
  979.  
  980. function SWEP:Holster(switchtowep)
  981.     if not IsValid(switchtowep) then
  982.         switchtowep = self.Owner
  983.     end
  984.  
  985.     if self.Callback.Holster then
  986.         local val = self.Callback.Holster(self, switchtowep)
  987.         if val then return val end
  988.     end
  989.  
  990.     if self.WriteKills then
  991.         self:WriteKills()
  992.  
  993.         if SERVER then
  994.             self:CallOnClient("WriteKills", "")
  995.         end
  996.     end
  997.  
  998.     if not self:OwnerIsValid() then return end
  999.     self:SetShotgunCancel(true)
  1000.     self:CleanParticles()
  1001.  
  1002.     if SERVER then
  1003.         self:CallOnClient("CleanParticles", "")
  1004.     end
  1005.  
  1006.     self.PenetrationCounter = 0
  1007.     self:SetReloading(false)
  1008.     self:SetDrawing(false)
  1009.     self:SetInspecting(false)
  1010.     self:SetDrawingEnd(l_CT() - 1)
  1011.     self:SetReloadingEnd(l_CT() - 1)
  1012.  
  1013.     if IsFirstTimePredicted() then
  1014.         self:SetSwapTarget(switchtowep)
  1015.     end
  1016.  
  1017.     if self == switchtowep then return end
  1018.  
  1019.     if not self:GetCanHolster() then
  1020.         if not self:GetHolstering() then
  1021.             self:SetHolstering(true)
  1022.             success, anim = self:ChooseHolsterAnim()
  1023.  
  1024.             if not success then
  1025.                 anim = -1
  1026.                 seqtime = self.ProceduralHolsterTime
  1027.             elseif IsValid(self.OwnerViewModel) then
  1028.                 seqtime = self.OwnerViewModel:SequenceDuration()
  1029.             else
  1030.                 seqtime = 0
  1031.             end
  1032.             dt = l_CT() + (self.SequenceLengthOverride[anim] or seqtime)
  1033.  
  1034.             if self.ShootWhileDraw == false then
  1035.                 self:SetNextPrimaryFire(dt)
  1036.             end
  1037.  
  1038.             if CLIENT then
  1039.                 self:SetUnpredictedHolstering(true)
  1040.                 self:SetHolsteringEnd(l_CT() + 999)
  1041.             end
  1042.  
  1043.             if SERVER then
  1044.                 self:SetHolsteringEnd(dt)
  1045.             end
  1046.         end
  1047.     else
  1048.         if CLIENT then
  1049.             self:CleanModels(self.VElements)
  1050.             self:CleanModels(self.WElements)
  1051.         end
  1052.  
  1053.         return true
  1054.     end
  1055. end
  1056.  
  1057. --[[
  1058. Function Name:  AdjustMouseSensitivity
  1059. Syntax: Should not normally be called.
  1060. Returns:  SWEP sensitivity multiplier.
  1061. Purpose:  Standard SWEP Function
  1062. ]]--
  1063.  
  1064. local fovv
  1065.  
  1066. function SWEP:AdjustMouseSensitivity()
  1067.     if self.Callback.AdjustMouseSensitivity then
  1068.         local val = self.Callback.AdjustMouseSensitivity(self)
  1069.         if val then return val end
  1070.     end
  1071.  
  1072.     local sensval = 1
  1073.  
  1074.     if self:GetIronSights() then
  1075.         sensval = sensval * sensitivity_cvar:GetFloat() / 100
  1076.  
  1077.         if sensitivity_fov_cvar:GetFloat() then
  1078.             if self.Scoped_3D then
  1079.                 fovv = math.Clamp( math.pow(self.RTScopeFOV,3),1,self.Owner:GetFOV())
  1080.             else
  1081.                 fovv = self.Owner:GetFOV()
  1082.             end
  1083.             fovv = fovv / ( self.Scoped_3D and self.Secondary.ScopeZoom or 1 )
  1084.             sensval = sensval * math.atan(resrat * math.tan(math.rad(fovv / 2))) / math.atan(resrat * math.tan(math.rad(self.DefaultFOV / 2)))
  1085.         else
  1086.             sensval = sensval
  1087.         end
  1088.  
  1089.         if sensitivity_speed_cvar:GetBool() then
  1090.             sensval = sensval * self.IronSightsMoveSpeed
  1091.         end
  1092.     end
  1093.  
  1094.     sensval = sensval * l_Lerp(CLIENT and self.CLIronSightsProgress or self:GetIronSightsRatio(), 1, self.IronSightsSensitivity)
  1095.  
  1096.     return sensval
  1097. end
  1098.  
  1099. --[[
  1100. Function Name:  TranslateFOV
  1101. Syntax: Should not normally be called.  Takes default FOV as parameter.
  1102. Returns:  New FOV.
  1103. Purpose:  Standard SWEP Function
  1104. ]]--
  1105.  
  1106. function SWEP:TranslateFOV(fov)
  1107.     if self.Callback.TranslateFOV then
  1108.         local val = self.Callback.TranslateFOV(self, fov)
  1109.         if val then return val end
  1110.     end
  1111.  
  1112.     --local nfov=l_Lerp( l_Max( self.CLIronSightsProgress - ( self.Scoped and self.ScopeOverlayThreshold or 0 ), 0  ) / ( 1 - ( self.Scoped and self.ScopeOverlayThreshold or 0 ) ),fov,fov*(self.Secondary.IronFOV/90))
  1113.     local nfov = l_Lerp(self.CLIronSightsProgress, fov, fov * (self.Secondary.IronFOV / 90))
  1114.  
  1115.     return l_Lerp(self.CLRunSightsProgress, nfov, nfov + self.SprintFOVOffset)
  1116. end
  1117.  
  1118. --[[
  1119. Function Name:  Think
  1120. Syntax: self:Think()
  1121. Returns:  Nothing.
  1122. Notes:  This is blank.
  1123. Purpose:  Standard SWEP Function
  1124. ]]--
  1125. function SWEP:Think()
  1126.     if self.Callback.Think then
  1127.         local val = self.Callback.Think(self)
  1128.         if val then return val end
  1129.     end
  1130. end
  1131.  
  1132. --[[
  1133. Function Name:  ViewModelFlip
  1134. Syntax: self:ViewModelFlip().  Called from Think2.
  1135. Returns:  Nothing.
  1136. Notes:  Allows you to toggle lefthanded.
  1137. Purpose:  Standard SWEP Function
  1138. ]]--
  1139. local shouldflip
  1140.  
  1141. function SWEP:ViewModelFlipFunc()
  1142.     if not cl_vm_flip_cv then
  1143.         cl_vm_flip_cv = GetConVar("cl_tfa_viewmodel_flip")
  1144.     end
  1145.  
  1146.     local righthanded = true
  1147.  
  1148.     if SERVER and self.Owner:GetInfoNum("cl_tfa_viewmodel_flip", 0) == 1 then
  1149.         righthanded = false
  1150.     end
  1151.  
  1152.     if CLIENT and cl_vm_flip_cv:GetBool() then
  1153.         righthanded = false
  1154.     end
  1155.  
  1156.     shouldflip = self.ViewModelFlipDefault
  1157.  
  1158.     if not righthanded then
  1159.         shouldflip = not self.ViewModelFlipDefault
  1160.     end
  1161.  
  1162.     if self.ViewModelFlip ~= shouldflip then
  1163.         self.ViewModelFlip = shouldflip
  1164.     end
  1165. end
  1166.  
  1167. --[[
  1168. Function Name:  Think2
  1169. Syntax: self:Think2().  Called from PlayerThink.
  1170. Returns:  Nothing.
  1171. Notes:  Essential for calling other important functions.  This is called from PlayerThink.  It's used because SWEP:Think() isn't always called.
  1172. Purpose:  Standard SWEP Function
  1173. ]]--
  1174. function SWEP:Think2()
  1175.     if not self:OwnerIsValid() then return end
  1176.  
  1177.     if self.Callback.Think2 then
  1178.         local val = self.Callback.Think2(self)
  1179.         if val then return val end
  1180.     end
  1181.  
  1182.     self:ProcessEvents()
  1183.     self:ProcessFireMode()
  1184.     self:MainUpdate()
  1185.     self:ProcessHoldType()
  1186.     self:ViewModelFlipFunc()
  1187.  
  1188.     if self.CustomBaseThink then
  1189.         self:CustomBaseThink()
  1190.     end
  1191. end
  1192.  
  1193. --[[
  1194. Function Name:  MainUpdate
  1195. Syntax: self:MainUpdate().  This is called per-think.
  1196. Returns:  Nothing.  However, calculates OMG so much stuff what is this horrible hacky code that allows you to use bolt action snipers, shotguns, and normal guns all in the same base?!!!111oneoneone
  1197. Notes:  This is essential.
  1198. Purpose:  Don't remove this, seriously.
  1199. ]]--
  1200.  
  1201. function SWEP:WeaponUse( plyv )
  1202.     plyv:ConCommand("+use")
  1203.  
  1204.     if sp then
  1205.         plyv:ConCommand("+use")
  1206.  
  1207.         timer.Simple(0, function()
  1208.             if IsValid(plyv) then
  1209.                 plyv:ConCommand("-use")
  1210.             end
  1211.         end)
  1212.  
  1213.         timer.Simple(0.1, function()
  1214.             if IsValid(self) then
  1215.                 self:Deploy()
  1216.  
  1217.                 if IsValid(self.Owner) then
  1218.                     self.Owner:ConCommand("-use")
  1219.                 end
  1220.             end
  1221.         end)
  1222.     else
  1223.         timer.Simple(0.09, function()
  1224.             if IsValid(plyv) then
  1225.                 plyv:ConCommand("-use")
  1226.             end
  1227.         end)
  1228.  
  1229.         timer.Simple(0.1, function()
  1230.             if IsValid(plyv) then
  1231.                 plyv:ConCommand("-use")
  1232.             end
  1233.             if IsValid(self) then
  1234.                 self:Deploy()
  1235.  
  1236.                 if IsValid(self.Owner) then
  1237.                     self.Owner:ConCommand("-use")
  1238.                 end
  1239.             end
  1240.         end)
  1241.     end
  1242. end
  1243.  
  1244. function SWEP:ShotgunReload( ctv )
  1245.     ct = ctv
  1246.     if (self:GetShotgunInsertingShell() == false) then
  1247.         if not self:GetShotgunPumping() then
  1248.             if self.StartAnimInsertShell then
  1249.                 local curclip = self:Clip1()
  1250.                 local amounttoreplace = 1
  1251.                 self:SetClip1(curclip + amounttoreplace)
  1252.                 self.Owner:RemoveAmmo(amounttoreplace, self.Primary.Ammo)
  1253.                 self.StartAnimInsertShell = false
  1254.                 self:SetReloading(true)
  1255.                 self:SetReloadingEnd(ct + 0)
  1256.                 self:SetNextPrimaryFire(ct + 0.01)
  1257.             else
  1258.                 self:SetShotgunInsertingShell(true)
  1259.                 self:SendViewModelAnim(ACT_VM_RELOAD, self.ShellTime, true)
  1260.                 self:ResetEvents()
  1261.  
  1262.                 if IsValid(self.Owner) then
  1263.                     if not self.ShellTime and IsValid(self.OwnerViewModel) then
  1264.                         self:SetReloadingEnd(ct + self.OwnerViewModel:SequenceDuration(self.OwnerViewModel:SelectWeightedSequence(ACT_VM_RELOAD)))
  1265.                         self:SetNextPrimaryFire(ct + (self.SequenceLengthOverride[ACT_VM_RELOAD] and self.SequenceLengthOverride[ACT_VM_RELOAD] or self.OwnerViewModel:SequenceDuration(self.OwnerViewModel:SelectWeightedSequence(ACT_VM_RELOAD))))
  1266.                     else
  1267.                         self:SetReloadingEnd(ct + self.ShellTime)
  1268.                         self:SetNextPrimaryFire(ct + self.ShellTime)
  1269.                     end
  1270.                 else
  1271.                     self:SetReloadingEnd(ct + self.ShellTime)
  1272.                     self:SetNextPrimaryFire(ct + self.ShellTime)
  1273.                 end
  1274.  
  1275.                 self:SetReloading(true)
  1276.                 isreloading = true
  1277.             end
  1278.         else
  1279.             self:SetReloading(false)
  1280.             self:SetShotgunPumping(false)
  1281.             self:SetReloadingEnd(ct - 1)
  1282.             self:SetNextPrimaryFire(ct + 0.01)
  1283.             isreloading = false
  1284.         end
  1285.     else
  1286.         local maxclip = self.Primary.ClipSize
  1287.         local curclip = self:Clip1()
  1288.         local ammopool = self:GetAmmoReserve()
  1289.  
  1290.         if curclip >= maxclip or ammopool <= 0 or self:GetShotgunNeedsPump() then
  1291.             self:SetShotgunInsertingShell(false)
  1292.             self:SendViewModelAnim(ACT_SHOTGUN_RELOAD_FINISH)
  1293.  
  1294.             if IsValid(self.Owner) then
  1295.                 if IsValid(self.OwnerViewModel) then
  1296.                     self:SetReloadingEnd(ct + self.OwnerViewModel:SequenceDuration(self.OwnerViewModel:SelectWeightedSequence(ACT_SHOTGUN_RELOAD_FINISH)))
  1297.                     self:SetNextPrimaryFire(ct + (self.SequenceLengthOverride[ACT_SHOTGUN_RELOAD_FINISH] and self.SequenceLengthOverride[ACT_SHOTGUN_RELOAD_FINISH] or self.OwnerViewModel:SequenceDuration(self.OwnerViewModel:SelectWeightedSequence(ACT_SHOTGUN_RELOAD_FINISH))))
  1298.                 else
  1299.                     self:SetReloadingEnd(ct + self.ShellTime)
  1300.                     self:SetNextPrimaryFire(ct + self.ShellTime)
  1301.                 end
  1302.             else
  1303.                 self:SetReloadingEnd(ct + self.ShellTime)
  1304.                 self:SetNextPrimaryFire(ct + self.ShellTime)
  1305.             end
  1306.  
  1307.             self:SetReloading(true)
  1308.             self:SetShotgunPumping(true)
  1309.             self:SetShotgunNeedsPump(false)
  1310.         else
  1311.             local amounttoreplace = 1
  1312.             self:SetClip1(curclip + amounttoreplace)
  1313.             self.Owner:RemoveAmmo(amounttoreplace, self.Primary.Ammo)
  1314.             curclip = self:Clip1()
  1315.  
  1316.             if (curclip < maxclip) then
  1317.                 self:SendViewModelAnim(ACT_VM_RELOAD, self.ShellTime, true)
  1318.                 self:ResetEvents()
  1319.                 self:SetReloading(true)
  1320.                 self:SetShotgunInsertingShell(true)
  1321.  
  1322.                 if not self.ShellTime and IsValid(self.Owner) and  IsValid(self.OwnerViewModel) then
  1323.                     self:SetReloadingEnd(ct + self.OwnerViewModel:SequenceDuration(self.OwnerViewModel:SelectWeightedSequence(ACT_VM_RELOAD)))
  1324.                     self:SetNextPrimaryFire(ct + (self.SequenceLengthOverride[ACT_VM_RELOAD] and self.SequenceLengthOverride[ACT_VM_RELOAD] or self.OwnerViewModel:SequenceDuration(self.OwnerViewModel:SelectWeightedSequence(ACT_VM_RELOAD))))
  1325.                 else
  1326.                     self:SetReloadingEnd(ct + self.ShellTime)
  1327.                     self:SetNextPrimaryFire(ct + self.ShellTime)
  1328.                 end
  1329.             else
  1330.                 self:SetReloadingEnd(ct - 1)
  1331.                 self:SetNextPrimaryFire(ct + 0.01)
  1332.                 self:SetReloading(true)
  1333.                 self:SetShotgunInsertingShell(true)
  1334.             end
  1335.  
  1336.             if self:GetShotgunCancel() then
  1337.                 self:SetShotgunCancel(false)
  1338.                 self:SetReloading(true)
  1339.                 self:SetShotgunNeedsPump(true)
  1340.                 self:SetReloadingEnd(ct - 1)
  1341.                 self:SetNextPrimaryFire(ct + 0.01)
  1342.             end
  1343.         end
  1344.     end
  1345. end
  1346.  
  1347. function SWEP:MainUpdate()
  1348.     if self.Callback.ProcessTimers then
  1349.         local val = self.Callback.ProcessTimers(self)
  1350.         if val then return val end
  1351.     end
  1352.  
  1353.     if not self.HasDetectedValidAnimations then
  1354.         self:DetectValidAnimations()
  1355.     end
  1356.  
  1357.     ct = l_CT()
  1358.     ft = l_FT()
  1359.     owent = self.Owner
  1360.     isreloading = self:GetReloading()
  1361.     isshooting = self:GetShooting()
  1362.     isdrawing = self:GetDrawing()
  1363.     isholstering = self:GetHolstering()
  1364.     issighting = self:GetIronSights()
  1365.     issprinting = self:GetSprinting()
  1366.     isbursting = self:GetBursting()
  1367.     ischangingsilence = self:GetChangingSilence()
  1368.     isfiremodechanging = self:GetFireModeChanging()
  1369.     isinspecting = self:GetInspecting()
  1370.     isfidgeting = self:GetFidgeting()
  1371.     fe = self:GetFidgetingEnd()
  1372.     isbolttimer = self:GetBoltTimer()
  1373.     bash = self.GetBashing and self:GetBashing()
  1374.  
  1375.     if isbolttimer then
  1376.         bts = self:GetBoltTimerStart()
  1377.         bte = self:GetBoltTimerEnd()
  1378.     else
  1379.         bts = ct + 1
  1380.         bte = ct + 1
  1381.     end
  1382.  
  1383.     if SERVER then
  1384.         isr = self:GetIronSightsRatio()
  1385.         rsr = self:GetRunSightsRatio()
  1386.         inspr = self:GetInspectingRatio()
  1387.         self:UpdateViewModel()
  1388.     end
  1389.  
  1390.     spr_old = issprinting
  1391.     is_old = issighting
  1392.  
  1393.     if SERVER then
  1394.         hudhangtime = owent:GetInfoNum("cl_tfa_hud_hangtime", 1)
  1395.     else
  1396.         hudhangtime = hudhangtime_cvar:GetFloat()
  1397.     end
  1398.  
  1399.     if isfidgeting and ct > fe then
  1400.         isfidgeting = false
  1401.         self:SetFidgeting(false)
  1402.     end
  1403.  
  1404.     if not isfidgeting and fe > 0 then
  1405.         fe = -1
  1406.         self:SetFidgetingEnd(-1)
  1407.     end
  1408.  
  1409.     if isdrawing and ct > self:GetDrawingEnd() then
  1410.         if IsValid(self.OwnerViewModel) then
  1411.             self.DefaultAtt = self.OwnerViewModel:GetAttachment(self:GetFPMuzzleAttachment())
  1412.         end
  1413.  
  1414.         self:SetDrawing(false)
  1415.         isdrawing = false
  1416.     end
  1417.  
  1418.     if isbolttimer and ct > bte then
  1419.         isbolttimer = false
  1420.         self:SetBoltTimer(false)
  1421.         self:SetBoltTimerStart(ct - 1)
  1422.         self:SetBoltTimerEnd(ct - 1)
  1423.     end
  1424.  
  1425.     if isreloading and ct > self:GetReloadingEnd() then
  1426.         if not self.Shotgun then
  1427.             self:CompleteReload()
  1428.             isreloading = false
  1429.         else
  1430.             self:ShotgunReload(ct)
  1431.         end
  1432.     end
  1433.  
  1434.     if isholstering and ct > self:GetHolsteringEnd() then
  1435.         self:SetCanHolster(true)
  1436.         self:SetHolstering(false)
  1437.  
  1438.         if IsFirstTimePredicted() and (CLIENT or sp) then
  1439.             self:CleanModels(self.VElements)
  1440.             self:CleanModels(self.WElements)
  1441.         end
  1442.  
  1443.         if SERVER then
  1444.             stwep = self:GetSwapTarget()
  1445.  
  1446.             if IsValid(stwep) then
  1447.                 if stwep == owent then
  1448.                     self:WeaponUse( owent )
  1449.                 else
  1450.                     self.Owner:SelectWeapon(stwep:GetClass())
  1451.                 end
  1452.             end
  1453.         end
  1454.     end
  1455.  
  1456.     if isbursting and ct > self:GetNextBurst() then
  1457.         mb = self:GetMaxBurst()
  1458.  
  1459.         if self:GetBurstCount() >= mb then
  1460.             self:SetBursting(false)
  1461.             self:SetBurstCount(0)
  1462.             del = self:GetBurstDelay(mb)
  1463.             self:SetNextPrimaryFire(math.max(ct + del, self:GetNextPrimaryFire()))
  1464.         else
  1465.             self:PrimaryAttack()
  1466.         end
  1467.     end
  1468.  
  1469.     if isshooting and ct > self:GetShootingEnd() then
  1470.         self:SetShooting(false)
  1471.         isshooting = false
  1472.     end
  1473.  
  1474.     if isfiremodechanging and ct > self:GetFireModeChangeEnd() then
  1475.         self:SetFireModeChanging(false)
  1476.         self:SetFireModeChangeEnd(ct - 1)
  1477.     end
  1478.  
  1479.     if ischangingsilence and ct > self:GetNextSilenceChange() then
  1480.         self:SetSilenced(not self:GetSilenced())
  1481.         self:SetChangingSilence(false)
  1482.         self:SetNextSilenceChange(ct - 1)
  1483.         self:UpdateMuzzleAttachment()
  1484.     end
  1485.  
  1486.     if not (isreloading or isshooting or isdrawing or isholstering or ischangingsilence or isfiremodechanging) and self:GetNextIdleAnim() < ct then
  1487.  
  1488.         if not self.DisableIdleAnimations then
  1489.             success, tanim = self:ChooseIdleAnim()
  1490.         end
  1491.  
  1492.         local vm = vm or self.OwnerViewModel
  1493.         local animtime
  1494.  
  1495.         if IsValid(vm) then
  1496.             animtime = vm:SequenceDuration()
  1497.         else
  1498.             animtime = self.SequenceLength[tanim] or 1
  1499.         end
  1500.  
  1501.         if self.SequenceLengthOverride[tanim] then
  1502.             animtime = self.SequenceLengthOverride[tanim]
  1503.         end
  1504.  
  1505.         self:SetNextIdleAnim(ct + animtime)
  1506.     end
  1507.  
  1508.     --[[UserInput]]
  1509.     issighting = false
  1510.     issprinting = false
  1511.  
  1512.     if IsValid(owent) then
  1513.         if not (self.data and self.data.ironsights == 0) then
  1514.             if CLIENT then
  1515.                 if not ironsights_toggle_cvar:GetBool() then
  1516.                     if owent:KeyDown(IN_ATTACK2) then
  1517.                         issighting = true
  1518.                     end
  1519.                 else
  1520.                     issighting = self:GetIronSightsRaw()
  1521.  
  1522.                     if owent:KeyPressed(IN_ATTACK2) then
  1523.                         issighting = not issighting
  1524.                         self:SetIronSightsRaw(issighting)
  1525.                     end
  1526.                 end
  1527.             else
  1528.                 if owent:GetInfoNum("cl_tfa_ironsights_toggle", 0) == 0 then
  1529.                     if owent:KeyDown(IN_ATTACK2) then
  1530.                         issighting = true
  1531.                     end
  1532.                 else
  1533.                     issighting = self:GetIronSightsRaw()
  1534.  
  1535.                     if owent:KeyPressed(IN_ATTACK2) then
  1536.                         issighting = not issighting
  1537.                         self:SetIronSightsRaw(issighting)
  1538.                     end
  1539.                 end
  1540.             end
  1541.         end
  1542.  
  1543.         isnumber = issighting and 0 or 1
  1544.         rsnumber = issprinting and 1 or 0
  1545.  
  1546.         if owent:KeyDown(IN_SPEED) and owent:GetVelocity():Length() > owent:GetWalkSpeed() * (self.MoveSpeed * (1 - isnumber) + self.IronSightsMoveSpeed * isnumber ) then
  1547.             issprinting = true
  1548.         end
  1549.     end
  1550.  
  1551.     --[[IronsSprint]]
  1552.     nw = false
  1553.  
  1554.     if self:GetUnpredictedHolstering() or self.IsHolding then
  1555.         isholstering = true
  1556.     end
  1557.  
  1558.     if owent.TFACasting or (owent.tfacastoffset and owent.tfacastoffset > 0.1) then
  1559.         issprinting = false
  1560.     end
  1561.  
  1562.     if self:Clip1() == 0 and (not dryfire_cvar:GetBool()) then
  1563.         if self:GetBursting() then
  1564.             self:SetBursting(false)
  1565.             self:SetNextBurst(ct - 1)
  1566.             self:SetBurstCount(0)
  1567.         end
  1568.     elseif self:Clip1() < 0 and IsValid(owent) and self:GetAmmoReserve() <= 0 and (not dryfire_cvar:GetBool()) then
  1569.         if self:GetBursting() then
  1570.             self:SetBursting(false)
  1571.             self:SetNextBurst(ct - 1)
  1572.             self:SetBurstCount(0)
  1573.         end
  1574.     end
  1575.  
  1576.     if self:GetNearWallRatio() > 0.01 then
  1577.         nw = true
  1578.     end
  1579.  
  1580.     if self.IsHolding or (isbolttimer and ct > bts and ct < bte) then
  1581.         issighting = false
  1582.     end
  1583.  
  1584.     if (bash) then
  1585.         if issighting then
  1586.             issighting = false
  1587.         end
  1588.  
  1589.         if issprinting then
  1590.             issprinting = false
  1591.         end
  1592.  
  1593.         if isinspecting then
  1594.             self:SetInspecting(false)
  1595.             isinspecting = false
  1596.         end
  1597.  
  1598.         if isbursting then
  1599.             isbursting = false
  1600.             self:SetBursting(false)
  1601.             self:SetNextBurst(CurTime() - 1)
  1602.             self:SetBurstCount(0)
  1603.         end
  1604.  
  1605.         if nw then
  1606.             self:SetNearWall(false)
  1607.             nw = false
  1608.         end
  1609.     end
  1610.  
  1611.     if (issprinting or self:IsSafety()) then
  1612.         issighting = false
  1613.  
  1614.         if isinspecting then
  1615.             self:SetInspecting(false)
  1616.             isinspecting = false
  1617.         end
  1618.  
  1619.         if isbursting then
  1620.             self:SetBursting(false)
  1621.             self:SetNextBurst(ct - 1)
  1622.             self:SetBurstCount(0)
  1623.             isbursting = false
  1624.         end
  1625.     end
  1626.  
  1627.     if isfidgeting then
  1628.         if (issighting) then
  1629.             self:ChooseIdleAnim()
  1630.             self:SetFidgeting(false)
  1631.             isfidgeting = false
  1632.         elseif (isshooting) then
  1633.             self:SetFidgeting(false)
  1634.             isfidgeting = false
  1635.         elseif (issprinting) then
  1636.             self:ChooseIdleAnim()
  1637.             self:SetFidgeting(false)
  1638.             isfidgeting = false
  1639.         end
  1640.     end
  1641.  
  1642.     if (isinspecting) then
  1643.         issighting = false
  1644.     end
  1645.  
  1646.     if (ischangingsilence) then
  1647.         issighting = false
  1648.  
  1649.         if isbursting then
  1650.             self:SetBursting(false)
  1651.             self:SetNextBurst(ct - 1)
  1652.             self:SetBurstCount(0)
  1653.             isbursting = false
  1654.         end
  1655.     end
  1656.  
  1657.     if self.UnSightOnReload and isreloading then
  1658.         issighting = false
  1659.  
  1660.         if isinspecting then
  1661.             self:SetInspecting(false)
  1662.             self:SetInspectingRatio(0)
  1663.             isinspecting = false
  1664.         end
  1665.     end
  1666.  
  1667.     if isdrawing and not self.SightWhileDraw then
  1668.         if isinspecting then
  1669.             self:SetInspecting(false)
  1670.             self:SetInspectingRatio(0)
  1671.             isinspecting = false
  1672.         end
  1673.  
  1674.         issighting = false
  1675.  
  1676.         if isfidgeting then
  1677.             self:SetFidgeting(false)
  1678.             isfidgeting = false
  1679.         end
  1680.     end
  1681.  
  1682.     if (isholstering) then
  1683.         issighting = false
  1684.  
  1685.         if isinspecting then
  1686.             self:SetInspecting(false)
  1687.             self:SetInspectingRatio(0)
  1688.             isinspecting = false
  1689.         end
  1690.  
  1691.         self:SetBursting(false)
  1692.  
  1693.         if not self.SightWhileHolster then
  1694.             issighting = false
  1695.         end
  1696.  
  1697.         if isfidgeting then
  1698.             self:SetFidgeting(false)
  1699.             isfidgeting = false
  1700.         end
  1701.     end
  1702.  
  1703.     if (nw) then
  1704.         issighting = false
  1705.  
  1706.         if isinspecting then
  1707.             self:SetInspecting(false)
  1708.             isinspecting = false
  1709.         end
  1710.  
  1711.         if isbursting then
  1712.             self:SetBursting(false)
  1713.             self:SetNextBurst(ct - 1)
  1714.             self:SetBurstCount(0)
  1715.             isbursting = false
  1716.         end
  1717.  
  1718.         if isfidgeting then
  1719.             self:ChooseIdleAnim()
  1720.             self:SetFidgeting(false)
  1721.             isfidgeting = false
  1722.         end
  1723.     end
  1724.  
  1725.     if (is_old ~= issighting) then
  1726.         if ((CLIENT and IsFirstTimePredicted()) or (SERVER and sp)) then
  1727.             if (issighting == false) then
  1728.                 self:EmitSound(self.IronOutSound or "TFA.IronOut")
  1729.             else
  1730.                 self:EmitSound(self.IronInSound or "TFA.IronIn")
  1731.             end
  1732.         end
  1733.  
  1734.         self:SetIronSights(issighting)
  1735.  
  1736.         if ((CLIENT and not ironsights_resight_cvar:GetBool()) or (SERVER and owent:GetInfoNum("cl_tfa_ironsights_resight", 0) == 0)) then
  1737.             self:SetIronSightsRaw(issighting)
  1738.         end
  1739.     end
  1740.  
  1741.     if spr_old ~= issprinting then
  1742.         self:SetSprinting(issprinting)
  1743.     end
  1744.  
  1745.     --[[Serverside Update Functions]]--
  1746.     isnumber = issighting and 1 or 0
  1747.     rsnumber = issprinting and 1 or 0
  1748.  
  1749.     if SERVER then
  1750.         --if !sp then
  1751.         self:CalculateNearWallSH()
  1752.         --end
  1753.         compensatedft = ft / (self.IronSightTime * 0.4)
  1754.         compensatedft_sp = ft / ((self.RunSightTime and self.RunSightTime or self.IronSightTime * 2) * 0.4)
  1755.         compensatedft_cr = ft / self.ToCrouchTime
  1756.         newratio = l_mathApproach(isr, isnumber, (isnumber - isr) * compensatedft)
  1757.  
  1758.         if math.abs(newratio - isr) > tonetwork_thresh then
  1759.             self:SetIronSightsRatio(newratio)
  1760.         end
  1761.  
  1762.         newratio = l_mathApproach(rsr, rsnumber, (rsnumber - rsr) * compensatedft_sp)
  1763.  
  1764.         if math.abs(newratio - rsr) > tonetwork_thresh then
  1765.             self:SetRunSightsRatio(newratio)
  1766.         end
  1767.  
  1768.         if inspr > tonetwork_thresh then
  1769.             self:SetInspectingRatio(l_mathApproach(inspr, isinspecting and 1 or 0, ft / self.IronSightTime))
  1770.         end
  1771.  
  1772.         self.CrouchingRatioV = l_mathApproach(self.CrouchingRatioV or 0, owent:Crouching() and 1 or 0, ft / self.ToCrouchTime)
  1773.         self.JumpingRatioV = l_mathApproach(self.JumpingRatioV or 0, owent:IsOnGround() and 0 or 1, ft / self.ToCrouchTime)
  1774.  
  1775.         if self.CrouchingRatioV > tonetwork_thresh then
  1776.             self:SetCrouchingRatio(self.CrouchingRatioV)
  1777.         end
  1778.  
  1779.         if self.JumpingRatioV > tonetwork_thresh then
  1780.             self:SetJumpingRatio(self.JumpingRatioV)
  1781.         end
  1782.  
  1783.         if self.Primary.SpreadRecovery then
  1784.             self.SpreadRatioV = l_mathClamp(self:GetSpreadRatio() - self.Primary.SpreadRecovery * ft, 1, self.Primary.SpreadMultiplierMax)
  1785.  
  1786.             if self.SpreadRatioV > tonetwork_thresh then
  1787.                 self:SetSpreadRatio(self.SpreadRatioV)
  1788.             end
  1789.         end
  1790.     end
  1791.  
  1792.     --[[Clientside Caching]]
  1793.     --
  1794.     if CLIENT then
  1795.         self.cl_cache_isreloading = isreloading
  1796.         self.cl_cache_isbolting = isbolttimer
  1797.         self.cl_cache_isfmc = isfiremodechanging
  1798.     end
  1799. end
  1800.  
  1801. --[[
  1802. Function Name:  PreDrawOpaqueRenderables
  1803. Syntax: self:PreDrawOpaqueRenderables()
  1804. Returns:  Nothing.
  1805. Notes: Does SWEP.Offset
  1806. Purpose:  Feature
  1807. ]]--
  1808. function SWEP:PreDrawOpaqueRenderables()
  1809. if self.Callback.PreDrawOpaqueRenderables then
  1810.     local val = self.Callback.PreDrawOpaqueRenderables(self)
  1811.     if val then return val end
  1812. end
  1813. end
  1814.  
  1815. --[[
  1816. Function Name:  CycleFireMode
  1817. Syntax: self:CycleFireMode()
  1818. Returns:  Nothing.
  1819. Notes: Cycles to next firemode.
  1820. Purpose:  Feature
  1821. ]]--
  1822. function SWEP:CycleFireMode()
  1823.     local fm = self:GetFireMode()
  1824.     fm = fm + 1
  1825.  
  1826.     if fm >= #self.FireModes then
  1827.         fm = 1
  1828.     end
  1829.  
  1830.     self:SetFireMode(fm)
  1831.     if IsFirstTimePredicted() then
  1832.         self:EmitSound("Weapon_AR2.Empty")
  1833.     end
  1834.     self:SetNextBurst(l_CT() + math.max(1 / (self:GetRPM() / 60), 0.25))
  1835.     self:SetNextPrimaryFire(l_CT() + math.max(1 / (self:GetRPM() / 60), 0.25))
  1836.     self:SetFireModeChanging(true)
  1837.     self:SetFireModeChangeEnd(l_CT() + math.max(1 / (self:GetRPM() / 60), 0.25))
  1838. end
  1839.  
  1840. --[[
  1841. Function Name:  CycleSafety
  1842. Syntax: self:CycleSafety()
  1843. Returns:  Nothing.
  1844. Notes: Toggles safety
  1845. Purpose:  Feature
  1846. ]]--
  1847. function SWEP:CycleSafety()
  1848.     ct = l_CT()
  1849.     local fm = self:GetFireMode()
  1850.  
  1851.     if fm ~= #self.FireModes then
  1852.         self.LastFireMode = fm
  1853.         self:SetFireMode(#self.FireModes)
  1854.     else
  1855.         self:SetFireMode(self.LastFireMode or 1)
  1856.     end
  1857.  
  1858.     self:EmitSound("Weapon_AR2.Empty")
  1859.     self:SetNextBurst(ct + math.max(1 / (self:GetRPM() / 60), 0.25))
  1860.     self:SetNextPrimaryFire(ct + math.max(1 / (self:GetRPM() / 60), 0.25))
  1861.     self:SetFireModeChanging(true)
  1862.     self:SetFireModeChangeEnd(ct + math.max(1 / (self:GetRPM() / 60), 0.25))
  1863. end
  1864.  
  1865. --[[
  1866. Function Name:  ProcessFireMode
  1867. Syntax: self:ProcessFireMode()
  1868. Returns:  Nothing.
  1869. Notes: Processes fire mode changing and whether the swep is auto or not.
  1870. Purpose:  Feature
  1871. ]]--
  1872. local fm
  1873.  
  1874. function SWEP:ProcessFireMode()
  1875.     if self.Callback.ProcessFireMode then
  1876.         local val = self.Callback.ProcessFireMode(self)
  1877.         if val then return val end
  1878.     end
  1879.  
  1880.     fm = self.FireModes[self:GetFireMode()]
  1881.  
  1882.     if fm == "Automatic" or fm == "Auto" then
  1883.         self.Primary.Automatic = true
  1884.     else
  1885.         self.Primary.Automatic = false
  1886.     end
  1887. end
  1888.  
  1889. --[[
  1890. Function Name:  CanPrimaryAttack
  1891. Syntax: self:CanPrimaryAttack()
  1892. Returns:  True/false can we shoot
  1893. Notes: Set clip to -1 to use reserve.
  1894. Purpose:  Main SWEP function
  1895. ]]--
  1896. function SWEP:CanPrimaryAttack()
  1897.     if self.Primary.NumShots > 1 then
  1898.         if (self:Clip1() < 1 and self.Primary.ClipSize ~= -1) then
  1899.             if not self.HasPlayedEmptyClick then
  1900.                 self:EmitSound("Weapon_Pistol.Empty")
  1901.                 self.HasPlayedEmptyClick = true
  1902.             end
  1903.  
  1904.             self:SetNextPrimaryFire(l_CT() + 1 / (self:GetRPM() / 60))
  1905.  
  1906.             if not dryfire_cvar:GetBool() then
  1907.                 self:Reload( true )
  1908.             end
  1909.  
  1910.             return false
  1911.         elseif (self.Primary.ClipSize == -1 and self:Ammo1() < 1) then
  1912.             return false
  1913.         end
  1914.     else
  1915.         if (self:Clip1() < self.Primary.AmmoConsumption and self.Primary.ClipSize ~= -1) then
  1916.             if not self.HasPlayedEmptyClick then
  1917.                 self:EmitSound("Weapon_Pistol.Empty")
  1918.                 self.HasPlayedEmptyClick = true
  1919.             end
  1920.  
  1921.             self:SetNextPrimaryFire(l_CT() + 1 / (self:GetRPM() / 60))
  1922.  
  1923.             if not dryfire_cvar:GetBool() then
  1924.                 self:Reload( true )
  1925.             end
  1926.  
  1927.             return false
  1928.         elseif (self.Primary.ClipSize == -1 and self:Ammo1() < self.Primary.AmmoConsumption) then
  1929.             return false
  1930.         end
  1931.     end
  1932.  
  1933.     self.HasPlayedEmptyClick = false
  1934.  
  1935.     return true
  1936. end
  1937. --[[
  1938. Function Name:  PrimaryAttack
  1939. Syntax: self:PrimaryAttack().  However, to shoot a bullet, ShootBulletInformation or ShootBullet should be called.  This is really only for when the player or the burst fire mechanism willingly fires.
  1940. Returns:  Nothing.
  1941. Notes: Called when you try to primaryattack.
  1942. Purpose:  Main SWEP function
  1943. ]]--
  1944.  
  1945. function SWEP:PrimaryAttack()
  1946.     if self.Callback.PrimaryAttack then
  1947.         local val = self.Callback.PrimaryAttack(self)
  1948.         if val then return val end
  1949.     end
  1950.  
  1951.     if not self:OwnerIsValid() then return end
  1952.     self:UpdateConDamage()
  1953.  
  1954.     if (self:GetHolstering()) then
  1955.         if (self.ShootWhileHolster == false) then
  1956.             return
  1957.         else
  1958.             self:SetHolsteringEnd(l_CT() - 0.1)
  1959.             self:SetHolstering(false)
  1960.             self:SetUnpredictedHolstering(false)
  1961.         end
  1962.     end
  1963.  
  1964.     if (self:GetReloading() and self.Shotgun and not self:GetShotgunPumping() and not self:GetShotgunNeedsPump()) then
  1965.         self:SetShotgunCancel(true)
  1966.         --[[
  1967.         self:SetShotgunInsertingShell(true)
  1968.         self:SetShotgunPumping(false)
  1969.         self:SetShotgunNeedsPump(true)
  1970.         self:SetReloadingEnd(l_CT()-1)
  1971.         ]]--
  1972.  
  1973.         return
  1974.     end
  1975.  
  1976.     if self:IsSafety() then
  1977.         self:EmitSound("Weapon_AR2.Empty")
  1978.         self.LastSafetyShoot = self.LastSafetyShoot or 0
  1979.  
  1980.         if l_CT() < self.LastSafetyShoot + 0.2 then
  1981.             self:CycleSafety()
  1982.         end
  1983.  
  1984.         self.LastSafetyShoot = l_CT()
  1985.  
  1986.         return
  1987.     end
  1988.  
  1989.     if (self:GetChangingSilence()) then return end
  1990.     if (self:GetNearWallRatio() > 0.05) then return end
  1991.     if not self:OwnerIsValid() then return end
  1992.  
  1993.     if self.FiresUnderwater == false and self.Owner:WaterLevel() >= 3 then
  1994.         if self:CanPrimaryAttack() then
  1995.             self:SetNextPrimaryFire(l_CT() + 0.5)
  1996.             self:EmitSound("Weapon_AR2.Empty")
  1997.         end
  1998.  
  1999.         return
  2000.     end
  2001.  
  2002.     if (self.Owner:KeyDown(IN_USE) and self.CanBeSilenced and self.Owner:KeyPressed(IN_ATTACK)) then
  2003.         if (self:CanPrimaryAttack() and not self:GetChangingSilence()) then
  2004.             --self:SetSilenced(!self:GetSilenced())
  2005.             success, tanim = self:ChooseSilenceAnim(not self:GetSilenced())
  2006.             self:SetChangingSilence(true)
  2007.             self:SetNextSilenceChange(l_CT() + self.SequenceLength[tanim])
  2008.             self:SetNextPrimaryFire(l_CT() + 1 / (self:GetRPM() / 60))
  2009.         end
  2010.  
  2011.         return
  2012.     end
  2013.  
  2014.     if self:GetNextPrimaryFire() > l_CT() then return end
  2015.  
  2016.     if self:GetReloading() then
  2017.         self:CompleteReload()
  2018.     end
  2019.  
  2020.     if not self:CanPrimaryAttack() then return end
  2021.  
  2022.     --if self.Owner:IsPlayer() then
  2023.     if self:GetRunSightsRatio() < 0.1 then
  2024.         self.ProceduralHolsterFactor = 0
  2025.         self:SetHolstering(false)
  2026.         self:SetUnpredictedHolstering(false)
  2027.         self:ResetEvents()
  2028.         self:SetInspecting(false)
  2029.         self:SetInspectingRatio(0)
  2030.         self:SetInspectingRatio(0)
  2031.         --self:SendViewModelAnim(0)
  2032.         self:ToggleAkimbo(false)
  2033.         self:ShootBulletInformation(SERVER or (CLIENT and IsFirstTimePredicted()))
  2034.         success, tanim = self:ChooseShootAnim(SERVER or (CLIENT and IsFirstTimePredicted())) -- View model animation
  2035.  
  2036.         if self:OwnerIsValid() and self.Owner.SetAnimation then
  2037.             self.Owner:SetAnimation(PLAYER_ATTACK1) -- 3rd Person Animation
  2038.         end
  2039.  
  2040.         self:TakePrimaryAmmo(math.min(self.Primary.AmmoConsumption, self.Primary.ClipSize > 0 and self:Clip1() or self:Ammo1()))
  2041.         self.PenetrationCounter = 0
  2042.         self:SetShooting(true)
  2043.         self:SetShootingEnd(l_CT() + self.OwnerViewModel:SequenceDuration())
  2044.  
  2045.         if self.BoltAction then
  2046.             self:SetBoltTimer(true)
  2047.             local t1, t2
  2048.             t1 = l_CT() + self.BoltTimerOffset
  2049.             t2 = l_CT() + (self.SequenceLengthOverride[tanim] or self.OwnerViewModel:SequenceDuration())
  2050.  
  2051.             if t1 < t2 then
  2052.                 self:SetBoltTimerStart(t1)
  2053.                 self:SetBoltTimerEnd(t2)
  2054.             else
  2055.                 self:SetBoltTimerStart(t2)
  2056.                 self:SetBoltTimerEnd(t1)
  2057.             end
  2058.         end
  2059.  
  2060.         CurrentCone, CurrentRecoil = self:CalculateConeRecoil()
  2061.         self:Recoil(CurrentRecoil, SERVER or (CLIENT and IsFirstTimePredicted()))
  2062.         self:SetSpreadRatio(l_mathClamp(self:GetSpreadRatio() + self.Primary.SpreadIncrement, 1, self.Primary.SpreadMultiplierMax))
  2063.  
  2064.         if (CLIENT or sp) and IsFirstTimePredicted() then
  2065.             self.CLSpreadRatio = l_mathClamp(self.CLSpreadRatio + self.Primary.SpreadIncrement, 1, self.Primary.SpreadMultiplierMax)
  2066.         end
  2067.  
  2068.         self:SetBursting(true)
  2069.         self:SetNextBurst(l_CT() + 1 / (self:GetRPM() / 60))
  2070.         self:SetBurstCount(self:GetBurstCount() + 1)
  2071.         self:SetNextPrimaryFire(l_CT() + 1 / (self:GetRPM() / 60))
  2072.  
  2073.         if self.Akimbo then
  2074.             self:SetNextSecondaryFire(math.max(self:GetNextSecondaryFire(), l_CT() + 0.01))
  2075.         end
  2076.  
  2077.         if not self:GetSilenced() then
  2078.             if self.Primary.Sound then
  2079.                 self:PlaySound(self.Primary.SoundTable and self.Primary.SoundTable or self.Primary.Sound)
  2080.             end
  2081.         else
  2082.             if self.Primary.SilencedSound then
  2083.                 self:PlaySound(self.Primary.SilencedSound)
  2084.             elseif self.Primary.Sound then
  2085.                 self:PlaySound(self.Primary.SoundTable and self.Primary.SoundTable or self.Primary.Sound)
  2086.             end
  2087.         end
  2088.  
  2089.         if self.EjectionSmoke and (SERVER or (CLIENT and IsFirstTimePredicted())) and not (self.LuaShellEject and self.LuaShellEjectDelay > 0) then
  2090.             self:EjectionSmoke()
  2091.         end
  2092.  
  2093.         self:DoAmmoCheck()
  2094.     end
  2095. end
  2096.  
  2097. --[[
  2098. Function Name:  PlayerThink
  2099. Syntax: self:PlayerThink( player ).  Shouldn't be called manually usually, just on each think tick.
  2100. Returns:  Nothing.
  2101. Notes: Critical to processing the ironsights progress and stuff.
  2102. Purpose:  Main SWEP function
  2103. ]]--
  2104.  
  2105. function SWEP:PlayerThink(ply)
  2106.     if self.Callback.PlayerThink then
  2107.         local val = self.Callback.PlayerThink(self, ply)
  2108.         if val then return val end
  2109.     end
  2110.  
  2111.     heldentindex = self.Owner:GetNW2Int("LastHeldEntityIndex", -1)
  2112.     heldent = Entity(heldentindex)
  2113.  
  2114.     if heldentindex ~= -1 and IsValid(heldent) and heldent.IsPlayerHolding and not heldent:IsPlayerHolding() then
  2115.         self.Owner:SetNW2Int("LastHeldEntityIndex", -1)
  2116.         heldent = nil
  2117.     end
  2118.  
  2119.     if (CLIENT and ply == self.Owner) or SERVER then
  2120.         self:Think2()
  2121.     end
  2122.  
  2123.     if SERVER and self.PlayerThinkServer then
  2124.         self:PlayerThinkServer(ply)
  2125.         self:ProcessEffects()
  2126.     end
  2127.  
  2128.     if CLIENT and ply == self.Owner then
  2129.         self:PlayerThinkClient(ply)
  2130.     end
  2131. end
  2132.  
  2133. --[[
  2134. Function Name:  PlayerThinkServer
  2135. Syntax: self:PlayerThinkServer( player ).  Shouldn't be called manually, since it's called by SWEP:PlayerThink().
  2136. Returns:  Nothing.
  2137. Notes: Unused ATM.
  2138. Purpose:  Main SWEP function
  2139. ]]--
  2140. function SWEP:PlayerThinkServer(ply)
  2141.     if self.Callback.PlayerThinkServer then
  2142.         local val = self.Callback.PlayerThinkServer(self, ply)
  2143.         if val then return val end
  2144.     end
  2145. end
  2146.  
  2147. --[[
  2148. Function Name:  PlayerThinkClient
  2149. Syntax: self:PlayerThinkClient( player ).  Shouldn't be called manually, since it's called by SWEP:PlayerThink().
  2150. Returns:  Nothing.
  2151. Notes: Unused ATM.
  2152. Purpose:  Main SWEP function
  2153. ]]--
  2154. function SWEP:PlayerThinkClient(ply)
  2155.     if self.Callback.PlayerThinkClient then
  2156.         local val = self.Callback.PlayerThinkClient(self, ply)
  2157.         if val then return val end
  2158.     end
  2159. end
  2160.  
  2161. --[[
  2162. Function Name:  ProcessEvents
  2163. Syntax: self:ProcessEvents( ).
  2164. Returns:  Nothing.
  2165. Notes: Critical for the event table to function.
  2166. Purpose:  Main SWEP function
  2167. ]]--
  2168. function SWEP:ProcessEvents()
  2169.     if not self:OwnerIsValid() then return end
  2170.  
  2171.     if self.Callback.ProcessEvents then
  2172.         local val = self.Callback.ProcessEvents(self)
  2173.         if val then return val end
  2174.     end
  2175.  
  2176.     --if sp and !CLIENT then self:CallOnClient("ProcessEvents","") end
  2177.     if not IsValid(self.OwnerViewModel) then return end
  2178.     local actv = self:GetLastActivity()
  2179.     self.lastact = actv
  2180.  
  2181.     local evtbl = self.EventTable[actv]
  2182.  
  2183.     if not self.lastlastact then
  2184.         self.lastlastact = 0
  2185.     end
  2186.  
  2187.     if self.lastlastact ~= actv then
  2188.         self:ResetEvents()
  2189.     end
  2190.  
  2191.     self.lastlastact = actv
  2192.  
  2193.     if not evtbl then return end
  2194.     for k, v in pairs(evtbl) do
  2195.         if v.called or l_CT() < self.EventTimer + v.time then continue end
  2196.         v.called = true
  2197.  
  2198.         if v.client == nil then
  2199.             v.client = true
  2200.         end
  2201.  
  2202.         if v.type == "lua" then
  2203.             if v.server == nil then
  2204.                 v.server = true
  2205.             end
  2206.  
  2207.             if (v.client and CLIENT and (not v.client_predictedonly or self.Owner == LocalPlayer())) or (v.server and SERVER) and v.value then
  2208.                 v.value(self, self.OwnerViewModel)
  2209.             end
  2210.         elseif v.type == "snd" or v.type == "sound" then
  2211.             if v.server == nil then
  2212.                 v.server = false
  2213.             end
  2214.  
  2215.             if SERVER then
  2216.                 if v.client then
  2217.                     net.Start("tfaSoundEvent")
  2218.                     net.WriteEntity(self)
  2219.                     net.WriteString(v.value or "")
  2220.  
  2221.                     if sp then
  2222.                         net.Broadcast()
  2223.                     else
  2224.                         net.SendOmit(self.Owner)
  2225.                     end
  2226.                 elseif v.server and v.value and v.value ~= "" then
  2227.                     self:EmitSound(v.value)
  2228.                 end
  2229.             elseif v.client and self.Owner == LocalPlayer() and not sp and v.value and v.value ~= "" then
  2230.                 self:EmitSound(v.value)
  2231.             end
  2232.         end
  2233.     end
  2234. end
  2235.  
  2236. --[[
  2237. Function Name:  PlayerThinkClientFrame
  2238. Syntax: self:PlayerThinkClientFrame( player ).  Shouldn't be called manually, since it's called by before each frame.
  2239. Returns:  Nothing.
  2240. Notes: Critical for the clientside/predicted ironsights.
  2241. Purpose:  Main SWEP function
  2242. ]]--
  2243.  
  2244. function SWEP:PlayerThinkClientFrame(ply)
  2245.     self.DefaultFOV = TFADUSKFOV or ply:GetFOV()
  2246.     self:CorrectScopeFOV(self.DefaultFOV)
  2247.  
  2248.     self:UpdateViewModel()
  2249.     tsv = 1
  2250.  
  2251.     if sv_cheats_cv:GetBool() then
  2252.         tsv = tsv * host_timescale_cv:GetFloat()
  2253.     end
  2254.  
  2255.     tsv = tsv * game.GetTimeScale()
  2256.     rtime = l_RT()
  2257.     RealFrameTime = rtime - (self.lastrealtime or rtime)
  2258.     self.rft = RealFrameTime
  2259.     self.lastrealtime = rtime
  2260.  
  2261.     if self.Callback.PlayerThinkClientFrame then
  2262.         local val = self.Callback.PlayerThinkClientFrame(self, ply)
  2263.         if val then return val end
  2264.     end
  2265.  
  2266.     self:ProcessEffects()
  2267.     self:CalculateNearWallCLF(RealFrameTime)
  2268.     self:ViewModelFlipFunc()
  2269.     is = self:GetIronSights() and 1 or 0
  2270.     insp = self:GetInspecting() and 1 or 0
  2271.     rel_proc = self:GetReloading() and not legacy_reloads_cv:GetBool()
  2272.  
  2273.     if self.Owner.TFACasting or (self.Owner.tfacastoffset and self.Owner.tfacastoffset > 0.1) then
  2274.         rel_proc = true
  2275.     end
  2276.  
  2277.     rs = ((self:GetSprinting() or self:IsSafety()) and not rel_proc) and 1 or 0
  2278.     isr = self.CLIronSightsProgress
  2279.     rsr = self.CLRunSightsProgress
  2280.     inspr = self.CLInspectingProgress
  2281.     crouchr = self.CLCrouchProgress
  2282.     jumpr = self.CLJumpProgress
  2283.     ftv = math.max(RealFrameTime, 1 / fps_max_cvar:GetFloat()) * tsv
  2284.     ftvc = ftv
  2285.     seq = 0
  2286.     act = -2
  2287.  
  2288.     if IsValid(self.OwnerViewModel) then
  2289.         seq = self.OwnerViewModel:GetSequence()
  2290.         act = self.OwnerViewModel:GetSequenceActivity(seq)
  2291.     end
  2292.  
  2293.     compensatedft = ftv / (self.IronSightTime * 0.4)
  2294.     compensatedft_sp = ftv / ((self.RunSightTime or self.IronSightTime * 2) * 0.4)
  2295.     compensatedft_cr = ftv / self.ToCrouchTime
  2296.     newratio = l_mathApproach(isr, is, (is - isr) * compensatedft)
  2297.     self.CLIronSightsProgress = newratio
  2298.     newratio = l_mathApproach(rsr, rs, (rs - rsr) * compensatedft_sp)
  2299.     self.CLRunSightsProgress = newratio
  2300.     newratio = l_mathApproach(crouchr, self.Owner:Crouching() and 1 or 0, compensatedft_cr)
  2301.     self.CLCrouchProgress = newratio
  2302.     newratio = l_mathApproach(inspr, insp, (insp - inspr) * compensatedft)
  2303.     self.CLInspectingProgress = newratio
  2304.     newratio = l_mathApproach(jumpr, 1 - (self.Owner:IsOnGround() and 1 or 0), compensatedft_cr)
  2305.     self.CLJumpProgress = newratio
  2306.     self.CLSpreadRatio = l_mathClamp(self.CLSpreadRatio - self.Primary.SpreadRecovery * ftv, 1, self.Primary.SpreadMultiplierMax)
  2307.     self:DoBobFrame()
  2308.  
  2309.     if not self.Blowback_PistolMode or self:Clip1() == -1 or self:Clip1() > 0.1 or self.Blowback_PistolMode_Disabled[ self:GetLastActivity() ] then
  2310.         self.BlowbackCurrent = l_mathApproach(self.BlowbackCurrent, 0, self.BlowbackCurrent * ftv * 15)
  2311.     end
  2312.  
  2313.     self.BlowbackCurrentRoot = l_mathApproach(self.BlowbackCurrentRoot, 0, self.BlowbackCurrentRoot * ftv * 15)
  2314.     heldentindex = self.Owner:GetNW2Int("LastHeldEntityIndex", -1)
  2315.     heldent = Entity(heldentindex)
  2316.  
  2317.     if heldentindex ~= -1 and IsValid(heldent) and heldent.IsPlayerHolding and not heldent:IsPlayerHolding() then
  2318.         self.Owner:SetNW2Int("LastHeldEntityIndex", -1)
  2319.         heldent = nil
  2320.     end
  2321.  
  2322.     if self:IsHidden() then
  2323.         self.Owner:DrawViewModel(false)
  2324.         local vmod = self.Owner:GetViewModel()
  2325.  
  2326.         if IsValid(vmod) and not self.hiddenHasYetToStopParticles then
  2327.             vmod:StopParticles()
  2328.             self.hiddenHasYetToStopParticles = true
  2329.         end
  2330.     else
  2331.         if self.hiddenHasYetToStopParticles then
  2332.             self.hiddenHasYetToStopParticles = false
  2333.         end
  2334.  
  2335.         self.Owner:DrawViewModel(true)
  2336.     end
  2337.  
  2338.     local nhf = 0
  2339.  
  2340.     if l_CT() > (self.HolsterEndUnpredicted or 9999999) then
  2341.         self:SetUnpredictedHolstering(false)
  2342.     end
  2343.  
  2344.     if not self.DoProceduralHolster then
  2345.         nhf = 0
  2346.     elseif self:GetHolstering() or self:GetUnpredictedHolstering() then
  2347.         nhf = 1
  2348.     end
  2349.  
  2350.     if self:GetProceduralReloading() then
  2351.         nhf = 1
  2352.     end
  2353.  
  2354.     self.ProceduralHolsterFactor = l_mathApproach(self.ProceduralHolsterFactor, nhf, math.Clamp(math.sqrt(self.ProceduralHolsterFactor), 0.1, 1) * ftv * self.ProceduralHolsterTime * 15)
  2355.  
  2356.     if self:GetDrawing() and not self:GetProceduralReloading() and nfh ~= 1 then
  2357.         self.ProceduralHolsterFactor = 0
  2358.     end
  2359. end
  2360.  
  2361. --[[
  2362. Function Name:  AltAttack
  2363. Syntax: self:AltAttack( ).
  2364. Returns:  Not sure that it returns anything.
  2365. Notes: This is called when you do +zoom
  2366. Purpose:  Main SWEP function
  2367. ]]--
  2368. function SWEP:AltAttack()
  2369.     if self.Callback.AltAttack then
  2370.         local val = self.Callback.AltAttack(self)
  2371.         if val then return val end
  2372.     end
  2373.  
  2374.     return false
  2375. end
  2376.  
  2377. --[[
  2378. Function Name:  CanCKeyInspect
  2379. Syntax: self:CanCKeyInspect( ).
  2380. Returns:  true/false.
  2381. Notes:  Can we do R-key inspection?
  2382. Purpose:
  2383. ]]--
  2384.  
  2385. function SWEP:CanCKeyInspect()
  2386.     if not ckeyvar then
  2387.         ckeyvar = GetConVar("cl_tfa_inspection_ckey")
  2388.     end
  2389.  
  2390.     if ckeyvar and CLIENT and ckeyvar:GetBool() then return true end
  2391.  
  2392.     if SERVER and self:OwnerIsValid() and self.Owner:GetInfoNum("cl_tfa_inspection_ckey", -1) == 1 then return true end
  2393.  
  2394.     return false
  2395. end
  2396.  
  2397. --[[
  2398. Function Name:  Reload
  2399. Syntax: self:Reload( ).
  2400. Returns:  Not sure that it returns anything.
  2401. Notes:  This reloads the gun, and the way it does so is slightly hacky and depends on holdtype.  Revolvers should be the only guns using revolver holdtype for this to properly function.
  2402. Purpose:  Main SWEP function
  2403. ]]--
  2404. function SWEP:Reload( released )
  2405.     if self.Callback.Reload then
  2406.         local val = self.Callback.Reload(self)
  2407.         if val then return val end
  2408.     end
  2409.  
  2410.     if self.Owner:KeyPressed(IN_RELOAD) and self.Owner:KeyDown(IN_USE) and not self:GetReloading() then
  2411.         if self.SelectiveFire and not self.Owner:KeyDown(IN_SPEED) then
  2412.             self:CycleFireMode()
  2413.         elseif self.Owner:KeyDown(IN_SPEED) then
  2414.             self:CycleSafety()
  2415.         end
  2416.         return
  2417.     end
  2418.  
  2419.     if ( not released ) and ( not legacy_reloads_cv:GetBool() ) then return end
  2420.  
  2421.     self:SetBurstCount(0)
  2422.     self:SetBursting(false)
  2423.     self:SetNextBurst(l_CT() - 1)
  2424.     if self:GetReloading() then return end
  2425.     if self.GetBashing and self:GetBashing() then return end
  2426.     isbolttimer = self:GetBoltTimer()
  2427.     if isbolttimer and (l_CT() > self:GetBoltTimerStart()) and (l_CT() < self:GetBoltTimerEnd()) then return end
  2428.  
  2429.     if legacy_reloads_cv:GetBool() and not  dryfire_cvar:GetBool() and not self.Owner:KeyDown(IN_RELOAD) then
  2430.         self:ChooseDryFireAnim()
  2431.         return
  2432.     end
  2433.  
  2434.     if legacy_reloads_cv:GetBool() and not ( self.Owner:KeyDown(IN_RELOAD) or self.Owner:KeyPressed(IN_ATTACK) ) then return end
  2435.     if (self:GetBursting()) then return end
  2436.     --if self.SelectiveFire then
  2437.     if IsValid(self.Owner) and self.Owner:KeyDown(IN_USE) then return end
  2438.  
  2439.     --end
  2440.     if self.AllowReloadWhileNearWall == false and self:GetNearWallRatio() > 0.05 then return end
  2441.  
  2442.     if (self:GetHolstering()) then
  2443.         if (self.AllowReloadWhileHolster == false) then
  2444.             return
  2445.         else
  2446.             self:SetHolsteringEnd(l_CT() - 0.1)
  2447.             self:SetHolstering(false)
  2448.             self:SetUnpredictedHolstering(false)
  2449.         end
  2450.     end
  2451.  
  2452.     if self:GetDrawing() and self.AllowReloadWhileDraw == false then return end
  2453.     if self:GetSprinting() and (not self.AllowReloadWhileSprinting and legacy_reloads_cv:GetBool()) then return end
  2454.  
  2455.     if (l_CT() < self:GetReloadingEnd()) then
  2456.         self:SetReloadingEnd(l_CT() - 1)
  2457.     end
  2458.  
  2459.     if (self:GetChangingSilence()) then return end
  2460.     if self.Primary.ClipSize == -1 then return end
  2461.  
  2462.     if (self:Clip1() < (self.Primary.ClipSize + (self:CanChamber() and 1 or 0)) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0) or (self.Akimbo and (self:Clip2() < (self.Secondary.ClipSize + (self:CanChamber() and 1 or 0)) and self.Owner:GetAmmoCount(self.Secondary.Ammo) > 0)) then
  2463.         self:SetFidgeting(false)
  2464.         self:SetReloading(true)
  2465.  
  2466.         --self:ProcessTimers()
  2467.         if self.UnSightOnReload then
  2468.             self:SetIronSights(false)
  2469.         end
  2470.  
  2471.         self:ProcessHoldType()
  2472.         self:SetInspecting(false)
  2473.         --self:SetInspectingRatio(0)
  2474.         --self:DefaultReload( ACT_VM_RELOAD )
  2475.  
  2476.         if self.DoProceduralReload then
  2477.             success, tanim = self:ChooseProceduralReloadAnim()
  2478.         elseif not self.Shotgun then
  2479.             success, tanim = self:ChooseReloadAnim()
  2480.         else
  2481.             success, tanim = self:ChooseShotgunReloadAnim()
  2482.             self:SetShotgunInsertingShell(false)
  2483.             self:SetShotgunPumping(false)
  2484.         end
  2485.  
  2486.         timer.Simple(0, function()
  2487.             if not IsValid(self) or not self:OwnerIsValid() then return end
  2488.             self:SetHoldType(self.DefaultHoldType and self.DefaultHoldType or self.HoldType)
  2489.  
  2490.             if not self.ThirdPersonReloadDisable and (SERVER or (CLIENT and not self:IsFirstPerson())) then
  2491.                 self.Owner:SetAnimation(PLAYER_RELOAD) -- 3rd Person Animation
  2492.             end
  2493.         end)
  2494.  
  2495.         if (CLIENT) then
  2496.             timer.Simple(0, function()
  2497.                 if not IsValid(self) or not self:OwnerIsValid() then return end
  2498.  
  2499.                 if not self.ThirdPersonReloadDisable and (SERVER or (CLIENT and not self:IsFirstPerson())) then
  2500.                     self.Owner:SetAnimation(PLAYER_RELOAD) -- 3rd Person Animation
  2501.                 end
  2502.             end)
  2503.         end
  2504.  
  2505.         local AnimationTime = self.Owner:GetViewModel():SequenceDuration()
  2506.         if not success then
  2507.             AnimationTime = 0
  2508.         end
  2509.  
  2510.         if self.DoProceduralReload then
  2511.             AnimationTime = self.ProceduralReloadTime
  2512.         end
  2513.  
  2514.         dt = l_CT() + (self.SequenceLengthOverride[tanim] or AnimationTime)
  2515.         self.prevdrawcount = self.drawcount
  2516.         self:SetReloadingEnd(dt)
  2517.         self.ReloadingTime = dt
  2518.         self:SetNextPrimaryFire(dt)
  2519.         self:SetNextSecondaryFire(dt)
  2520.         self:SetNextIdleAnim(l_CT() + AnimationTime)
  2521.     else
  2522.         self:CheckAmmo()
  2523.     end
  2524. end
  2525.  
  2526. function SWEP:CheckAmmo()
  2527.     if (self.SequenceEnabled[ACT_VM_FIDGET] or self.InspectionActions) and not self:GetFidgeting() and not self:GetIronSights() and not self:GetSprinting() and not self:GetFidgeting() and not self:GetInspecting() and not self:GetReloading() and not self:GetDrawing() and not self:GetChangingSilence() then
  2528.         self:SetFidgeting(true)
  2529.         succ,tanim = self:ChooseInspectAnim()
  2530.         self:SetFidgetingEnd( CurTime() + self.SequenceLength[tanim] or self.SequenceLength[tanim] or 1 )
  2531.     end
  2532. end
  2533.  
  2534. --[[
  2535. Function Name:  Sway
  2536. Syntax: self:Sway( ang ).
  2537. Returns:  New angle.
  2538. Notes:  This is used for calculating the swep viewmodel sway.
  2539. Purpose:  Main SWEP function
  2540. ]]--
  2541.  
  2542. function SWEP:Sway(pos, ang)
  2543.     if not self:OwnerIsValid() then return pos, ang end
  2544.     ang:Normalize()
  2545.     ft = (SysTime() - (self.LastSys or SysTime())) * game.GetTimeScale()
  2546.  
  2547.     if ft > l_FT() then
  2548.         ft = l_FT()
  2549.     end
  2550.  
  2551.     ft = l_mathClamp(ft, 0, 1 / 30)
  2552.  
  2553.     if sv_cheats_cv:GetBool() and host_timescale_cv:GetFloat() < 1 then
  2554.         ft = ft * host_timescale_cv:GetFloat()
  2555.     end
  2556.  
  2557.     self.LastSys = SysTime()
  2558.     --angrange = our availalbe ranges
  2559.     --rate = rate to restore our angle to the proper one
  2560.     --fac = factor to multiply by
  2561.     --each is interpolated from normal value to the ironsights value using iron sights ratio
  2562.     local angrange = l_Lerp(self:GetIronSightsRatio(), 7.5, 2.5) * gunswaycvar:GetFloat()
  2563.     local rate = l_Lerp(self:GetIronSightsRatio(), 15, 30)
  2564.     local fac = l_Lerp(self:GetIronSightsRatio(), 0.6, 0.15)
  2565.     --calculate angle differences
  2566.     anga = self.Owner:EyeAngles() - oldang
  2567.     oldang = self.Owner:EyeAngles()
  2568.     angb.y = angb.y + (0 - angb.y) * ft * 5
  2569.     angb.p = angb.p + (0 - angb.p) * ft * 5
  2570.  
  2571.     --fix jitter
  2572.     if angb.y < 50 and anga.y > 0 and anga.y < 25 then
  2573.         angb.y = angb.y + anga.y / 5
  2574.     end
  2575.  
  2576.     if angb.y > -50 and anga.y < 0 and anga.y > -25 then
  2577.         angb.y = angb.y + anga.y / 5
  2578.     end
  2579.  
  2580.     if angb.p < 50 and anga.p < 0 and anga.p < 25 then
  2581.         angb.p = angb.p - anga.p / 5
  2582.     end
  2583.  
  2584.     if angb.p > -50 and anga.p > 0 and anga.p > -25 then
  2585.         angb.p = angb.p - anga.p / 5
  2586.     end
  2587.  
  2588.     --limit range
  2589.     angb.p = l_mathClamp(angb.p, -angrange, angrange)
  2590.     angb.y = l_mathClamp(angb.y, -angrange, angrange)
  2591.     --recover
  2592.     angc.y = angc.y + (angb.y / 15 - angc.y) * ft * rate
  2593.     angc.p = angc.p + (angb.p / 15 - angc.p) * ft * rate
  2594.     --finally, blend it into the angle
  2595.     ang:RotateAroundAxis(oldang:Up(), angc.y * 15 * (self.ViewModelFlip and -1 or 1) * fac)
  2596.     ang:RotateAroundAxis(oldang:Right(), angc.p * 15 * fac)
  2597.     ang:RotateAroundAxis(oldang:Forward(), angc.y * 10 * fac)
  2598.     pos:Add(oldang:Right() * angc.y * posfac)
  2599.     pos:Add(oldang:Up() * -angc.p * posfac)
  2600.  
  2601.     return pos, util_NormalizeAngles(ang)
  2602. end
  2603.  
  2604. --[[
  2605. Function Name:  GetViewModelPosition
  2606. Syntax: self:GetViewModelPosition(pos, ang ).
  2607. Returns:  New position and angle.
  2608. Notes:  This is used for calculating the swep viewmodel position.  However, don't put per-frame logic in this.  Instead do that in PlayerThinkClientFrame
  2609. Purpose:  Main SWEP function
  2610. ]]--
  2611.  
  2612. dusk_fov = GetConVar("cl_tfa_dusk_view_fov")
  2613. fov_desired = GetConVar("fov_desired")
  2614.  
  2615. function SWEP:GetViewModelPosition(pos, ang)
  2616.     if self.Callback.GetViewModelPosition then
  2617.         local val, val2 = self.Callback.GetViewModelPosition(self, pos, ang)
  2618.         if val then return val, val2 end
  2619.     end
  2620.  
  2621.     if not self.ogviewmodelfov then
  2622.         self.ogviewmodelfov = self.ViewModelFOV
  2623.     end
  2624.  
  2625.     vmfov = self.ogviewmodelfov * fovmod_mult:GetFloat()
  2626.     vmfov = vmfov + fovmod_add:GetFloat()
  2627.     if dusk_fov then
  2628.         vmfov = vmfov / math.pow( dusk_fov:GetFloat() / ( fov_desired and fov_desired:GetFloat() or 90 ), 2 )
  2629.     end
  2630.     self.ViewModelFOV = vmfov
  2631.     pos, ang = self:Sway(pos, ang)
  2632.     if self:IsHidden() then return pos + hidevec, ang end
  2633.     isp = l_mathClamp(self.CLIronSightsProgress, 0, 1) --self:GetIronSightsRatio()
  2634.     rsp = l_mathClamp(self.CLRunSightsProgress, 0, 1) --self:GetRunSightsRatio()
  2635.     nwp = l_mathClamp(self.CLNearWallProgress, 0, 1) --self:GetNearWallRatio()
  2636.     inspectrat = l_mathClamp(self.CLInspectingProgress, 0, 1) --self:GetInspectingRatio()
  2637.     tmp_ispos = self.SightsPos and self.SightsPos or self.IronSightsPos
  2638.     tmp_isa = self.SightsAng and self.SightsAng or self.IronSightsAng
  2639.     tmp_rspos = self.RunSightsPos and self.RunSightsPos or tmp_ispos
  2640.     tmp_rsa = self.RunSightsAng and self.RunSightsAng or tmp_isa
  2641.  
  2642.     if not self.InspectPos then
  2643.         self.InspectPos = self.InspectPosDef * 1
  2644.  
  2645.         if self.ViewModelFlip then
  2646.             self.InspectPos.x = self.InspectPos.x * -1
  2647.         end
  2648.     end
  2649.  
  2650.     if not self.InspectAng then
  2651.         self.InspectAng = self.InspectAngDef * 1
  2652.  
  2653.         if self.ViewModelFlip then
  2654.             self.InspectAng.x = self.InspectAngDef.x * 1
  2655.             self.InspectAng.y = self.InspectAngDef.y * -1
  2656.             self.InspectAng.z = self.InspectAngDef.z * -1
  2657.         end
  2658.     end
  2659.  
  2660.     local tmp_inspectpos = self.InspectPos
  2661.     local tmp_inspecta = self.InspectAng
  2662.     local opos = pos * 1
  2663.     if tmp_isa == nil then return end
  2664.     ang:RotateAroundAxis(ang:Right(), self.VMAng.x)
  2665.     --The viewmodel angular offset, constantly.
  2666.     ang:RotateAroundAxis(ang:Up(), self.VMAng.y)
  2667.     ang:RotateAroundAxis(ang:Forward(), self.VMAng.z)
  2668.     ang:Normalize()
  2669.     ang2.p = ang.p
  2670.     ang3.p = ang.p
  2671.     ang4.p = ang.p
  2672.     ang5.p = ang.p
  2673.     ang2.y = ang.y
  2674.     ang3.y = ang.y
  2675.     ang4.y = ang.y
  2676.     ang5.y = ang.y
  2677.     ang2.r = ang.r
  2678.     ang3.r = ang.r
  2679.     ang4.r = ang.r
  2680.     ang5.r = ang.r
  2681.     --[[
  2682.     self.SwayScale  = l_Lerp(isp,1,self.IronBobMult)
  2683.     self.SwayScale  = l_Lerp(rsp,self.SwayScale,self.SprintBobMult)
  2684.     ]]--
  2685.     --self.BobScale     = l_Lerp(isp,1,self.IronBobMult)
  2686.     --self.BobScale  = l_Lerp(rsp,self.BobScale,self.SprintBobMult)
  2687.     self.BobScale = 0
  2688.     self.SwayScale = 0
  2689.     mvfac = self.Owner:GetVelocity():Length() / self.Owner:GetRunSpeed()
  2690.     self.BobScaleCustom = l_Lerp(isp, 1, l_Lerp(mvfac, self.IronBobMult, self.IronBobMultWalk))
  2691.     self.BobScaleCustom = l_Lerp(rsp, self.BobScaleCustom, self.SprintBobMult)
  2692.     self.BobScaleCustom = l_Lerp(self.CLInspectingProgress, self.BobScaleCustom, 0.2)
  2693.  
  2694.     if isp > qerp_threshold then
  2695.         ang2:RotateAroundAxis(ang2:Right(), tmp_isa.x)
  2696.         ang2:RotateAroundAxis(ang2:Up(), tmp_isa.y)
  2697.         ang2:RotateAroundAxis(ang2:Forward(), tmp_isa.z)
  2698.         ang = QerpAngle(isp, ang, ang2)
  2699.     end
  2700.  
  2701.     if rsp > qerp_threshold then
  2702.         ang3:RotateAroundAxis(ang3:Right(), tmp_rsa.x)
  2703.         ang3:RotateAroundAxis(ang3:Up(), tmp_rsa.y)
  2704.         ang3:RotateAroundAxis(ang3:Forward(), tmp_rsa.z)
  2705.         ang = QerpAngle(rsp, ang, ang3)
  2706.     end
  2707.  
  2708.     if nwp > qerp_threshold then
  2709.         tmp_nwsightsang = tmp_rsa
  2710.  
  2711.         if self.NearWallSightsAng then
  2712.             tmp_nwsightsang = self.NearWallSightsAng
  2713.         end
  2714.  
  2715.         ang4:RotateAroundAxis(ang4:Right(), tmp_nwsightsang.x)
  2716.         ang4:RotateAroundAxis(ang4:Up(), tmp_nwsightsang.y)
  2717.         ang4:RotateAroundAxis(ang4:Forward(), tmp_nwsightsang.z)
  2718.         ang = QerpAngle(nwp, ang, ang4)
  2719.     end
  2720.  
  2721.     if inspectrat > qerp_threshold then
  2722.         ang5:RotateAroundAxis(ang5:Right(), tmp_inspecta.x)
  2723.         ang5:RotateAroundAxis(ang5:Up(), tmp_inspecta.y)
  2724.         ang5:RotateAroundAxis(ang5:Forward(), tmp_inspecta.z)
  2725.         ang = QerpAngle(inspectrat, ang, ang5)
  2726.     end
  2727.  
  2728.     opos:Add(ang:Right() * self.VMPos.x)
  2729.     opos:Add(ang:Forward() * self.VMPos.y)
  2730.     opos:Add(ang:Up() * self.VMPos.z)
  2731.     pos:Add(ang:Right() * self.VMPos.x)
  2732.     pos:Add(ang:Forward() * self.VMPos.y)
  2733.     pos:Add(ang:Up() * self.VMPos.z)
  2734.  
  2735.     if isp > qerp_threshold then
  2736.         target = pos * 1 -- Copy pos to target
  2737.         target:Add(ang:Right() * tmp_ispos.x)
  2738.         target:Add(ang:Forward() * tmp_ispos.y)
  2739.         target:Add(ang:Up() * tmp_ispos.z)
  2740.         pos = QerpVector(isp, pos, target)
  2741.     end
  2742.  
  2743.     if rsp > qerp_threshold then
  2744.         target = pos * 1 -- Copy pos to target
  2745.         target:Add(ang:Right() * tmp_rspos.x)
  2746.         target:Add(ang:Forward() * tmp_rspos.y)
  2747.         target:Add(ang:Up() * tmp_rspos.z)
  2748.         pos = QerpVector(rsp, pos, target)
  2749.     end
  2750.  
  2751.     if nwp > qerp_threshold then
  2752.         tmp_nwsightspos = tmp_rspos
  2753.  
  2754.         if self.NearWallSightsPos then
  2755.             tmp_nwsightspos = self.NearWallSightsPos
  2756.         end
  2757.  
  2758.         target = opos * 1 -- Copy pos to target
  2759.         target:Add(ang:Right() * tmp_nwsightspos.x)
  2760.         target:Add(ang:Forward() * tmp_nwsightspos.y)
  2761.         target:Add(ang:Up() * tmp_nwsightspos.z)
  2762.         pos = QerpVector(nwp, pos, target)
  2763.     end
  2764.  
  2765.     if inspectrat > qerp_threshold then
  2766.         target = opos * 1 -- Copy pos to target
  2767.         target:Add(ang:Right() * tmp_inspectpos.x)
  2768.         target:Add(ang:Forward() * tmp_inspectpos.y)
  2769.         target:Add(ang:Up() * tmp_inspectpos.z)
  2770.         pos = QerpVector(inspectrat, pos, target)
  2771.     end
  2772.  
  2773.     if self.BlowbackEnabled and self.BlowbackCurrentRoot > qerp_threshold then
  2774.         --if !(  self.Blowback_PistolMode and !( self:Clip1()==-1 or self:Clip1()>0 ) ) then
  2775.         pos:Add(ang:Right() * self.BlowbackVector.x * self.BlowbackCurrentRoot)
  2776.         pos:Add(ang:Forward() * self.BlowbackVector.y * self.BlowbackCurrentRoot)
  2777.         pos:Add(ang:Up() * self.BlowbackVector.z * self.BlowbackCurrentRoot)
  2778.         --end
  2779.     end
  2780.  
  2781.     --Start viewbob code
  2782.     local gunbobintensity = gunbob_intensity_cvar:GetFloat() * 0.65 * 0.66
  2783.     pos, ang = self:CalculateBob(pos, ang, gunbobintensity)
  2784.     local qerp1 = l_Lerp(self.CLIronSightsProgress and self.CLIronSightsProgress or 0, 0, self.ViewModelFlip and 1 or -1) * 15
  2785.     if not ang then return end
  2786.     ang:RotateAroundAxis(ang:Forward(), -Qerp(self.CLIronSightsProgress and self.CLIronSightsProgress or 0, qerp1, 0))
  2787.     --End viewbob code
  2788.     --Start scope compensation code
  2789.     if self.CLIronSightsProgress > self.ScopeOverlayThreshold and self.Scoped then pos:Add( ang:Up() * (-10) ) end
  2790.     pos:Add(ang:Right() * cl_tfa_viewmodel_offset_x:GetFloat() * (1 - isp) * (self.ViewModelFlip and -1 or 1))
  2791.     pos:Add(ang:Forward() * cl_tfa_viewmodel_offset_y:GetFloat() * (1 - isp))
  2792.     pos:Add(ang:Up() * cl_tfa_viewmodel_offset_z:GetFloat() * (1 - isp))
  2793.     pos:Add(ang:Right() * self.ProceduralHolsterFactor * self.ProceduralHolsterPos.x * (self.ViewModelFlip and -1 or 1))
  2794.     pos:Add(ang:Forward() * self.ProceduralHolsterFactor * self.ProceduralHolsterPos.y)
  2795.     pos:Add(ang:Up() * self.ProceduralHolsterFactor * self.ProceduralHolsterPos.z)
  2796.     ang:RotateAroundAxis(ang:Right(), self.ProceduralHolsterFactor * self.ProceduralHolsterAng.x)
  2797.     ang:RotateAroundAxis(ang:Up(), self.ProceduralHolsterFactor * self.ProceduralHolsterAng.y * (self.ViewModelFlip and -1 or 1))
  2798.     ang:RotateAroundAxis(ang:Forward(), self.ProceduralHolsterFactor * self.ProceduralHolsterAng.z * (self.ViewModelFlip and -1 or 1))
  2799.     ang:Normalize()
  2800.  
  2801.     return pos, ang
  2802. end
  2803.  
  2804. --[[ Generic Backend Functions  ]]--
  2805. function SWEP:GetPrimaryAmmoType()
  2806.     return self.Primary.Ammo or ""
  2807. end
  2808.  
  2809. --[[
  2810. Function Name:  CalculateConeRecoil
  2811. Syntax: self:CalculateConeRecoil().
  2812. Returns:  Spray cone, Recoil
  2813. Notes:  This is serverside/shared.  For per-frame, like used for the HUD, use ClientCalculateConeRecoil
  2814. Purpose:  Main SWEP function
  2815. ]]--
  2816.  
  2817. function SWEP:CalculateConeRecoil()
  2818.     if self.Callback.CalculateConeRecoil then
  2819.         local val, val2 = self.Callback.CalculateConeRecoil(self)
  2820.         if val then return val, val2 end
  2821.     end
  2822.  
  2823.     if not IsValid(self) then return 0, 0 end
  2824.     if not IsValid(self.Owner) then return 0, 0 end
  2825.     tmpiron = self:GetIronSights()
  2826.     local dynacc = false
  2827.     isr = self:GetIronSightsRatio()
  2828.  
  2829.     if dynacc_cvar:GetBool() and (self.Primary.NumShots <= 1) then
  2830.         dynacc = true
  2831.     end
  2832.  
  2833.     local isr_1 = l_mathClamp(isr * 2, 0, 1)
  2834.     local isr_2 = l_mathClamp((isr - 0.5) * 2, 0, 1)
  2835.     local acv = self.Primary.Spread or self.Primary.Accuracy
  2836.     local recv = self.Primary.Recoil * 5
  2837.  
  2838.     if dynacc then
  2839.         CurrentCone = l_Lerp(isr_2, l_Lerp(isr_1, acv, acv * self.ChangeStateAccuracyMultiplier), self.Primary.IronAccuracy)
  2840.         CurrentRecoil = l_Lerp(isr_2, l_Lerp(isr_1, recv, recv * self.ChangeStateRecoilMultiplier), recv * self.IronRecoilMultiplier)
  2841.     else
  2842.         CurrentCone = l_Lerp(isr, acv, self.Primary.IronAccuracy)
  2843.         CurrentRecoil = l_Lerp(isr, recv, recv * self.IronRecoilMultiplier)
  2844.     end
  2845.  
  2846.     local crc_1 = l_mathClamp(self:GetCrouchingRatio() * 2, 0, 1)
  2847.     local crc_2 = l_mathClamp((self:GetCrouchingRatio() - 0.5) * 2, 0, 1)
  2848.  
  2849.     if dynacc then
  2850.         CurrentCone = l_Lerp(crc_2, l_Lerp(crc_1, CurrentCone, CurrentCone * self.ChangeStateAccuracyMultiplier), CurrentCone * self.CrouchAccuracyMultiplier)
  2851.         CurrentRecoil = l_Lerp(crc_2, l_Lerp(crc_1, CurrentRecoil, self.Primary.Recoil * self.ChangeStateRecoilMultiplier), CurrentRecoil * self.CrouchRecoilMultiplier)
  2852.     end
  2853.  
  2854.     local ovel = self.Owner:GetVelocity():Length()
  2855.     local vfc_1 = l_mathClamp(ovel / 180, 0, 1)
  2856.  
  2857.     if dynacc then
  2858.         CurrentCone = l_Lerp(vfc_1, CurrentCone, CurrentCone * self.WalkAccuracyMultiplier)
  2859.         CurrentRecoil = l_Lerp(vfc_1, CurrentRecoil, CurrentRecoil * self.WallRecoilMultiplier)
  2860.     end
  2861.  
  2862.     local jr = self:GetJumpingRatio()
  2863.  
  2864.     if dynacc then
  2865.         CurrentCone = l_Lerp(jr, CurrentCone, CurrentCone * self.JumpAccuracyMultiplier)
  2866.         CurrentRecoil = l_Lerp(jr, CurrentRecoil, CurrentRecoil * self.JumpRecoilMultiplier)
  2867.     end
  2868.  
  2869.     CurrentCone = CurrentCone * self:GetSpreadRatio()
  2870.  
  2871.     if mult_cvar then
  2872.         CurrentCone = CurrentCone * mult_cvar:GetFloat()
  2873.     end
  2874.  
  2875.     return CurrentCone, CurrentRecoil
  2876. end
  2877.  
  2878. --[[
  2879. Function Name:  ClientCalculateConeRecoil
  2880. Syntax: self:ClientCalculateConeRecoil().
  2881. Returns:  Spray cone, Recoil
  2882. Notes:  This is clientside and should only be called there.
  2883. Purpose:  Main SWEP function
  2884. ]]--
  2885. function SWEP:ClientCalculateConeRecoil()
  2886.     if not IsValid(self) then return 0, 0 end
  2887.     if not IsValid(self.Owner) then return 0, 0 end
  2888.  
  2889.     if self.Callback.ClientCalculateConeRecoil then
  2890.         local val, val2 = self.Callback.ClientCalculateConeRecoil(self)
  2891.         if val then return val, val2 end
  2892.     end
  2893.     tmpiron = self:GetIronSights()
  2894.     local dynacc = false
  2895.     isr = self.CLIronSightsProgress
  2896.  
  2897.     if dynacc_cvar:GetBool() and (self.Primary.NumShots <= 1) then
  2898.         dynacc = true
  2899.     end
  2900.  
  2901.     local isr_1 = l_mathClamp(isr * 2, 0, 1)
  2902.     local isr_2 = l_mathClamp((isr - 0.5) * 2, 0, 1)
  2903.     local acv = self.Primary.Spread or self.Primary.Accuracy
  2904.     local recv = self.Primary.Recoil * 5
  2905.  
  2906.     if dynacc then
  2907.         CurrentCone = l_Lerp(isr_2, l_Lerp(isr_1, acv, acv * self.ChangeStateAccuracyMultiplier), self.Primary.IronAccuracy)
  2908.         CurrentRecoil = l_Lerp(isr_2, l_Lerp(isr_1, recv, recv * self.ChangeStateRecoilMultiplier), recv * self.IronRecoilMultiplier)
  2909.     else
  2910.         CurrentCone = l_Lerp(isr, acv, self.Primary.IronAccuracy)
  2911.         CurrentRecoil = l_Lerp(isr, recv, recv * self.IronRecoilMultiplier)
  2912.     end
  2913.  
  2914.     local crc_1 = l_mathClamp(self.CLCrouchProgress * 2, 0, 1)
  2915.     local crc_2 = l_mathClamp((self.CLCrouchProgress - 0.5) * 2, 0, 1)
  2916.  
  2917.     if dynacc then
  2918.         CurrentCone = l_Lerp(crc_2, l_Lerp(crc_1, CurrentCone, CurrentCone * self.ChangeStateAccuracyMultiplier), CurrentCone * self.CrouchAccuracyMultiplier)
  2919.         CurrentRecoil = l_Lerp(crc_2, l_Lerp(crc_1, CurrentRecoil, self.Primary.Recoil * self.ChangeStateRecoilMultiplier), CurrentCone * self.CrouchRecoilMultiplier)
  2920.     end
  2921.  
  2922.     local ovel = self.Owner:GetVelocity():Length()
  2923.     local vfc_1 = l_mathClamp(ovel / 180, 0, 1)
  2924.  
  2925.     if dynacc then
  2926.         CurrentCone = l_Lerp(vfc_1, CurrentCone, CurrentCone * self.WalkAccuracyMultiplier)
  2927.         CurrentRecoil = l_Lerp(vfc_1, CurrentRecoil, CurrentRecoil * self.WallRecoilMultiplier)
  2928.     end
  2929.  
  2930.     local jr = self.CLJumpProgress
  2931.  
  2932.     if dynacc then
  2933.         CurrentCone = l_Lerp(jr, CurrentCone, CurrentCone * self.JumpAccuracyMultiplier)
  2934.         CurrentRecoil = l_Lerp(jr, CurrentRecoil, CurrentRecoil * self.JumpRecoilMultiplier)
  2935.     end
  2936.  
  2937.     if mult_cvar then
  2938.         CurrentCone = CurrentCone * mult_cvar:GetFloat()
  2939.     end
  2940.  
  2941.     CurrentCone = CurrentCone * self.CLSpreadRatio
  2942.  
  2943.     return CurrentCone, CurrentRecoil
  2944. end
  2945.  
  2946. --[[
  2947. Function Name:  CalculateNearWallSH
  2948. Syntax: self:CalculateNearWallSH().
  2949. Returns:  Nothing.  However, calculates nearwall for the server.
  2950. Notes:  This is the server/shared equivalent of CalculateNearWallCLF.
  2951. Purpose:  Feature
  2952. ]]--
  2953. local nearwall_cvar = GetConVar("sv_tfa_near_wall")
  2954. local trent
  2955.  
  2956. function SWEP:CalculateNearWallSH()
  2957.     if not IsValid(self.Owner) then return end
  2958.     if not nearwall_cvar:GetBool() then return end
  2959.  
  2960.     if self.Callback.CalculateNearWallSH then
  2961.         local val = self.Callback.CalculateNearWallSH(self)
  2962.         if val then return val end
  2963.     end
  2964.  
  2965.     local vnearwall
  2966.     vnearwall = false
  2967.     bash = self.GetBashing and self:GetBashing()
  2968.  
  2969.     if not bash then
  2970.         local tracedata = {}
  2971.         tracedata.start = self.Owner:GetShootPos()
  2972.         tracedata.endpos = tracedata.start + self.Owner:EyeAngles():Forward() * self.WeaponLength
  2973.         tracedata.mask = MASK_SHOT
  2974.         tracedata.ignoreworld = false
  2975.         tracedata.filter = self.Owner
  2976.         local traceres = util.TraceLine(tracedata)
  2977.  
  2978.         if traceres.Hit and traceres.Fraction > 0 and traceres.Fraction < 1 then
  2979.             trent = traceres.Entity
  2980.  
  2981.             if traceres.MatType ~= MAT_FLESH and traceres.MatType ~= MAT_GLASS and not (IsValid(trent) and trent:IsNPC()) then
  2982.                 vnearwall = true
  2983.             end
  2984.         end
  2985.  
  2986.         self:SetNearWallRatio(l_mathApproach(self:GetNearWallRatio(), vnearwall and l_mathClamp(1 - traceres.Fraction, 0, 1) or 0, l_FT() / self.NearWallTime))
  2987.     else
  2988.         self:SetNearWallRatio(l_mathApproach(self:GetNearWallRatio(), 0, l_FT() / self.NearWallTime))
  2989.     end
  2990. end
  2991.  
  2992. --[[
  2993. Function Name:  CalculateNearWallCLF
  2994. Syntax: self:CalculateNearWallCLF().  This is called per-frame.
  2995. Returns:  Nothing.  However, calculates nearwall for the client.
  2996. Notes:  This is clientside only.
  2997. Purpose:  Feature
  2998. ]]--
  2999. local tg
  3000.  
  3001. function SWEP:CalculateNearWallCLF( ftin )
  3002.     ft = ftin or l_FT()
  3003.     if not (CLIENT or sp) then return end
  3004.     if not IsValid(self.Owner) then return end
  3005.     if not nearwall_cvar:GetBool() then return end
  3006.  
  3007.     if self.Callback.CalculateNearWallCLF then
  3008.         local val = self.Callback.CalculateNearWallCLF(self)
  3009.         if val then return val end
  3010.     end
  3011.  
  3012.     local vnearwall
  3013.     vnearwall = false
  3014.     bash = self.GetBashing and self:GetBashing()
  3015.  
  3016.     if not bash then
  3017.         local tracedata = {}
  3018.         tracedata.start = self.Owner:GetShootPos()
  3019.         tracedata.endpos = tracedata.start + self.Owner:EyeAngles():Forward() * self.WeaponLength
  3020.         tracedata.mask = MASK_SHOT
  3021.         tracedata.ignoreworld = false
  3022.         tracedata.filter = self.Owner
  3023.         local traceres = util.TraceLine(tracedata)
  3024.  
  3025.         if traceres.Hit and traceres.Fraction > 0 and traceres.Fraction < 1 then
  3026.             trent = traceres.Entity
  3027.  
  3028.             if traceres.MatType ~= MAT_FLESH and traceres.MatType ~= MAT_GLASS and not (IsValid(trent) and trent:IsNPC()) then
  3029.                 vnearwall = true
  3030.             end
  3031.         end
  3032.  
  3033.         tg = vnearwall and l_mathClamp(1 - traceres.Fraction, 0, 1) or 0
  3034.         self.CLNearWallProgress = l_mathApproach(self.CLNearWallProgress, tg, (ft / math.pow(self.NearWallAnimationTime, 2)) * (tg - self.CLNearWallProgress))
  3035.         self.CLOldNearWallProgress = l_mathApproach(self.CLOldNearWallProgress or 0, vnearwall and 1 or 0, ft / self.NearWallTime)
  3036.     else
  3037.         tg = 0
  3038.         self.CLNearWallProgress = l_mathApproach(self.CLNearWallProgress, tg, (ft / math.pow(self.NearWallAnimationTime, 2)) * (tg - self.CLNearWallProgress))
  3039.         self.CLOldNearWallProgress = l_mathApproach(self.CLOldNearWallProgress or 0, vnearwall and 1 or 0, ft / self.NearWallTime)
  3040.     end
  3041. end
  3042.  
  3043. --[[
  3044. Function Name:  ProcessHoldType
  3045. Syntax: self:ProcessHoldType().  This is called per-think.
  3046. Returns:  Nothing.
  3047. Notes:  This calculates your holdtype.
  3048. Purpose:  Feature.
  3049. ]]--
  3050. dynholdtypecvar = GetConVar("sv_tfa_holdtype_dynamic", 1)
  3051.  
  3052. function SWEP:ProcessHoldType()
  3053.     if self.Callback.ProcessHoldType then
  3054.         local val = self.Callback.ProcessHoldType(self)
  3055.         if val then return val end
  3056.     end
  3057.  
  3058.     if not self.DefaultHoldType then
  3059.         self.DefaultHoldType = self.HoldType or "ar2"
  3060.     end
  3061.  
  3062.     if not self.SprintHoldType then
  3063.         self.SprintHoldType = self.SprintHoldTypes[self.DefaultHoldType] or "passive"
  3064.  
  3065.         if self.SprintHoldTypeOverride and self.SprintHoldTypeOverride ~= "" then
  3066.             self.SprintHoldType = self.SprintHoldTypeOverride
  3067.         end
  3068.     end
  3069.  
  3070.     if not self.IronHoldType then
  3071.         self.IronHoldType = self.IronSightHoldTypes[self.DefaultHoldType] or "rpg"
  3072.  
  3073.         if self.IronSightHoldTypeOverride and self.IronSightHoldTypeOverride ~= "" then
  3074.             self.IronHoldType = self.IronSightHoldTypeOverride
  3075.         end
  3076.     end
  3077.  
  3078.     if not self.ReloadHoldType then
  3079.         self.ReloadHoldType = self.ReloadHoldTypes[self.DefaultHoldType] or "ar2"
  3080.  
  3081.         if self.ReloadHoldTypeOverride and self.ReloadHoldTypeOverride ~= "" then
  3082.             self.ReloadHoldType = self.ReloadHoldTypeOverride
  3083.         end
  3084.     end
  3085.  
  3086.     if not self.SetCrouchHoldType then
  3087.         self.SetCrouchHoldType = true
  3088.         self.CrouchHoldType = self.CrouchHoldTypes[self.DefaultHoldType]
  3089.  
  3090.         if self.CrouchHoldTypeOverride and self.CrouchHoldTypeOverride ~= "" then
  3091.             self.CrouchHoldType = self.CrouchHoldTypeOverride
  3092.         end
  3093.     end
  3094.  
  3095.     local curhold, targhold
  3096.     curhold = self:GetHoldType()
  3097.     targhold = self.DefaultHoldType
  3098.  
  3099.     if self:OwnerIsValid() and self.Owner:Crouching() and self.CrouchHoldType then
  3100.         targhold = self.CrouchHoldType
  3101.     else
  3102.         if self:GetIronSights() then
  3103.             targhold = self.IronHoldType
  3104.         end
  3105.  
  3106.         if self:GetReloading() then
  3107.             targhold = self.ReloadHoldType
  3108.         end
  3109.     end
  3110.  
  3111.     if self:GetSprinting() or self:GetHolstering() or self:IsSafety() then
  3112.         targhold = self.SprintHoldType
  3113.     end
  3114.  
  3115.     if targhold ~= curhold then
  3116.         self:SetHoldType(targhold)
  3117.     end
  3118. end
  3119.  
  3120. function SWEP:CompleteReload()
  3121.     if self.Callback.CompleteReload then
  3122.         local val = self.Callback.CompleteReload(self)
  3123.         if val then return val end
  3124.     end
  3125.  
  3126.     if not self.Shotgun then
  3127.         hudhangtime = 1
  3128.  
  3129.         if self:OwnerIsValid() then
  3130.             if SERVER then
  3131.                 hudhangtime = self.Owner:GetInfoNum("cl_tfa_hud_hangtime", 1)
  3132.             else
  3133.                 hudhangtime = hudhangtime_cvar:GetFloat()
  3134.             end
  3135.  
  3136.             local maxclip = self.Primary.ClipSize
  3137.             local curclip = self:Clip1()
  3138.             local amounttoreplace = math.min(maxclip - curclip + (((self:Clip1() > 0) and self:CanChamber()) and 1 or 0), self.Owner:GetAmmoCount(self.Primary.Ammo))
  3139.             self:SetClip1(curclip + amounttoreplace)
  3140.             self.Owner:RemoveAmmo(amounttoreplace, self.Primary.Ammo)
  3141.  
  3142.             if self.Akimbo then
  3143.                 maxclip = self.Secondary.ClipSize
  3144.                 curclip = self:Clip2()
  3145.                 amounttoreplace = math.min(maxclip - curclip + (((self:Clip2() > 0) and self:CanChamber()) and 1 or 0), self.Owner:GetAmmoCount(self.Secondary.Ammo))
  3146.                 self:SetClip2(curclip + amounttoreplace)
  3147.                 self.Owner:RemoveAmmo(amounttoreplace, self.Secondary.Ammo)
  3148.             end
  3149.         end
  3150.  
  3151.         self:SetReloading(false)
  3152.         self:SetBurstCount(0)
  3153.         self:SetBursting(false)
  3154.     end
  3155. end
  3156.  
  3157. function SWEP:ToggleInspect()
  3158.     if self.Callback.ToggleInspect then
  3159.         local val = self.Callback.ToggleInspect(self)
  3160.         if val then return val end
  3161.     end
  3162.  
  3163.     if self:CanCKeyInspect() and self:GetRunSightsRatio() < 0.1 and self:GetNearWallRatio() < 0.1 and not self:GetDrawing() and not self:GetHolstering() and not self:GetReloading() and not self:GetFidgeting() and not self:GetIronSights() and self.SequenceEnabled[ACT_VM_FIDGET] then
  3164.         self:SetInspecting(false)
  3165.  
  3166.         if CLIENT then
  3167.             net.Start("tfaInspect")
  3168.             net.WriteBool(false)
  3169.             net.SendToServer()
  3170.         end
  3171.  
  3172.         self:SetFidgeting(true)
  3173.         local succ = self:ChooseInspectAnim()
  3174.  
  3175.         if succ then
  3176.             self:SetNextIdleAnim(CurTime() + self.OwnerViewModel:SequenceDuration())
  3177.         else
  3178.             self:SetNextIdleAnim(CurTime() + math.max(1, self.OwnerViewModel:SequenceDuration()))
  3179.         end
  3180.  
  3181.         self:SetFidgetingEnd(self:GetNextIdleAnim())
  3182.  
  3183.         return
  3184.     end
  3185.  
  3186.     if not self:GetIronSights() and self:GetRunSightsRatio() < 0.1 and self:GetNearWallRatio() < 0.1 and not self:GetDrawing() and not self:GetHolstering() and not self:GetReloading() and not self:GetFidgeting() then
  3187.         local oldinsp = self:GetInspecting()
  3188.         self:SetInspecting(not oldinsp)
  3189.  
  3190.         if CLIENT then
  3191.             net.Start("tfaInspect")
  3192.             net.WriteBool(not oldinsp)
  3193.             net.SendToServer()
  3194.         end
  3195.  
  3196.         self:SetNextIdleAnim(-1)
  3197.     end
  3198. end
  3199.  
  3200. function SWEP:ShotgunInterrupt()
  3201.     if self.Callback.ShotgunInterrupt then
  3202.         local val = self.Callback.ShotgunInterrupt(self)
  3203.         if val then return val end
  3204.     end
  3205.  
  3206.     self:SetShotgunCancel(true)
  3207.  
  3208.     if ( self:GetReloading() and self.Shotgun and not self:GetShotgunPumping() and not self:GetShotgunNeedsPump() ) and CLIENT then
  3209.         net.Start("tfaShotgunInterrupt")
  3210.         net.SendToServer()
  3211.     end
  3212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement