Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. SWEP.Base = "weapon_tttbase"
  2.  
  3. if SERVER then
  4. AddCSLuaFile("shared.lua")
  5.  
  6. SWEP.HoldType = "pistol"
  7.  
  8. elseif CLIENT then
  9. SWEP.PrintName = "HeadCrab Launcher"
  10. SWEP.Slot = 6
  11. SWEP.SlotPos = 3
  12. SWEP.DrawCrosshair = false
  13.  
  14. SWEP.EquipMenuData = {
  15. type = "Weapon",
  16. desc = "Makes 4-15 headcrabs."
  17. }
  18.  
  19.  
  20. end
  21.  
  22.  
  23. SWEP.Spawnable = true
  24. SWEP.AdminSpawnable = true
  25. SWEP.ViewModel = "models/weapons/v_pist_usp.mdl"
  26. SWEP.WorldModel = "models/weapons/w_pist_usp.mdl"
  27.  
  28. SWEP.NoSights = true
  29. SWEP.Kind = WEAPON_EQUIP
  30.  
  31. SWEP.CanBuy = {ROLE_TRAITOR}
  32. SWEP.Icon = "VGUI/ttt/icon_silenced"
  33. SWEP.LimitedStock = false
  34. --SWEP.WeaponID = RPG
  35.  
  36. SWEP.Primary.ClipSize = -1
  37. SWEP.Primary.DefaultClip = -1
  38. SWEP.Primary.Automatic = true
  39. SWEP.Primary.Ammo = nil
  40. SWEP.Secondary.ClipSize = -1
  41. SWEP.Secondary.DefaultClip = -1
  42. SWEP.Secondary.Automatic = false
  43. SWEP.Secondary.Ammo = "none"
  44.  
  45. local ShootSoundFire = Sound("Airboat.FireGunHeavy")
  46. local ShootSoundFail = Sound("WallHealth.Deny")
  47. local YawIncrement = 20
  48. local PitchIncrement = 10
  49.  
  50. if CLIENT then language.Add("Undone_CrabLaunch", "Undone Headcrab Canister.") end
  51.  
  52. function SWEP:Initialize() if SERVER then self:SetWeaponHoldType(self.HoldType) end self:SetNWBool("Used", false) end
  53.  
  54. function SWEP:PrimaryAttack(bSecondary)
  55. if self:GetNWBool("Used", false) then return false end
  56.  
  57. local tr = self.Owner:GetEyeTrace()
  58. local aBaseAngle = tr.HitNormal:Angle()
  59. local aBasePos = tr.HitPos
  60. local bScanning = true
  61. local iPitch = 10
  62. local iYaw = -180
  63. local iLoopLimit = 0
  64. local iProcessedTotal = 0
  65. local tValidHits = {}
  66.  
  67. while (bScanning && iLoopLimit < 500) do
  68. iYaw = iYaw + YawIncrement
  69. iProcessedTotal = iProcessedTotal + 1
  70. if (iYaw >= 180) then
  71. iYaw = -180
  72. iPitch = iPitch - PitchIncrement
  73. end
  74.  
  75. local tLoop = util.QuickTrace(aBasePos, (aBaseAngle+Angle(iPitch,iYaw,0)):Forward()*40000)
  76. if (tLoop.HitSky || bSecondary) then
  77. table.insert(tValidHits,tLoop)
  78. end
  79.  
  80. if (iPitch <= -80) then
  81. bScanning = false
  82. end
  83. iLoopLimit = iLoopLimit + 1
  84. end
  85.  
  86. local iHits = table.Count(tValidHits)
  87. if (iHits > 0) then
  88. self:SetNWBool("Used", true)
  89. self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
  90. if SERVER then
  91. self.Owner:SetAnimation(PLAYER_ATTACK1)
  92. local iRand = math.random(1,iHits)
  93. local tRand = tValidHits[iRand]
  94.  
  95. local ent = ents.Create("env_headcrabcanister")
  96. ent:SetPos(aBasePos)
  97. ent:SetAngles((tRand.HitPos-tRand.StartPos):Angle())
  98. ent:SetKeyValue("HeadcrabType", math.random(0,2))
  99. ent:SetKeyValue("HeadcrabCount", math.random(4,15))
  100. //ent:SetKeyValue("HeadcrabCount", 0)
  101. ent:SetKeyValue("FlightSpeed", math.random(2500,6000))
  102. ent:SetKeyValue("FlightTime", math.random(2,5))
  103. ent:SetKeyValue("Damage", math.random(50,90))
  104. ent:SetKeyValue("DamageRadius", math.random(300,512))
  105. ent:SetKeyValue("SmokeLifetime", math.random(5,10))
  106. ent:SetKeyValue("StartingHeight", 1000)
  107. local iSpawnFlags = 8192
  108. if (bSecondary) then iSpawnFlags = iSpawnFlags + 4096 end //If Secondary, spawn impacted.
  109. ent:SetKeyValue("spawnflags", iSpawnFlags)
  110.  
  111. ent:Spawn()
  112.  
  113. ent:Input("FireCanister", self.Owner, self.Owner)
  114.  
  115. undo.Create("CrabLaunch")
  116. undo.AddEntity(ent)
  117. undo.SetPlayer(self.Owner)
  118. undo.AddFunction(function(undo)
  119. for k, v in pairs(ents.FindByClass("npc_headcrab*"))do
  120. if (v:GetOwner() == ent) then v:Remove() end
  121. end
  122. end)
  123. undo.Finish()
  124. self:EmitSound(ShootSoundFire)
  125. end
  126. else
  127. self:EmitSound(ShootSoundFail)
  128. end
  129. tLoop = nil
  130. tValidHits = nil
  131. return true
  132. end
  133.  
  134. function SWEP:ShouldDropOnDie()
  135. return false
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement