Advertisement
Guest User

Untitled

a guest
Sep 4th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.73 KB | None | 0 0
  1.  
  2. AddCSLuaFile()
  3.  
  4. SWEP.PrintName  = "Fists"
  5.  
  6. SWEP.Author     = "Kilburn, robotboy655, MaxOfS2D & Tenrys"
  7. 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."
  8.  
  9. SWEP.Spawnable  = true
  10. SWEP.UseHands   = true
  11. SWEP.DrawAmmo   = false
  12.  
  13. SWEP.ViewModel  = "models/weapons/c_arms_citizen.mdl"
  14. SWEP.WorldModel = ""
  15. SWEP.Base= "weapon_tttbase"
  16. SWEP.AutoSpawnable = false
  17. SWEP.Kind =  WEAPON_MELEE
  18. SWEP.NoSights = true
  19. SWEP.IsSilent = true
  20. SWEP.AutoSpawnable = false
  21. SWEP.AllowDelete = false -- never removed for weapon reduction
  22. SWEP.AllowDrop = false
  23.  SWEP.Icon = "vgui/ttt/ak47_icon_dark.png"
  24. SWEP.ViewModelFlip= false
  25.  
  26.  
  27. SWEP.ViewModelFOV   = 52
  28. SWEP.Slot           = 0
  29. SWEP.SlotPos        = 5
  30.  
  31. SWEP.Primary.ClipSize       = -1
  32. SWEP.Primary.DefaultClip    = -1
  33. SWEP.Primary.Automatic      = true
  34. SWEP.Primary.Ammo           = "none"
  35. SWEP.Primary.Delay = 0.5
  36. SWEP.Secondary.ClipSize     = -1
  37. SWEP.Secondary.DefaultClip  = -1
  38. SWEP.Secondary.Automatic    = true
  39. SWEP.Secondary.Ammo         = "none"
  40. SWEP.Secondary.Delay = 3
  41.  
  42. local SwingSound = Sound( "weapons/slam/throw.wav" )
  43. local HitSound = Sound( "Flesh.ImpactHard" )
  44.  
  45. function SWEP:Initialize()
  46.  
  47.     self:SetHoldType( "fist" )
  48.  
  49. end
  50.  
  51. function SWEP:PreDrawViewModel( vm, wep, ply )
  52.  
  53.     vm:SetMaterial( "engine/occlusionproxy" ) -- Hide that view model with hacky material
  54.  
  55. end
  56.  
  57. SWEP.HitDistance = 48
  58.  
  59. function SWEP:SetupDataTables()
  60.    
  61.     self:NetworkVar( "Float", 0, "NextMeleeAttack" )
  62.     self:NetworkVar( "Float", 1, "NextIdle" )
  63.     self:NetworkVar( "Int", 2, "Combo" )
  64.    
  65. end
  66.  
  67. function SWEP:UpdateNextIdle()
  68.  
  69.     local vm = self.Owner:GetViewModel()
  70.     self:SetNextIdle( CurTime() + vm:SequenceDuration() )
  71.    
  72. end
  73.  
  74. function SWEP:PrimaryAttack( right )
  75.  
  76.     self.Owner:SetAnimation( PLAYER_ATTACK1 )
  77.  
  78.     local anim = "fists_left"
  79.     if ( right ) then anim = "fists_right" end
  80.     if ( self:GetCombo() >= 2 ) then
  81.         anim = "fists_uppercut"
  82.     end
  83.  
  84.     local vm = self.Owner:GetViewModel()
  85.     vm:SendViewModelMatchingSequence( vm:LookupSequence( anim ) )
  86.  
  87.     self:EmitSound( SwingSound )
  88.  
  89.     self:UpdateNextIdle()
  90.     self:SetNextMeleeAttack( CurTime() + 0.2 )
  91.    
  92.     self:SetNextPrimaryFire( CurTime() + 0.9 )
  93.     self:SetNextSecondaryFire( CurTime() + 0.9 )
  94.  
  95. end
  96.  
  97. function SWEP:SecondaryAttack()
  98.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  99.    self.Weapon:SetNextSecondaryFire( CurTime() + 0.1 )
  100.  
  101.    local tr = self.Owner:GetEyeTrace(MASK_SHOT)
  102.  
  103.    if tr.Hit and IsValid(tr.Entity) and tr.Entity:IsPlayer() and (self.Owner:EyePos() - tr.HitPos):Length() < 100 then
  104.       local ply = tr.Entity
  105.  
  106.       if SERVER then
  107.    CreateConVar("ttt_crowbar_pushforce", "395", FCVAR_NOTIFY)
  108. end
  109.  
  110.       if SERVER and (not ply:IsFrozen()) then
  111.          local pushvel = tr.Normal * GetConVar("ttt_crowbar_pushforce"):GetFloat()
  112.  
  113.          -- limit the upward force to prevent launching
  114.          pushvel.z = math.Clamp(pushvel.z, 50, 100)
  115.  
  116.          ply:SetVelocity(ply:GetVelocity() + pushvel)
  117.          self.Owner:SetAnimation( PLAYER_ATTACK1 )
  118.  
  119.          ply.was_pushed = {att=self.Owner, t=CurTime()} --, infl=self}
  120.       end
  121.  
  122.       self.Weapon:EmitSound(HitSound)      
  123.     local anim = "fists_right"
  124.     if ( right ) then anim = "fists_left" end
  125.     if ( self:GetCombo() >= 2 ) then
  126.         anim = "fists_uppercut"
  127.     end
  128.       self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  129.    end
  130. end
  131.  
  132. --function SWEP:SecondaryAttack()
  133. --  self:PrimaryAttack( true )
  134. --end
  135.  
  136. function SWEP:DealDamage()
  137.  
  138.     local anim = self:GetSequenceName(self.Owner:GetViewModel():GetSequence())
  139.  
  140.     self.Owner:LagCompensation( true )
  141.    
  142.     local tr = util.TraceLine( {
  143.         start = self.Owner:GetShootPos(),
  144.         endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
  145.         filter = self.Owner
  146.     } )
  147.  
  148.     if ( !IsValid( tr.Entity ) ) then
  149.         tr = util.TraceHull( {
  150.             start = self.Owner:GetShootPos(),
  151.             endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
  152.             filter = self.Owner,
  153.             mins = Vector( -10, -10, -8 ),
  154.             maxs = Vector( 10, 10, 8 )
  155.         } )
  156.     end
  157.  
  158.     -- We need the second part for single player because SWEP:Think is ran shared in SP.
  159.     if ( tr.Hit && !( game.SinglePlayer() && CLIENT ) ) then
  160.         self:EmitSound( HitSound )
  161.     end
  162.  
  163.     local hit = false
  164.  
  165.     if ( SERVER && IsValid( tr.Entity ) && ( tr.Entity:IsNPC() || tr.Entity:IsPlayer() || tr.Entity:Health() > 0 ) ) then
  166.         local dmginfo = DamageInfo()
  167.    
  168.         local attacker = self.Owner
  169.         if ( !IsValid( attacker ) ) then attacker = self end
  170.         dmginfo:SetAttacker( attacker )
  171.  
  172.         dmginfo:SetInflictor( self )
  173.         dmginfo:SetDamage( math.random( 8, 12 ) )
  174.  
  175.         if ( anim == "fists_left" ) then
  176.             dmginfo:SetDamageForce( self.Owner:GetRight() * 4912 + self.Owner:GetForward() * 9998 ) -- Yes we need those specific numbers
  177.         elseif ( anim == "fists_right" ) then
  178.             dmginfo:SetDamageForce( self.Owner:GetRight() * -4912 + self.Owner:GetForward() * 9989 )
  179.         elseif ( anim == "fists_uppercut" ) then
  180.             dmginfo:SetDamageForce( self.Owner:GetUp() * 5158 + self.Owner:GetForward() * 10012 )
  181.             dmginfo:SetDamage( math.random( 12, 24 ) )
  182.         end
  183.  
  184.         tr.Entity:TakeDamageInfo( dmginfo )
  185.         hit = true
  186.  
  187.     end
  188.  
  189.     if ( SERVER && IsValid( tr.Entity ) ) then
  190.         local phys = tr.Entity:GetPhysicsObject()
  191.         if ( IsValid( phys ) ) then
  192.             tr.Entity:Fire("Break", 0.1)
  193.             phys:ApplyForceOffset( self.Owner:GetAimVector() * 80 * phys:GetMass(), tr.HitPos )
  194.         end
  195.     end
  196.  
  197.     if ( SERVER ) then
  198.         if ( hit && anim != "fists_uppercut" ) then
  199.             self:SetCombo( self:GetCombo() + 1 )
  200.         else
  201.             self:SetCombo( 0 )
  202.         end
  203.     end
  204.  
  205.     self.Owner:LagCompensation( false )
  206.  
  207. end
  208.  
  209. function SWEP:OnRemove()
  210.    
  211.     if ( IsValid( self.Owner ) && CLIENT && self.Owner:IsPlayer() ) then
  212.         local vm = self.Owner:GetViewModel()
  213.         if ( IsValid( vm ) ) then vm:SetMaterial( "" ) end
  214.     end
  215.    
  216. end
  217.  
  218. function SWEP:Holster( wep )
  219.  
  220.     self:OnRemove()
  221.  
  222.     return true
  223.  
  224. end
  225.  
  226. function SWEP:Deploy()
  227.  
  228.     local vm = self.Owner:GetViewModel()
  229.     vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_draw" ) )
  230.    
  231.     self:UpdateNextIdle()
  232.    
  233.     if ( SERVER ) then
  234.         self:SetCombo( 0 )
  235.     end
  236.    
  237.     return true
  238.  
  239. end
  240.  
  241. function SWEP:Think()
  242.    
  243.     local vm = self.Owner:GetViewModel()
  244.     local curtime = CurTime()
  245.     local idletime = self:GetNextIdle()
  246.    
  247.     if ( idletime > 0 && CurTime() > idletime ) then
  248.  
  249.         vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) )
  250.        
  251.         self:UpdateNextIdle()
  252.  
  253.     end
  254.    
  255.     local meleetime = self:GetNextMeleeAttack()
  256.    
  257.     if ( meleetime > 0 && CurTime() > meleetime ) then
  258.  
  259.         self:DealDamage()
  260.        
  261.         self:SetNextMeleeAttack( 0 )
  262.  
  263.     end
  264.    
  265.     if ( SERVER && CurTime() > self:GetNextPrimaryFire() + 0.1 ) then
  266.        
  267.         self:SetCombo( 0 )
  268.        
  269.     end
  270.    
  271. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement