· 9 years ago · Oct 11, 2016, 09:18 PM
1AddCSLuaFile( )
2------------------------------------------------------
3if not VNTCB then return false end -- Prevent this file from loading if for some odd reason the base Lua isn't loaded
4------------------------------------------------------
5-- Jesse V92's Custom SWep Base --
6-- Start Date: 2016/07/14 --
7-- Purpose: Create a good SWep base --
8------------------------------------------------------
9-- If you want to make weapons, you need to change --
10-- only the values listed with comments below. --
11-- The rest of it has been coded so it will read --
12-- these values and react properly. --
13-- If you want to make SWeps, refer to samples. --
14-- Those will show you in how to make SWeps. --
15-- When in doubt, contact me. --
16------------------------------------------------------
17-- REMOVE LINES YOU DID NOT CHANGE! --
18-- THIS WILL SPEED UP LOAD TIMES! --
19------------------------------------------------------
20-- Spawn settings -- Can we spawn this?
21------------------------------------------------------
22SWEP.Spawnable = false -- (Boolean) Can be spawned via the menu
23SWEP.AdminOnly = true -- (Boolean) Admin only spawnable
24------------------------------------------------------
25-- Client Information -- Info used in the client block of the weapon
26------------------------------------------------------
27SWEP.WeaponName = VNTBases.Wep -- (String) Name of the weapon script
28SWEP.WeaponEntityName = SWEP.WeaponName .. "_ent" -- (String) Name of the weapon entity in Lua/Entities/Entityname.lua
29SWEP.GrenadeLauncherEntity = VNTGLType.GLUS -- (String) Name of the grenade launcher shell entity in Lua/Entities/Entityname.lua
30SWEP.GrenadeLauncherForce = 1750 -- (Integer) Force of grenade launchers and shell throwers like that.
31SWEP.PrintName = "V92's Custom SWep Base" -- (String) Printed name on menu
32SWEP.Manufacturer = VNTMaker.VNT -- (String) Gun company that makes this weapon
33SWEP.CountryOfOrigin = VNTCountry.USA -- (String) Country of origin
34SWEP.MagazineName = VNTMagazine.magNATO556 -- (String) The name of the magazine the weapon uses - used in my Weapon Magazine System
35SWEP.Category = VNTCategory.VNT -- (String) Category
36SWEP.Instructions = VNTCB.instructions -- (String) Instruction
37SWEP.Author = VNTCB.author -- (String) Author
38SWEP.Contact = VNTCB.contact -- (String) Contact
39SWEP.Slot = VNTBucket.Utility -- (Integer) Bucket to place weapon in, See autorun/sh_v92_code_base.lua; 1 to 6
40SWEP.SlotPos = VNTSlot.Utility -- (Integer) Bucket position, See autorun/sh_v92_code_base.lua
41SWEP.WEPSLOT = VNTType.None -- (String) Weapon type, See autorun/sh_v92_code_base.lua; Primary, Secondary, Melee, GrenadeOne, GrenadeTwo, Mine, Supply, None
42SWEP.ViewModelFOV = 54 -- (Integer) First-person field of view
43SWEP.WorkshopID = "505106454" -- (Integer) Workshop ID number of the upload that contains this file.
44------------------------------------------------------
45-- Model Information -- Model settings and infomation
46------------------------------------------------------
47SWEP.ViewModelFlip = false -- (Boolean) Only used for vanilla CS:S models
48SWEP.ViewModel = Model( "" ) -- (String) View model - v_*
49SWEP.WorldModel = Model( "" ) -- (String) World model - w_*
50SWEP.UseHands = false -- (Boolean) Leave at false unless the model uses C_Arms
51SWEP.HoldType = "ar2" -- (String) Hold type for our weapon, refer to wiki for animation sets
52SWEP.GrabStock = false -- (Boolean) If true, when we crouch, we'll hold the stock; useful for snipers or machine guns
53------------------------------------------------------
54-- Gun Types -- Set the type of weapon
55------------------------------------------------------
56SWEP.WeaponType = 1 -- (Integer) 1=Melee, 2=Pistol, 3=Rifle, 4=Shotgun, 5=Sniper, 6=Entity Shooter, 7=Rocket Launcher
57SWEP.DeployableType = 0 -- (Integer) 0=None, 1=Grenade Launcher, 2=Bipod, 3=Model Swap Bipod, 4=Model Swep Stock Deploy, 5=Deployable
58SWEP.ViewModelBipod = Model( "" ) -- (String) Model swap bipod view model
59SWEP.WorldModelBipod = Model( "" ) -- (String) Model swap bipod world model
60SWEP.SuppressorType = 0 -- (Integer) 0=No Suppressor, 1=Model Swap, 2=Animation
61SWEP.ViewModelSuppressed = Model( "" ) -- (String) The Suppressed view model
62SWEP.WorldModelSuppressed = Model( "" ) -- (String) The Suppressed world model
63SWEP.StockType = 0 -- (Integer) 0=No Stock, 1=Model Swap
64SWEP.ViewModelStockOut = Model( "" ) -- (String) The Suppressed view model
65SWEP.WorldModelStockOut = Model( "" ) -- (String) The Suppressed world model
66------------------------------------------------------
67-- Machine Gun Settings -- Things typically used on machine guns
68------------------------------------------------------
69SWEP.BeltFed = false -- (Boolean) Is it belt fed?
70SWEP.HasBeltBG = false -- (Boolean) Does it have bodygroups for the ammo belt?
71SWEP.BeltFedBG = { 2 , 0 , 10 } -- (Table: Int, Int, Int) Belt BG, sub-group start, sub-group end; used for guns that have bodygroups for the bullets on the belt depleting; I.E., INS M249
72------------------------------------------------------
73-- Shotgun Settings -- Settings for shotguns
74------------------------------------------------------
75SWEP.PumpAction = false -- (Boolean) Is the shotgun pump action?
76SWEP.ShellReload = false -- (Boolean) Does this weapon use individual shells?
77------------------------------------------------------
78-- Sniper Settings -- Settings for sniper rifles
79------------------------------------------------------
80SWEP.ScopeType = 0 -- (Integer) Type of scope, 0=none, 1=overlay, 2=Render Target
81SWEP.ScopeMaterial = 0 -- (Integer) Type of overlay, 0=Red Dot, 1=EOTech, 2=ACOG, 3=SVD, 4=M14, 5=L42A1, 6=PSG1, 7=German tri-bar
82SWEP.ScopeMaterialCustom = nil -- (String: Material) Path to the scope overlay you want to use if you use an overlay scope
83SWEP.ScopeMultipliers = { 8 , 4 } -- (Table: Float, Float) X magnification of the scope, ACOG would 4, etc.
84SWEP.ScopeOverlayScale = 0.5 -- (Float) Scale of the scope overlay
85SWEP.DefaultZoom = 1 -- (Float) Current zoom, default to 1; DON'T CHANGE
86SWEP.BoltAction = false -- (Boolean) Is this bolt action? Removes the player from the scope after firing
87SWEP.ReturnToScope = false -- (Boolean) Return to scope after cycling the bolt?
88SWEP.HasVariableZoom = false -- (Boolean) Does the weapon have variable zoom?
89SWEP.IsCloseZoomed = false
90------------------------------------------------------
91-- Primary Fire Settings -- Settings for the primary fire of the weapon
92------------------------------------------------------
93SWEP.Primary.DefaultClip = 0 -- (Integer) Default number of ammo you spawn with
94SWEP.Primary.ClipSize = -1 -- (Integer) Size of a magazine
95SWEP.Primary.ClipSizePlus = 1 -- (Integer) How many extra bullets to add if CanChamber is true
96SWEP.Primary.Ammo = "pistol" -- (String) Primary ammo used by the weapon, bullets probably
97SWEP.Primary.RPM = 0 -- (Integer) Go to a wikipxedia page and look at the RPM of the weapon, then put that here - the base will do the math
98SWEP.Primary.Delay = ( 60 / SWEP.Primary.RPM )
99SWEP.Primary.PureDmg = 1 -- (Integer) Base damage, put one number here and the base will do the rest
100SWEP.Primary.Damage = math.random( SWEP.Primary.PureDmg - 3 , SWEP.Primary.PureDmg + 3 )
101SWEP.Primary.NumShots = 1 -- (Integer) How many bullets per shot; think of this as a shotgun shell, higher integer, more pellets
102SWEP.Primary.Cone = 0.004 -- (Float) Accuracy of the weapon; 0.004 is the average for rifles, 0.006 for short-barrel weapons, 0.008 for pistols
103SWEP.Primary.MaxCone = ( SWEP.Primary.Cone * 10 )
104SWEP.Primary.ConeCoil = ( SWEP.Primary.Cone / 2 )
105SWEP.Primary.Automatic = false -- (Boolean) Is the primary fire automatic or semi-auto?
106------------------------------------------------------
107-- Secondary Fire Settings -- Settings for the alt-fire; if it has none, leave this be
108------------------------------------------------------
109SWEP.Secondary.ClipSize = -1 -- (Integer) Size of a secondary magazine; if no alt-fire, set to -1
110SWEP.Secondary.DefaultClip = -1 -- (Integer) Default number of projectiles in the alt fire mag; if none, set to -1
111SWEP.Secondary.Automatic = false -- (Boolean) Is the alt-fire automatic or semi-auto?
112------------------------------------------------------
113-- Gun Mechanics -- Various things to tweak the effects and feedback
114------------------------------------------------------
115SWEP.IsEntityShooter = false -- (Boolean) Does this weapon shoot entities instead of bullets?
116SWEP.CanReloadWhenNotEmpty = true -- (Boolean) Can we reload when not empty? true=M16, false=M1 Garand
117SWEP.CanChamber = true -- (Boolean) Can we load a round into the chamber?
118SWEP.FireMode = { false , true , false , false } -- (Table: Boolean, Boolean, Boolean, Boolean ) Enable different fire modes on the weapon; Has modes, Has Single, Has Burst, Has Auto - in that order. You can have more than one, but the first must be true
119SWEP.CurrentMode = 1 -- (Integer) Current fire mode of the weapon; used to set the default mode; corresponds to the FireMode table
120SWEP.DeployDelay = 0 -- (Float) Time for the deploy animation to play; this isn't needed, may remove it
121SWEP.BurstCount = 3 -- (Integer) Amounts of shots to be fired by burst
122SWEP.BurstDelay = 0.05 -- (Float) Time between bolt cycles in the burst
123SWEP.BurstShots = ( SWEP.BurstCount + 1 )
124SWEP.BurstCounter = 0
125SWEP.BurstTimer = 0
126SWEP.Weight = 0 -- (Integer) The weight in Kilogrammes of our weapon - used in my weapon weight mod!
127SWEP.CanPenetrate = true -- (Boolean) Should the bullets CanPenetrate through surfaces?
128SWEP.Ricochet = true -- (Boolean) Should the bullet richochet?
129SWEP.CanFireUnderwater = false -- (Boolean) Can we shoot underwater?
130SWEP.JammingChance = 1000 -- (Integer) Jam chance for the weapon between 1 and this number
131SWEP.MaxPenetration = 15 -- (Integer) Max penetration
132SWEP.MaxWoodPenetration = 18 -- (Integer) Max wood penetration
133------------------------------------------------------
134-- Special FX -- Muzzle flashes, shell casings, etc
135------------------------------------------------------
136SWEP.MuzzleAttach = 1 -- (Integer) The number of the attachment point for muzzle flashes, typically "1"
137SWEP.ShellAttach = 2 -- (Integer) The number of the attachment point for shell ejections, typically "2"
138SWEP.ShellEffect = "" -- (String) Name of the file in Lua/effects/shelleject.lua to use for shell ejections; leave blank for none
139SWEP.ShellDelay = 0 -- (Float) Time between shot firing and shell ejection; useful for bolt-actions and things like that that need a delay
140SWEP.UseTracer = true -- (Boolean) Do we use tracers?
141SWEP.TracerRandomizer = 1 -- (Integer) Between 0 and this number, chance to make a TracerType if UseTracer is true
142SWEP.TracerType = 0 -- (Integer) 0 = Normal TracerType, 1 = Ar2 TracerType, 2 = Airboat Gun TracerType, 3 = Normal TracerType + Sparks Impact
143SWEP.CustomTracer = nil -- (String) Custom TracerType effect; lua/effects/*.lua
144------------------------------------------------------
145-- Melee Settings --
146------------------------------------------------------
147SWEP.MeleeAnimType = 0 -- (Integer) Melee type; 0=holdtype animation, 1=pistol whip, 2=rifle butt
148SWEP.MeleeRange = 70 -- (Integer) Range of melee weapon swings
149SWEP.HasMeleeAttack = false -- (Boolean) Does this weapon have a pistol whip or rifle butt animation?
150SWEP.AltFireMelee = false -- (Boolean) Is the alt fire a melee attack?
151SWEP.IsBladedMelee = false -- (Boolean) Is the melee a blade?
152------------------------------------------------------
153-- Akimbo Settings -- Settings for akimbo weapons; I.E. CSS Dualies
154------------------------------------------------------
155SWEP.IsAkimbo = false -- (Boolean) Is this an akimbo weapon?
156SWEP.MuzzleAttachLeft = 3 -- (Integer) The number of the attachment point for left muzzle flashes, typically "3"
157SWEP.ShellAttachLeft = 4 -- (Integer) The number of the attachment point for left shell ejections, typically "4"
158SWEP.BurstCountLeft = 3 -- (Integer) Amounts of shots to be fired by burst, left hand weapon; used in akimbo
159SWEP.BurstDelayLeft = 0.05 -- (Float) Time between bolt cycles in the burst, left hand weapon; used in akimbo
160SWEP.BurstShotsL = ( SWEP.BurstCountLeft + 1 )
161SWEP.BurstCounterL = 0
162SWEP.BurstTimerL = 0
163------------------------------------------------------
164-- Custom Sounds -- Setup sounds here!
165------------------------------------------------------
166SWEP.SND_PrimaryFire = Sound( "Weapon_SMG1.Single" ) -- (String) Primary shoot sound
167SWEP.SND_PrimarySuppressedFire = Sound( "Weapon_SMG1.Special1" ) -- (String) Primary suppressed shoot sound
168SWEP.SND_PrimaryDryFire = Sound( "Weapon_SMG1.Special2" ) -- (String) Primary dry fire sound
169SWEP.SND_GrenadeLauncherFire = Sound( "Weapon_SMG1.Double" ) -- (String) Grenade launcher sound
170SWEP.SND_Reload = Sound( "Weapon_SMG1.Reload" ) -- (String) Reload sound
171SWEP.SND_ShotgunReloadStart = nil -- (String) Foley sound for ACT_SHOTGUN_RELOAD_START if the model doesn't have one defined internally
172SWEP.SND_ShotgunShellInsert = nil -- (String) Shell insert sound for ACT_VM_RELOAD if the model doesn't have one defined internally
173SWEP.SND_ShotgunPump = nil -- (String) Pump sound for ACT_SHOTGUN_PUMP if the model doesn't have one defined internally
174SWEP.SND_ShotgunReloadEnd = nil -- (String) Foley sound for ACT_SHOTGUN_RELOAD_FINISH if the model doesn't have one defined internally
175SWEP.SND_JamSmallPistol = Sound( "Jam.Short.Pistol" ) -- (String) Little jam sound for pistols
176SWEP.SND_JamLargePistol = Sound( "Jam.Long.Pistol" ) -- (String) Big jam sound for pistols
177SWEP.SND_JamSmall = Sound( "Jam.Short.Rifle" ) -- (String) Little jam sound for everything else
178SWEP.SND_JamLarge = Sound( "Jam.Long.Rifle" ) -- (String) Big jam sound for everything else
179SWEP.SND_IronsightIn = Sound( "VNT.SWep.IronIn1" ) -- (String) Sound for going into steel sight
180SWEP.SND_IronsightOut = Sound( "VNT.SWep.IronOut1" ) -- (String) Sound for going out of steel sight
181SWEP.SND_PistolWhipHit = Sound( "VNT.SWep.Melee.WhipHit" ) -- (String) Sound for pistol whip hits
182SWEP.SND_PistolWhipMiss = Sound( "VNT.SWep.Melee.WhipMiss" ) -- (String) Sound for pistol whip misses
183SWEP.SND_MeleeHitWall = Sound( "VNT.SWep.Melee.HitWall" ) -- (String) Sound for melee world hits
184SWEP.SND_MeleeHitCharacter = Sound( "VNT.SWep.Melee.HitFlesh" ) -- (String) Sound for melee flesh hits
185SWEP.SND_MeleeMissed = Sound( "VNT.SWep.Melee.Slash" ) -- (String) Sound for melee misses
186SWEP.SND_ZoomIn = Sound( "VNT.SWep.ZoomIn" ) -- (String) Sound used when zooming into a scope
187SWEP.SND_ZoomOut = Sound( "VNT.SWep.ZoomOut" ) -- (String) Sound used when zooming out of a scope
188SWEP.SND_CycleZoomIn = Sound( "VNT.SWep.ZoomCycleIn" ) -- (String) Sound used when cycling the zoom level of a scope
189SWEP.SND_CycleZoomOut = Sound( "VNT.SWep.ZoomCycleOut" ) -- (String) Sound used when cycling the zoom level of a scope
190------------------------------------------------------
191-- Ironsight & Run Positions -- Set our model transforms for running and ironsights
192------------------------------------------------------
193SWEP.IronSightsPos = Vector( 0 , 0 , 0 ) -- (Vector) Ironsight XYZ Transform
194SWEP.IronSightsAng = Vector( 0 , 0 , 0 ) -- (Vector) Ironsight XYZ Rotation
195SWEP.StockIronSightsPos = Vector( 0 , 0 , 0 ) -- (Vector) Unfolded Stock Ironsight XYZ Transform
196SWEP.StockIronSightsAng = Vector( 0 , 0 , 0 ) -- (Vector) Unfolded Stock Ironsight XYZ Rotation
197SWEP.RunArmOffset = Vector( 0 , -0 , 1.5 ) -- (Vector) Sprinting XYZ Transform
198SWEP.RunArmAngle = Vector( -35 , -3 , 0 ) -- (Vector) Sprinting XYZ Rotation
199------------------------------------------------------
200-- Setup --
201------------------------------------------------------
202SWEP.DisableDuplicator = true
203SWEP.BaseCone = SWEP.Primary.Cone
204SWEP.FirstDraw = GetConVarNumber( "VNT_SWep_Base_DrawToggle" )
205SWEP.LauncherLoaded = false
206SWEP.FiringPinForward = false
207SWEP.LauncherPinForward = false
208SWEP.ActionDelay = CurTime( )
209SWEP.PistolPunchesX = { -0.6 , -0.5 , -0.4 , -0.3 , 0.3 , 0.4 , 0.5 , 0.6 }
210SWEP.PistolPunchesY = { -1 , -0.9 , -0.8 , -0.7 , -0.6 , -0.5 , -0.4 }
211SWEP.RiflePunchesX = { -0.6 , -0.5 , -0.4 , -0.3 , 0.3 , 0.4 , 0.5 , 0.6 }
212SWEP.RiflePunchesY = { -0.7 , -0.6 , -0.5 , -0.4 }
213
214if CLIENT then
215 SWEP.DrawWeaponInfoBox = true
216 SWEP.BounceWeaponIcon = false
217 SWEP.DrawAmmo = true
218 SWEP.DrawCrosshair = false
219 SWEP.AutoSwitchTo = false
220 SWEP.AutoSwitchFrom = false
221 SWEP.CSMuzzleFlashes = true
222 SWEP.WepSelectIcon = surface.GetTextureID( "vgui/hud/" .. SWEP.WeaponName )
223 SWEP.RenderGroup = RENDERGROUP_BOTH
224 language.Add( SWEP.WeaponName , SWEP.PrintName ) -- Add a language value for our weapon
225 killicon.Add( SWEP.WeaponName , "vgui/entities/" .. SWEP.WeaponName , Color( 255 , 255 , 255 ) ) -- Make our spawn icon our kill icon
226
227 function SWEP:CustomDrawHUD( )
228 end -- Draw your own custom stuff here
229elseif SERVER then
230 resource.AddWorkshop( SWEP.WorkshopID )
231end -- Setup Clientside Info - This block must be in every weapon!
232
233function SWEP:Initialize( )
234 --self:SetWeaponHoldType(self.HoldType)
235 -- Drop on death
236 self.Owner:ShouldDropWeapon( true )
237 self:ShouldDropOnDie( true )
238 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
239
240 if self.WeaponType == 6 then
241 self:SetVNTSBLchrLoaded( true )
242 end
243end -- Called when the weapon is first loaded
244
245------------------------------------------------------
246------------------------------------------------------
247-- Nothing beyond this needs to be included --
248------------------------------------------------------
249------------------------------------------------------
250
251function SWEP:SetupDataTables( )
252 self:NetworkVar( "Bool" , 0 , "VNTSBHolstered" ) -- Holstered
253 self:NetworkVar( "Bool" , 1 , "VNTSBSuppressed" ) -- Suppressed
254 self:NetworkVar( "Bool" , 2 , "VNTSBIronSighted" ) -- Ironsights
255 self:NetworkVar( "Bool" , 3 , "VNTSBScopedIn" ) -- Scoped
256 self:NetworkVar( "Bool" , 4 , "VNTSBJammedL" ) -- Little Jam
257 self:NetworkVar( "Bool" , 5 , "VNTSBJammedB" ) -- Big Jam
258 self:NetworkVar( "Bool" , 7 , "VNTSBBipod" ) -- Bipod
259 self:NetworkVar( "Bool" , 8 , "VNTSBGLauncher" ) -- Grenade Launcher
260 self:NetworkVar( "Bool" , 9 , "VNTSBLchrLoaded" ) -- GL is Loaded
261 self:NetworkVar( "Bool" , 10 , "VNTSBProne" ) -- Player is Prone
262 self:NetworkVar( "Bool" , 11 , "VNTSBShotgunRel" ) -- Shotgun is reloading
263 self:NetworkVar( "Bool" , 12 , "VNTSBStock" ) -- Shotgun is reloading
264 self:NetworkVar( "Float" , 0 , "VNTSBHolsterTime" ) -- Holster time delay
265 self:NetworkVar( "Float" , 1 , "VNTSBZoom" ) -- Zoom
266end -- Setup our networked shit
267
268if CLIENT then
269 local IronsightToggleTime = 0.3
270
271 -----------------------------------------------------------
272 -- SWEP:DrawHUD()
273 -- You can draw to the HUD here. It will only draw when
274 -- the client has the weapon deployed.
275 -----------------------------------------------------------
276 function SWEP:DrawHUD( )
277 self:CustomDrawHUD( )
278 local TEX_Semi = surface.GetTextureID( "jessev92/ui/insmic/semi" )
279 local TEX_Burst = surface.GetTextureID( "jessev92/ui/insmic/burst" )
280 local TEX_Auto = surface.GetTextureID( "jessev92/ui/insmic/auto" )
281 local TEX_Bipod = surface.GetTextureID( "jessev92/ui/insmic/bipod" )
282 local TEX_Cache = surface.GetTextureID( "jessev92/ui/insmic/cache" )
283 local SizeX = ( ScreenScale( 40 ) * GetConVarNumber( "VNT_SWep_Base_IconSize" ) )
284 local SizeY = ( ScreenScale( 40 ) * GetConVarNumber( "VNT_SWep_Base_IconSize" ) )
285
286 if self:GetVNTSBHolstered( ) == false then
287 if self.CurrentMode == 1 then
288 surface.SetDrawColor( 255 , 255 , 255 , 255 )
289 surface.SetTexture( TEX_Semi )
290 surface.DrawTexturedRect( ScrW( ) * 0.94 + GetConVarNumber( "VNT_SWep_Base_RoFX" ) , ScrH( ) * 0.825 + GetConVarNumber( "VNT_SWep_Base_RoFY" ) , SizeX , SizeY )
291 elseif self.CurrentMode == 2 then
292 -- If in burst mode then
293 surface.SetDrawColor( 255 , 255 , 255 , 255 )
294 surface.SetTexture( TEX_Burst )
295 surface.DrawTexturedRect( ScrW( ) * 0.94 + GetConVarNumber( "VNT_SWep_Base_RoFX" ) , ScrH( ) * 0.825 + GetConVarNumber( "VNT_SWep_Base_RoFY" ) , SizeX , SizeY )
296 elseif self.CurrentMode == 3 then
297 -- If in auto mode then
298 surface.SetDrawColor( 255 , 255 , 255 , 255 )
299 surface.SetTexture( TEX_Auto )
300 surface.DrawTexturedRect( ScrW( ) * 0.94 + GetConVarNumber( "VNT_SWep_Base_RoFX" ) , ScrH( ) * 0.825 + GetConVarNumber( "VNT_SWep_Base_RoFY" ) , SizeX , SizeY )
301 elseif self.CurrentMode == 4 then
302 -- If Safety'd then
303 surface.SetDrawColor( 255 , 255 , 255 , 0 )
304 end -- If in Semi-Auto mode then
305
306 if self:GetVNTSBGLauncher( ) == true then
307 surface.SetDrawColor( 255 , 255 , 255 , 255 )
308 surface.SetTexture( TEX_Cache )
309 surface.DrawTexturedRect( ScrW( ) * 0.925 + GetConVarNumber( "VNT_SWep_Base_CacheX" ) , ScrH( ) * 0.7 + GetConVarNumber( "VNT_SWep_Base_CacheY" ) , SizeX , SizeY )
310 end
311
312 if self:GetVNTSBBipod( ) == true then
313 surface.SetDrawColor( 255 , 255 , 255 , 255 )
314 surface.SetTexture( TEX_Bipod )
315 surface.DrawTexturedRect( ScrW( ) * 0.925 + GetConVarNumber( "VNT_SWep_Base_CacheX" ) , ScrH( ) * 0.7 + GetConVarNumber( "VNT_SWep_Base_CacheY" ) , SizeX , SizeY )
316 end
317 end
318
319 if self.ScopeType == 1 then
320 surface.SetDrawColor( 255 , 255 , 255 , 255 )
321 local SWid = surface.ScreenWidth( )
322 local SHei = surface.ScreenHeight( )
323 local ScSize = self.ScopeOverlayScale
324 local ScMat = self.ScopeMaterial
325 local TEX_REDDOT = surface.GetTextureID( "jessev92/ui/scope/crosshair_reddot" )
326 local TEX_EOTECH = surface.GetTextureID( "jessev92/ui/scope/crosshair_eotech" )
327 local TEX_ACOG = surface.GetTextureID( "jessev92/ui/scope/crosshair_acog" )
328 local TEX_SVD = surface.GetTextureID( "jessev92/ui/scope/crosshair_svd" )
329 local TEX_M14 = surface.GetTextureID( "jessev92/ui/scope/crosshair_m14" )
330 local TEX_L42A1 = surface.GetTextureID( "jessev92/ui/scope/crosshair_l42a1" )
331 local TEX_PSG1 = surface.GetTextureID( "jessev92/ui/scope/crosshair_psg1" )
332 local TEX_GERMAN = surface.GetTextureID( "jessev92/ui/scope/crosshair_german" )
333
334 if self:GetVNTSBScopedIn( ) == true then
335 -- (Integer) Type of overlay, 0=Red Dot, 1=EOTech, 2=ACOG, 3=SVD, 4=M14, 5=L42A1
336 if ScopeMaterialCustom != nil then
337 surface.SetMaterial( self.ScopeMaterialCustom )
338 else
339 if ScMat == 0 then
340 surface.SetTexture( TEX_REDDOT )
341 elseif ScMat == 1 then
342 surface.SetTexture( TEX_EOTECH )
343 elseif ScMat == 2 then
344 surface.SetTexture( TEX_ACOG )
345 elseif ScMat == 3 then
346 surface.SetTexture( TEX_SVD )
347 elseif ScMat == 4 then
348 surface.SetTexture( TEX_M14 )
349 elseif ScMat == 5 then
350 surface.SetTexture( TEX_L42A1 )
351 elseif ScMat == 6 then
352 surface.SetTexture( TEX_PSG1 )
353 elseif ScMat == 7 then
354 surface.SetTexture( TEX_GERMAN )
355 end
356 end
357 surface.DrawTexturedRect( ( ( SWid / 2 ) - ( SHei / 2 ) ) , ( 0 ) , SHei , SHei )
358 end
359 end
360
361 return true
362 end
363
364 ----------------------------------------------------------
365 -- SWEP:GetViewModelPosition() -- Allows you to re-position the view model.
366 ----------------------------------------------------------
367 function SWEP:GetViewModelPosition( pos , ang )
368 local bIron = self:GetVNTSBIronSighted( )
369 local Holster = self:GetVNTSBHolstered( )
370 local DashDelta = 0
371
372 if ( ( self.Owner:KeyDown( IN_SPEED ) ) and ( self.Owner:GetVelocity( ):Length( ) > self.Owner:GetWalkSpeed( ) ) ) or self.NearWall and ( self.WeaponType ~= 1 ) then
373 if ( not self.DashStartTime ) then
374 self.DashStartTime = CurTime( )
375 end
376
377 --how much movment when running
378 self.SwayScale = 2.0
379 self.BobScale = 2.0
380 --movment time
381 DashDelta = math.Clamp( ( ( CurTime( ) - self.DashStartTime ) / 0.15 ) ^ 1.2 , 0 , 1 )
382 else
383 if ( self.DashStartTime ) then
384 self.DashEndTime = CurTime( )
385 end
386
387 --how much movement when in or out of ironsights
388 if ( self:GetVNTSBIronSighted( ) == true ) then
389 self.SwayScale = 0.1
390 self.BobScale = 0.1
391 else
392 self.SwayScale = 1.0
393 self.BobScale = 1.0
394 end
395
396 --movment time
397 if ( self.DashEndTime ) then
398 DashDelta = math.Clamp( ( ( CurTime( ) - self.DashEndTime ) / 0.15 ) ^ 1.2 , 0 , 1 )
399 DashDelta = 1 - DashDelta
400
401 if ( DashDelta == 0 ) then
402 self.DashEndTime = nil
403 end
404 end
405
406 self.DashStartTime = nil
407 end
408
409 --now all the movment and stuff
410 if ( DashDelta ) then
411 local Down = ang:Up( ) * -1
412 local Right = ang:Right( )
413 local Forward = ang:Forward( )
414 local UseVector = false
415
416 if ( not self.RunArmAngle.pitch ) then
417 UseVector = true
418 end
419
420 if ( UseVector == true ) then
421 ang:RotateAroundAxis( ang:Right( ) , self.RunArmAngle.x * DashDelta )
422 ang:RotateAroundAxis( ang:Up( ) , self.RunArmAngle.y * DashDelta )
423 ang:RotateAroundAxis( ang:Forward( ) , self.RunArmAngle.z * DashDelta )
424 pos = pos + self.RunArmOffset.x * ang:Right( ) * DashDelta
425 pos = pos + self.RunArmOffset.y * ang:Forward( ) * DashDelta
426 pos = pos + self.RunArmOffset.z * ang:Up( ) * DashDelta
427 else
428 ang:RotateAroundAxis( Right , self.RunArmAngle.pitch * DashDelta )
429 ang:RotateAroundAxis( Down , self.RunArmAngle.yaw * DashDelta )
430 ang:RotateAroundAxis( Forward , self.RunArmAngle.roll * DashDelta )
431 pos = pos + ( Down * self.RunArmOffset.x + Forward * self.RunArmOffset.y + Right * self.RunArmOffset.z ) * DashDelta
432 end
433
434 if ( self.DashEndTime ) then return pos , ang end
435 end
436
437 if ( self:GetVNTSBIronSighted( ) ~= self.LastIron ) then
438 self.LastIron = self:GetVNTSBIronSighted( )
439 self.IronTime = CurTime( )
440
441 if ( self:GetVNTSBIronSighted( ) == true ) then
442 self.SwayScale = 0.1
443 self.BobScale = 0.1
444 else
445 self.SwayScale = 1.0
446 self.BobScale = 1.0
447 end
448 end
449
450 local IronTime = self.IronTime or 0
451 if ( self:GetVNTSBIronSighted( ) == false and IronTime < CurTime( ) - IronsightToggleTime ) then return pos , ang end
452 local Mul = 1.0
453
454 if ( IronTime > CurTime( ) - IronsightToggleTime ) then
455 Mul = math.Clamp( ( CurTime( ) - IronTime ) / IronsightToggleTime , 0 , 1 )
456
457 if ( not bIron ) then
458 Mul = 1 - Mul
459 end
460 end
461 if self:GetVNTSBStock() == true then
462 if ( self.StockIronSightsAng ) then
463 ang = ang * 1
464 ang:RotateAroundAxis( ang:Right( ) , self.StockIronSightsAng.x * Mul )
465 ang:RotateAroundAxis( ang:Up( ) , self.StockIronSightsAng.y * Mul )
466 ang:RotateAroundAxis( ang:Forward( ) , self.StockIronSightsAng.z * Mul )
467 end
468
469 local Right = ang:Right( )
470 local Up = ang:Up( )
471 local Forward = ang:Forward( )
472 pos = pos + self.StockIronSightsPos.x * Right * Mul
473 pos = pos + self.StockIronSightsPos.y * Forward * Mul
474 pos = pos + self.StockIronSightsPos.z * Up * Mul
475 else
476 if ( self.IronSightsAng ) then
477 ang = ang * 1
478 ang:RotateAroundAxis( ang:Right( ) , self.IronSightsAng.x * Mul )
479 ang:RotateAroundAxis( ang:Up( ) , self.IronSightsAng.y * Mul )
480 ang:RotateAroundAxis( ang:Forward( ) , self.IronSightsAng.z * Mul )
481 end
482
483 local Right = ang:Right( )
484 local Up = ang:Up( )
485 local Forward = ang:Forward( )
486 pos = pos + self.IronSightsPos.x * Right * Mul
487 pos = pos + self.IronSightsPos.y * Forward * Mul
488 pos = pos + self.IronSightsPos.z * Up * Mul
489 end
490 return pos , ang
491 end
492
493 -----------------------------------------------------------
494 -- SWEP:AdjustMouseSensitivity()
495 -- Allows you to adjust the mouse sensitivity.
496 -----------------------------------------------------------
497 function SWEP:AdjustMouseSensitivity( )
498 if ( self:GetVNTSBScopedIn( ) == true ) then
499 if self.IsCloseZoomed == true then
500 return 0.05
501 else
502 return 0.15
503 end
504 elseif ( self:GetVNTSBIronSighted( ) == true ) then
505 return 0.25
506 else
507 return 1
508 end
509 end
510
511 -----------------------------------------------------------
512 -- SWEP:GetTracerOrigin()
513 -- Allows you to override where the TracerType comes from (in first person view)
514 -- returning anything but a vector indicates that you want the default action.
515 -----------------------------------------------------------
516 function SWEP:GetTracerOrigin( )
517 end
518end
519
520------------------------------------------------------
521-- Primary Fire Functions --
522------------------------------------------------------
523function SWEP:CanPrimaryAttack( )
524 if self.Owner:IsPlayer( ) and self.Owner:IsValid( ) then
525 if self:GetVNTSBHolstered( ) == true or self:Clip1( ) <= 0 or self:GetVNTSBJammedB( ) == true or self:GetVNTSBJammedL( ) == true or self.Owner:KeyDown( IN_SPEED ) or self.NearWall then
526 -- mag's empty
527 --(self.Primary.ClipSize <= 0 and self.Melee == false) or -- or we don't use ammo/we're not melee
528 --not self.Owner:IsNPC() or -- or we're not an NPC
529 -- or we have a big jam
530 -- or we have a small jam
531 -- or we're sprinting
532 -- or we're near a wall
533 -- If the mag is empty, the bolt is back, and we're not a melee then
534 if ( self:Clip1( ) <= 0 ) and self.FiringPinForward == false and self.WeaponType ~= 1 then
535 if self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true then
536 else
537 end
538
539 -- play our suppressed dry fire
540 --self:SendWeaponAnim( ACT_VM_DRYFIRE_SILENCED )
541 --self:SendWeaponAnim(ACT_VM_DRYFIRE)
542 if ( self.WeaponType == 2 ) then
543 self:EmitSound( "VNT.SWep.Empty6" )
544 else
545 self:EmitSound( "VNT.SWep.Empty5" )
546 end
547
548 self.FiringPinForward = true
549 end
550
551 return false -- we can't shoot
552 end -- If holstered,
553 end
554
555 return true -- we can shoot
556end -- Check if we can run +attack
557
558function SWEP:PrimaryAttack( )
559
560 -- Run our melee function
561 if self.WeaponType == 1 then
562 self:Melee( )
563
564 return false
565 end
566
567 -- we can't fire underwater & we're underwater
568 if ( self.CanFireUnderwater == false and self.Owner:WaterLevel( ) > 2 ) then
569 return false
570 else
571 if self:GetVNTSBScopedIn( ) == true then
572 if self.BoltAction == true then
573 if ( self:GetVNTSBScopedIn( ) == true or self:GetVNTSBIronSighted( ) == true ) then
574 self:ToggleIronsights( )
575 end
576
577 if self.ReturnToScope == true then
578 timer.Simple( 0.6 , function( )
579 self:ToggleIronsights( )
580 end )
581 end
582 end
583 end
584
585 -- If you're pressing Use+Mouse1 and we're not in iron sights, and we're not a melee then
586 if ( self.Owner:KeyDown( IN_USE ) and ( self:GetVNTSBIronSighted( ) == false or self:GetVNTSBStock( ) == false or self:GetVNTSBScopedIn( ) == false or self:GetVNTSBGLauncher( ) == false ) ) then
587 -- If you press Mouse 1 + Use, Toggle our GL or Bipod mode if we have them
588 if ( self.DeployableType ~= 0 ) then
589 -- If we have a GL
590 if self.DeployableType == 1 then
591 -- Toggle our GL mode and end the function
592 if SERVER then
593 self:ToggleGrenadeMode( )
594 end
595
596 return false
597 elseif self.DeployableType == 2 or self.DeployableType == 3 then
598 -- If we have a bipod
599 -- Toggle our bipod deployment and end the function
600 if SERVER then
601 self:ToggleBipod( )
602 end
603
604 return false
605 elseif self.DeployableType == 4 then
606 -- If we have a stock
607 -- Toggle our stock deployment and end the function
608 if SERVER then
609 self:ToggleStock( )
610 end
611
612 return false
613 else
614 -- else if you didn't read and put both of them to true, set them both to false to prevent errors, sorry boys.
615 self.DeployableType = 0
616 end
617 end
618 end
619
620 -- Check for various things that say, "hey fucktard, you can't shoot now"
621 if not self:CanPrimaryAttack( ) then return end
622
623 -- If we're in GL mode and action delay has expire then
624 if self:GetVNTSBGLauncher( ) == true then
625 -- If the launcher is empty, and the bolt is back then
626 if self:GetVNTSBLchrLoaded( ) == false and self.LauncherPinForward == false then
627 -- Emit our empty sound
628 self:EmitSound( self.SND_PrimaryDryFire )
629 -- Set a delay
630 self:SetNextPrimaryFire( CurTime( ) + self.Primary.Delay )
631 self:SetNextSecondaryFire( CurTime( ) + self.Primary.Delay )
632 -- Bolt is forward
633 self.LauncherPinForward = true
634 elseif self:GetVNTSBLchrLoaded( ) == true and self.LauncherPinForward == false then
635
636 self:SetNextPrimaryFire( CurTime( ) + self.Primary.Delay )
637 self:SetNextSecondaryFire( CurTime( ) + self.Primary.Delay )
638
639 self:TakeSecondaryAmmo( 1 )
640 self:FireViewPunches( )
641 self:SetVNTSBLchrLoaded( false )
642 self:EmitSound( self.SND_GrenadeLauncherFire )
643
644 if CLIENT then
645 -- If our muzzle flashes are enabled
646 if GetConVarNumber( "VNT_SWep_Base_FlashToggle" ) ~= 0 then
647 self.Owner:MuzzleFlash( )
648 -- Emit our muzzle flash
649 local FX = EffectData( )
650 FX:SetOrigin( self.Owner:GetShootPos( ) )
651 FX:SetEntity( self )
652 FX:SetStart( self.Owner:GetShootPos( ) )
653 FX:SetNormal( self.Owner:GetAimVector( ) )
654 FX:SetAttachment( self.MuzzleAttach )
655 -- emit normal rifle smoke
656 util.Effect( "fx_smoke_rifle_ins" , FX )
657 end
658 end
659
660 self:EntityLauncher( )
661 end
662
663 -- Exit our attack function
664 return false
665 end
666
667 -- If our mag isn't empty
668 if self:Clip1( ) > 0 then
669 -- If we're suppressed then
670 if self:GetVNTSBSuppressed( ) == true then
671 -- Emit our suppressed sound
672 self:EmitSound( self.SND_PrimarySuppressedFire )
673 else
674 -- Else emit the normal sound
675 self:EmitSound( self.SND_PrimaryFire )
676 end
677
678 -- Run our view punches
679 self:FireViewPunches( )
680
681 if self.WeaponType == 6 then
682 self:Recoil( 0.225 , true )
683 self:EntityShooter( )
684 self:TakePrimaryAmmo( 1 )
685 else
686 if self.CurrentMode == 1 then
687 self.Primary.Automatic = false
688 self:Recoil( 0.225 , true )
689 self:FireBullet( self.Primary.Damage , self.Primary.Recoil , self.Primary.NumShots , self.Primary.Cone )
690 self:SetNextPrimaryFire( CurTime( ) + self.Primary.Delay )
691 self:TakePrimaryAmmo( 1 )
692 elseif self.CurrentMode == 2 then
693 self.Primary.Automatic = false
694 self:Recoil( 0.225 , true )
695 self.BurstTimer = CurTime( )
696 self.BurstCounter = self.BurstShots - 1
697 self:SetNextPrimaryFire( CurTime( ) + 0.5 )
698 elseif self.CurrentMode == 3 then
699 self.Primary.Automatic = true
700 self:Recoil( 0.225 , true )
701 self:FireBullet( self.Primary.Damage , self.Primary.Recoil , self.Primary.NumShots , self.Primary.Cone )
702 self:SetNextPrimaryFire( CurTime( ) + self.Primary.Delay )
703 self:TakePrimaryAmmo( 1 )
704 end
705 end
706
707 -- Muzzle flashes & shells
708 self:ShootEffects( )
709 -- Play our firing animations
710 self:PlayFiringAnimation( )
711
712 if self:SelectWeightedSequence( ACT_SHOTGUN_PUMP ) and self.PUMPACTION == true then
713 -- If we have a pump sound defined
714 if self.SND_ShotgunPump ~= nil then
715 -- Play a finish sound
716 self:EmitSound( self.SND_ShotgunPump )
717 end
718
719 self:SendWeaponAnim( ACT_SHOTGUN_PUMP )
720 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
721 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
722 end
723
724 -- Add a delay before we fire our next bullet based on RPM
725 self.ActionDelay = ( CurTime( ) + self.Primary.Delay )
726
727 -- If our Jam toggle is set to true then
728 if GetConVarNumber( "VNT_SWep_Base_JamToggle" ) ~= 0 then
729 -- If we're holstered or mag is empty then quit
730 if self:GetVNTSBHolstered( ) == true or self:Clip1( ) <= 1 then return end
731 -- Set our Jam chance to be based on our CVar
732 local JammingChance = math.random( 1 , self.JammingChance )
733
734 -- If we hit our small jam chance
735 if JammingChance > ( JammingChance - 5 ) then
736 -- Set jammed little to true and run the function
737 self:SetVNTSBJammedL( true )
738 self:Jammed( )
739 elseif JammingChance <= 1 then
740 -- Else if we hit one
741 -- Set our big jam to true and run the function
742 self:SetVNTSBJammedB( true )
743 self:Jammed( )
744 end
745 end
746 end
747 end
748end -- +attack1 has been pressed.
749
750------------------------------------------------------
751-- Secondary Fire Functions --
752------------------------------------------------------
753function SWEP:CanSecondaryAttack( )
754 if self.Owner:IsPlayer( ) and self.Owner:IsValid( ) then
755 if ( self:GetVNTSBHolstered( ) == true ) or self:Clip2( ) <= 0 or self.Secondary.ClipSize <= 0 or self:GetVNTSBJammedB( ) == true or self:GetVNTSBJammedL( ) == true or self.Owner:KeyDown( IN_SPEED ) or self.WeaponType == 1 or self.NearWall then
756 -- mag's empty
757 -- or we don't use ammo
758 -- or we have a big jam
759 -- or we have a small jam
760 -- or we're sprinting
761 -- or we're a melee
762 -- or we're near a wall
763 return false -- we can't shoot
764 else
765 return true -- we can shoot
766 end -- If holstered,
767 end
768end -- Check if we can run +attack2
769
770function SWEP:SecondaryAttack( )
771 if not IsFirstTimePredicted( ) then return end
772
773 if self.AltFireMelee == true then
774 self:Melee()
775 return false
776 end
777
778 if ( self.WeaponType == 1 ) then
779 -- if we're a melee, holster
780 if self.Owner:KeyDown( IN_USE ) then
781 self:ToggleHolster( )
782 else
783 return false
784 end
785 elseif self:GetVNTSBScopedIn( ) == true and ( self.Owner:KeyDown( IN_USE ) ) then
786 self:ToggleZoom( )
787 else
788 if ( self.Owner:KeyDown( IN_USE ) and not self:GetVNTSBScopedIn( ) == true ) then
789 -- cycle the fire mode
790 self:ToggleFireMode( )
791 elseif not ( self.Owner:KeyDown( IN_USE ) ) and self.Owner:KeyDown( IN_WALK ) then
792 -- Toggle the suppressor
793 self:ToggleSuppressor( )
794 elseif self.IsAkimbo == true then
795 -- Check for various things that say, "hey fucktard, you can't shoot now"
796 if not self:CanSecondaryAttack( ) then return end
797
798 -- If our mag isn't empty
799 if self:Clip2( ) > 0 then
800 -- If we're suppressed then
801 if self:GetVNTSBSuppressed( ) == true then
802 -- Emit our suppressed sound
803 self:EmitSound( self.SND_PrimarySuppressedFire )
804 else
805 -- Else emit the normal sound
806 self:EmitSound( self.SND_PrimaryFire )
807 end
808
809 -- Run our view punches
810 self:FireViewPunches( )
811
812 if self.CurrentMode == 1 then
813 self.Primary.Automatic = false
814
815 if self:CanSecondaryAttack( ) then
816 self:Recoil( 0.225 , true )
817 self:FireBulletL( self.Primary.Damage , self.Primary.Recoil , self.Primary.NumShots , self.Primary.Cone )
818 self:SetNextSecondaryFire( CurTime( ) + self.Primary.Delay )
819 self:TakeSecondaryAmmo( 1 )
820 end
821 elseif self.CurrentMode == 2 then
822 self.Primary.Automatic = false
823
824 if self:CanSecondaryAttack( ) then
825 self:Recoil( 0.225 , true )
826 self.BurstTimerL = CurTime( )
827 self.BurstCounterL = self.BurstShotsL - 1
828 self:SetNextSecondaryFire( CurTime( ) + 0.5 )
829 end
830 elseif self.CurrentMode == 3 then
831 self.Primary.Automatic = true
832
833 if self:CanSecondaryAttack( ) then
834 self:Recoil( 0.225 , true )
835 self:FireBulletL( self.Primary.Damage , self.Primary.Recoil , self.Primary.NumShots , self.Primary.Cone )
836 self:SetNextSecondaryFire( CurTime( ) + self.Primary.Delay )
837 self:TakeSecondaryAmmo( 1 )
838 end
839 end
840
841 -- Muzzle flashes & shells
842 self:ShootEffectsLeftHand( )
843 -- Play our firing animations
844 self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
845 -- Add a delay before we fire our next bullet based on RPM
846 self.ActionDelay = ( CurTime( ) + self.Primary.Delay + 0.05 )
847
848 -- If our Jam toggle is set to true then
849 if GetConVarNumber( "VNT_SWep_Base_JamToggle" ) ~= 0 then
850 -- If we're holstered or mag is empty then quit
851 if self:GetVNTSBHolstered( ) == true or self:Clip2( ) <= 1 then return end
852 -- Set our Jam chance to be based on our CVar
853 local JammingChance = math.random( 1 , GetConVarNumber( "VNT_SWep_Base_JamChance" ) )
854
855 -- If we hit our small jam chance
856 if JammingChance > ( JammingChance - 5 ) then
857 -- Set jammed little to true and run the function
858 self:SetVNTSBJammedL( true )
859 self:Jammed( )
860 elseif JammingChance <= 1 then
861 -- Else if we hit one
862 -- Set our big jam to true and run the function
863 self:SetVNTSBJammedB( true )
864 self:Jammed( )
865 end
866 end
867 end
868
869 return false
870 else
871 -- If we're in iron sights, pull out of them
872 self:ToggleIronsights( )
873 end
874 end
875end -- +attack2 has been pressed.
876
877------------------------------------------------------
878-- Play Firing Animations --
879------------------------------------------------------
880function SWEP:PlayFiringAnimation( )
881 -- If we're owner, a player, valid, and alive then
882 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) then
883 if ( self:GetVNTSBIronSighted( ) == true ) then
884 if self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_SHOOTLAST ) and self:Clip1() < 1 then
885 self:SendWeaponAnim( ACT_VM_SHOOTLAST )
886 elseif ( self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true ) then
887 self:SendWeaponAnim( ACT_VM_PRIMARYATTACK_SILENCED )
888 elseif ( self:GetVNTSBGLauncher( ) == true or self:GetVNTSBBipod( ) == true ) then
889 self:SendWeaponAnim( ACT_VM_DEPLOYED_FIRE )
890 elseif self.IsAkimbo == true then
891 self:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
892 else
893 self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
894 end
895 elseif ( self:GetVNTSBIronSighted( ) == false ) then
896 if self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_SHOOTLAST ) and self:Clip1() < 1 then
897 self:SendWeaponAnim( ACT_VM_SHOOTLAST )
898 elseif ( self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true ) and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_PRIMARYATTACK_SILENCED ) then
899 self:SendWeaponAnim( ACT_VM_PRIMARYATTACK_SILENCED )
900 elseif ( self:GetVNTSBGLauncher( ) == true or self:GetVNTSBBipod( ) == true ) and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DEPLOYED_FIRE ) then
901 self:SendWeaponAnim( ACT_VM_DEPLOYED_FIRE )
902 elseif self.IsAkimbo == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_SECONDARYATTACK ) then
903 self:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
904 else
905 self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
906 end
907 end
908 end
909end -- Play firing animations
910
911------------------------------------------------------
912-- Reload Functions --
913------------------------------------------------------
914function SWEP:Reload( )
915
916 local ATime = self.Owner:GetViewModel( ):SequenceDuration( )
917 local CTime = CurTime( )
918 local BTime = CTime + ATime
919 local DTime = CTime > ATime
920
921 -- If action delay is still in effect or we're sprinting, return false and end this function
922 if ( self.ActionDelay > CurTime( ) ) or self.Owner:KeyDown( IN_SPEED ) then return false end
923
924 -- If we can't reload when not empty and
925 if self.CanReloadWhenNotEmpty == false and self:Clip1() != 0 then return false end
926
927 -- If we're in iron sights, toggle out of them and continue
928 if self:GetVNTSBIronSighted( ) == true or self:GetVNTSBScopedIn( ) == true then
929 self:ToggleIronsights( )
930 end
931
932 -- If you're holstered and you press USE & RELOAD at the same time, toss the weapon away
933 if self:GetVNTSBHolstered( ) == true and not self.Owner:KeyDown( IN_USE ) then
934
935 -- End our function here
936 return false
937
938 elseif self:GetVNTSBHolstered( ) == true and self.Owner:KeyDown( IN_USE ) then
939
940 -- If you're holstered and you press USE+RELOAD throw our weapon
941 -- Play the holster animation
942 self:SendWeaponAnim( ACT_VM_HOLSTER )
943
944 if CLIENT then
945
946 -- Set a delay so we aren't shooting while throwing
947 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
948 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
949
950 self.ActionDelay = ( CurTime( ) + 10 )
951
952 elseif SERVER then
953
954 -- Return the ammo from the mag
955 self.Owner:GiveAmmo( self:Clip1( ) , self:GetPrimaryAmmoType( ) , true )
956
957 -- Run the throw function
958 self:Throw( )
959
960 end
961
962 -- End our function
963 return false
964
965 end
966
967 -- If we're: Holstered, JamB, JamL, or Mag is superloaded, and you're not pressing USE while holstered, return false and end this function
968 if ( self:GetVNTSBJammedB( ) or self:GetVNTSBJammedL( ) ) or ( self:Clip1( ) == ( self:Clip1( ) + self.Primary.ClipSizePlus ) ) then return false end
969
970 -- If we have our GL deployed then
971 if self:GetVNTSBGLauncher( ) == true or self.IsEntityShooter == true then
972
973 -- If we have ammo for it, and it's not loaded then
974 if self.Owner:GetAmmoCount( self.Secondary.Ammo ) > 0 and self:GetVNTSBLchrLoaded( ) == false then
975
976 -- Play the specified deploy reload
977 if self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_RELOAD_DEPLOYED ) then
978 self:SendWeaponAnim( ACT_VM_RELOAD_DEPLOYED )
979 end
980
981 if CLIENT then
982
983 -- Set our time to fire until after the sequence has played
984 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
985 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
986
987 elseif SERVER then
988
989 -- Now we're loaded so signal we can fire
990 self:SetVNTSBLchrLoaded( true )
991
992 -- Our hammer is back
993 self.LauncherPinForward = false
994
995 end
996 end
997
998 -- Return false and end the reload function
999 return false
1000
1001 end
1002
1003 if self.ShellReload == true then
1004
1005 if ( self:Clip1() < self.Primary.ClipSize ) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
1006
1007 if self:GetVNTSBShotgunRel( ) == true then return false end
1008
1009 -- Play our anim
1010 self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_START )
1011
1012 self:SetVNTSBShotgunRel( true )
1013
1014 self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1015 self:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1016
1017 end
1018
1019 return false
1020
1021 end
1022
1023 -- if mag is < mag size, and we have ammo then
1024 if ( self:Clip1( ) < self.Primary.ClipSize ) and ( self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
1025
1026 if SERVER then
1027
1028 -- Play a sound in third-person
1029 self.Owner:EmitSound( self.SND_Reload )
1030
1031 end
1032
1033 -- Play the next function
1034 self:ReloadAnimation( )
1035
1036 end
1037
1038end -- Reload is being pressed.
1039
1040function SWEP:ReloadAnimation( )
1041
1042 -- Call the reload animations so it plays them
1043 self:DefaultReload( ACT_VM_RELOAD )
1044 self.Owner:SetAnimation( PLAYER_RELOAD )
1045
1046 -- If mag is 0 and it has empty animations then
1047 if ( self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_RELOAD_SILENCED ) ) then
1048 self:SendWeaponAnim( ACT_VM_RELOAD_SILENCED )
1049 elseif ( self:Clip1( ) == 0 and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_RELOAD_EMPTY ) ) then
1050 -- Play the empty reload animation
1051 self:SendWeaponAnim( ACT_VM_RELOAD_EMPTY )
1052 else
1053 -- Else if our mag is empty and we don't have empty anims then
1054 -- Play our normal reload animation
1055 self:SendWeaponAnim( ACT_VM_RELOAD )
1056 end
1057
1058 -- Else if we can put one in the chamber
1059 if self:Clip1( ) > 0 and self.CanChamber == true then
1060 -- Run our timer for the round in the chamber
1061 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) + 0.75 , function( )
1062 if ( not IsValid( self.Owner ) or not IsValid( self ) or not self.Owner:Alive( ) or ( self.Owner:GetAmmoCount( self.Primary.Ammo ) < 1 ) ) then return end
1063 -- Remove the difference from the slot
1064 self.Owner:RemoveAmmo( 1 , self:GetPrimaryAmmoType( ) )
1065 -- Set our mag to ClipSizePlus
1066 self:SetClip1( self:Clip1( ) + self.Primary.ClipSizePlus )
1067 end )
1068 end
1069
1070 if self.WeaponType == 6 then
1071 self:SetVNTSBLchrLoaded( true )
1072 end
1073end -- Specialty reload stuff
1074
1075function SWEP:EndSGReload()
1076
1077 self:SetVNTSBShotgunRel( false )
1078
1079 self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH )
1080 self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1081 self:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1082
1083 return false
1084end
1085
1086------------------------------------------------------
1087-- Holster and Deploy Functions --
1088------------------------------------------------------
1089function SWEP:Holster( )
1090 if ( self:Clip1( ) == 0 and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_HOLSTER_EMPTY ) ) then
1091 self:SendWeaponAnim( ACT_VM_HOLSTER_EMPTY )
1092 else
1093 self:SendWeaponAnim( ACT_VM_HOLSTER )
1094 end
1095
1096 -- self:SetVNTSBHolsterTime( self.Owner:GetViewModel():SequenceDuration() )
1097 -- If our delay is up, switch'em up
1098 -- if self:GetVNTSBHolsterTime() == 0 then
1099 -- If our holster time is 0 then true, switch
1100 -- return true
1101 -- else
1102 -- If our holster time isn't then quit
1103 -- return false
1104 -- end
1105 return true
1106end -- We're swapping weapons
1107
1108function SWEP:Deploy( )
1109 --[[
1110 if self:GetVNTSBHolstered() == true then
1111 if self.Owner:KeyDown(IN_DUCK) then
1112 self:SetWeaponHoldType(self.HoldType)
1113 else
1114 self:SetWeaponHoldType("passive")
1115 end
1116 else
1117 self:SetWeaponHoldType(self.HoldType)
1118 end
1119 --]]
1120 -- If we're suppressed and we're using a budget suppressor
1121 if self:GetVNTSBSuppressed( ) == true then
1122 if self.SuppressorType == 1 then
1123 -- Set our models to the suppressed versions
1124 self.ViewModel = self.ViewModelSuppressed
1125 self.WorldModel = self.WorldModelSuppressed
1126 elseif self.SuppressorType == 2 then
1127 -- Set our models to the suppressed versions
1128 self.WorldModel = self.WorldModelSuppressed
1129 end
1130 elseif self:GetVNTSBBipod( ) == true then
1131 if self.DeployableType == 2 then
1132 -- Set our models to the bipod versions
1133 self.WorldModel = self.WorldModelBipod
1134 self.STOCKGRAB = true
1135 elseif self.DeployableType == 3 then
1136 -- Set our models to the bipod versions
1137 self.ViewModel = self.ViewModelBipod
1138 self.WorldModel = self.WorldModelBipod
1139 self.STOCKGRAB = true
1140 end
1141 elseif self:GetVNTSBStock( ) == true then
1142 -- Set our models to the suppressed versions
1143 self.ViewModel = self.ViewModelStockOut
1144 self.WorldModel = self.WorldModelStockOut
1145 else
1146 -- Reset our models
1147 self.ViewModel = self.ViewModel
1148 self.WorldModel = self.WorldModel
1149 end
1150
1151 -- Run our special function
1152 self:DeployAnimation( )
1153
1154 if SERVER then
1155 if self.Primary.Cone > self.BaseCone then
1156 self.Primary.Cone = self.BaseCone
1157 end
1158
1159 self.CrouchPane = 1
1160 elseif CLIENT then
1161 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
1162 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
1163 self.ActionDelay = ( CurTime( ) + self.DeployDelay + 0.05 )
1164 end
1165
1166 -- If we're in iron sights, toggle out of them and continue
1167 if self:GetVNTSBIronSighted( ) == true then
1168 self:ToggleIronsights( )
1169 end
1170
1171 -- If we're holstered continue
1172 if self:GetVNTSBHolstered( ) == true then return true end
1173
1174 -- If we're a shotgun we're not reloading
1175 if self.Shotgun == true then
1176 self:SetVNTSBShotgunRel( false )
1177 end
1178end -- We just deployed our weapon
1179
1180function SWEP:DeployAnimation( )
1181 if ( self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DRAW_SILENCED ) ) then
1182 self:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
1183 elseif ( self:Clip1( ) == 0 and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DRAW_EMPTY ) ) then
1184 self:SendWeaponAnim( ACT_VM_DRAW_EMPTY )
1185 else
1186 self:SendWeaponAnim( ACT_VM_DRAW )
1187 end
1188end -- Specialty deploy stuff
1189
1190------------------------------------------------------
1191-- Think Functions --
1192------------------------------------------------------
1193function SWEP:Think( )
1194 local MaxRunSpeed = GetConVarNumber( "VNT_SWep_Base_Speed_Run" )
1195 local MaxWalkSpeed = GetConVarNumber( "VNT_SWep_Base_Speed_Walk" )
1196 local ATime = self.Owner:GetViewModel( ):SequenceDuration( )
1197 local CTime = CurTime( )
1198 local BTime = CTime + ATime
1199 local DTime = CTime > ATime
1200
1201 -- If we're owner, a player, valid, and alive then
1202 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) then
1203 -- Run our second think function in the children
1204 self:CustomThink( )
1205
1206 -- If we're holstered, return and end
1207 if self:GetVNTSBHolstered( ) == true then return end
1208
1209 if self:GetVNTSBBipod( ) == true then
1210 self.Owner:SetRunSpeed( MaxRunSpeed / 3 )
1211 self.Owner:SetWalkSpeed( MaxWalkSpeed / 3 )
1212 elseif ( self.Owner:KeyDown( IN_SPEED ) and self:GetVNTSBBipod( ) == true ) then
1213 self:ToggleBipod( )
1214 elseif self:GetVNTSBBipod( ) == false then
1215 self.Owner:SetRunSpeed( MaxRunSpeed )
1216 self.Owner:SetWalkSpeed( MaxWalkSpeed )
1217 end
1218
1219 --if (self.BoltAction) and (self.Owner:KeyPressed(IN_ATTACK2) or self.Owner:KeyPressed(IN_RELOAD)) then self.ReturnToScope = false end
1220 if self.CurrentMode == 2 then
1221 -- Reset our burst counter to prevent it from continuing to fire after reloading
1222 if self:Clip1( ) <= 0 then
1223 self.BurstCounter = 0
1224 end
1225
1226 if self:Clip2( ) <= 0 then
1227 self.BurstCounterL = 0
1228 end
1229
1230 -- If we're in Burst mode and we can attack then
1231 if self:CanPrimaryAttack( ) then
1232 -- If burst timer + delay < CurTime and burst count is > 0 then
1233 if self.BurstTimer + self.BurstDelay < CurTime( ) and self.BurstCounter > 0 then
1234 -- If we're suppressed then
1235 if self:GetVNTSBSuppressed( ) == true then
1236 -- Emit our suppressed sound
1237 self:EmitSound( self.SND_PrimarySuppressedFire )
1238 else
1239 -- Else emit the normal sound
1240 self:EmitSound( self.SND_PrimaryFire )
1241 end
1242
1243 -- Minus one off
1244 self.BurstCounter = self.BurstCounter - 1
1245 -- Reset the timer
1246 self.BurstTimer = CurTime( )
1247 -- Run our fire bullet function
1248 self:FireBullet( self.Primary.Damage , self.Primary.Recoil , self.Primary.NumShots , self.Primary.Cone )
1249 -- Set our next fire times
1250 self:SetNextPrimaryFire( CurTime( ) + self.Primary.Delay )
1251 -- Take a bullet
1252 self:TakePrimaryAmmo( 1 )
1253 end
1254 end
1255
1256 -- If we're in Burst mode and we can attack then
1257 if self:CanSecondaryAttack( ) then
1258 -- If burst timer + delay < CurTime and burst count is > 0 then
1259 if self.BurstTimerL + self.BurstDelayLeft < CurTime( ) and self.BurstCounterL > 0 then
1260 -- If we're suppressed then
1261 if self:GetVNTSBSuppressed( ) == true then
1262 -- Emit our suppressed sound
1263 self:EmitSound( self.SND_PrimarySuppressedFire )
1264 else
1265 -- Else emit the normal sound
1266 self:EmitSound( self.SND_PrimaryFire )
1267 end
1268
1269 -- Minus one off
1270 self.BurstCounterL = self.BurstCounterL - 1
1271 -- Reset the timer
1272 self.BurstTimerL = CurTime( )
1273 -- Run our fire bullet function
1274 self:FireBullet( self.Primary.Damage , self.Primary.Recoil , self.Primary.NumShots , self.Primary.Cone )
1275 -- Set our next fire times
1276 self:SetNextSecondaryFire( CurTime( ) + self.Primary.Delay )
1277 -- Take a bullet
1278 self:TakeSecondaryAmmo( 1 )
1279 end
1280 end
1281 end
1282
1283 -- If mag isn't empty
1284 if self:Clip1( ) > 0 then
1285 -- Prevents the bolt from clicking more than once when the mag is empty
1286 self.FiringPinForward = false
1287 end
1288
1289 -- Get our eye trace
1290 local Tr = self.Owner:GetEyeTrace( )
1291
1292 -- If our trace hit a valid ent, an NPC, a Player, and it's a pistol then
1293 if Tr.Entity:IsValid( ) then
1294 if Tr.Entity:GetClass( ) == self.GrenadeLauncherEntity then return end
1295
1296 if ( Tr.Entity:IsNPC( ) or Tr.Entity:IsPlayer( ) ) and not ( self.WeaponType == 1 ) then
1297 -- Don't shoot
1298 self.DontNearWall = true
1299 else
1300 -- Else shoot
1301 self.DontNearWall = false
1302 end
1303 end
1304
1305 -- If trace hit something, and the distance is within range, and we're not near a wall, and don't shoot is false then
1306 if ( Tr.Hit and Tr.HitPos:Distance( self.Owner:GetShootPos( ) ) < 45 ) and not ( self.NearWall and self.DontNearWall and self.WeaponType == 1 ) then
1307 -- We're near a wall
1308 self.NearWall = true
1309
1310 -- If we're not holstered, we're not sprinting, and we're in iron sights
1311 if self:GetVNTSBHolstered( ) == false and not self.Owner:KeyDown( IN_SPEED ) and self:GetVNTSBIronSighted( ) == true then
1312 -- Toggle out of iron sights
1313 self:ToggleIronsights( )
1314 end
1315 elseif Tr.HitPos:Distance( self.Owner:GetShootPos( ) ) > 46 and self.NearWall then
1316 -- Else if the trace distance is out of range and we're near a wall then
1317 -- Do a short wait so we can animate, then set the near to false
1318 timer.Simple( 0.2 , function( )
1319 self.NearWall = false
1320 end )
1321 end
1322
1323 -- If we're iron sighted, and we sprint, toggle out of them
1324 if self:GetVNTSBIronSighted( ) == true and self.Owner:KeyDown( IN_SPEED ) then
1325 self:ToggleIronsights( )
1326 end
1327
1328 if self.ScopeType == 1 then
1329 if self:GetVNTSBScopedIn( ) == true then
1330 self.Owner:DrawViewModel( false )
1331 else
1332 self.Owner:DrawViewModel( true )
1333 end
1334 end
1335
1336 if self.Owner:KeyDown( IN_RELOAD ) then
1337 if self:GetVNTSBScopedIn( ) == true then
1338 self.Owner:DrawViewModel( true )
1339 end
1340 end
1341
1342 if self:GetVNTSBShotgunRel( ) == true and (self.Owner:KeyPressed( IN_ATTACK ) or self.Owner:KeyPressed( IN_ATTACK2 ) or self.Owner:KeyPressed( IN_SPEED ) ) then
1343 self:EndSGReload( )
1344 end
1345
1346 if self.ShellReload == true then
1347 if self.ActionDelay and CurTime() >= self.ActionDelay and self:GetVNTSBShotgunRel( ) == true then
1348 if self:Clip1() >= self.Primary.ClipSize or self:Ammo1() <= 0 or self.Owner:KeyReleased( IN_RELOAD ) then
1349 self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH )
1350 self.ActionDelay = CurTime()
1351 self:SetVNTSBShotgunRel( false )
1352 self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1353 self:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1354 elseif self:Clip1() < self.Primary.ClipSize and self:Ammo1() > 0 then
1355 self:SendWeaponAnim(ACT_VM_RELOAD)
1356 self.ActionDelay = CurTime() + self.Owner:GetViewModel():SequenceDuration()
1357 self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1358 self:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
1359 self:SetClip1(self:Clip1() + 1)
1360 self.Owner:RemoveAmmo( 1, self.Primary.Ammo )
1361 end
1362 end
1363 end
1364
1365 -- If we press use, and we're not moving then
1366 if ( self.Owner:KeyPressed( IN_USE ) and self.HASHELPHAND == true ) and not ( self:GetVNTSBScopedIn( ) == true or self:GetVNTSBIronSighted( ) == true ) then
1367 if CLIENT then
1368 -- Play the first-person animations
1369 self:SpecialAnimation( self.ANIHANDOUT )
1370
1371 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) , function( )
1372 self:SpecialAnimation( self.ANIHANDLOOP )
1373 end )
1374
1375 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) , function( )
1376 self:SpecialAnimation( self.ANIHANDIN )
1377 end )
1378 elseif SERVER then
1379 -- Play the world animation
1380 self.Owner:DoAnimationEvent( self.ANIHANDWORLD )
1381 end
1382 end
1383
1384 -- If you turn on STOCKGRAB, you will hold the stock while crouching
1385 self.UseWorldAnimations = true
1386
1387 if self.UseWorldAnimations == true then
1388 if self:GetVNTSBIronSighted( ) == true then
1389 if self.WeaponType == 2 then
1390 self:SetWeaponHoldType( "revolver" )
1391 end
1392
1393 if self.WeaponType == 3 then
1394 if self.Owner:KeyDown( IN_DUCK ) and self.STOCKGRAB == false then
1395 self:SetWeaponHoldType( "ar2" )
1396 else
1397 self:SetWeaponHoldType( "rpg" )
1398 end
1399 end
1400
1401 if self.WeaponType == 4 then
1402 self:SetWeaponHoldType( "ar2" )
1403 end
1404
1405 if self.WeaponType == 5 then
1406 self:SetWeaponHoldType( "rpg" )
1407 end
1408 else
1409 if self.WeaponType == 3 then
1410 if self.Owner:KeyDown( IN_DUCK ) and self.STOCKGRAB == false then
1411 self:SetWeaponHoldType( "ar2" )
1412 else
1413 self:SetWeaponHoldType( "rpg" )
1414 end
1415 end
1416 end
1417 else
1418 self:SetWeaponHoldType( self.HoldType )
1419 end
1420
1421 -- if we're holstered then
1422 if self:GetVNTSBHolstered( ) == true then
1423 -- if it's a pistol
1424 if self.WeaponType == 1 or self.WeaponType == 2 then
1425 -- play the normal animation
1426 self:SetWeaponHoldType( "normal" )
1427 else
1428 -- else it's not
1429 -- If we crouching then
1430 if self.Owner:KeyDown( IN_DUCK ) then
1431 -- There's no crouch for passive, so play the normal
1432 self:SetWeaponHoldType( "normal" )
1433 else
1434 -- else we're standing
1435 -- play the passive anim
1436 self:SetWeaponHoldType( "passive" )
1437 end
1438 end
1439 else
1440 -- Else we're not holstered
1441 -- reset our hold type
1442 self:SetWeaponHoldType( self.HoldType )
1443 end
1444
1445 if SERVER then end
1446
1447 --local curWep = self.Owner:GetWeapon(self)
1448 if ( self.Owner:KeyDown( IN_WALK ) and self.Owner:KeyDown( IN_RELOAD ) ) and self.ActionDelay <= CurTime( ) then
1449 self:Melee( )
1450 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
1451 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
1452 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
1453 end
1454
1455 if self.ScopeType == 2 then
1456 if self.IsCloseZoomed == true then
1457 self.DefaultZoom = self.ScopeMultipliers[ 2 ]
1458 else
1459 self.DefaultZoom = self.ScopeMultipliers[ 1 ]
1460 end
1461 end
1462
1463 self:NextThink( CurTime( ) )
1464 end
1465end -- Called every frame
1466
1467function SWEP:CustomThink( ) -- Called every frame for custom stuff
1468-- Used in child SWeps
1469end
1470
1471------------------------------------------------------
1472-- Bullet Firing Functions --
1473------------------------------------------------------
1474function SWEP:ShootEffects( )
1475 -- Play our third-person firing animation
1476 self.Owner:SetAnimation( PLAYER_ATTACK1 )
1477 -- If we're not valid, it's not predicted, we're dead, return and end the function
1478 if not ( IsValid( self.Owner ) or IsFirstTimePredicted( ) or self.Owner:Alive( ) ) then return end
1479
1480 if self:GetVNTSBSuppressed( ) == false then
1481 -- If our muzzle flashes are enabled
1482 if GetConVarNumber( "VNT_SWep_Base_FlashToggle" ) ~= 0 then
1483 self.Owner:MuzzleFlash( )
1484 -- Emit our muzzle flash
1485 local FX = EffectData( )
1486 FX:SetOrigin( self.Owner:GetShootPos( ) )
1487 FX:SetEntity( self )
1488 FX:SetStart( self.Owner:GetShootPos( ) )
1489 FX:SetNormal( self.Owner:GetAimVector( ) )
1490 FX:SetAttachment( self.MuzzleAttach )
1491
1492 -- If it's a shotgun then
1493 if ( self.WeaponType == 4 ) then
1494 -- Emit shotgun smoke
1495 util.Effect( "fx_smoke_shotgun_ins" , FX )
1496 else
1497 -- else emit normal rifle smoke
1498 util.Effect( "fx_smoke_rifle_ins" , FX )
1499 end
1500 end
1501 end
1502
1503 -- If our shell ejections are enabled
1504 if GetConVarNumber( "VNT_SWep_Base_ShellToggle" ) ~= 0 then
1505 -- Wait for our shell delay and then run the function
1506 timer.Simple( self.ShellDelay , function( )
1507 -- If we're not valid, it's not predicted, we're dead, return and end the function
1508 if not ( IsValid( self.Owner ) or IsFirstTimePredicted( ) or self.Owner:Alive( ) ) then return end
1509 local FX = EffectData( )
1510 FX:SetEntity( self )
1511 FX:SetNormal( self.Owner:GetAimVector( ) )
1512 FX:SetAttachment( self.ShellAttach )
1513 util.Effect( self.ShellEffect , FX , true , true )
1514 end )
1515 end
1516end -- Controls effects like shells and flashes for our right hand weapon
1517
1518function SWEP:ShootEffectsLeftHand( )
1519 -- Play our third-person firing animation
1520 self.Owner:SetAnimation( PLAYER_ATTACK1 )
1521 -- If we're not valid, it's not predicted, we're dead, return and end the function
1522 if not ( IsValid( self.Owner ) or IsFirstTimePredicted( ) or self.Owner:Alive( ) ) then return end
1523
1524 if self:GetVNTSBSuppressed( ) == false then
1525 -- If our muzzle flashes are enabled
1526 if GetConVarNumber( "VNT_SWep_Base_FlashToggle" ) ~= 0 then
1527 self.Owner:MuzzleFlash( )
1528 -- Emit our muzzle flash
1529 local FX = EffectData( )
1530 FX:SetOrigin( self.Owner:GetShootPos( ) )
1531 FX:SetEntity( self )
1532 FX:SetStart( self.Owner:GetShootPos( ) )
1533 FX:SetNormal( self.Owner:GetAimVector( ) )
1534 FX:SetAttachment( self.MuzzleAttachLeft )
1535
1536 -- If it's a shotgun then
1537 if ( self.WeaponType == 4 ) then
1538 -- Emit shotgun smoke
1539 util.Effect( "fx_smoke_shotgun_ins" , FX )
1540 else
1541 -- else emit normal rifle smoke
1542 util.Effect( "fx_smoke_rifle_ins" , FX )
1543 end
1544 end
1545 end
1546
1547 -- If our shell ejections are enabled
1548 if GetConVarNumber( "VNT_SWep_Base_ShellToggle" ) ~= 0 then
1549 -- Wait for our shell delay and then run the function
1550 timer.Simple( self.ShellDelay , function( )
1551 -- If we're not valid, it's not predicted, we're dead, return and end the function
1552 if not ( IsValid( self.Owner ) or IsFirstTimePredicted( ) or self.Owner:Alive( ) ) then return end
1553 local FX = EffectData( )
1554 FX:SetEntity( self )
1555 FX:SetNormal( self.Owner:GetAimVector( ) )
1556 FX:SetAttachment( self.ShellAttachLeft )
1557 util.Effect( self.ShellEffect , FX , true , true )
1558 end )
1559 end
1560end -- Controls effects like shells and flashes for our left hand weapon
1561
1562function SWEP:Recoil( int , bool )
1563end -- Controls recoil
1564
1565function SWEP:FireBullet( dmg , recoil , numbul , cone )
1566 numbul = numbul or 1
1567 cone = cone or 0.01
1568
1569 if self.CurrentMode == 1 then
1570 self.SingleAccom = 0.2
1571 else
1572 self.SingleAccom = 0
1573 end
1574
1575 if not self.Owner:OnGround( ) then
1576 self.CrouchPane = 1.4
1577 elseif self.Owner.Incapped == true then
1578 self.CrouchPane = 0.5 - self.SingleAccom
1579 elseif self.Owner:Crouching( ) then
1580 --[[elseif self.Owner.IsProne() == true then
1581 if self.Owner:GetVelocity():Length() >= 30 then
1582 self.CrouchPane = 0.425 - self.SingleAccom
1583 else
1584 self.CrouchPane = 0.2 - self.SingleAccom
1585 end--]]
1586 if self.Owner:GetVelocity( ):Length( ) >= 30 then
1587 self.CrouchPane = 0.65 - self.SingleAccom
1588 else
1589 self.CrouchPane = 0.365 - self.SingleAccom
1590 end
1591 else
1592 if self.Owner:GetVelocity( ):Length( ) >= 100 then
1593 self.CrouchPane = 1.05 - self.SingleAccom
1594 else
1595 self.CrouchPane = 0.95 - self.SingleAccom
1596 end
1597 end
1598
1599 if not self.SmokeFire then
1600 self.SmokeFire = 1
1601 end
1602
1603 self.SmokeFire = self.SmokeFire + 1
1604
1605 if SERVER then
1606 if self.Primary.Cone < self.Primary.MaxCone then
1607 self.Primary.Cone = self.Primary.Cone + ( self.Primary.ConeCoil * 1.5 ) * self.CrouchPane
1608
1609 if self.Primary.Cone < self.BaseCone then
1610 self.Primary.Cone = self.BaseCone
1611 end
1612
1613 if self:GetVNTSBIronSighted( ) == true or self:GetVNTSBBipod( ) == true then
1614 if self.Primary.Cone > self.Primary.MaxCone * 0.9 then
1615 self.Primary.Cone = self.Primary.MaxCone * 0.9
1616 end
1617 else
1618 if self.Primary.Cone > self.Primary.MaxCone * 1.75 then
1619 self.Primary.Cone = self.Primary.MaxCone * 1.75
1620 end
1621 end
1622 end
1623 end
1624
1625 local bullet = { }
1626 bullet.Num = numbul
1627 bullet.Src = self.Owner:GetShootPos()
1628 --bullet.Src = self:LookupAttachment( self.MuzzleAttach )
1629 bullet.Dir = self.Owner:GetAimVector( )
1630
1631 if self:GetVNTSBIronSighted( ) == true and self:GetVNTSBBipod( ) == false then
1632 bullet.Spread = Vector( cone * 0.8 , cone * 0.8 , 0 )
1633 elseif self:GetVNTSBIronSighted( ) == true and self:GetVNTSBBipod( ) == true then
1634 bullet.Spread = Vector( cone * 0.4 , cone * 0.4 , 0 )
1635 elseif self:GetVNTSBIronSighted( ) == false and self:GetVNTSBBipod( ) == true then
1636 bullet.Spread = Vector( cone * 0.5 , cone * 0.5 , 0 )
1637 else
1638 bullet.Spread = Vector( cone , cone , 0 )
1639 end
1640
1641 if self.UseTracer == true then
1642 bullet.TracerType = math.random( 0 , self.TracerRandomizer )
1643 else
1644 bullet.TracerType = 0
1645 end
1646
1647 if self.CustomTracer ~= nil then
1648 bullet.TracerName = self.CustomTracer
1649 end
1650
1651 bullet.Force = 1 * dmg
1652 bullet.Damage = dmg
1653 bullet.Attacker = self.Owner
1654 bullet.Callback = function( a , b , c ) return self:BPenetration( a , b , c ) end
1655
1656 if SERVER then
1657 self.Owner:LagCompensation( true )
1658 end
1659
1660 self:FireBullets( bullet )
1661
1662 if SERVER then
1663 self.Owner:LagCompensation( false )
1664 end
1665end -- Controls bullets
1666
1667function SWEP:FireBulletL( dmg , recoil , numbul , cone )
1668 numbul = numbul or 1
1669 cone = cone or 0.01
1670
1671 if self.CurrentMode == 1 then
1672 self.SingleAccom = 0.2
1673 else
1674 self.SingleAccom = 0
1675 end
1676
1677 if not self.Owner:OnGround( ) then
1678 self.CrouchPane = 1.4
1679 elseif self.Owner.Incapped == true then
1680 self.CrouchPane = 0.5 - self.SingleAccom
1681 elseif self.Owner:Crouching( ) then
1682 --[[elseif self.Owner.IsProne() == true then
1683 if self.Owner:GetVelocity():Length() >= 30 then
1684 self.CrouchPane = 0.425 - self.SingleAccom
1685 else
1686 self.CrouchPane = 0.2 - self.SingleAccom
1687 end--]]
1688 if self.Owner:GetVelocity( ):Length( ) >= 30 then
1689 self.CrouchPane = 0.65 - self.SingleAccom
1690 else
1691 self.CrouchPane = 0.365 - self.SingleAccom
1692 end
1693 else
1694 if self.Owner:GetVelocity( ):Length( ) >= 100 then
1695 self.CrouchPane = 1.05 - self.SingleAccom
1696 else
1697 self.CrouchPane = 0.95 - self.SingleAccom
1698 end
1699 end
1700
1701 if not self.SmokeFire then
1702 self.SmokeFire = 1
1703 end
1704
1705 self.SmokeFire = self.SmokeFire + 1
1706
1707 if SERVER then
1708 if self.Primary.Cone < self.Primary.MaxCone then
1709 self.Primary.Cone = self.Primary.Cone + ( self.Primary.ConeCoil * 1.5 ) * self.CrouchPane
1710
1711 if self.Primary.Cone < self.BaseCone then
1712 self.Primary.Cone = self.BaseCone
1713 end
1714
1715 if self:GetVNTSBIronSighted( ) == true or self:GetVNTSBBipod( ) == true then
1716 if self.Primary.Cone > self.Primary.MaxCone * 0.9 then
1717 self.Primary.Cone = self.Primary.MaxCone * 0.9
1718 end
1719 else
1720 if self.Primary.Cone > self.Primary.MaxCone * 1.75 then
1721 self.Primary.Cone = self.Primary.MaxCone * 1.75
1722 end
1723 end
1724 end
1725 end
1726
1727 local bullet = { }
1728 bullet.Num = numbul
1729 bullet.Src = self.Owner:GetShootPos()
1730 --bullet.Src = self:LookupAttachment( self.MuzzleAttachLeft )
1731 bullet.Dir = self.Owner:GetAimVector( )
1732
1733 if self:GetVNTSBIronSighted( ) == true and self:GetVNTSBBipod( ) == false then
1734 bullet.Spread = Vector( cone * 0.8 , cone * 0.8 , 0 )
1735 elseif self:GetVNTSBIronSighted( ) == true and self:GetVNTSBBipod( ) == true then
1736 bullet.Spread = Vector( cone * 0.4 , cone * 0.4 , 0 )
1737 elseif self:GetVNTSBIronSighted( ) == false and self:GetVNTSBBipod( ) == true then
1738 bullet.Spread = Vector( cone * 0.5 , cone * 0.5 , 0 )
1739 else
1740 bullet.Spread = Vector( cone , cone , 0 )
1741 end
1742
1743 if self.UseTracer == true then
1744 bullet.TracerType = math.random( 0 , self.TracerRandomizer )
1745 else
1746 bullet.TracerType = 0
1747 end
1748
1749 if self.CustomTracer ~= nil then
1750 bullet.TracerName = self.CustomTracer
1751 end
1752
1753 bullet.Force = 1 * dmg
1754 bullet.Damage = dmg
1755 bullet.Attacker = self.Owner
1756 bullet.Callback = function( a , b , c ) return self:BPenetration( a , b , c ) end
1757
1758 if SERVER then
1759 self.Owner:LagCompensation( true )
1760 end
1761
1762 self:FireBullets( bullet )
1763
1764 if SERVER then
1765 self.Owner:LagCompensation( false )
1766 end
1767end -- Controls bullets
1768
1769function SWEP:BulletPenetrate( bouncenum , attacker , tr , dmginfo , isplayer )
1770 local DoDefaultEffect = true
1771 if ( tr.MatType == MAT_SAND ) or ( tr.Entity:IsPlayer( ) or tr.Entity:IsNPC( ) ) then return end
1772 if ( bouncenum > 3 ) then return end
1773 local PenetrationDirection = tr.Normal * self.MaxPenetration
1774
1775 if ( tr.MatType == MAT_METAL ) then
1776 PenetrationDirection = tr.Normal * ( self.MaxPenetration - 3 )
1777 end
1778
1779 if ( tr.MatType == MAT_DIRT or tr.MatType == MAT_WOOD or tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH or tr.MatType == MAT_GLASS or tr.MatType == MAT_PLASTIC or tr.MatType == MAT_VENT or tr.MatType == MAT_COMPUTER ) then
1780 PenetrationDirection = tr.Normal * self.MaxWoodPenetration
1781 end
1782
1783 local trace = { }
1784 trace.endpos = tr.HitPos
1785 trace.start = tr.HitPos + PenetrationDirection
1786 trace.mask = MASK_SHOT
1787 trace.filter = { self.Owner }
1788 local trace = util.TraceLine( trace )
1789 if ( trace.StartSolid or trace.Fraction >= 1.0 or tr.Fraction <= 0.0 ) then return end
1790 local DMGX = 0.5
1791
1792 if ( tr.MatType == MAT_CONCRETE ) then
1793 DMGX = 0.9
1794 elseif ( tr.MatType == MAT_METAL ) then
1795 DMGX = 0.85
1796 elseif ( tr.MatType == MAT_WOOD ) then
1797 DMGX = 0.8
1798 elseif ( tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH ) then
1799 DMGX = 0.9
1800 elseif ( tr.MatType == MAT_GLASS ) then
1801 DMGX = 0.88
1802 elseif ( tr.MatType == MAT_GRATE ) then
1803 DMGX = 0.9
1804 elseif ( tr.MatType == MAT_PLASTIC ) then
1805 DMGX = 0.95
1806 elseif ( tr.MatType == MAT_VENT ) then
1807 DMGX = 0.92
1808 elseif ( tr.MatType == MAT_ANTLION ) then
1809 DMGX = 0.8
1810 elseif ( tr.MatType == MAT_DIRT ) then
1811 DMGX = 0.82
1812 elseif ( tr.MatType == MAT_SAND ) then
1813 DMGX = 0.65
1814 elseif ( tr.MatType == MAT_FOLIAGE ) then
1815 DMGX = 0.95
1816 elseif ( tr.MatType == MAT_COMPUTER ) then
1817 DMGX = 0.9
1818 elseif ( tr.MatType == MAT_SLOSH ) then
1819 DMGX = 0.85
1820 elseif ( tr.MatType == MAT_TILE ) then
1821 DMGX = 0.9
1822 end
1823
1824 local bullet = {
1825 Num = 1 ,
1826 Src = trace.HitPos ,
1827 Dir = tr.Normal ,
1828 Spread = Vector( 0 , 0 , 0 ) ,
1829 TracerType = 1 ,
1830 Force = 2 * dmginfo:GetDamage( ) * DMGX ,
1831 Damage = ( dmginfo:GetDamage( ) * DMGX ) ,
1832 HullSize = 2 ,
1833 Attacker = attacker
1834 }
1835
1836 bullet.Callback = function( a , b , c )
1837 if ( self.Ricochet ) then return self:RicochetCallback( bouncenum + 1 , a , b , c ) end
1838 end
1839
1840 timer.Simple( 0.01 , function( )
1841 attacker.FireBullets( attacker , bullet , true )
1842 end )
1843
1844 return true
1845end -- Controls penetration
1846
1847function SWEP:RicochetCallback( bouncenum , attacker , tr , dmginfo )
1848 local DoDefaultEffect = true
1849 if ( tr.HitSky ) then return end
1850
1851 if ( self.CanPenetrate ) and ( self:BulletPenetrate( bouncenum , attacker , tr , dmginfo ) ) then
1852 return {
1853 damage = true ,
1854 effects = DoDefaultEffect
1855 }
1856 end
1857
1858 if ( SERVER ) then
1859 util.ScreenShake( tr.HitPos , 2.2 , 0.1 , 0.3 , 38 )
1860 end
1861
1862 if ( self.Ricochet == true ) then
1863 return {
1864 damage = true ,
1865 effects = DoDefaultEffect
1866 }
1867 end
1868
1869 if ( bouncenum > self.MaxRicochet ) then return end
1870 local trace = { }
1871 trace.start = tr.HitPos
1872 trace.endpos = trace.start + ( tr.HitNormal * 16384 )
1873 local trace = util.TraceLine( trace )
1874 local DotProduct = tr.HitNormal:Dot( tr.Normal * -1 )
1875
1876 local bullet = {
1877 Num = 1 ,
1878 Src = tr.HitPos + ( tr.HitNormal * 5 ) ,
1879 Dir = ( ( 2 * tr.HitNormal * DotProduct ) + tr.Normal ) + ( VectorRand( ) * 0.05 ) ,
1880 Spread = Vector( 0 , 0 , 0 ) ,
1881 TracerType = 1 ,
1882 TracerName = "" ,
1883 Force = dmginfo:GetDamage( ) * 0.9 ,
1884 Damage = dmginfo:GetDamage( ) * 0.95 ,
1885 HullSize = 2 ,
1886 Attacker = attacker
1887 }
1888
1889 bullet.Callback = function( a , b , c )
1890 if ( self.Ricochet ) then return self:RicochetCallback( bouncenum + 1 , a , b , c ) end
1891 end
1892
1893 timer.Simple( 0.01 , function( )
1894 attacker.FireBullets( attacker , bullet , true )
1895 end )
1896
1897 return {
1898 damage = true ,
1899 effects = DoDefaultEffect
1900 }
1901end -- Controls ricochets
1902
1903function SWEP:BPenetration( a , b , c )
1904 return self:RicochetCallback( 0 , a , b , c )
1905end -- Tech for penetration
1906
1907function SWEP:FireViewPunches( )
1908 -- If we're owner, a player, valid, and alive then
1909 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) then
1910 -- If our GL is deployed then
1911 if self:GetVNTSBGLauncher( ) == true then
1912 -- Reset our view punch
1913 self.Owner:ViewPunchReset( )
1914
1915 -- Add a random punch
1916 if self.WeaponType > 2 then
1917 self.Owner:ViewPunch( Angle( table.Random( self.RiflePunchesY ) * 1 , table.Random( self.RiflePunchesX ) * self.Primary.Cone * 4 , 0 ) )
1918 elseif self.WeaponType == 2 then
1919 self.Owner:ViewPunch( Angle( table.Random( self.PistolPunchesY ) * 1 , table.Random( self.PistolPunchesX ) * self.Primary.Cone * 4 , 0 ) )
1920 end
1921 else
1922 -- else our GL isn't out
1923 -- If we're in iron sights then
1924 if self:GetVNTSBIronSighted( ) == true and self.WeaponType ~= 1 then
1925 -- Reset our view punch
1926 self.Owner:ViewPunchReset( )
1927
1928 -- Add a smaller random punch
1929 if self.WeaponType > 2 then
1930 self.Owner:ViewPunch( Angle( table.Random( self.RiflePunchesY ) * 0.5 , table.Random( self.RiflePunchesX ) * self.Primary.Cone * 3 , 0 ) )
1931 elseif self.WeaponType == 2 then
1932 self.Owner:ViewPunch( Angle( table.Random( self.PistolPunchesY ) * 0.5 , table.Random( self.PistolPunchesX ) * self.Primary.Cone * 3 , 0 ) )
1933 end
1934 elseif self:GetVNTSBIronSighted( ) == false and self.WeaponType ~= 1 then
1935 -- Reset our view punch
1936 self.Owner:ViewPunchReset( )
1937
1938 -- Add a bigger random punch
1939 if self.WeaponType > 2 then
1940 self.Owner:ViewPunch( Angle( table.Random( self.RiflePunchesY ) * 1 , table.Random( self.RiflePunchesX ) * self.Primary.Cone * 6 , 0 ) )
1941 elseif self.WeaponType == 2 then
1942 self.Owner:ViewPunch( Angle( table.Random( self.PistolPunchesY ) * 1 , table.Random( self.PistolPunchesX ) * self.Primary.Cone * 6 , 0 ) )
1943 end
1944 else
1945 self.Owner:ViewPunch( Angle( table.Random( self.RiflePunchesY ) * 4 , table.Random( self.RiflePunchesX ) * self.Primary.Cone * 10 , 0 ) )
1946 end
1947 end
1948 end
1949end -- View Punches
1950
1951------------------------------------------------------
1952-- Prone Functions --
1953------------------------------------------------------
1954function SWEP:IsProne( )
1955 return self.Owner:GetNW2Bool( "prone_isprone" )
1956end -- Are we prone?
1957
1958function SWEP:PlayProneAnimation( )
1959 if self.Owner:IsProne( ) then
1960 print( "prone" )
1961 end
1962end -- Play prone animations
1963
1964------------------------------------------------------
1965-- Toggles --
1966------------------------------------------------------
1967
1968function SWEP:ToggleOutAndIn( )
1969 self:Holster( )
1970
1971 if SERVER then
1972 self.Owner:SelectWeapon( "v92_int_blank" )
1973 end -- This has got to be
1974
1975 self:Deploy( )
1976
1977 if SERVER then
1978 self.Owner:SelectWeapon( self.WeaponName )
1979 end -- the dumbest fix,
1980
1981 self:Deploy( )
1982
1983 if SERVER then
1984 self.Owner:SelectWeapon( "v92_int_blank" )
1985 end -- but damned
1986
1987 self:Deploy( )
1988
1989 if SERVER then
1990 self.Owner:SelectWeapon( self.WeaponName )
1991 end -- if it works
1992
1993 self:Deploy( )
1994end
1995
1996function SWEP:ToggleStock( )
1997 -- If we're owner, a player, valid, and alive, and we have a supressor then
1998 if ( self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) ) and ( self.StockType ~= 0 ) then
1999
2000 -- If we're silenced then
2001 if self:GetVNTSBStock( ) == true then
2002
2003 self:SetVNTSBStock( false )
2004
2005 self:ToggleOutAndIn()
2006
2007 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
2008 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2009 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2010
2011 if CLIENT then
2012 self.Owner:PrintMessage( HUD_PRINTTALK , "Stock Folded" )
2013 end
2014
2015 -- Add our delay to prevent spam
2016 self.ActionDelay = CurTime( ) + 1
2017
2018 elseif self:GetVNTSBStock( ) == false then
2019 -- else if we're not silenced
2020 self:SetVNTSBStock( true )
2021
2022 self:ToggleOutAndIn()
2023
2024 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
2025 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2026 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2027
2028 if CLIENT then
2029 self.Owner:PrintMessage( HUD_PRINTTALK , "Stock Deployed" )
2030 end
2031
2032 -- Add our delay for the same reason
2033 self.ActionDelay = CurTime( ) + 1
2034
2035 end
2036
2037 else
2038
2039 -- If we don't have a supressor or we're not valid, return back and end the function
2040 return false
2041
2042 end
2043end -- Toggle our supressor
2044
2045function SWEP:ToggleFireMode( )
2046 -- If we're owner, a player, valid, and alive, and our gun has fire modes, and the toggle timer is expired then
2047 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and self.ActionDelay <= CurTime( ) then
2048 if self:GetVNTSBIronSighted( ) == true then
2049 self:ToggleIronsights( )
2050 end
2051
2052 -- Cycle to the next mode
2053 self.CurrentMode = self.CurrentMode + 1
2054
2055 -- If we're too small, reset it
2056 if self.CurrentMode <= 1 then
2057 self.CurrentMode = 1
2058 end
2059
2060 -- If our CurrentMode goes higher than 4
2061 if self.CurrentMode > 4 then
2062 -- Toggle the holster off
2063 self:ToggleHolster( )
2064
2065 -- Play our draw animation and add a delay
2066 if ( self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DRAW_SILENCED ) ) then
2067 self:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
2068 elseif self:Clip1( ) <= 0 and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DRAW_EMPTY ) then
2069 self:SendWeaponAnim( ACT_VM_DRAW_EMPTY )
2070 else
2071 self:SendWeaponAnim( ACT_VM_DRAW )
2072 end
2073
2074 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2075 -- Reset our fire mode to single shot
2076 self.CurrentMode = 1
2077 end
2078
2079 -- This checks if a mode is false; it prevents you having to cycle out of the mode twice
2080 if self.FireMode[ 2 ] == false and self.CurrentMode == 1 then
2081 self.CurrentMode = 2
2082 end
2083
2084 if self.FireMode[ 3 ] == false and self.CurrentMode == 2 then
2085 self.CurrentMode = 3
2086 end
2087
2088 if self.FireMode[ 4 ] == false and self.CurrentMode == 3 then
2089 self.CurrentMode = 4
2090 end
2091
2092 -- If single fire is true, and current mode is 1 then
2093 if self.FireMode[ 2 ] == true and self.CurrentMode == 1 then
2094 -- Tell our player that he's in Semi-Auto
2095 if CLIENT then
2096 self.Owner:PrintMessage( HUD_PRINTTALK , "1 - Semi-Auto" )
2097 end
2098
2099 -- Emit our switch sound
2100 self:EmitSound( "Weapon_SMG1.Special1" )
2101 elseif self.FireMode[ 3 ] == true and self.CurrentMode == 2 then
2102 -- If burst fire is true, and current mode is 2 then
2103 -- Tell our player that he's in Burst
2104 if CLIENT then
2105 self.Owner:PrintMessage( HUD_PRINTTALK , self.BurstCount .. " - Burst" )
2106 end
2107
2108 -- Emit our switch sound
2109 self:EmitSound( "Weapon_SMG1.Special1" )
2110 elseif self.FireMode[ 4 ] == true and self.CurrentMode == 3 then
2111 -- If auto fire is true, and current mode is 3 then
2112 -- Tell our player that he's in Automatic
2113 if CLIENT then
2114 self.Owner:PrintMessage( HUD_PRINTTALK , "A - Automatic" )
2115 end
2116
2117 -- Emit our switch sound
2118 self:EmitSound( "Weapon_SMG1.Special1" )
2119 elseif self.CurrentMode == 4 then
2120 -- If current mode is 4 then
2121 -- Toggle our holster
2122 self:ToggleHolster( )
2123
2124 -- Tell our player that he's in Safety
2125 if CLIENT then
2126 self.Owner:PrintMessage( HUD_PRINTTALK , "S - Safety" )
2127 end
2128
2129 -- Emit our switch sound
2130 self:EmitSound( "Weapon_SMG1.Special2" )
2131 end
2132
2133 -- If we have mode switch anims, and current mode isn't safety then
2134 if self.CurrentMode ~= 4 then
2135 -- If we're iron sighted and we have mode anims for irons then
2136 if self:GetVNTSBIronSighted( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IFIREMODE ) then
2137 -- Play our specified anim
2138 self:SendWeaponAnim( ACT_VM_IFIREMODE )
2139 elseif self:GetVNTSBIronSighted( ) == false and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_FIREMODE ) then
2140 -- Play our specified anim
2141 self:SendWeaponAnim( ACT_VM_FIREMODE )
2142 elseif self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_UNDEPLOY ) then
2143 -- else we aren't iron sighted or we don't have mode iron anims
2144 -- Play our specified normal switch fire anim
2145 self:SendWeaponAnim( ACT_VM_UNDEPLOY )
2146 end
2147
2148 -- Add a delay based on animation time
2149 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2150 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2151 else
2152 -- Else add a basic float time
2153 self:SetNextPrimaryFire( CurTime( ) + 0.2 )
2154 self:SetNextSecondaryFire( CurTime( ) + 0.2 )
2155 end
2156
2157 -- Add a delay before we can swap
2158 self.ActionDelay = CurTime() + 0.2
2159 end
2160end -- Change our fire modes
2161
2162function SWEP:ToggleSuppressor( )
2163 -- If we're owner, a player, valid, and alive, and we have a supressor then
2164 --print("print")
2165 if ( self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) ) and ( self.SuppressorType ~= 0 ) then
2166 -- If we're silenced then
2167 if self:GetVNTSBSuppressed( ) == true then
2168 self:SetVNTSBSuppressed( false )
2169
2170 if self.SuppressorType == 1 then
2171
2172 self:ToggleOutAndIn()
2173
2174 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
2175 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2176 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2177
2178 elseif self.SuppressorType == 2 then
2179
2180 -- Take our supressor off
2181 self:SendWeaponAnim( ACT_VM_DETACH_SILENCER )
2182 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
2183 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2184 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2185
2186 end
2187
2188 if CLIENT then
2189 self.Owner:PrintMessage( HUD_PRINTTALK , "Suppressor Off" )
2190 end
2191
2192 -- Add our delay to prevent spam
2193 self.ActionDelay = CurTime( ) + 1
2194 elseif self:GetVNTSBSuppressed( ) == false then
2195 -- else if we're not silenced
2196 self:SetVNTSBSuppressed( true )
2197
2198 if self.SuppressorType == 1 then
2199
2200 self:ToggleOutAndIn()
2201
2202 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
2203 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2204 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2205 elseif self.SuppressorType == 2 then
2206 -- Attach the supressor
2207 self:SendWeaponAnim( ACT_VM_ATTACH_SILENCER )
2208 self.ActionDelay = ( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) + 0.25 )
2209 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2210 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2211 end
2212
2213 if CLIENT then
2214 self.Owner:PrintMessage( HUD_PRINTTALK , "Suppressor On" )
2215 end
2216
2217 -- Add our delay for the same reason
2218 self.ActionDelay = CurTime( ) + 1
2219 end
2220 else
2221 -- If we don't have a supressor or we're not valid, return back and end the function
2222 return false
2223 end
2224end -- Toggle our supressor
2225
2226function SWEP:ToggleBipod( )
2227 -- If we're owner, a player, valid, and alive, and our gun has fire modes, and the toggle timer is expired then
2228 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and self.ActionDelay <= CurTime( ) then
2229 if self:GetVNTSBBipod( ) == true then
2230 self:SetVNTSBBipod( false )
2231
2232 if CLIENT then
2233 self.Owner:PrintMessage( HUD_PRINTTALK , "Bipod Up" )
2234 end
2235
2236 self:ToggleOutAndIn()
2237
2238 elseif self:GetVNTSBBipod( ) == false then
2239 self:SetVNTSBBipod( true )
2240
2241 if CLIENT then
2242 self.Owner:PrintMessage( HUD_PRINTTALK , "Bipod Down" )
2243 end
2244
2245 self:ToggleOutAndIn()
2246
2247 end
2248
2249 -- Add a delay before we can swap
2250 self.ActionDelay = self.ActionDelay + 1
2251 end
2252end -- Toggle our bipod
2253
2254function SWEP:ToggleGrenadeMode( )
2255 -- If we're owner, a player, valid, and alive, and our delay is expired, and we have a GL then
2256 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and self.ActionDelay <= CurTime( ) then
2257 -- If we're not in GL mode then
2258 if self:GetVNTSBGLauncher( ) == false then
2259 -- We are now!
2260 self:SetVNTSBGLauncher( true )
2261
2262 if self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DRAW_DEPLOYED ) then
2263 -- else play our normal deployed draw anim
2264 self:SendWeaponAnim( ACT_VM_DRAW_DEPLOYED )
2265 end
2266
2267 -- Tell our player that he's in GL mode
2268 if CLIENT then
2269 self.Owner:PrintMessage( HUD_PRINTTALK , "Grenade Launcher On" )
2270 end
2271 elseif self:GetVNTSBGLauncher( ) == true then
2272 -- else if we are in GL mode then
2273 if self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_HOLSTER_M203 ) then
2274 -- Play the deploy holster anim
2275 self:SendWeaponAnim( ACT_VM_HOLSTER_M203 )
2276 end
2277
2278 -- Turn off the launcher mode
2279 self:SetVNTSBGLauncher( false )
2280
2281 -- Tell our player that he's in GL mode
2282 if CLIENT then
2283 self.Owner:PrintMessage( HUD_PRINTTALK , "Grenade Launcher Off" )
2284 end
2285 end
2286
2287 -- Add a delay before we can swap
2288 self.ActionDelay = self.ActionDelay + 2
2289 -- Add a delay based on sequence speed
2290 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2291 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2292 end
2293end -- Toggle our grenade launcher
2294
2295function SWEP:ToggleIronsights( )
2296 -- If we're owner, a player, valid, and alive, and not holstered, and our delay is expired then
2297 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and self:GetVNTSBHolstered( ) == false and self.ActionDelay <= CurTime( ) then
2298 -- If we're not iron sighted then
2299 if self:GetVNTSBIronSighted( ) == false then
2300 if self.ScopeType == 1 then
2301 if ( self:GetVNTSBScopedIn( ) == false ) then
2302 self.Weapon:EmitSound( self.SND_ZoomIn )
2303 self:SetVNTSBZoom( self.ScopeMultipliers[ 1 ] )
2304 self.Owner:SetFOV( 60 * self.ScopeMultipliers[ 1 ] , 0.3 )
2305 end
2306 elseif self.ScopeType == 2 then
2307 if ( self:GetVNTSBScopedIn( ) == false ) then
2308 self.Weapon:EmitSound( self.SND_ZoomIn )
2309 self.Owner:SetFOV( self.ViewModelFOV - 10 , 0.3 )
2310 end
2311 end
2312
2313 -- Set our FoV
2314 self.IsCloseZoomed = false
2315 -- Set our Iron sighted to true
2316 self:SetVNTSBIronSighted( true )
2317 self:SetVNTSBScopedIn( true )
2318
2319 -- if mag is empty and we have empty anims then
2320 if ( self:Clip1( ) == 0 and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_EMPTY ) ) then
2321 -- play our empty idle anims
2322 self:SendWeaponAnim( ACT_VM_IDLE_EMPTY )
2323 self:SetNextPrimaryFire( CurTime( ) + 0.3 )
2324 self:SetNextSecondaryFire( CurTime( ) + 0.3 )
2325 else
2326 -- else if mag isn't empty or we don't have empty anims then
2327 -- if we have a suppressor and we're suppressed
2328 if self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_SILENCED ) then
2329 -- play our suppressed idle
2330 self:SendWeaponAnim( ACT_VM_IDLE_SILENCED )
2331 else
2332 -- play our normal idle anims
2333 self:SendWeaponAnim( ACT_VM_IDLE )
2334 end
2335
2336 -- add a slight float delay before we can fire since we can't use anim length here
2337 self:SetNextPrimaryFire( CurTime( ) + 0.3 )
2338 self:SetNextSecondaryFire( CurTime( ) + 0.3 )
2339 end
2340
2341 -- Set our animaion speed to 0 to make aiming easier
2342 self.Owner:GetViewModel( ):SetPlaybackRate( 0 )
2343 elseif self:GetVNTSBIronSighted( ) == true then
2344 if self.ScopeType == 1 then
2345 if ( self:GetVNTSBScopedIn( ) == true ) then
2346 self.Weapon:EmitSound( self.SND_ZoomOut )
2347 self:SetVNTSBZoom( self.DefaultZoom )
2348 self.Owner:SetFOV( 0 , 0.3 )
2349 end
2350 elseif self.ScopeType == 2 then
2351 if ( self:GetVNTSBScopedIn( ) == true ) then
2352 self.Weapon:EmitSound( self.SND_ZoomOut )
2353 self.Owner:SetFOV( 0 , 0.3 )
2354 end
2355 end
2356
2357 -- Reset our FOV
2358 self.IsCloseZoomed = false
2359 -- Set our iron sight to false
2360 self:SetVNTSBIronSighted( false )
2361 self:SetVNTSBScopedIn( false )
2362
2363 -- if mag is empty and we have empty anims then
2364 if ( self:Clip1( ) == 0 and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_EMPTY ) ) then
2365 -- play our idle empty anim
2366 self:SendWeaponAnim( ACT_VM_IDLE_EMPTY )
2367 self:SetNextPrimaryFire( CurTime( ) + 0.3 )
2368 self:SetNextSecondaryFire( CurTime( ) + 0.3 )
2369 else
2370 -- else if mag isn't empty or we don't have empty anims then
2371 -- if we have a suppressor and we're suppressed
2372 if self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_SILENCED ) then
2373 -- play our suppressed idle
2374 self:SendWeaponAnim( ACT_VM_IDLE_SILENCED )
2375 else
2376 -- play our normal idle anims
2377 self:SendWeaponAnim( ACT_VM_IDLE )
2378 end
2379
2380 -- play a delay since we can't use non-existant animation lengths
2381 self:SetNextPrimaryFire( CurTime( ) + 0.3 )
2382 self:SetNextSecondaryFire( CurTime( ) + 0.3 )
2383 end
2384
2385 -- Reset our snimation speed
2386 self.Owner:GetViewModel( ):SetPlaybackRate( 1 )
2387 end
2388 end
2389
2390 -- Add a delay before we can swap
2391 self.ActionDelay = self.ActionDelay + 0.3
2392end -- Toggle our iron sights
2393
2394function SWEP:ToggleZoom( )
2395 -- If we're owner, a player, valid, and alive, and not holstered, and our delay is expired then
2396 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and self:GetVNTSBHolstered( ) == false and self.ActionDelay <= CurTime( ) then
2397 if self.HasVariableZoom == true then
2398 if self.ScopeType == 1 then
2399 if self:GetVNTSBScopedIn( ) == true and self.IsCloseZoomed == false then
2400 -- Set our FoV
2401 self.Owner:SetFOV( 60 * self.ScopeMultipliers[ 2 ] , 0.3 )
2402 self.IsCloseZoomed = true
2403 self:EmitSound( self.SND_CycleZoomIn )
2404 elseif self:GetVNTSBScopedIn( ) == true and self.IsCloseZoomed == true then
2405 -- Set our FoV
2406 self.Owner:SetFOV( 60 * self.ScopeMultipliers[ 1 ] , 0.3 )
2407 self.IsCloseZoomed = false
2408 self:EmitSound( self.SND_CycleZoomOut )
2409 end
2410 elseif self.ScopeType == 2 then
2411 if self:GetVNTSBScopedIn( ) == true and self.IsCloseZoomed == false then
2412 self.IsCloseZoomed = true
2413 self:EmitSound( self.SND_CycleZoomIn )
2414 elseif self:GetVNTSBScopedIn( ) == true and self.IsCloseZoomed == true then
2415 self.IsCloseZoomed = false
2416 self:EmitSound( self.SND_CycleZoomOut )
2417 end
2418 else
2419 return false
2420 end
2421 else
2422 return false
2423 end
2424 end
2425
2426 -- Add a delay before we can swap
2427 self.ActionDelay = self.ActionDelay + 0.2
2428end
2429
2430function SWEP:ToggleHolster( )
2431 -- If we're owner, a player, valid, and alive, and our delay has expired then
2432 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and self.ActionDelay <= CurTime( ) then
2433 -- if we're not holstered then
2434 if self:GetVNTSBHolstered( ) == false then
2435 -- we are now!
2436 self:SetVNTSBHolstered( true )
2437
2438 -- Turn off iron sights if we're in them
2439 if self:GetVNTSBIronSighted( ) == true then
2440 self:ToggleIronsights( )
2441 end
2442
2443 -- Add a toggle delay
2444 self.ActionDelay = CurTime( ) + 1
2445
2446 -- if we have low anims then
2447 if self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DOWN_M203 ) or self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_LOWERED ) then
2448 -- if we're in launcher mode then
2449 if self:GetVNTSBGLauncher( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DOWN_M203 ) then
2450 -- play the down deployed anim
2451 self:SendWeaponAnim( ACT_VM_DOWN_M203 )
2452 elseif self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_LOWERED ) then
2453 -- else we're not in launcher mode
2454 -- play the normal down animation
2455 self:SendWeaponAnim( ACT_VM_IDLE_LOWERED )
2456 end
2457 elseif self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_HOLSTER ) then
2458 -- else we don't have low anims, so just play the holster anim
2459 self:SendWeaponAnim( ACT_VM_HOLSTER )
2460 end
2461 else
2462 -- if we're holstered
2463 -- if we have a suppressor and we're suppressed
2464 if self.SuppressorType == 2 and self:GetVNTSBSuppressed( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_DRAW_SILENCED ) then
2465 -- play our suppressed draw
2466 self:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
2467 elseif self:GetVNTSBGLauncher( ) == true and self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_IDLE_M203 ) then
2468 -- play the deployed anim
2469 self:SendWeaponAnim( ACT_VM_IDLE_M203 )
2470 elseif self.Owner:GetViewModel( ):SelectWeightedSequence( ACT_VM_LOWERED_TO_IDLE ) then
2471 self:SendWeaponAnim( ACT_VM_LOWERED_TO_IDLE )
2472 else
2473 -- Play our normal draw anim
2474 self:SendWeaponAnim( ACT_VM_DRAW )
2475 end
2476
2477 -- set our holster to false
2478 self:SetVNTSBHolstered( false )
2479 end
2480
2481 -- add a delay
2482 self.ActionDelay = CurTime( ) + 1
2483 end
2484end -- Toggle our holster
2485
2486------------------------------------------------------
2487-- Entity Shooter Functions --
2488------------------------------------------------------
2489function SWEP:EntityShooter( )
2490 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) then
2491 -- If the launcher is empty, and the bolt is back then
2492 if ( self:GetVNTSBLchrLoaded( ) == false and self.LauncherPinForward == false ) then
2493 -- Emit our empty sound
2494 self:EmitSound( self.SND_PrimaryDryFire )
2495 -- Set a delay
2496 self:SetNextPrimaryFire( CurTime( ) + 0.2 )
2497 self:SetNextSecondaryFire( CurTime( ) + 0.2 )
2498 -- Bolt is forward
2499 self.LauncherPinForward = true
2500 elseif ( self:GetVNTSBLchrLoaded( ) == true and self.LauncherPinForward == false ) then
2501 self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
2502 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2503 self:SetNextSecondaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2504 self:TakePrimaryAmmo( 1 )
2505 self:FireViewPunches( )
2506 self:SetVNTSBLchrLoaded( false )
2507 self:EmitSound( self.SND_PrimaryFire )
2508
2509 if CLIENT then
2510 -- If our muzzle flashes are enabled
2511 if GetConVarNumber( "VNT_SWep_Base_FlashToggle" ) ~= 0 then
2512 self.Owner:MuzzleFlash( )
2513 -- Emit our muzzle flash
2514 local FX = EffectData( )
2515 FX:SetOrigin( self.Owner:GetShootPos( ) )
2516 FX:SetEntity( self )
2517 FX:SetStart( self.Owner:GetShootPos( ) )
2518 FX:SetNormal( self.Owner:GetAimVector( ) )
2519 FX:SetAttachment( self.MuzzleAttach )
2520 -- emit normal rifle smoke
2521 util.Effect( "fx_smoke_rifle_ins" , FX )
2522 end
2523 end
2524
2525 self:EntityLauncher( )
2526 end
2527
2528 -- Exit our attack function
2529 return false
2530 end
2531end
2532
2533function SWEP:EntityLauncher( )
2534 if SERVER then
2535 local LaunchedGren = ents.Create( self.GrenadeLauncherEntity )
2536 LaunchedGren:SetPos( self.Owner:GetShootPos( ) + self.Owner:EyeAngles( ):Right( ) * 0 )
2537 LaunchedGren:SetAngles( self.Owner:EyeAngles( ) + Angle( 0 , 180 , 0 ) )
2538 LaunchedGren:SetOwner( self.Owner )
2539 LaunchedGren:Spawn( )
2540 LaunchedGren:Activate( )
2541 LaunchedGren:SetVelocity( self.Owner:EyeAngles( ):Forward( ) * self.GrenadeLauncherForce + Vector( 0 , 0 , 50 ) )
2542 end
2543end
2544
2545------------------------------------------------------
2546-- Toss Weapon Functions --
2547------------------------------------------------------
2548--function SWEP:Equip()end
2549function SWEP:OnDrop( )
2550 return false
2551end
2552
2553function SWEP:Throw( )
2554 -- If we're owner, a player, valid, and alive then
2555 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) then
2556 -- Play our holster animation
2557
2558 if self:SelectWeightedSequence( ACT_VM_HOLSTER ) then
2559 self:SendWeaponAnim( ACT_VM_HOLSTER )
2560 end
2561
2562 self.Owner:DoAnimationEvent( ACT_GMOD_GESTURE_ITEM_GIVE )
2563 self:EmitSound( "VNT.SWep.Throw1" )
2564
2565 -- Get our position
2566 local pos = self.Owner:GetShootPos( )
2567 pos = pos + self.Owner:GetForward( ) * 24
2568 pos = pos + self.Owner:GetRight( ) * 0
2569 pos = pos + self.Owner:GetUp( ) * 2
2570
2571 local weaponEnt = self.WeaponEntityName:GetClass()
2572
2573 -- ents.Create only exists in the server realm
2574-- if SERVER then
2575 -- Run our drop animation
2576
2577 -- Give our holster and 3rd person anims time to finish
2578 timer.Simple( 0.9 , function( )
2579 -- Create our weapon entity
2580 local Tosser = ents.Create( weaponEnt )
2581 Tosser:SetAngles( self.Owner:EyeAngles( ) )
2582 Tosser:SetPos( pos )
2583 Tosser:Spawn( )
2584 Tosser:Activate( )
2585 -- Activate our physics
2586 local phys = Tosser:GetPhysicsObject( )
2587 phys:SetVelocity( self.Owner:GetAimVector( ) * 256 )
2588 phys:AddAngleVelocity( Vector( 47 , 0 , 0 ) )
2589 -- Remove the weapon from our slots
2590 self.Owner:StripWeapon( self.WeaponName )
2591 end )
2592
2593 -- And return to the last used weapon
2594 RunConsoleCommand( "lastinv" )
2595-- end
2596 end
2597end -- Throw our weapon
2598
2599------------------------------------------------------
2600-- Jamming Functions --
2601------------------------------------------------------
2602function SWEP:Jammed( )
2603 -- If we're owner, a player, valid, and alive then
2604 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) then
2605 -- If we're a small jam then
2606 if self:GetVNTSBJammedL( ) == true then
2607 -- Print the text
2608 if ( CLIENT ) then
2609 self.Owner:PrintMessage( HUD_PRINTTALK , "Magazine Jam!" )
2610 end
2611
2612 -- Toggle out of iron sights
2613 if self:GetVNTSBIronSighted( ) == true then
2614 self:ToggleIronsights( )
2615 end
2616
2617 -- get the duration of the sequence and run the function
2618 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) , function( )
2619 -- if the player or weapon isn't valid, and we're not predicted, and the owner isn't alive then quit
2620 if ( not IsValid( self.Owner ) or not IsValid( self ) ) or ( not IsFirstTimePredicted( ) or not self.Owner:Alive( ) ) then return end
2621
2622 -- play the holster animation
2623 --self:SendWeaponAnim( ACT_VM_HOLSTER )
2624 -- if we're a pistol then
2625 if ( self.WeaponType == 2 ) then
2626 -- play the pistol jam sound
2627 self:EmitSound( self.SND_JamSmallPistol )
2628 else
2629 -- else play the rifle jam sound
2630 self:EmitSound( self.SND_JamSmall )
2631 end
2632
2633 -- get our sequence + 2 and run func
2634 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) + 2 , function( )
2635 -- if the player or weapon isn't valid, and we're not predicted, and the owner isn't alive then quit
2636 if ( not IsValid( self.Owner ) or not IsValid( self ) ) or ( not IsFirstTimePredicted( ) or not self.Owner:Alive( ) ) then return end
2637
2638 if self.SuppressorType == 2 then
2639 else
2640 end
2641
2642 --self:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
2643 --self:SendWeaponAnim( ACT_VM_DRAW )
2644 -- get the sequence duration of the draw anim
2645 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) , function( )
2646 -- if the player or weapon isn't valid, and we're not predicted, and the owner isn't alive then quit
2647 if ( not IsValid( self.Owner ) or not IsValid( self ) ) or ( not IsFirstTimePredicted( ) or not self.Owner:Alive( ) ) then return end
2648 -- clear the chamber
2649 self:TakePrimaryAmmo( 1 )
2650 -- we're not jammed
2651 self:SetVNTSBJammedL( false )
2652 end )
2653 end )
2654 end )
2655 end
2656
2657 -- If we're a big jam then
2658 if self:GetVNTSBJammedB( ) == true then
2659 -- Print the text
2660 if ( CLIENT ) then
2661 self.Owner:PrintMessage( HUD_PRINTTALK , "Function Jam!" )
2662 end
2663
2664 -- Toggle out of iron sights
2665 if self:GetVNTSBIronSighted( ) == true then
2666 self:ToggleIronsights( )
2667 end
2668
2669 -- get the duration of the sequence and run the function
2670 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) , function( )
2671 -- if the player or weapon isn't valid, and we're not predicted, and the owner isn't alive then quit
2672 if ( not IsValid( self.Owner ) or not IsValid( self ) ) or ( not IsFirstTimePredicted( ) or not self.Owner:Alive( ) ) then return end
2673
2674 -- play the holster animation
2675 --self:SendWeaponAnim( ACT_VM_HOLSTER )
2676 -- if we're a pistol then
2677 if ( self.WeaponType == 2 ) then
2678 -- play the pistol jam sound
2679 self:EmitSound( self.SND_JamLargePistol )
2680 else
2681 -- else play the rifle jam sound
2682 self:EmitSound( self.SND_JamLarge )
2683 end
2684
2685 -- get our sequence + 2 and run func
2686 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) + 2 , function( )
2687 -- if the player or weapon isn't valid, and we're not predicted, and the owner isn't alive then quit
2688 if ( not IsValid( self.Owner ) or not IsValid( self ) ) or ( not IsFirstTimePredicted( ) or not self.Owner:Alive( ) ) then return end
2689
2690 if self.SuppressorType == 2 then
2691 else
2692 end
2693
2694 --self:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
2695 --self:SendWeaponAnim( ACT_VM_DRAW )
2696 -- get the sequence duration of the draw anim
2697 timer.Simple( self.Owner:GetViewModel( ):SequenceDuration( ) , function( )
2698 -- if the player or weapon isn't valid, and we're not predicted, and the owner isn't alive then quit
2699 if ( not IsValid( self.Owner ) or not IsValid( self ) ) or ( not IsFirstTimePredicted( ) or not self.Owner:Alive( ) ) then return end
2700 -- clear the chamber
2701 self:TakePrimaryAmmo( 1 )
2702 -- we're not jammed
2703 self:SetVNTSBJammedB( false )
2704 end )
2705 end )
2706 end )
2707 end
2708 end
2709end -- Run our Jammed functions
2710
2711------------------------------------------------------
2712-- Melee Functions --
2713------------------------------------------------------
2714function SWEP:Melee( )
2715 -- If we're owner, a player, valid, and alive then
2716 if self.Owner and self.Owner:IsPlayer( ) and self.Owner:IsValid( ) and self.Owner:Alive( ) and not ( self.Owner:KeyDown( IN_SPEED ) ) then
2717 local tr = { }
2718 tr.start = self.Owner:GetShootPos( )
2719 tr.endpos = self.Owner:GetShootPos( ) + ( self.Owner:GetAimVector( ) * self.MeleeRange )
2720 tr.filter = self.Owner
2721 tr.mask = MASK_SHOT
2722 local trace = util.TraceLine( tr )
2723 local trEnt = trace.Entity
2724 if ( trace.HitSky ) then return end
2725 -- Play the melee attack animation
2726 if self.MeleeAnimType == 2 then
2727 self.Owner:DoAnimationEvent( ACT_GMOD_GESTURE_MELEE_SHOVE_2HAND )
2728 elseif self.MeleeAnimType == 1 then
2729 self.Owner:DoAnimationEvent( ACT_GMOD_GESTURE_MELEE_SHOVE_1HAND )
2730 end
2731
2732 if trace.Hit then
2733 if trEnt:IsWorld( ) then
2734 if self.HasMeleeAttack != false then
2735 self:EmitSound( self.SND_PistolWhipHit )
2736 self:SendWeaponAnim( ACT_VM_HITCENTER2 )
2737 else
2738 self:EmitSound( self.SND_MeleeHitWall )
2739 end
2740 --print("Melee hit world!")
2741 -- Play animation
2742 -- Play hit sound
2743 -- Make sparks
2744 local FX = EffectData( )
2745 FX:SetOrigin( trace.HitPos )
2746 FX:SetEntity( self.ViewModel )
2747 FX:SetStart( trace.HitPos )
2748 FX:SetNormal( trace.HitNormal )
2749 FX:SetAngles( ( self.Owner:GetForward( ) * -16 ):Angle( ) )
2750 FX:SetScale( 1.5 )
2751 FX:SetRadius( 0.9 )
2752 FX:SetMagnitude( 0.6 )
2753 if self.IsBladedMelee == true then
2754 -- make decal
2755 util.Effect( "Sparks" , FX )
2756 util.Decal( "ManhackCut" , trace.HitPos + trace.HitNormal , trace.HitPos - trace.HitNormal )
2757 end
2758 elseif trEnt:IsNPC( ) or trEnt:IsPlayer( ) then
2759 --print("Melee hit character!")
2760 -- Play animation
2761 --self:SendWeaponAnim( ACT_VM_HITCENTER )
2762 -- Play hit sound
2763 if self.HasMeleeAttack != false then
2764 self:EmitSound( self.SND_PistolWhipHit )
2765 self:SendWeaponAnim( ACT_VM_HITCENTER2 )
2766 else
2767 self:EmitSound( self.SND_MeleeHitCharacter )
2768 end
2769 -- Make blood
2770 local FX = EffectData( )
2771 FX:SetOrigin( trace.HitPos )
2772 FX:SetEntity( self.ViewModel )
2773 FX:SetStart( trace.HitPos )
2774 FX:SetNormal( trace.HitNormal )
2775 FX:SetAngles( ( self.Owner:GetForward( ) * -16 ):Angle( ) )
2776 FX:SetScale( 1.5 )
2777 FX:SetRadius( 0.9 )
2778 FX:SetMagnitude( 0.6 )
2779 if self.IsBladedMelee == true then
2780 -- make decal
2781 util.Effect( "Blood" , FX )
2782 util.Decal( "ManhackCut" , trace.HitPos + trace.HitNormal , trace.HitPos - trace.HitNormal )
2783 end
2784 -- Do our damage
2785 if SERVER then
2786 local dmg = DamageInfo( )
2787 dmg:SetDamage( self.Primary.Damage )
2788 dmg:SetAttacker( self.Owner )
2789 dmg:SetInflictor( self )
2790 dmg:SetDamageForce( self.Owner:GetAimVector( ) * 300 )
2791 dmg:SetDamagePosition( trace.HitPos )
2792 dmg:SetDamageType( DMG_SLASH )
2793 -- Apply damage to target
2794 self.Owner:LagCompensation( true )
2795 trEnt:TakeDamageInfo( dmg )
2796 self.Owner:LagCompensation( false )
2797 end
2798 elseif trEnt:GetPhysicsObject( ):IsValid( ) and not ( trEnt:IsPlayer( ) or trEnt:IsNPC( ) or trEnt:IsWorld( ) ) then
2799 --print("Melee hit physics object!")
2800 -- Play animation
2801 --self:SendWeaponAnim( ACT_VM_HITCENTER2 )
2802 -- Play hit sound
2803 if self.HasMeleeAttack != false then
2804 self:EmitSound( self.SND_PistolWhipHit )
2805 self:SendWeaponAnim( ACT_VM_HITCENTER2 )
2806 else
2807 self:EmitSound( self.SND_MeleeHitWall )
2808 end
2809
2810 if self.IsBladedMelee == true then
2811 -- make decal
2812 util.Decal( "ManhackCut" , trace.HitPos + trace.HitNormal , trace.HitPos - trace.HitNormal )
2813 end
2814 -- Apply force
2815 trEnt:GetPhysicsObject( ):ApplyForceOffset( self.Owner:GetAimVector( ) * 80 * trEnt:GetPhysicsObject( ):GetMass( ) , trace.HitPos )
2816
2817 -- Do our damage
2818 if SERVER then
2819 local dmg = DamageInfo( )
2820 dmg:SetDamage( self.Primary.Damage / 4 )
2821 dmg:SetAttacker( self.Owner )
2822 dmg:SetInflictor( self )
2823 dmg:SetDamageForce( self.Owner:GetAimVector( ) * 300 )
2824 dmg:SetDamagePosition( trace.HitPos )
2825 dmg:SetDamageType( DMG_SLASH )
2826 -- Apply damage to target
2827 self.Owner:LagCompensation( true )
2828 trEnt:TakeDamageInfo( dmg )
2829 self.Owner:LagCompensation( false )
2830 end
2831 end
2832 else
2833 --print("Melee missed!")
2834 -- Play animation
2835 --self:SendWeaponAnim( ACT_VM_MISSCENTER )
2836 -- Play hit sound
2837
2838 if self.HasMeleeAttack != false then
2839 self:EmitSound( self.SND_PistolWhipMiss )
2840 self:EmitSound( self.SND_MeleeMissed )
2841 self:SendWeaponAnim( ACT_VM_HITCENTER2 )
2842 else
2843 self:EmitSound( self.SND_MeleeMissed )
2844 end
2845 end
2846
2847 -- Play our third-person firing animation
2848 self.Owner:SetAnimation( PLAYER_ATTACK1 )
2849 -- Play normal sound
2850 -- Make ViewModel pistol whip effect
2851 self:FireViewPunches( )
2852 self:SetNextPrimaryFire( CurTime( ) + self.Owner:GetViewModel( ):SequenceDuration( ) )
2853 end
2854end -- Are we a melee weapon
2855
2856------------------------------------------------------
2857-- Animation Functions --
2858------------------------------------------------------
2859function SWEP:SpecialAnimation( anim )
2860 self.ViewModel:SetSequence( self.ViewModel:LookupSequence( anim ) )
2861 --self.ViewModel:SetCycle(0)
2862 self:SetCycle( 0 )
2863end -- Play animations not normally called by ACT_VM_*