- if SERVER then
- AddCSLuaFile( "shared.lua" )
- end
- SWEP.HoldType = "ar2"
- if CLIENT then
- SWEP.PrintName = "Mosin-Nagant"
- SWEP.Slot = 2
- SWEP.Icon = "VGUI/ttt/icon_m16"
- SWEP.ViewModelFlip = false
- end
- SWEP.Base = "weapon_tttbase"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.Kind = WEAPON_HEAVY
- SWEP.WeaponID = AMMO_M16
- SWEP.Primary.Delay = 1.3
- SWEP.Primary.Recoil = 1.6
- SWEP.Primary.Automatic = false
- SWEP.Primary.Damage = 65
- SWEP.Primary.Cone = 0.005
- SWEP.Primary.Ammo = "357"
- SWEP.Primary.ClipSize = 5
- SWEP.Primary.ClipMax = 20
- SWEP.Primary.DefaultClip = 15
- SWEP.AmmoEnt = "item_ammo_357_ttt"
- SWEP.ViewModel = "models/weapons/t_mosin.mdl"
- SWEP.WorldModel = "models/weapons/tw_mosin.mdl"
- SWEP.Secondary.Damage = 75
- SWEP.Secondary.Range = 75
- SWEP.Primary.Sound = Sound( "Weapon_G3SG1.Single" )
- SWEP.Zoom = 30
- SWEP.ZoomTime = 0.5
- SWEP.IronSightsPos = Vector (-4.9771, -1.8352, 2.661)
- SWEP.IronSightsAng = Vector (-0.0583, 0.1181, -0.0011)
- SWEP.AutoSpawnable = true
- SWEP.reloadtimer = 0
- function SWEP:SetupDataTables()
- self:DTVar("Bool", 0, "reloading")
- return self.BaseClass.SetupDataTables(self)
- end
- function SWEP:Reload()
- self:SetIronsights( false )
- --if self.Weapon:GetNetworkedBool( "reloading", false ) then return end
- if self.dt.reloading then return end
- if not IsFirstTimePredicted() then return end
- if self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then
- if self:StartReload() then
- return
- end
- end
- end
- function SWEP:StartReload()
- --if self.Weapon:GetNWBool( "reloading", false ) then
- if self.dt.reloading then
- return false
- end
- if not IsFirstTimePredicted() then return false end
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- local ply = self.Owner
- if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then
- return false
- end
- local wep = self.Weapon
- if wep:Clip1() >= self.Primary.ClipSize then
- return false
- end
- wep:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
- self.reloadtimer = CurTime() + wep:SequenceDuration()
- --wep:SetNWBool("reloading", true)
- self.dt.reloading = true
- return true
- end
- function SWEP:PerformReload()
- local ply = self.Owner
- -- prevent normal shooting in between reloads
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then return end
- local wep = self.Weapon
- if wep:Clip1() >= self.Primary.ClipSize then return end
- self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
- self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
- wep:SendWeaponAnim(ACT_VM_RELOAD)
- self.reloadtimer = CurTime() + wep:SequenceDuration()
- end
- function SWEP:FinishReload()
- self.dt.reloading = false
- self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)
- self.reloadtimer = CurTime() + self.Weapon:SequenceDuration()
- end
- function SWEP:CanPrimaryAttack()
- if self.Weapon:Clip1() <= 0 then
- self:EmitSound( "Weapon_Shotgun.Empty" )
- self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- return false
- end
- return true
- end
- function SWEP:Think()
- if self.dt.reloading and IsFirstTimePredicted() then
- if self.Owner:KeyDown(IN_ATTACK) then
- self:FinishReload()
- return
- end
- if self.reloadtimer <= CurTime() then
- if self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
- self:FinishReload()
- elseif self.Weapon:Clip1() < self.Primary.ClipSize then
- self:PerformReload()
- else
- self:FinishReload()
- end
- return
- end
- end
- end
- function SWEP:Deploy()
- self.dt.reloading = false
- self.reloadtimer = 0
- return self.BaseClass.Deploy(self)
- end
- function SWEP:SecondaryAttack()
- if self.NoSights or (not self.IronSightsPos) then return end
- --if self:GetNextSecondaryFire() > CurTime() then return end
- self:SetIronsights(not self:GetIronsights())
- self:SetNextSecondaryFire(CurTime() + 0.3)
- if self.Owner:KeyDown (IN_USE) then
- self:SetIronsights( false )
- self.Owner:LagCompensation(true)
- local spos = self.Owner:GetShootPos()
- local sdest = spos + (self.Owner:GetAimVector() * 70)
- local kmins = Vector(1,1,1) * -10
- local kmaxs = Vector(1,1,1) * 10
- local tr = util.TraceHull({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL, mins=kmins, maxs=kmaxs})
- -- Hull might hit environment stuff that line does not hit
- if not ValidEntity(tr.Entity) then
- tr = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL})
- end
- local hitEnt = tr.Entity
- -- effects
- if ValidEntity(hitEnt) then
- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
- local edata = EffectData()
- edata:SetStart(spos)
- edata:SetOrigin(tr.HitPos)
- edata:SetNormal(tr.Normal)
- edata:SetEntity(hitEnt)
- if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then
- util.Effect("BloodImpact", edata)
- end
- else
- self.Weapon:SendWeaponAnim( ACT_VM_SWINGMISS )
- end
- if SERVER then
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- end
- if SERVER and tr.Hit and tr.HitNonWorld and ValidEntity(hitEnt) then
- if hitEnt:IsPlayer() then
- -- knife damage is never karma'd, so don't need to take that into
- -- account we do want to avoid rounding error strangeness caused by
- -- other damage scaling, causing a death when we don't expect one, so
- -- when the target's health is close to kill-point we just kill
- if hitEnt:Health() < (self.Secondary.Damage + 10) then
- self:StabKill(tr, spos, sdest)
- else
- local dmg = DamageInfo()
- dmg:SetDamage(self.Secondary.Damage)
- dmg:SetAttacker(self.Owner)
- dmg:SetInflictor(self.Weapon or self)
- dmg:SetDamageForce(self.Owner:GetAimVector() * 5)
- dmg:SetDamagePosition(self.Owner:GetPos())
- dmg:SetDamageType(DMG_SLASH)
- hitEnt:DispatchTraceAttack(dmg, spos + (self.Owner:GetAimVector() * 3), sdest)
- end
- end
- end
- end
- end