1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
-- Variables that are used on both client and server
SWEP.Gun = ("m9k_dbarrel") -- must be the name of your swep but NO CAPITALS!
if (GetConVar(SWEP.Gun.."_allowed")) != nil then
if not (GetConVar(SWEP.Gun.."_allowed"):GetBool()) then SWEP.Base = "bobs_blacklisted" SWEP.PrintName = SWEP.Gun return end
end
SWEP.Category = "M9K Shotguns"
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
SWEP.ShellEjectAttachment = "2" -- Should be "2" for CSS models or "1" for hl2 models
SWEP.PrintName = "Double Barrel Shotgun" -- Weapon name (Shown on HUD)
SWEP.Slot = 3 -- Slot in the weapon selection menu
SWEP.SlotPos = 21 -- Position in the slot
SWEP.DrawAmmo = true -- Should draw the default HL2 ammo counter
SWEP.DrawWeaponInfoBox = false -- Should draw the weapon info box
SWEP.BounceWeaponIcon = false -- Should the weapon icon bounce?
SWEP.DrawCrosshair = true -- set false if you want no crosshair
SWEP.Weight = 30 -- rank relative ot other weapons. bigger is better
SWEP.AutoSwitchTo = true -- Auto switch to if we pick it up
SWEP.AutoSwitchFrom = true -- Auto switch from if you pick up a better weapon
SWEP.HoldType = "shotgun" -- how others view you carrying the weapon
-- normal melee melee2 fist knife smg ar2 pistol rpg physgun grenade shotgun crossbow slam passive
-- you're mostly going to use ar2, smg, shotgun or pistol. rpg and crossbow make for good sniper rifles
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/v_doublebarrl.mdl" -- Weapon view model
SWEP.WorldModel = "models/weapons/w_double_barrel_shotgun.mdl" -- Weapon world model
SWEP.Base = "bobs_shotty_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Primary.Sound = Sound("Double_Barrel.Single") -- script that calls the primary fire sound
SWEP.Primary.RPM = 180 -- This is in Rounds Per Minute
SWEP.Primary.ClipSize = 2 -- Size of a clip
SWEP.Primary.DefaultClip = 30 -- Default number of bullets in a clip
SWEP.Primary.KickUp = 10 -- Maximum up recoil (rise)
SWEP.Primary.KickDown = 5 -- Maximum down recoil (skeet)
SWEP.Primary.KickHorizontal = 5 -- Maximum up recoil (stock)
SWEP.Primary.Automatic = false -- Automatic/Semi Auto
SWEP.Primary.Ammo = "buckshot" -- pistol, 357, smg1, ar2, buckshot, slam, SniperPenetratedRound, AirboatGun
-- Pistol, buckshot, and slam always ricochet. Use AirboatGun for a light metal peircing shotgun pellets
SWEP.Secondary.IronFOV = 0 -- How much you 'zoom' in. Less is more!
SWEP.data = {} --The starting firemode
SWEP.data.ironsights = 1
SWEP.ShellTime = .5
SWEP.Primary.NumShots = 18 -- How many bullets to shoot per trigger pull, AKA pellets
SWEP.Primary.Damage = 10 -- Base damage per bullet
SWEP.Primary.Spread = .03 -- Define from-the-hip accuracy 1 is terrible, .0001 is exact)
SWEP.Primary.IronAccuracy = .03 -- Ironsight accuracy, should be the same for shotguns
-- Because irons don't magically give you less pellet spread!
-- Enter iron sight info and bone mod info below
SWEP.IronSightsPos = Vector(0, 0, 0)
SWEP.IronSightsAng = Vector(0, 0, 0)
SWEP.SightsPos = Vector(0, 0, 0)
SWEP.SightsAng = Vector(0, 0, 0)
SWEP.RunSightsPos = Vector(11.475, -7.705, -2.787)
SWEP.RunSightsAng = Vector(0.574, 51.638, 5.737)
SWEP.Secondary.Sound = Sound("dbarrel_dblast")
local PainMulti = 1
if GetConVar("M9KDamageMultiplier") == nil then
PainMulti = 1
print("M9KDamageMultiplier is missing! You may have hit the lua limit! Reverting multiplier to 1.")
else
PainMulti = GetConVar("M9KDamageMultiplier"):GetFloat()
if PainMulti < 0 then
PainMulti = PainMulti * -1
print("Your damage multiplier was in the negatives. It has been reverted to a positive number. Your damage multiplier is now "..PainMulti)
end
end
function NewM9KDamageMultiplierDB(cvar, previous, new)
print("multiplier has been changed ")
if GetConVar("M9KDamageMultiplier") == nil then
PainMulti = 1
print("M9KDamageMultiplier is missing! You may have hit the lua limit! Reverting multiplier to 1, you will notice no changes.")
else
PainMulti = GetConVar("M9KDamageMultiplier"):GetFloat()
if PainMulti < 0 then
PainMulti = PainMulti * -1
end
end
end
cvars.AddChangeCallback("M9KDamageMultiplier", NewM9KDamageMultiplierDB)
function SWEP:SecondaryAttack()
local timerName = "ShotgunReload_" .. self.Owner:UniqueID()
if (timer.Exists(timerName)) then return end
if self:CanPrimaryAttack() and self.Owner:IsPlayer() then
if self.Weapon:Clip1() == 2 then
if !self.Owner:KeyDown(IN_SPEED) and !self.Owner:KeyDown(IN_RELOAD) then
self:ShootBulletInformation2()
self.Weapon:TakePrimaryAmmo(2)
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:EmitSound(self.Secondary.Sound)
--self.Owner:ViewPunch(Angle(-15, math.Rand(-20,-25), 0))
local fx = EffectData()
fx:SetEntity(self.Weapon)
fx:SetOrigin(self.Owner:GetShootPos())
fx:SetNormal(self.Owner:GetAimVector())
fx:SetAttachment(self.MuzzleAttachment)
if GetConVar("M9KGasEffect") != nil then
if GetConVar("M9KGasEffect"):GetBool() then
util.Effect("m9k_rg_muzzle_rifle",fx)
end
end
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:MuzzleFlash()
self.Weapon:SetNextSecondaryFire(CurTime()+1/((self.Primary.RPM/2)/60))
self:CheckWeaponsAndAmmo()
self.RicochetCoin = (math.random(1,8))
if self.BoltAction then self:BoltBack() end
end
elseif self.Weapon:Clip1() == 1 then
self.Weapon:PrimaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime()+1/((self.Primary.RPM/2)/60))
elseif self.Weapon:Clip1() == 0 then
self:Reload()
end
end
end
function SWEP:PrimaryAttack()
local timerName = "ShotgunReload_" .. self.Owner:UniqueID()
if (timer.Exists(timerName)) then return end
if self:CanPrimaryAttack() and self.Owner:IsPlayer() then
if !self.Owner:KeyDown(IN_SPEED) and !self.Owner:KeyDown(IN_RELOAD) then
self:ShootBulletInformation()
self.Weapon:TakePrimaryAmmo(1)
if self.Silenced then
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK_SILENCED )
self.Weapon:EmitSound(self.Primary.SilencedSound)
else
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:EmitSound(self.Primary.Sound)
end
local fx = EffectData()
fx:SetEntity(self.Weapon)
fx:SetOrigin(self.Owner:GetShootPos())
fx:SetNormal(self.Owner:GetAimVector())
fx:SetAttachment(self.MuzzleAttachment)
if GetConVar("M9KGasEffect") != nil then
if GetConVar("M9KGasEffect"):GetBool() then
util.Effect("m9k_rg_muzzle_rifle",fx)
end
end
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:MuzzleFlash()
self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
self:CheckWeaponsAndAmmo()
self.RicochetCoin = (math.random(1,4))
if self.BoltAction then self:BoltBack() end
end
elseif self:CanPrimaryAttack() and self.Owner:IsNPC() then
self:ShootBulletInformation()
self.Weapon:TakePrimaryAmmo(1)
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:EmitSound(self.Primary.Sound)
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:MuzzleFlash()
self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
self.RicochetCoin = (math.random(1,4))
end
end
function SWEP:ShootBulletInformation2()
local CurrentDamage
local CurrentRecoil
local CurrentCone
local basedamage
CurrentCone = self.Primary.Spread
local damagedice = math.Rand(.85,1.3)
basedamage = PainMulti * self.Primary.Damage
CurrentDamage = basedamage * damagedice
CurrentRecoil = self.Primary.Recoil
self:ShootBullet(CurrentDamage, CurrentRecoil, 31, .06)
end
/*---------------------------------------------------------
Name: SWEP:Reload()
Desc: Reload is being pressed.
---------------------------------------------------------*/
function SWEP:Reload()
if not IsValid(self) then return end
if not IsValid(self.Owner) then return end
if not self.Owner:IsPlayer() then return end
local maxcap = self.Primary.ClipSize
local spaceavail = self.Weapon:Clip1()
local shellz = (maxcap) - (spaceavail) + 1
if (timer.Exists("ShotgunReload")) or self.Owner.NextReload > CurTime() or maxcap == spaceavail then return end
if self.Owner:IsPlayer() then
self.Weapon:SetNextPrimaryFire(CurTime() + 1) -- wait one second before you can shoot again
self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START) -- sending start reload anim
self.Owner:SetAnimation( PLAYER_RELOAD )
self.Owner.NextReload = CurTime() + 1
if (SERVER) then
self.Owner:SetFOV( 0, 0.15 )
self:SetIronsights(false)
end
if SERVER and self.Owner:Alive() then
local timerName = "ShotgunReload_" .. self.Owner:UniqueID()
timer.Create(timerName,
(self.ShellTime + .05),
shellz,
function() if not IsValid(self) then return end
if IsValid(self.Owner) and IsValid(self.Weapon) then
if self.Owner:Alive() then
self:InsertShell()
end
end end)
end
elseif self.Owner:IsNPC() then
self.Weapon:DefaultReload(ACT_VM_RELOAD)
end
end
function SWEP:Think()
if not IsValid(self) then return end
if not IsValid(self.Owner) then return end
if not self.Owner:IsPlayer() then return end
if self.Owner.NextReload == nil then self.Owner.NextReload = CurTime() + 1 end
local timerName = "ShotgunReload_" .. self.Owner:UniqueID()
--if the owner presses shoot while the timer is in effect, then...
-- if (self.Owner:KeyPressed(IN_ATTACK)) and (timer.Exists(timerName)) and not (self.Owner:KeyDown(IN_SPEED)) then
-- if self:CanPrimaryAttack() then --well first, if we actually can attack, then...
-- timer.Destroy(timerName) -- kill the timer, and
-- self:PrimaryAttack()-- ATTAAAAACK!
-- end
-- end
if self.InsertingShell == true and self.Owner:Alive() then
vm = self.Owner:GetViewModel()-- its a messy way to do it, but holy shit, it works!
vm:ResetSequence(vm:LookupSequence("after_reload")) -- Fuck you, garry, why the hell can't I reset a sequence in multiplayer?
vm:SetPlaybackRate(.01) -- or if I can, why does facepunch have to be such a shitty community, and your wiki have to be an unreadable goddamn mess?
self.InsertingShell = false -- You get paid for this, what's your excuse?
end
self:IronSight()
end
function SWEP:InsertShell()
if not IsValid(self) then return end
if not IsValid(self.Owner) then return end
if not self.Owner:IsPlayer() then return end
local timerName = "ShotgunReload_" .. self.Owner:UniqueID()
if self.Owner:Alive() then
local curwep = self.Owner:GetActiveWeapon()
if curwep:GetClass() != self.Gun then
timer.Destroy(timerName)
return end
if (self.Weapon:Clip1() >= self.Primary.ClipSize or self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0) then
-- if clip is full or ammo is out, then...
self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) -- send the pump anim
timer.Destroy(timerName) -- kill the timer
self.Weapon:SetNextPrimaryFire(CurTime()+.55)
self.Weapon:SetNextSecondaryFire(CurTime()+.55)
elseif (self.Weapon:Clip1() <= self.Primary.ClipSize and self.Owner:GetAmmoCount(self.Primary.Ammo) >= 0) then
self.InsertingShell = true --well, I tried!
timer.Simple( .05, function() self:ShellAnimCaller() end)
self.Owner:RemoveAmmo(1, self.Primary.Ammo, false) -- out of the frying pan
self.Weapon:SetClip1(self.Weapon:Clip1() + 1) -- into the fire
end
else
timer.Destroy(timerName) -- kill the timer
end
end
if GetConVar("M9KDefaultClip") == nil then
print("M9KDefaultClip is missing! You may have hit the lua limit!")
else
if GetConVar("M9KDefaultClip"):GetInt() != -1 then
SWEP.Primary.DefaultClip = SWEP.Primary.ClipSize * GetConVar("M9KDefaultClip"):GetInt()
end
end
if GetConVar("M9KUniqueSlots") != nil then
if not (GetConVar("M9KUniqueSlots"):GetBool()) then
SWEP.SlotPos = 2
end
end
|