Advertisement
Guest User

Taser

a guest
Aug 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1. local FailDist = 300 //How far can the Tazer "Bullets" go? The more, the further it will go.
  2.  
  3. if ( SERVER ) then
  4.  
  5. AddCSLuaFile( "shared.lua" )
  6. SWEP.Weight = 2
  7. SWEP.AutoSwitchTo = true
  8. SWEP.AutoSwitchFrom = true
  9. SWEP.HoldType = "pistol"
  10. SWEP.Category = "X-Ray Gaming"
  11. SWEP.Spawnable = true
  12. SWEP.AdminSpawnable = true
  13. SWEP.AdminOnly = false //Is the Weapon for Admins only? false = All People can use it ; true = Only Admins can use it.
  14. end
  15.  
  16. if ( CLIENT ) then
  17.  
  18. SWEP.PrintName = "Taser";
  19. SWEP.Slot = 2;
  20. SWEP.SlotPos = 1;
  21. SWEP.DrawAmmo = false;
  22. SWEP.DrawCrosshair = true;
  23. SWEP.Category = "X-Ray Gaming"
  24. SWEP.Spawnable = true
  25. SWEP.AdminSpawnable = true
  26. SWEP.AdminOnly = false //Is the Weapon for Admins only? false = All People can use it ; true = Only Admins can use it.
  27. end
  28.  
  29.  
  30. SWEP.Contact = "";
  31. SWEP.Purpose = "Tasing people who is a treat";
  32. SWEP.Instructions = "Left Click = Taser someone ; Right Click = Tazer them once on the ground.";
  33.  
  34.  
  35. SWEP.ViewModel = "models/weapons/cg_ocrp2/v_taser.mdl"
  36. SWEP.WorldModel = "models/weapons/cg_ocrp2/w_taser.mdl"
  37. SWEP.UseHands = false
  38. SWEP.ViewModelFOV = 70
  39. SWEP.HoldType = "pistol"
  40.  
  41. SWEP.SwayScale = .25
  42.  
  43. SWEP.Primary.ClipSize = 1
  44. SWEP.Primary.DefaultClip = 20
  45. SWEP.Primary.Automatic = false
  46. SWEP.Primary.Ammo = "Pistol"
  47.  
  48. SWEP.Secondary.ClipSize = -1
  49. SWEP.Secondary.DefaultClip = -1
  50. SWEP.Secondary.Automatic = true
  51. SWEP.Secondary.Ammo = ""
  52.  
  53. local taseredrags = {}
  54. local taseruniquetimer1 = 0
  55.  
  56.  
  57. function SWEP:Reload()
  58. self.Weapon:DefaultReload( ACT_VM_RELOAD )
  59. end
  60.  
  61. function SWEP:PrimaryAttack()
  62. if ( !self:CanPrimaryAttack() ) then return end
  63. local eyetrace = self.Owner:GetEyeTrace();
  64. if !eyetrace.Entity:IsPlayer() then
  65. if !eyetrace.Entity:IsNPC() then return end
  66. end
  67.  
  68. self.Weapon:EmitSound( "weapons/crossbow/bolt_fly4.wav")
  69. self.BaseClass.ShootEffects( self )
  70. self:TakePrimaryAmmo(1)
  71. self:SetNextPrimaryFire(5)
  72.  
  73.  
  74. if (!SERVER) then return end
  75.  
  76. if eyetrace.Entity:IsPlayer() then
  77. if self.Owner:GetPos():Distance(eyetrace.Entity:GetPos()) < FailDist then
  78. self.Owner:ChatPrint("The player has been tased")
  79. self:tasePlayer(eyetrace.Entity)
  80. self.Owner:ConCommand( "say /me slots a new battery into his stun gun. It takes 3 seconds to charge.")
  81. else
  82. self.Owner:ConCommand( "say /me slots a new battery into his stun gun. It takes 3 seconds to charge.")
  83. timer.Simple( 3, function()
  84. self.Owner:RemoveAmmo( 100, "GaussEnergy" )
  85. self:SetClip1( 100, "GaussEnergy" )
  86. self.Weapon:EmitSound( "items/battery_pickup.wav" )
  87. self._ReloadBugFix = 0
  88. end);
  89. return
  90. end
  91. end
  92. if eyetrace.Entity:IsNPC() then
  93. if self.Owner:GetPos():Distance(eyetrace.Entity:GetPos()) < FailDist then
  94. self.Owner:ConCommand( "say /me slots a new battery into his stun gun. It takes 3 seconds to charge.")
  95. timer.Simple( 3, function()
  96. self.Owner:RemoveAmmo( 100, "GaussEnergy" )
  97. self:SetClip1( 100, "GaussEnergy" )
  98. self.Weapon:EmitSound( "items/battery_pickup.wav" )
  99. self._ReloadBugFix = 0
  100. end);
  101. self:taseNPC(eyetrace.Entity, self.Owner)
  102. else
  103. self.Owner:ChatPrint("The player is too far away!" )
  104. return
  105. end
  106. end
  107. end
  108.  
  109.  
  110. function SWEP:tasePlayer(ply)
  111.  
  112. local rag = ents.Create( "prop_ragdoll" )
  113. if not rag:IsValid() then return end
  114.  
  115.  
  116. rag:SetModel( ply:GetModel() )
  117. rag:SetKeyValue( "origin", ply:GetPos().x .. " " .. ply:GetPos().y .. " " .. ply:GetPos().z )
  118. rag:SetAngles(ply:GetAngles())
  119.  
  120.  
  121. rag.taseredply = ply
  122. table.insert(taseredrags, rag)
  123.  
  124.  
  125. ply:StripWeapons()
  126. ply:DrawViewModel(false)
  127. ply:DrawWorldModel(false)
  128. ply:Spectate(OBS_MODE_CHASE)
  129. ply:SpectateEntity(rag)
  130.  
  131.  
  132. rag:Spawn()
  133. rag:Activate()
  134.  
  135.  
  136. rag:GetPhysicsObject():SetVelocity(4*ply:GetVelocity())
  137.  
  138.  
  139.  
  140. self:setrevivedelay(rag)
  141.  
  142. end
  143.  
  144. function SWEP:taseNPC(npc, npcShooter)
  145.  
  146. local skin = npc:GetSkin()
  147. local wep = ""
  148. local possibleWep = ents.FindInSphere(npc:GetPos(),0.01)
  149. for k, v in pairs(possibleWep) do
  150. if string.find(v:GetClass(),"weapon_") == 1 then
  151. wep = v:GetClass()
  152. end
  153. end
  154.  
  155. local citType = ""
  156. local citMed = 0
  157. if npc:GetClass() == "npc_citizen" then
  158. citType = string.sub(npc:GetModel(),21,21)
  159. if string.sub(npc:GetModel(),22,22) == "m" then citMed = 1 end
  160. end
  161.  
  162.  
  163. local rag = ents.Create( "prop_ragdoll" )
  164. if not rag:IsValid() then return end
  165.  
  166.  
  167. rag:SetModel( npc:GetModel() )
  168. rag:SetKeyValue( "origin", npc:GetPos().x .. " " .. npc:GetPos().y .. " " .. npc:GetPos().z )
  169. rag:SetAngles(npc:GetAngles())
  170.  
  171.  
  172. rag.tasewasNPC = true
  173. rag.tasenpcType = npc:GetClass()
  174. rag.tasenpcWep = wep
  175. rag.tasenpcCitType = citType
  176. rag.tasenpcCitMed = citMed
  177. rag.tasenpcSkin = skin
  178. rag.tasenpcShooter = npcShooter
  179. table.insert(taseredrags, rag)
  180.  
  181.  
  182. rag:Spawn()
  183. rag:Activate()
  184.  
  185.  
  186. rag:GetPhysicsObject():SetVelocity(8*npc:GetVelocity())
  187.  
  188.  
  189. npc:Remove()
  190.  
  191. self:setrevivedelay(rag)
  192.  
  193.  
  194. end
  195.  
  196.  
  197.  
  198. function SWEP:setrevivedelay(rag)
  199. if taseruniquetimer1 > 30 then
  200. taseruniquetimer1 = 0
  201. end
  202. taseruniquetimer1 = taseruniquetimer1 + 1
  203. // Wanna set the Taser Time? Change the "7" below this line to any number you want. 7 = 7 Seconds.
  204. timer.Create("revivedelay"..taseruniquetimer1, 15, 1, function() self:taserevive(rag) end)
  205. end
  206.  
  207. function SWEP:taserevive(ent)
  208.  
  209. if !ent then return end
  210.  
  211. if ent.taseredply then
  212. if ( !ent.taseredply:IsValid() ) then return end
  213. local phy = ent:GetPhysicsObject()
  214. phy:EnableMotion(false)
  215. ent:SetSolid(SOLID_NONE)
  216. ent.taseredply:DrawViewModel(true)
  217. ent.taseredply:DrawWorldModel(true)
  218. ent.taseredply:Spawn()
  219. ent.taseredply:SetPos(ent:GetPos())
  220. ent.taseredply:SetVelocity(ent:GetPhysicsObject():GetVelocity())
  221.  
  222.  
  223.  
  224. elseif ent.tasewasNPC then
  225. local npc = ents.Create(ent.tasenpcType)
  226.  
  227. util.PrecacheModel(ent:GetModel())
  228. npc:SetModel(ent:GetModel())
  229. local spawnPos = ent:GetPos()+Vector(0,0,0)
  230.  
  231. npc:SetPos(spawnPos)
  232. npc:SetSkin(ent.tasenpcSkin)
  233. npc:SetAngles(Angle(0,ent:GetAngles().y,0))
  234.  
  235. //if ent.tasenpcWep != "" then
  236. //npc:SetKeyValue("additionalequipment",ent.tasenpcWep)
  237. //end
  238.  
  239. if ent.taseentType == "npc_citizen" then
  240. npc:SetKeyValue("citizentype",ent.tasenpcCitType)
  241. if ent.tasenpcCitType == "3" && ent.tasenpcCitMed==1 then
  242. npc:SetKeyValue("spawnflags","131072")
  243. end
  244. end
  245.  
  246. npc:Spawn()
  247. npc:Activate()
  248.  
  249. cleanup.Add (uplayer, "NPC", npc);
  250.  
  251. undo.Create ("Tasered NPC");
  252. undo.AddEntity (npc);
  253. undo.SetPlayer (ent.tasenpcShooter);
  254.  
  255. undo.Finish();
  256.  
  257.  
  258.  
  259. else
  260. return
  261. end
  262.  
  263. for k, v in pairs(taseredrags) do
  264. if v == ent then
  265. table.remove( taseredrags, k )
  266. end
  267. end
  268. ent:Remove()
  269.  
  270. end
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. function SWEP:SecondaryAttack()
  279. if table.Count( taseredrags ) == 0 then return end
  280.  
  281. self.Owner:EmitSound( "Weapon_Pistol.Empty")
  282. self.Owner:EmitSound( "Weapon_Shotgun.Empty")
  283. if (!SERVER) then return end
  284.  
  285. for k, v in pairs(taseredrags) do
  286. local shock1 = math.random(-1200, 1200 )
  287. local shock2 = math.random(-1200, 1200 )
  288. local shock3 = math.random(-1200, 1200 )
  289. v:GetPhysicsObject():ApplyForceCenter( Vector( shock1, shock2, shock3 ) )
  290. end
  291.  
  292. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement