Advertisement
Actowolfy

weapon_ttt_rdetonate.lua

Sep 18th, 2014
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.62 KB | None | 0 0
  1. if SERVER then
  2.     AddCSLuaFile()
  3.    
  4. end
  5.  
  6. SWEP.HoldType                   = "slam"
  7.  
  8.    SWEP.PrintName = "Remote Detonator"
  9. if CLIENT then
  10.    SWEP.Slot = 6
  11.  
  12.    SWEP.ViewModelFOV = 10
  13.  
  14.    SWEP.EquipMenuData = {
  15.       type = "item_weapon",
  16.       desc = "Primary: Plant bomb on player or\na corpse.\n\nSecondary: Trigger explosive."
  17.    };
  18.  
  19.    SWEP.Icon = "VGUI/ttt/icon_splode"
  20. end
  21.  
  22.  
  23. SWEP.Base = "weapon_tttbase"
  24.  
  25. SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
  26. SWEP.WorldModel = "models/weapons/w_defuser.mdl"
  27.  
  28. SWEP.DrawCrosshair              = false
  29. SWEP.Secondary.Damage           = 400
  30. SWEP.Primary.ClipSize           = -1
  31. SWEP.Primary.DefaultClip        = -1
  32. SWEP.Primary.Automatic          = true
  33. SWEP.Primary.Delay = 0.15
  34. SWEP.Primary.Ammo               = "none"
  35. SWEP.Secondary.ClipSize         = -1
  36. SWEP.Secondary.DefaultClip      = -1
  37. SWEP.Secondary.Automatic        = true
  38. SWEP.Secondary.Ammo             = "none"
  39. SWEP.Secondary.Delay = 0.1
  40.  
  41. SWEP.Kind = WEAPON_EQUIP
  42. SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
  43. SWEP.WeaponID = AMMO_DEFUSER
  44. SWEP.LimitedStock = true -- only buyable once
  45.  
  46.  
  47. --SWEP.AllowDrop = false
  48.  
  49. local sou = Sound("Weapon_TMP.Clipin")
  50. local sou2 = Sound("Default.PullPin_Grenade")
  51.  
  52. local function tWarn(ent,armed)
  53.   umsg.Start("c4_warn", GetTraitorFilter(true))
  54.   umsg.Short(ent:EntIndex())
  55.   umsg.Bool(armed)
  56.   umsg.Vector(ent:GetPos())
  57.   umsg.Float(0)
  58.   umsg.End()
  59. end
  60.  
  61. function SWEP:PrimaryAttack()
  62.         if not IsValid(self.Owner) then return end
  63.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  64.    if self.attach then return false end
  65.    if SERVER and self.Owner:GetNWBool('disguised',false) == true and string.len(self.Owner:GetNWString('disgas','')) > 0 then self.Owner:ConCommand('ttt_set_disguise 0') end
  66.         if SERVER and _rdm then
  67.                 local stid = self.Owner:SteamID()
  68.                 if not _rdm.shotsFired[stid] then _rdm.shotsFired[stid] = {} end
  69.                 table.insert(_rdm.shotsFired[stid],CurTime())
  70.         end
  71.         if SERVER and ShootLog then ShootLog(Format("WEAPON:\t %s [%s] planted a %s", self.Owner:Nick(), self.Owner:GetRoleString(), self.Weapon:GetClass())) end
  72.  
  73.    local spos = self.Owner:GetShootPos()
  74.    local sdest = spos + (self.Owner:GetAimVector() * 120)
  75.         if self.Owner.LagCompensation then -- for some reason not always true
  76.       self.Owner:LagCompensation(true)
  77.    end
  78.    local tr = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT})
  79.    if not tr.Entity or not IsValid(tr.Entity) then return end
  80.         if IsValid(tr.Entity) and tr.Entity:GetClass() == "player" then
  81.                 if SERVER then
  82.                         local ply = tr.Entity
  83.                         if not self.attach then
  84.                                 self.attach = ply:UniqueID()
  85.                                 self.atype = 'ply'
  86.                                 sound.Play(sou,ply:GetPos(),40)
  87.                                 if tWarn then tWarn(ply,true) end
  88.                         end
  89.                 end
  90.         elseif IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and tr.Entity.player_ragdoll then
  91.                 if SERVER then
  92.                         local rag = tr.Entity
  93.                         if not self.attach then
  94.                                 self.attach = rag.uqid
  95.                                 self.atype = 'rag'
  96.                                 sound.Play(sou,rag:GetPos(),40)
  97.                                 if tWarn then tWarn(rag,true) end
  98.                         end
  99.                 end
  100.         elseif IsValid(tr.Entity) and tr.Entity:GetClass() == 'ttt_health_station' then
  101.                 if SERVER then
  102.                         tr.toexp = self.Owner
  103.                         self.attach = tr.Entity:EntIndex()
  104.                         self.atype = 'hs'
  105.                         sound.Play(sou,tr.Entity:GetPos(),40)
  106.                         if tWarn then tWarn(tr.Entity,true) end
  107.                 end
  108.         end
  109.         if self.attach then
  110.                 self.planted = CurTime()
  111.                 self.Owner:ChatPrint("Planted!")
  112.                 self.Owner:AnimPerformGesture(ACT_GMOD_GESTURE_ITEM_GIVE)
  113.         end
  114.         self.Weapon:SetNextPrimaryFire( CurTime() + (self.Primary.Delay * 2) )
  115.         if self.Owner.LagCompensation then
  116.       self.Owner:LagCompensation(false)
  117.    end
  118. end
  119.  
  120. function SWEP:Detonate(v,t)
  121.         if SERVER and self.Owner:GetNWBool('disguised',false) == true and string.len(self.Owner:GetNWString('disgas','')) > 0 then self.Owner:ConCommand('ttt_set_disguise 0') end
  122.         if SERVER and _rdm then
  123.                 local stid = self.Owner:SteamID()
  124.                 if not _rdm.shotsFired[stid] then _rdm.shotsFired[stid] = {} end
  125.                 table.insert(_rdm.shotsFired[stid],CurTime())
  126.         end
  127.         if SERVER and ShootLog then ShootLog(Format("WEAPON:\t %s [%s] detonated a %s", self.Owner:Nick(), self.Owner:GetRoleString(), self.Weapon:GetClass())) end
  128.         local pos = v:GetPos()
  129.         local effect = EffectData()
  130.         effect:SetStart(pos)
  131.         effect:SetOrigin(pos)
  132.         local rad = 50
  133.         local dmg = 50
  134.         effect:SetScale(rad * 0.2)
  135.         effect:SetRadius(rad)
  136.         effect:SetMagnitude(dmg)
  137.         util.Effect("Explosion", effect, true, true)
  138.         local ent = ents.Create("weapon_ttt_rdetonate")
  139.         util.BlastDamage(ent,self.Owner,pos,rad,dmg)
  140.         ent:Remove()
  141. end
  142.  
  143. function SWEP:SecondaryAttack()
  144.         if SERVER then
  145.                 if self.planted and CurTime()-self.planted < 1 then return end
  146.                 if self.attach and self.attach != -1 then
  147.                         if self.atype == 'hs' then
  148.                                 for k,v in pairs(ents.FindByClass('ttt_new_hp')) do
  149.                                         if v:EntIndex() == self.attach then
  150.                                                 self.attach = -1
  151.                                                 sound.Play(Sound("Default.PullPin_Grenade"),v:GetPos())
  152.                                                 --timer.Simple(2, function()
  153.                                                         if tWarn then tWarn(v,false) end
  154.                                                         self:Detonate(v,1)
  155.                                                         self:Remove()
  156.                                                 --end)
  157.                                                 break
  158.                                         end
  159.                                 end
  160.                         else
  161.                                 for _, v in ipairs( player.GetAll() ) do
  162.                                         if v:UniqueID() == self.attach then
  163.                                                 if not v:Alive() then
  164.                                                         for _, v2 in ipairs( ents.FindByClass("prop_ragdoll") ) do
  165.                                                                 if IsValid(v2) then
  166.                                                                         if v2.player_ragdoll and v2.uqid == self.attach then
  167.                                                                                 self.attach = -1
  168.                                                                                 sound.Play(sou2,v2:GetPos())
  169.                                                                                 --timer.Simple(2, function()
  170.                                                                                         if tWarn then tWarn(v,false) tWarn(v2,false) end
  171.                                                                                         self:Detonate(v2,1)
  172.                                                                                         self:Remove()
  173.                                                                                 --end)
  174.                                                                                 break
  175.                                                                         end
  176.                                                                 end
  177.                                                         end
  178.                                                 else
  179.                                                         self.attach = -1
  180.                                                         sound.Play(sou2,v:GetPos())
  181.                                                         --timer.Simple(2, function()
  182.                                                                 if tWarn then tWarn(v,false) end
  183.                                                                 self:Detonate(v,2)
  184.                                                                 self:Remove()
  185.                                                         --end)
  186.                                                 end
  187.                                                 return true
  188.                                         end
  189.                                 end
  190.                         end
  191.                 end
  192.         end
  193.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  194.    self.Weapon:SetNextSecondaryFire( CurTime() + 0.1 )
  195. end
  196.  
  197.  
  198. if CLIENT then
  199.    function SWEP:Initialize()
  200.       //self:AddHUDHelp("defuser_help", nil, true)
  201.                 self.attach = nil
  202.       return self.BaseClass.Initialize(self)
  203.    end
  204.  
  205.    function SWEP:DrawWorldModel()
  206.       if not IsValid(self.Owner) then
  207.          self:DrawModel()
  208.       end
  209.    end
  210. end
  211.  
  212. function SWEP:Reload()
  213.    return false
  214. end
  215.  
  216. function SWEP:Deploy()
  217.    if SERVER and IsValid(self.Owner) then
  218.       self.Owner:DrawViewModel(false)
  219.    end
  220.    return true
  221. end
  222.  
  223.  
  224. function SWEP:OnDrop()
  225. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement