Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.83 KB | None | 0 0
  1. if SERVER then    AddCSLuaFile()
  2.    
  3. end
  4.  
  5. SWEP.HoldType                   = "slam"
  6.  
  7.    SWEP.PrintName = "Remote Detonator"
  8. if CLIENT then
  9.    SWEP.Slot = 6
  10.  
  11.    SWEP.ViewModelFOV = 10
  12.  
  13.    SWEP.EquipMenuData = {
  14.       type = "item_weapon",
  15.       desc = "Primary: Plant bomb on player or\na corpse.\n\nSecondary: Trigger explosive."
  16.    };
  17.  
  18.    SWEP.Icon = "VGUI/ttt/icon_splode"
  19. end
  20.  
  21.  
  22. SWEP.Base = "weapon_tttbase"
  23.  
  24. SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
  25. SWEP.WorldModel = "models/weapons/w_defuser.mdl"
  26.  
  27.  
  28. SWEP.DrawCrosshair              = false
  29. SWEP.Primary.ClipSize           = -1
  30. SWEP.Primary.DefaultClip        = -1
  31. SWEP.Primary.Automatic          = true
  32. SWEP.Primary.Delay = 0.15
  33. SWEP.Primary.Ammo               = "none"
  34. SWEP.Secondary.ClipSize         = -1
  35. SWEP.Secondary.DefaultClip      = -1
  36. SWEP.Secondary.Automatic        = true
  37. SWEP.Secondary.Ammo             = "none"
  38. SWEP.Secondary.Delay = 0.1
  39. SWEP.Secondary.Damage           = 175
  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.     local spos = self.Owner:GetShootPos()
  66.     local sdest = spos + (self.Owner:GetAimVector() * 120)
  67.     if self.Owner.LagCompensation then self.Owner:LagCompensation(true) end
  68.     local tr = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT})
  69.     if not tr.Entity or not IsValid(tr.Entity) then return end
  70.     if IsValid(tr.Entity) and tr.Entity:GetClass() == "player" then
  71.         if SERVER then
  72.             local ply = tr.Entity
  73.             if not self.attach then
  74.                 self.attach = ply:UniqueID()
  75.                 self.atype = "ply"
  76.                 sound.Play(sou,ply:GetPos(),40)
  77.                 if tWarn then tWarn(ply,true) end
  78.             end
  79.         end
  80.     elseif IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and tr.Entity.player_ragdoll then
  81.         if SERVER then
  82.             local rag = tr.Entity
  83.             if not self.attach then
  84.                 self.attach = rag.uqid
  85.                 self.atype = "rag"
  86.                 sound.Play(sou,rag:GetPos(),40)
  87.                 if tWarn then tWarn(rag,true) end
  88.             end
  89.         end
  90.     elseif IsValid(tr.Entity) and tr.Entity:GetClass() == "ttt_health_station" then
  91.         if SERVER then
  92.             tr.toexp = self.Owner
  93.             self.attach = tr.Entity:EntIndex()
  94.             self.atype = "hs"
  95.             sound.Play(sou,tr.Entity:GetPos(),40)
  96.             if tWarn then tWarn(tr.Entity,true) end
  97.         end
  98.     end
  99.     if self.attach then
  100.         self.planted = CurTime()
  101.         self.Owner:ChatPrint("Planted!")
  102.         self.Owner:AnimPerformGesture(ACT_GMOD_GESTURE_ITEM_GIVE)
  103.     end
  104.     self.Weapon:SetNextPrimaryFire( CurTime() + (self.Primary.Delay * 2) )
  105.     if self.Owner.LagCompensation then
  106.         self.Owner:LagCompensation(false)
  107.     end
  108. end
  109.  
  110. function SWEP:Detonate(v,t)
  111.     local pos = v:GetPos()
  112.     local effect = EffectData()
  113.     effect:SetStart(pos)
  114.     effect:SetOrigin(pos)
  115.     local rad = 50
  116.     local dmg = self.Secondary.Damage
  117.     effect:SetScale(rad * 0.2)
  118.     effect:SetRadius(rad)
  119.     effect:SetMagnitude(dmg)
  120.     util.Effect("Explosion", effect, true, true)
  121.     local ent = ents.Create("weapon_ttt_rdetonator")
  122.     util.BlastDamage(ent,self.Owner,pos,rad,dmg)
  123.     ent:Remove()
  124. end
  125.  
  126. function SWEP:SecondaryAttack()
  127.         if SERVER then
  128.                 if self.planted and CurTime()-self.planted < 1 then return end
  129.                 if self.attach and self.attach != -1 then
  130.                         if self.atype == "hs" then
  131.                                 for k,v in pairs(ents.FindByClass("ttt_health_station")) do
  132.                                         if v:EntIndex() == self.attach then
  133.                                                 self.attach = -1
  134.                                                 sound.Play(Sound("Default.PullPin_Grenade"),v:GetPos())
  135.                                                 if tWarn then tWarn(v,false) end
  136.                                                 self:Detonate(v,1)
  137.                                                 self:Remove()
  138.                                                 break
  139.                                         end
  140.                                 end
  141.                         else
  142.                                 for _, v in ipairs( player.GetAll() ) do
  143.                                         if v:UniqueID() == self.attach then
  144.                                                 if not v:Alive() then
  145.                                                         for _, v2 in ipairs( ents.FindByClass("prop_ragdoll") ) do
  146.                                                                 if IsValid(v2) then
  147.                                                                         if v2.player_ragdoll and v2.uqid == self.attach then
  148.                                                                                 self.attach = -1
  149.                                                                                 sound.Play(sou2,v2:GetPos())
  150.                                                                                 if tWarn then tWarn(v,false) tWarn(v2,false) end
  151.                                                                                 self:Detonate(v2,1)
  152.                                                                                 self:Remove()
  153.                                                                                 break
  154.                                                                         end
  155.                                                                 end
  156.                                                         end
  157.                                                 else
  158.                                                         self.attach = -1
  159.                                                         sound.Play(sou2,v:GetPos())
  160.                                                         if tWarn then tWarn(v,false) end
  161.                                                         self:Detonate(v,2)
  162.                                                         self:Remove()
  163.                                                 end
  164.                                                 return true
  165.                                         end
  166.                                 end
  167.                         end
  168.                 end
  169.         end
  170.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  171.    self.Weapon:SetNextSecondaryFire( CurTime() + 0.1 )
  172. end
  173.  
  174.  
  175. if CLIENT then
  176.    function SWEP:Initialize()
  177.       //self:AddHUDHelp("defuser_help", nil, true)
  178.                 self.attach = nil
  179.       return self.BaseClass.Initialize(self)
  180.    end
  181.  
  182.    function SWEP:DrawWorldModel()
  183.       if not IsValid(self.Owner) then
  184.          self:DrawModel()
  185.       end
  186.    end
  187. end
  188.  
  189. function SWEP:Reload()
  190.    return false
  191. end
  192.  
  193. function SWEP:Deploy()
  194.    if SERVER and IsValid(self.Owner) then
  195.       self.Owner:DrawViewModel(false)
  196.    end
  197.    return true
  198. end
  199.  
  200.  
  201. function SWEP:OnDrop()
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement