Advertisement
Guest User

Untitled

a guest
May 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. if CLIENT then
  4. SWEP.EquipMenuData = {
  5. type = "Weapon"
  6. };
  7. SWEP.Slot = 3
  8. SWEP.DrawCrosshair = false
  9. SWEP.Icon = "vgui/weapons/weapon_fartgrenade.png"
  10. end
  11.  
  12. SWEP.PrintName = "Fart Grenade"
  13. SWEP.Author = "SgtDark"
  14. SWEP.Base = "weapon_tttbase"
  15. SWEP.ViewModel = "models/weapons/v_grenade.mdl"
  16. SWEP.WorldModel = "models/weapons/w_grenade.mdl"
  17.  
  18. SWEP.Weight = 5
  19. SWEP.AutoSwitchFrom = true
  20. SWEP.Spawnable = true
  21. SWEP.AdminOnly = false
  22. SWEP.ViewModelFlip = false
  23.  
  24. SWEP.NoSights = true
  25. SWEP.Primary.ClipSize = -1
  26. SWEP.Primary.DefaultClip = -1
  27. SWEP.Primary.Automatic = false
  28. SWEP.Primary.Delay = 1.0
  29. SWEP.Primary.Ammo = "none"
  30. SWEP.Secondary.ClipSize = -1
  31. SWEP.Secondary.DefaultClip = -1
  32. SWEP.Secondary.Automatic = false
  33. SWEP.Secondary.Ammo = "none"
  34.  
  35. SWEP.Kind = WEAPON_NADE
  36. SWEP.IsGrenade = true
  37. SWEP.LimitedStock = false
  38. SWEP.CanBuy = {ROLE_TRAITOR, ROLE_DETECTIVE}
  39.  
  40. local fartSound = Sound("fart_1.wav")
  41. local dieSound = Sound("fart_2.wav")
  42. local throwSound = Sound("weapons/slam/throw.wav")
  43.  
  44. local hurtSounds = {
  45. Sound("vo/npc/Barney/ba_ohshit03.wav"),
  46. Sound("vo/k_lab/kl_ahhhh.wav"),
  47. Sound("vo/npc/male01/moan01.wav"),
  48. Sound("vo/npc/male01/moan04.wav"),
  49. Sound("vo/npc/male01/ohno.wav")}
  50. local hurtImpacts = {
  51. Sound("player/pl_pain5.wav"),
  52. Sound("player/pl_pain6.wav"),
  53. Sound("player/pl_pain7.wav")}
  54.  
  55.  
  56. function SWEP:Initialize()
  57. game.AddParticles("particles/fart_particle.pcf")
  58. PrecacheParticleSystem("fartsmoke")
  59. end
  60.  
  61. function SWEP:PrimaryAttack()
  62. self.Weapon:SendWeaponAnim(ACT_VM_THROW)
  63. self:Throw()
  64. end
  65.  
  66. function SWEP:Deploy()
  67. self.Weapon:SendWeaponAnim(ACT_VM_IDLE)
  68. end
  69.  
  70. function SWEP:Throw()
  71. if SERVER then
  72. local ply = self.Owner
  73. if not IsValid(ply) then return end
  74.  
  75. ply:EmitSound(throwSound)
  76.  
  77. local ang = ply:EyeAngles()
  78. local src = ply:GetPos() + (ply:Crouching() and ply:GetViewOffsetDucked() or ply:GetViewOffset())+ (ang:Forward() * 8) + (ang:Right() * 10)
  79. local target = ply:GetEyeTraceNoCursor().HitPos
  80. local tang = (target-src):Angle()
  81.  
  82. if tang.p < 90 then
  83. tang.p = -10 + tang.p * ((90 + 10) / 90)
  84. else
  85. tang.p = 360 - tang.p
  86. tang.p = -10 + tang.p * -((90 + 10) / 90)
  87. end
  88. tang.p=math.Clamp(tang.p,-90,90)
  89. local vel = math.min(800, (90 - tang.p) * 6)
  90. local thr = tang:Forward() * vel + ply:GetVelocity()
  91.  
  92.  
  93. self:CreateGrenade(src, Angle(0,0,0), thr, Vector(600, 0, 0), ply)
  94. self:Remove()
  95. end
  96. end
  97.  
  98. function SWEP:CreateGrenade(src, ang, vel, angimp, ply)
  99. local gren = ents.Create("prop_physics")
  100. if not IsValid(gren) then return end
  101.  
  102. gren:SetPos(src)
  103. gren:SetAngles(ang)
  104. gren:SetModel("models/weapons/w_grenade.mdl")
  105. gren:SetOwner(ply)
  106. gren:SetGravity(0.4)
  107. gren:SetFriction(0.2)
  108. gren:SetElasticity(0.45)
  109.  
  110. gren:Spawn()
  111. gren:PhysWake()
  112.  
  113. timer.Simple(3,function()
  114. if(!IsValid(gren)) then return end
  115.  
  116. ParticleEffect("fartsmoke",gren:GetPos()+Vector(-80,-40,0),Angle(0,0,0), nil)
  117. gren:EmitSound(fartSound)
  118. local v = {}
  119. timer.Create("fartsmoke_"..gren:EntIndex(), 0.5, 24, function()
  120. if(IsValid(gren)) then
  121. local left = timer.RepsLeft("fartsmoke_"..gren:EntIndex())
  122. local players = player.GetAll()
  123.  
  124. for p in pairs(player.GetAll()) do
  125.  
  126. local ply = players[p]
  127. local vel = ply:GetVelocity()
  128. local dir = (ply:GetPos()-gren:GetPos()):GetNormalized()
  129.  
  130. local dmg_rate = math.Clamp(ply:GetPos():Distance(gren:GetPos()),0,420)
  131. dmg_rate = (1-((1/420)*dmg_rate))
  132.  
  133. local zdist = ply:GetPos().z-gren:GetPos().z
  134. if(zdist < 0) then zdist = zdist*-1 end
  135.  
  136. if(dmg_rate <= 0 || zdist >= 160 || !ply:Alive())then continue end
  137.  
  138. local force = vel+dmg_rate*500*dir
  139. local isDead = ply:Health()-10 <= 0
  140.  
  141. ply:TakeDamage(10,self,self.Weapon)
  142. ply:ScreenFade( SCREENFADE.IN, Color( 255, 155, 0, 128 ), 0.3, 0 )
  143. ply:SetVelocity(force)
  144. print(zdist)
  145. if(!IsValid(v[ply:EntIndex()])) then
  146. ply:EmitSound(hurtSounds[math.random(1,5)])
  147. v[ply:EntIndex()] = ply
  148. end
  149.  
  150. if(ply:Health() > 0) then
  151. ply:EmitSound(hurtImpacts[math.random(1,3)])
  152. end
  153.  
  154. if(isDead) then
  155. ply:EmitSound(dieSound)
  156. end
  157. end
  158. if(left == 0) then
  159. gren:Remove()
  160. end
  161. end
  162. end)
  163. end)
  164.  
  165. local phys = gren:GetPhysicsObject()
  166. if IsValid(phys) then
  167. phys:SetVelocity(vel)
  168. phys:AddAngleVelocity(angimp)
  169. end
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement