Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 6.44 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  if SERVER then
  2.  
  3.    AddCSLuaFile( "shared.lua" )
  4. end
  5.  
  6. SWEP.HoldType                   = "ar2"
  7.    
  8.  
  9. if CLIENT then
  10.  
  11.    SWEP.PrintName                       = "Mosin-Nagant"                       
  12.    SWEP.Slot                            = 2
  13.  
  14.    SWEP.Icon = "VGUI/ttt/icon_m16"
  15.    SWEP.ViewModelFlip           = false
  16. end
  17.  
  18.  
  19. SWEP.Base                               = "weapon_tttbase"
  20. SWEP.Spawnable = true
  21. SWEP.AdminSpawnable = true
  22.  
  23. SWEP.Kind = WEAPON_HEAVY
  24. SWEP.WeaponID = AMMO_M16
  25.  
  26. SWEP.Primary.Delay       = 1.3
  27. SWEP.Primary.Recoil      = 1.6
  28. SWEP.Primary.Automatic   = false
  29. SWEP.Primary.Damage      = 65
  30. SWEP.Primary.Cone        = 0.005
  31. SWEP.Primary.Ammo        = "357"
  32. SWEP.Primary.ClipSize    = 5
  33. SWEP.Primary.ClipMax     = 20
  34. SWEP.Primary.DefaultClip = 15
  35. SWEP.AmmoEnt             = "item_ammo_357_ttt"
  36. SWEP.ViewModel                   = "models/weapons/t_mosin.mdl"
  37. SWEP.WorldModel                  = "models/weapons/tw_mosin.mdl"
  38. SWEP.Secondary.Damage    = 75
  39. SWEP.Secondary.Range     = 75
  40.  
  41. SWEP.Primary.Sound = Sound( "Weapon_G3SG1.Single" )
  42.  
  43. SWEP.Zoom = 30
  44. SWEP.ZoomTime = 0.5
  45.  
  46. SWEP.IronSightsPos = Vector (-4.9771, -1.8352, 2.661)
  47. SWEP.IronSightsAng = Vector (-0.0583, 0.1181, -0.0011)
  48. SWEP.AutoSpawnable = true
  49.  
  50. SWEP.reloadtimer = 0
  51.  
  52. function SWEP:SetupDataTables()
  53.    self:DTVar("Bool", 0, "reloading")
  54.  
  55.    return self.BaseClass.SetupDataTables(self)
  56. end
  57.  
  58. function SWEP:Reload()
  59.    self:SetIronsights( false )
  60.    
  61.    --if self.Weapon:GetNetworkedBool( "reloading", false ) then return end
  62.    if self.dt.reloading then return end
  63.  
  64.    if not IsFirstTimePredicted() then return end
  65.    
  66.    if self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then
  67.      
  68.       if self:StartReload() then
  69.          return
  70.       end
  71.    end
  72.  
  73. end
  74.  
  75. function SWEP:StartReload()
  76.    --if self.Weapon:GetNWBool( "reloading", false ) then
  77.    if self.dt.reloading then
  78.       return false
  79.    end
  80.  
  81.    if not IsFirstTimePredicted() then return false end
  82.  
  83.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  84.    
  85.    local ply = self.Owner
  86.    
  87.    if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then
  88.       return false
  89.    end
  90.  
  91.    local wep = self.Weapon
  92.    
  93.    if wep:Clip1() >= self.Primary.ClipSize then
  94.       return false
  95.    end
  96.  
  97.    wep:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
  98.  
  99.    self.reloadtimer =  CurTime() + wep:SequenceDuration()
  100.  
  101.    --wep:SetNWBool("reloading", true)
  102.    self.dt.reloading = true
  103.  
  104.    return true
  105. end
  106.  
  107. function SWEP:PerformReload()
  108.    local ply = self.Owner
  109.    
  110.    -- prevent normal shooting in between reloads
  111.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  112.  
  113.    if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then return end
  114.  
  115.    local wep = self.Weapon
  116.  
  117.    if wep:Clip1() >= self.Primary.ClipSize then return end
  118.  
  119.    self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
  120.    self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
  121.  
  122.    wep:SendWeaponAnim(ACT_VM_RELOAD)
  123.  
  124.    self.reloadtimer = CurTime() + wep:SequenceDuration()
  125. end
  126.  
  127. function SWEP:FinishReload()
  128.    self.dt.reloading = false
  129.    self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)
  130.    
  131.    self.reloadtimer = CurTime() + self.Weapon:SequenceDuration()
  132. end
  133.  
  134. function SWEP:CanPrimaryAttack()
  135.    if self.Weapon:Clip1() <= 0 then
  136.       self:EmitSound( "Weapon_Shotgun.Empty" )
  137.       self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  138.       return false
  139.    end
  140.    return true
  141. end
  142.  
  143. function SWEP:Think()
  144.    if self.dt.reloading and IsFirstTimePredicted() then
  145.       if self.Owner:KeyDown(IN_ATTACK) then
  146.          self:FinishReload()
  147.          return
  148.       end
  149.      
  150.       if self.reloadtimer <= CurTime() then
  151.  
  152.          if self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
  153.             self:FinishReload()
  154.          elseif self.Weapon:Clip1() < self.Primary.ClipSize then
  155.             self:PerformReload()
  156.          else
  157.             self:FinishReload()
  158.          end
  159.          return            
  160.       end
  161.    end
  162. end
  163.  
  164. function SWEP:Deploy()
  165.    self.dt.reloading = false
  166.    self.reloadtimer = 0
  167.    return self.BaseClass.Deploy(self)
  168. end
  169.  
  170. function SWEP:SecondaryAttack()
  171.    if self.NoSights or (not self.IronSightsPos) then return end
  172.    --if self:GetNextSecondaryFire() > CurTime() then return end
  173.    
  174.    self:SetIronsights(not self:GetIronsights())
  175.    
  176.    self:SetNextSecondaryFire(CurTime() + 0.3)
  177.    if self.Owner:KeyDown (IN_USE) then
  178.         self:SetIronsights( false )
  179.                 self.Owner:LagCompensation(true)
  180.  
  181.    local spos = self.Owner:GetShootPos()
  182.    local sdest = spos + (self.Owner:GetAimVector() * 70)
  183.  
  184.    local kmins = Vector(1,1,1) * -10
  185.    local kmaxs = Vector(1,1,1) * 10
  186.  
  187.    local tr = util.TraceHull({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL, mins=kmins, maxs=kmaxs})
  188.  
  189.    -- Hull might hit environment stuff that line does not hit
  190.    if not ValidEntity(tr.Entity) then
  191.       tr = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL})
  192.    end
  193.  
  194.    local hitEnt = tr.Entity
  195.  
  196.    -- effects
  197.    if ValidEntity(hitEnt) then
  198.       self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  199.  
  200.       local edata = EffectData()
  201.       edata:SetStart(spos)
  202.       edata:SetOrigin(tr.HitPos)
  203.       edata:SetNormal(tr.Normal)
  204.       edata:SetEntity(hitEnt)
  205.  
  206.       if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then
  207.          util.Effect("BloodImpact", edata)
  208.       end
  209.    else
  210.       self.Weapon:SendWeaponAnim( ACT_VM_SWINGMISS )
  211.    end
  212.  
  213.    if SERVER then
  214.       self.Owner:SetAnimation( PLAYER_ATTACK1 )
  215.    end
  216.  
  217.  
  218.    if SERVER and tr.Hit and tr.HitNonWorld and ValidEntity(hitEnt) then
  219.       if hitEnt:IsPlayer() then
  220.          -- knife damage is never karma'd, so don't need to take that into
  221.          -- account we do want to avoid rounding error strangeness caused by
  222.          -- other damage scaling, causing a death when we don't expect one, so
  223.          -- when the target's health is close to kill-point we just kill
  224.          if hitEnt:Health() < (self.Secondary.Damage + 10) then
  225.             self:StabKill(tr, spos, sdest)
  226.          else
  227.             local dmg = DamageInfo()
  228.             dmg:SetDamage(self.Secondary.Damage)
  229.             dmg:SetAttacker(self.Owner)
  230.             dmg:SetInflictor(self.Weapon or self)
  231.             dmg:SetDamageForce(self.Owner:GetAimVector() * 5)
  232.             dmg:SetDamagePosition(self.Owner:GetPos())
  233.             dmg:SetDamageType(DMG_SLASH)
  234.  
  235.             hitEnt:DispatchTraceAttack(dmg, spos + (self.Owner:GetAimVector() * 3), sdest)
  236.          end
  237.       end
  238.         end
  239. end
  240. end