AlioNiroti

Untitled

Jul 14th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1.  
  2. AddCSLuaFile()
  3.  
  4. SWEP.PrintName = "Fists"
  5. SWEP.Author = "Kilburn, robotboy655, MaxOfS2D & Tenrys"
  6. SWEP.Purpose = "Well we sure as hell didn't use guns! We would just wrestle Hunters to the ground with our bare hands! I used to kill ten, twenty a day, just using my fists."
  7.  
  8. SWEP.Slot = 0
  9. SWEP.SlotPos = 4
  10.  
  11. SWEP.Spawnable = true
  12.  
  13. SWEP.ViewModel = Model( "models/weapons/c_arms.mdl" )
  14. SWEP.WorldModel = ""
  15. SWEP.ViewModelFOV = 54
  16. SWEP.UseHands = true
  17.  
  18. SWEP.Primary.ClipSize = -1
  19. SWEP.Primary.DefaultClip = -1
  20. SWEP.Primary.Automatic = true
  21. SWEP.Primary.Ammo = "none"
  22.  
  23. SWEP.Secondary.ClipSize = -1
  24. SWEP.Secondary.DefaultClip = -1
  25. SWEP.Secondary.Automatic = true
  26. SWEP.Secondary.Ammo = "none"
  27.  
  28. SWEP.DrawAmmo = false
  29.  
  30. SWEP.HitDistance = 48
  31.  
  32. local SwingSound = Sound( "WeaponFrag.Throw" )
  33. local HitSound = Sound( "Flesh.ImpactHard" )
  34.  
  35. function SWEP:Initialize()
  36.  
  37. self:SetHoldType( "fist" )
  38.  
  39. end
  40.  
  41. function SWEP:SetupDataTables()
  42.  
  43. self:NetworkVar( "Float", 0, "NextMeleeAttack" )
  44. self:NetworkVar( "Float", 1, "NextIdle" )
  45. self:NetworkVar( "Int", 2, "Combo" )
  46.  
  47. end
  48.  
  49. function SWEP:UpdateNextIdle()
  50.  
  51. local vm = self.Owner:GetViewModel()
  52. self:SetNextIdle( CurTime() + vm:SequenceDuration() )
  53.  
  54. end
  55.  
  56. function SWEP:PrimaryAttack( right )
  57.  
  58. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  59.  
  60. local anim = "fists_left"
  61. if ( right ) then anim = "fists_right" end
  62. if ( self:GetCombo() >= 2 ) then
  63. anim = "fists_uppercut"
  64. end
  65.  
  66. local vm = self.Owner:GetViewModel()
  67. vm:SendViewModelMatchingSequence( vm:LookupSequence( anim ) )
  68.  
  69. self:EmitSound( SwingSound )
  70.  
  71. self:UpdateNextIdle()
  72. self:SetNextMeleeAttack( CurTime() + 0.2 )
  73.  
  74. self:SetNextPrimaryFire( CurTime() + 0.9 )
  75. self:SetNextSecondaryFire( CurTime() + 0.9 )
  76.  
  77. end
  78.  
  79. function SWEP:SecondaryAttack()
  80.  
  81. self:PrimaryAttack( true )
  82.  
  83. end
  84.  
  85. function SWEP:DealDamage()
  86.  
  87. local anim = self:GetSequenceName(self.Owner:GetViewModel():GetSequence())
  88.  
  89. self.Owner:LagCompensation( true )
  90.  
  91. local tr = util.TraceLine( {
  92. start = self.Owner:GetShootPos(),
  93. endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
  94. filter = self.Owner,
  95. mask = MASK_SHOT_HULL
  96. } )
  97.  
  98. if ( !IsValid( tr.Entity ) ) then
  99. tr = util.TraceHull( {
  100. start = self.Owner:GetShootPos(),
  101. endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
  102. filter = self.Owner,
  103. mins = Vector( -10, -10, -8 ),
  104. maxs = Vector( 10, 10, 8 ),
  105. mask = MASK_SHOT_HULL
  106. } )
  107. end
  108.  
  109. -- We need the second part for single player because SWEP:Think is ran shared in SP
  110. if ( tr.Hit && !( game.SinglePlayer() && CLIENT ) ) then
  111. self:EmitSound( HitSound )
  112. end
  113.  
  114. local hit = false
  115.  
  116. if ( SERVER && IsValid( tr.Entity ) && ( tr.Entity:IsNPC() || tr.Entity:IsPlayer() || tr.Entity:Health() > 0 ) ) then
  117. local dmginfo = DamageInfo()
  118.  
  119. local attacker = self.Owner
  120. if ( !IsValid( attacker ) ) then attacker = self end
  121. dmginfo:SetAttacker( attacker )
  122.  
  123. dmginfo:SetInflictor( self )
  124. dmginfo:SetDamage( math.random( 8, 12 ) )
  125.  
  126. if ( anim == "fists_left" ) then
  127. dmginfo:SetDamageForce( self.Owner:GetRight() * 4912 + self.Owner:GetForward() * 9998 ) -- Yes we need those specific numbers
  128. elseif ( anim == "fists_right" ) then
  129. dmginfo:SetDamageForce( self.Owner:GetRight() * -4912 + self.Owner:GetForward() * 9989 )
  130. elseif ( anim == "fists_uppercut" ) then
  131. dmginfo:SetDamageForce( self.Owner:GetUp() * 5158 + self.Owner:GetForward() * 10012 )
  132. dmginfo:SetDamage( math.random( 12, 24 ) )
  133. end
  134.  
  135. tr.Entity:TakeDamageInfo( dmginfo )
  136. hit = true
  137.  
  138. end
  139.  
  140. if ( SERVER && IsValid( tr.Entity ) ) then
  141. local phys = tr.Entity:GetPhysicsObject()
  142. if ( IsValid( phys ) ) then
  143. phys:ApplyForceOffset( self.Owner:GetAimVector() * 80 * phys:GetMass(), tr.HitPos )
  144. end
  145. end
  146.  
  147. if ( SERVER ) then
  148. if ( hit && anim != "fists_uppercut" ) then
  149. self:SetCombo( self:GetCombo() + 1 )
  150. else
  151. self:SetCombo( 0 )
  152. end
  153. end
  154.  
  155. self.Owner:LagCompensation( false )
  156.  
  157. end
  158.  
  159. function SWEP:OnDrop()
  160.  
  161. self:Remove() -- You can't drop fists
  162.  
  163. end
  164.  
  165. function SWEP:Deploy()
  166.  
  167. local vm = self.Owner:GetViewModel()
  168. vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_draw" ) )
  169.  
  170. self:UpdateNextIdle()
  171.  
  172. if ( SERVER ) then
  173. self:SetCombo( 0 )
  174. end
  175.  
  176. return true
  177.  
  178. end
  179.  
  180. function SWEP:Think()
  181.  
  182. local vm = self.Owner:GetViewModel()
  183. local curtime = CurTime()
  184. local idletime = self:GetNextIdle()
  185.  
  186. if ( idletime > 0 && CurTime() > idletime ) then
  187.  
  188. vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) )
  189.  
  190. self:UpdateNextIdle()
  191.  
  192. end
  193.  
  194. local meleetime = self:GetNextMeleeAttack()
  195.  
  196. if ( meleetime > 0 && CurTime() > meleetime ) then
  197.  
  198. self:DealDamage()
  199.  
  200. self:SetNextMeleeAttack( 0 )
  201.  
  202. end
  203.  
  204. if ( SERVER && CurTime() > self:GetNextPrimaryFire() + 0.1 ) then
  205.  
  206. self:SetCombo( 0 )
  207.  
  208. end
  209.  
  210. end
Add Comment
Please, Sign In to add comment