if (SHARED) then SWEP.Category = BTB.BaseName SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Base = "swep_btb_base" SWEP.ShellModel = "models/weapons/rifleshell.mdl" SWEP.ShellScale = 0.75 SWEP.ViewModel = "models/weapons/btb/v_cheytec.mdl" SWEP.WorldModel = "models/weapons/btb/w_cheytec.mdl" SWEP.AnimPrefix = "python" SWEP.HoldType = "revolver" SWEP.m_bFiresUnderwater = false SWEP.m_fFireDuration = 0.0 SWEP.m_nShotsFired = 0.0 SWEP.Primary.Empty = "BTB_SNIPERRIFLE.Empty" SWEP.Primary.Sound = "BTB_Cheytec.Fire" SWEP.Primary.Damage = 125 SWEP.Primary.NumShots = 1 SWEP.Primary.NumAmmo = SWEP.Primary.NumShots SWEP.Primary.Cone = VECTOR_CONE_8DEGREES SWEP.Primary.ClipSize = 5 SWEP.Primary.Delay = 0.085 SWEP.Primary.DefaultClip = 5 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "357" SWEP.Primary.Tracer = 2 SWEP.IronFOV = 15 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.HipHoldType = "ar2" SWEP.AimHoldType = "ar2" SWEP.LowHoldType = "passive" SWEP.Effect = {} SWEP.Effect.MuzzleScale = 5.0 -- functions SWEP.Reload = nil end if (SERVER) then AddCSLuaFile("shared.lua") end if (CLIENT) then killicon.Add("weapon_btb_cheytec","vgui/entities/weapon_btb_cheytec",Color(255,255,255,255)) end SWEP.m_flKickTime = engine.CurTime() SWEP.m_flKickBoost = 0.0 function SWEP:PrimaryAttack() local player = self:GetOwner() if self:CanPrimaryAttack() then self.m_nShotsFired = self.m_nShotsFired + 1 if self:Clip1() <= 0 and self.Primary.ClipSize > -1 then self:EmitSound(self.Primary.Empty) self:SetNextFireDelay(0.35) return end if self.m_bIsUnderwater and !self.m_bFiresUnderwater then self:EmitSound(self.Primary.Empty) self:SetNextFireDelay(0.35) return end if self:GetClipSize() > -1 and self:Clip1() == 0 or self:GetClipSize() <= -1 and !self:GetAmmoCount() then return end self:SendWeaponAnim(self:GetFireActivity()) self.m_flDuration = self:SequenceDuration() local iBulletsToFire = 0 local fireRate = self.Primary.Delay self:EmitSound(self.Primary.Sound) self:SetNextFireDelay(self.m_flDuration) iBulletsToFire = iBulletsToFire + self.Primary.NumShots if self:GetClipSize() > -1 then if iBulletsToFire > self:Clip1() then iBulletsToFire = self:Clip1() end end self:ShootBullet(self.Primary.Damage,iBulletsToFire,self.Primary.DynamicCone) end end function SWEP:Bolt() self:SendWeaponAnim(ACT_SHOTGUN_PUMP) self:SetNextFireDelay(self:SequenceDuration()) self:TakePrimaryAmmo(self.Primary.NumAmmo) self.m_bReloading = false end function SWEP:PrimaryAttack() local player = self:GetOwner() if !self:CanPrimaryAttack() then return end if self.m_bNeedsBolt then return end self.m_bDelayedFire1 = false local player = self:GetOwner() if player:IsValid() then if (self:Clip1() <= 0 and self:ClipSize() > -1) or (self:ClipSize() <= -1 or self:GetAmmoCount() <= 0) then if self:GetAmmoCount() <= 0 then self:DryFire() return else self:StartReload() return end elseif player:WaterLevel() >= 3 and self.m_bFiresUnderwater == false then self:EmitSound(self.Primary.Empty) self:SetNextFireDelay(0.2) self.m_flNextPrimaryAttack = engine.CurTime() + 0.2 return else -- If the firing button was just pressed, reset the firing time if player:KeyPressed(IN_ATTACK) then self:SetNextFireDelay(engine.CurTime()) self.m_flNextPrimaryAttack = engine.CurTime() end end if !player:IsNPC() then self:EmitSound(self.Primary.Sound) else self:EmitSound(self.Primary.SoundNPC) end self:SendWeaponAnim(ACT_VM_PRIMARYATTACK) self.m_flDuration = self:SequenceDuration() -- Don't fire again until fire animation has completed self:SetNextFireDelay(self.m_flDuration) self.m_flNextPrimaryAttack = engine.CurTime() + self.m_flDuration self:TakePrimaryAmmo(self.Primary.NumAmmo) player:SetAnimation(PLAYER_ATTACK1) self:ShootBullet(self.Primary.Damage,self.Primary.NumShots,self.Primary.DynamicCone) local punchAngle = Angle(0,0,0) punchAngle.p = math.abs(self.Primary.Damage / 30.0) *-1 punchAngle.y = punchAngle.p *-1 * math.sin(engine.CurTime() * math.random(10,20)) if engine.CurTime() < self.m_flKickTime then punchAngle.p = punchAngle.p * self.m_flKickBoost * 1.0 punchAngle.y = punchAngle.y * self.m_flKickBoost * 0.5 self.m_flKickBoost = self.m_flKickBoost + 0.5 else self.m_flKickBoost = 1.0 end if (game.SinglePlayer() and SERVER) or (!game.SinglePlayer() and CLIENT) then if prediction.IsFirstTimePredicted() then player:RecoilPush(punchAngle,1.0,3,18) end end if prediction.IsFirstTimePredicted() then self:MuzzleSmoke(self.Attachment["muzzle"]) end self.m_flKickTime = engine.CurTime() + self.m_flDuration self.m_bNeedsBolt = true end end function SWEP:SecondaryAttack() return false end function SWEP:StartReload() if !prediction.IsFirstTimePredicted() then return end if self.m_bNeedsBolt then return false end local player = self:GetOwner() if player:IsValid() then if self:Clip1() >= self:GetClipSize() or self:GetAmmoCount() <= 0 then return false end local j = math.min(1,self:GetAmmoCount()) if j <= 0 then return false end self:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START) self.m_flDuration = self:SequenceDuration() timer.Simple(self.m_flDuration * 0.5,function() if self:IsValid() then self:FillClip() end end) player:SetAnimation(PLAYER_RELOAD) self:SetNextFireDelay(self.m_flDuration) self.m_flNextAttack = engine.CurTime() self.m_flNextPrimaryAttack = engine.CurTime() + self.m_flDuration self.m_bReloading = true self:SetNetworkedBool("Reloading",self.m_bReloading) return true end end function SWEP:Reload(m_bReloading) if !IsFirstTimePredicted() then return end if !m_bReloading then return end if self:Clip1() >= self:GetClipSize() or self:GetAmmoCount() <= 0 then return false end local j = math.min(1,self:GetAmmoCount()) if j <= 0 then return false end self:FillClip() local player = self:GetOwner() if player:IsValid() then self:SendWeaponAnim(ACT_VM_RELOAD) self:SetNextFireDelay(self:SequenceDuration()) self.m_flNextAttack = engine.CurTime() self.m_flNextPrimaryAttack = engine.CurTime() + self:SequenceDuration() return true end end function SWEP:FinishReload() self:SetBodygroup(1,1) self.m_bReloading = false self:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) self:SetNextFireDelay(self:SequenceDuration()) self.m_flNextAttack = engine.CurTime() self.m_flNextPrimaryAttack = engine.CurTime() + self:SequenceDuration() self.m_bReloading = false self:SetNetworkedBool("Reloading",self.m_bReloading) end function SWEP:FillClip() local player = self:GetOwner() if player:IsValid() then if self:GetAmmoCount() > 0 then if self:Clip1() < self:GetClipSize() then self:SetClip1(self:Clip1() + 1) player:RemoveAmmo(1,self.Primary.Ammo) end end end end function SWEP:Bolt() local player = self:GetOwner() if player:IsValid() then self.m_bNeedsBolt = false if self.m_bDelayedReload then self.m_bDelayedReload = false self:StartReload() end self:SendWeaponAnim(ACT_SHOTGUN_PUMP) self:SetNextFireDelay(self:SequenceDuration()) self.m_flNextAttack = engine.CurTime() + self:SequenceDuration() self.m_flNextPrimaryAttack = engine.CurTime() + self:SequenceDuration() end end function SWEP:Think() local player = self:GetOwner() if !player then return end if self.m_bNeedsBolt and player:KeyDown(IN_RELOAD) then self.m_bDelayedReload = true end if self.m_bReloading then -- If I'm primary firing and have one round stop reloading and fire... if player:KeyDown(IN_ATTACK) and self:Clip1() >= 1 and !self.m_bNeedsBolt then self.m_bReloading = false self.m_bNeedsBolt = false self.m_bDelayedFire1 = true -- If I'm secondary firing and have two rounds stop reloading and fire elseif player:KeyDown(IN_ATTACK2) and self:Clip1() >= 2 and !self.m_bNeedsBolt then self.m_bReloading = false self.m_bNeedsBolt = false -- Reloading elseif self.m_flNextPrimaryAttack <= engine.CurTime() then -- If we're out of ammo, finish reloading if self:GetAmmoCount() <= 0 then self:FinishReload() return end -- If clip isn't full, reload again if self:Clip1() < self:GetClipSize() then self:Reload(self.m_bReloading) return else -- Clip full, stop reloading self:FinishReload() return end end else -- Make shotgun shell invisible self:SetBodygroup(1,1) end if self.m_bNeedsBolt and self.m_flNextPrimaryAttack <= engine.CurTime() then self:Bolt() return end if player:KeyDown(IN_RELOAD) and self:GetClipSize() > -1 and !self.m_bReloading then if !player:KeyDown(IN_ATTACK) and !player:KeyDown(IN_ATTACK2) then -- Reload when reload is pressed, or if no buttons are down and weapon is empty self:StartReload() end else -- No attack buttons down self.m_bFireOnEmpty = false if self:Ammo1() <= 0 and self.m_flNextPrimaryAttack < engine.CurTime() then return else -- Weapon is useable. Reload if empty and weapon has waited as long as it has to after firing. if self:Clip1() <= 0 and self.m_flNextPrimaryAttack < engine.CurTime() then if self:StartReload() then -- If we've successfully started to reload, we're done return end end end return end end function SWEP:HandleAccuracy() local player = self:GetOwner() local velocity = player:GetVelocity():Length2D() * 0.00050 self.Primary.DynamicCone = self.Primary.Cone + Vector(velocity,velocity,velocity) if self:InIronsights() then self.Primary.DynamicCone = self.Primary.DynamicCone * 0.0001 end if !player:OnGround() then self.Primary.DynamicCone = self.Primary.DynamicCone * 3.0 else if player:KeyDown(IN_DUCK) then self.Primary.DynamicCone = self.Primary.DynamicCone * 0.5 end end self.Primary.DynamicCone = self.Primary.DynamicCone end local iron_sensitivity = CreateClientConVar("btb_iron_sensitivity",0.5,true,false) function SWEP:AdjustMouseSensitivity(m_flSensitivity) local player = self:GetOwner() m_flSensitivity = 1.0 if self:InIronsights() then m_flSensitivity = m_flSensitivity * iron_sensitivity:GetFloat() * 0.15 if player:KeyDown(IN_SPEED) then m_flSensitivity = m_flSensitivity * 0.25 end end return m_flSensitivity end