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