Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----// Cloaking Device //----
- -- in game icon: https://i.imgur.com/rGXdNEw.png
- -- Author: Exho
- -- Version: 7/26/15
- if SERVER then
- AddCSLuaFile()
- util.AddNetworkString("cloakDamaged")
- resource.AddFile("materials/vgui/ttt/exho_cloak.png")
- end
- if CLIENT then
- SWEP.PrintName = "Cloaking Device"
- SWEP.Slot = 7
- SWEP.DrawAmmo = false
- SWEP.DrawCrosshair = false
- SWEP.Icon = "vgui/ttt/exho_cloak.png"
- SWEP.EquipMenuData = {
- type = "item_weapon",
- desc = "Allows you to become invisible for a short period of\ntime while holding the weapon\n\nIt will disable if you are damaged"
- };
- end
- SWEP.Author = "Exho"
- SWEP.HoldType = "normal"
- SWEP.Base = "weapon_tttbase"
- SWEP.Kind = WEAPON_EQUIP
- SWEP.CanBuy = { ROLE_TRAITOR, ROLE_DETECTIVE }
- SWEP.Primary.Ammo = "none"
- SWEP.Primary.Delay = 2
- SWEP.Secondary.Delay = 2
- SWEP.Primary.ClipSize = -1
- SWEP.Primary.ClipMax = -1
- SWEP.Primary.DefaultClip = -1
- SWEP.Primary.Automatic = false
- SWEP.AllowDrop = true
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.AutoSpawnable = false
- SWEP.ViewModel = "models/weapons/c_slam.mdl"
- SWEP.WorldModel = ""
- SWEP.UseHands = true
- SWEP.ViewModelFlip = false
- SWEP.LimitedUse = true
- SWEP.CloakTime = 15
- SWEP.CloakSound = "buttons/button1.wav"
- SWEP.CloakPowerCoolDown = 5
- SWEP.CloakDamageCooldown = 2
- SWEP.NextUnCloak = 1
- SWEP.NextCloak = 1
- SWEP.ThirdPer = false
- SWEP.Cloaked = false
- SWEP.CloakedPly = nil
- local plymeta = FindMetaTable( "Player" )
- function plymeta:isCloaked()
- return self:GetNWBool("isCloaked", false)
- end
- function SWEP:PrimaryAttack()
- self:Cloak()
- end
- function SWEP:SecondaryAttack()
- self:UnCloak("Cloak disabled!")
- end
- function SWEP:Cloak()
- local ply = self.Owner
- if not IsValid(ply) then return end
- if ply:isCloaked() then return end
- -- Variables
- ply:SetNWBool( "isCloaked", true)
- self.Cloaked = true
- self.CloakedPly = ply
- self:chatMessage("Cloak enabled!")
- -- Clean off any blood
- self.Owner:RemoveAllDecals()
- -- Make the player invisible
- ply:SetColor( Color(255, 255, 255, 1) )
- ply:SetMaterial( "sprites/heatwave" )
- ply:DrawShadow(false)
- ply:ConCommand("ttt_set_disguise 1")
- sound.Play(self.CloakSound, ply:GetPos(), 70, 100)
- self:SetNextSecondaryFire(CurTime()+self.NextUnCloak)
- timer.Create( ply:UniqueID().."_cloakingTime", self.CloakTime, 1, function()
- if self.Cloaked then
- self:UnCloak( "Out of power!" )
- sound.Play("ambient/levels/labs/electric_explosion1.wav", ply:GetPos(), 70, 100)
- end
- end)
- self.AllowDrop = false
- end
- function SWEP:UnCloak(text)
- local ply = self.Owner
- if not IsValid(ply) then return end
- if not ply:isCloaked() then return end
- -- Variables
- ply:SetNWBool( "isCloaked", false)
- self.Cloaked = false
- self.CloakedPly = nil
- self:chatMessage(text)
- -- Restore them back to their normal visible self
- timer.Destroy( ply:UniqueID().."_cloakingTime" )
- ply:SetMaterial("models/glass")
- ply:DrawShadow(true)
- ply:ConCommand("ttt_set_disguise 0")
- sound.Play(self.CloakSound, ply:GetPos(), 70, 100)
- self:SetNextPrimaryFire(CurTime()+self.NextCloak)
- self.AllowDrop = true
- end
- local seen = false
- function SWEP:chatMessage(args)
- if CLIENT then
- if seen then return end
- if LocalPlayer() != self.Owner then return end
- chat.AddText(Color(231, 56, 60),
- "[Cloak]",
- Color(255,255,255),
- ": ",
- args)
- seen = true
- timer.Simple(0.5, function() seen = false end)
- end
- end
- function SWEP:OnRemove()
- self:UnCloak("Cloak disabled!")
- return true
- end
- function SWEP:Holster()
- self:UnCloak("Cloak disabled!")
- return true
- end
- hook.Add("DoPlayerDeath", "cloak_deathDisable", function(ply)
- if ply:isCloaked() then
- local wep = ply:GetActiveWeapon()
- wep:UnCloak()
- end
- end)
- hook.Add("PlayerHurt", "cloak_damageDisable", function(ply)
- if ply:isCloaked() then
- local wep = ply:GetActiveWeapon()
- wep:UnCloak()
- -- This is serverside only so that chat messages won't work normally
- net.Start("cloakDamaged")
- net.Send( ply )
- end
- end)
- hook.Add("TTTPrepareRound", "UnCloakAll",function()
- for k, v in pairs(player.GetAll()) do
- -- Reset all the living players
- timer.Destroy( v:UniqueID().."_cloakingTime" )
- v:SetNWBool("isCloaked", false)
- v:SetMaterial("models/glass")
- v:DrawShadow(true)
- v:ConCommand("ttt_set_disguise 0")
- end
- end)
- if CLIENT then
- net.Receive( "cloakDamaged", function( len, ply )
- if LocalPlayer():isCloaked() then
- local wep = LocalPlayer():GetActiveWeapon()
- wep:UnCloak("Cloak damaged!")
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement