Advertisement
Exho

TTT Cloaking device

May 25th, 2022
1,292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | None | 0 0
  1. ----// Cloaking Device //----
  2. -- in game icon: https://i.imgur.com/rGXdNEw.png
  3. -- Author: Exho
  4. -- Version: 7/26/15
  5.  
  6. if SERVER then
  7.     AddCSLuaFile()
  8.     util.AddNetworkString("cloakDamaged")
  9.     resource.AddFile("materials/vgui/ttt/exho_cloak.png")
  10. end
  11.  
  12. if CLIENT then
  13.     SWEP.PrintName = "Cloaking Device"
  14.     SWEP.Slot = 7
  15.     SWEP.DrawAmmo = false
  16.     SWEP.DrawCrosshair = false
  17.        
  18.     SWEP.Icon = "vgui/ttt/exho_cloak.png"
  19.  
  20.     SWEP.EquipMenuData = {
  21.       type = "item_weapon",
  22.       desc = "Allows you to become invisible for a short period of\ntime while holding the weapon\n\nIt will disable if you are damaged"
  23.    };
  24. end
  25.  
  26. SWEP.Author              = "Exho"
  27. SWEP.HoldType            = "normal"
  28. SWEP.Base                = "weapon_tttbase"
  29. SWEP.Kind                = WEAPON_EQUIP
  30. SWEP.CanBuy              = { ROLE_TRAITOR, ROLE_DETECTIVE }
  31.  
  32. SWEP.Primary.Ammo        = "none"
  33. SWEP.Primary.Delay       = 2
  34. SWEP.Secondary.Delay     = 2
  35. SWEP.Primary.ClipSize    = -1
  36. SWEP.Primary.ClipMax     = -1
  37. SWEP.Primary.DefaultClip = -1
  38. SWEP.Primary.Automatic   = false
  39. SWEP.AllowDrop           = true
  40.  
  41. SWEP.Spawnable           = true
  42. SWEP.AdminSpawnable      = true
  43. SWEP.AutoSpawnable       = false
  44. SWEP.ViewModel           = "models/weapons/c_slam.mdl"
  45. SWEP.WorldModel          = ""
  46. SWEP.UseHands            = true
  47. SWEP.ViewModelFlip       = false
  48. SWEP.LimitedUse          = true
  49.  
  50. SWEP.CloakTime = 15
  51. SWEP.CloakSound = "buttons/button1.wav"
  52. SWEP.CloakPowerCoolDown = 5
  53. SWEP.CloakDamageCooldown = 2
  54. SWEP.NextUnCloak = 1
  55. SWEP.NextCloak = 1
  56. SWEP.ThirdPer = false
  57.  
  58. SWEP.Cloaked = false
  59. SWEP.CloakedPly = nil
  60.  
  61. local plymeta = FindMetaTable( "Player" )
  62. function plymeta:isCloaked()
  63.     return self:GetNWBool("isCloaked", false)
  64. end
  65.  
  66. function SWEP:PrimaryAttack()
  67.     self:Cloak()   
  68. end
  69.  
  70. function SWEP:SecondaryAttack()
  71.     self:UnCloak("Cloak disabled!")
  72. end
  73.  
  74. function SWEP:Cloak()
  75.     local ply = self.Owner
  76.    
  77.     if not IsValid(ply) then return end
  78.     if ply:isCloaked() then return end
  79.    
  80.     -- Variables
  81.     ply:SetNWBool( "isCloaked", true)
  82.     self.Cloaked = true
  83.     self.CloakedPly = ply
  84.    
  85.     self:chatMessage("Cloak enabled!")
  86.    
  87.     -- Clean off any blood
  88.     self.Owner:RemoveAllDecals()
  89.  
  90.     -- Make the player invisible
  91.     ply:SetColor( Color(255, 255, 255, 1) )            
  92.     ply:SetMaterial( "sprites/heatwave" )
  93.     ply:DrawShadow(false)
  94.     ply:ConCommand("ttt_set_disguise 1")
  95.    
  96.     sound.Play(self.CloakSound, ply:GetPos(), 70, 100)
  97.     self:SetNextSecondaryFire(CurTime()+self.NextUnCloak)
  98.        
  99.     timer.Create( ply:UniqueID().."_cloakingTime", self.CloakTime, 1, function()
  100.         if self.Cloaked then
  101.             self:UnCloak( "Out of power!" )
  102.             sound.Play("ambient/levels/labs/electric_explosion1.wav", ply:GetPos(), 70, 100)
  103.         end
  104.     end)
  105.    
  106.     self.AllowDrop = false
  107. end
  108.  
  109. function SWEP:UnCloak(text)
  110.     local ply = self.Owner
  111.    
  112.     if not IsValid(ply) then return end
  113.     if not ply:isCloaked() then return end
  114.    
  115.     -- Variables
  116.     ply:SetNWBool( "isCloaked", false)
  117.     self.Cloaked = false
  118.     self.CloakedPly = nil
  119.    
  120.     self:chatMessage(text)
  121.    
  122.     -- Restore them back to their normal visible self
  123.     timer.Destroy( ply:UniqueID().."_cloakingTime" )
  124.     ply:SetMaterial("models/glass")
  125.     ply:DrawShadow(true)
  126.     ply:ConCommand("ttt_set_disguise 0")
  127.    
  128.     sound.Play(self.CloakSound, ply:GetPos(), 70, 100)
  129.     self:SetNextPrimaryFire(CurTime()+self.NextCloak)
  130.    
  131.     self.AllowDrop = true
  132. end
  133.  
  134. local seen = false
  135. function SWEP:chatMessage(args)
  136.     if CLIENT then
  137.         if seen then return end
  138.         if LocalPlayer() != self.Owner then return end
  139.        
  140.         chat.AddText(Color(231, 56, 60),
  141.         "[Cloak]",
  142.         Color(255,255,255),
  143.         ": ",
  144.         args)
  145.         seen = true
  146.         timer.Simple(0.5, function() seen = false end)
  147.     end
  148. end
  149.  
  150. function SWEP:OnRemove()
  151.     self:UnCloak("Cloak disabled!")
  152.     return true
  153. end
  154.  
  155. function SWEP:Holster()
  156.     self:UnCloak("Cloak disabled!")
  157.     return true
  158. end
  159.  
  160. hook.Add("DoPlayerDeath", "cloak_deathDisable", function(ply)
  161.     if ply:isCloaked() then
  162.         local wep = ply:GetActiveWeapon()
  163.         wep:UnCloak()
  164.     end
  165. end)
  166.  
  167. hook.Add("PlayerHurt", "cloak_damageDisable", function(ply)
  168.     if ply:isCloaked() then
  169.         local wep = ply:GetActiveWeapon()
  170.         wep:UnCloak()
  171.        
  172.         -- This is serverside only so that chat messages won't work normally
  173.         net.Start("cloakDamaged")
  174.         net.Send( ply )
  175.     end
  176. end)
  177.  
  178. hook.Add("TTTPrepareRound", "UnCloakAll",function()
  179.     for k, v in pairs(player.GetAll()) do
  180.         -- Reset all the living players
  181.         timer.Destroy( v:UniqueID().."_cloakingTime" )
  182.         v:SetNWBool("isCloaked", false)
  183.        
  184.         v:SetMaterial("models/glass")
  185.         v:DrawShadow(true)
  186.         v:ConCommand("ttt_set_disguise 0")
  187.     end
  188. end)
  189.  
  190. if CLIENT then
  191.     net.Receive( "cloakDamaged", function( len, ply )
  192.         if LocalPlayer():isCloaked() then
  193.             local wep = LocalPlayer():GetActiveWeapon()
  194.             wep:UnCloak("Cloak damaged!")
  195.         end
  196.     end)
  197. end
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement