Advertisement
Exho

Untitled

Aug 15th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. if SERVER then
  2. AddCSLuaFile( "shared.lua" )
  3. end
  4.  
  5. SWEP.HoldType = "pistol"
  6.  
  7. if CLIENT then
  8.  
  9. SWEP.PrintName = "Taser"
  10. SWEP.Slot = 6
  11.  
  12. SWEP.ViewModelFlip = false
  13.  
  14. SWEP.EquipMenuData = {
  15. type = "item_weapon",
  16. desc = "Knock someone out for 30 seconds. Only useable once. Can purchase again."
  17. };
  18.  
  19. SWEP.Icon = "vgui/ttt/icon_skull.vmt"
  20. end
  21.  
  22. SWEP.Base = "weapon_tttbase"
  23.  
  24. SWEP.ViewModel = "models/weapons/c_pistol.mdl"
  25. SWEP.WorldModel = "models/weapons/w_pistol.mdl"
  26. SWEP.ViewModelFOV = 50
  27.  
  28. SWEP.DrawCrosshair = true
  29. SWEP.Primary.Damage = 25
  30. SWEP.Primary.ClipSize = -1
  31. SWEP.Primary.DefaultClip = -1
  32. SWEP.Primary.Automatic = true
  33. SWEP.Primary.Delay = 1.1
  34. SWEP.Primary.Ammo = "XBowBolt"
  35. SWEP.Secondary.ClipSize = -1
  36. SWEP.Secondary.DefaultClip = -1
  37. SWEP.Secondary.Automatic = true
  38. SWEP.Secondary.Ammo = "XBowBolt"
  39. SWEP.Secondary.Delay = 1.4
  40.  
  41. SWEP.Kind = WEAPON_EQUIP
  42. SWEP.CanBuy = {ROLE_DETECTIVE} -- only traitors can buy
  43. SWEP.LimitedStock = false -- only buyable once
  44. SWEP.WeaponID = AMMO_TASER
  45.  
  46. SWEP.IsSilent = false
  47.  
  48. -- Pull out faster than standard guns
  49. SWEP.DeploySpeed = 2
  50.  
  51. SWEP.Used = false
  52.  
  53. local taseredrags = {}
  54.  
  55. function SWEP:Initialize()
  56. hook.Add("TTTEndRound", "DontTaseMeBro", function()
  57. self.Used = true
  58. end)
  59. end
  60.  
  61. function SWEP:PrimaryAttack()
  62. if self.Used then
  63. self.Owner:PrintMessage( HUD_PRINTCENTER, "Batteries Depleted. Taser Useless." )
  64. return
  65. end
  66. local eyetrace = self.Owner:GetEyeTrace();
  67.  
  68. if !eyetrace.Entity:IsPlayer() then return end
  69.  
  70. self.Weapon:EmitSound( "Weapon_StunStick.Activate")
  71.  
  72. self.BaseClass.ShootEffects( self )
  73.  
  74. if not IsValid(eyetrace.Entity) or (self.Owner:EyePos():Distance(eyetrace.Entity:GetPos()) > 150) or not eyetrace.Entity:IsPlayer() then return end
  75.  
  76. if CLIENT then return end
  77.  
  78. if eyetrace.Entity:IsPlayer() then
  79.  
  80. self.Owner:PrintMessage( HUD_PRINTCENTER, "Now right click to electrocute "..eyetrace.Entity:GetName( ) )
  81.  
  82. self:tasePlayer(eyetrace.Entity) // If the it is a player then bring them down tranqPlayer()
  83. self.Used = true
  84.  
  85. end
  86. end
  87.  
  88. function SWEP:tasePlayer(ply)
  89. if not ply:Alive() then return end
  90.  
  91. if ply:InVehicle() then
  92. local vehicle = ply:GetParent()
  93. ply:ExitVehicle()
  94. end
  95.  
  96. ULib.getSpawnInfo( ply ) -- Collect information so we can respawn them in the same state.
  97.  
  98. local ragdoll = ents.Create( "prop_ragdoll" )
  99. ragdoll.ragdolledPly = ply
  100.  
  101. ragdoll:SetPos( ply:GetPos() )
  102. local velocity = ply:GetVelocity()
  103. ragdoll:SetAngles( ply:GetAngles() )
  104. ragdoll:SetModel( ply:GetModel() )
  105. ragdoll:Spawn()
  106. ragdoll:Activate()
  107. ply:SetParent( ragdoll ) -- So their player ent will match up (position-wise) with where their ragdoll is.
  108. -- Set velocity for each peice of the ragdoll
  109. local j = 1
  110. while true do -- Break inside
  111. local phys_obj = ragdoll:GetPhysicsObjectNum( j )
  112. if phys_obj then
  113. phys_obj:SetVelocity( velocity )
  114. j = j + 1
  115. else
  116. break
  117. end
  118. end
  119.  
  120. table.insert(taseredrags, ragdoll)
  121.  
  122. ply:Spectate( OBS_MODE_CHASE )
  123. ply:SpectateEntity( ragdoll )
  124. ply:StripWeapons() -- Otherwise they can still use the weapons.
  125.  
  126. ragdoll:DisallowDeleting( true, function( old, new ) ply.ragdoll = new end )
  127.  
  128. ply:DisallowSpawning( true )
  129.  
  130. ply.ragdoll = ragdoll
  131. ply:PrintMessage( HUD_PRINTCENTER, "You have been tasered. 30 seconds till revival" )
  132.  
  133. timer.Create("revivedelay"..ply:UniqueID(), 30, 1, function () taserrevive( ply ) end )
  134. end
  135.  
  136. function taserrevive(ply)
  137. ply:DisallowSpawning( false )
  138. ply:SetParent()
  139.  
  140. ply:UnSpectate() -- Need this for DarkRP for some reason, works fine without it in sbox
  141.  
  142. local ragdoll = ply.ragdoll
  143. ply.ragdoll = nil -- Gotta do this before spawn or our hook catches it
  144.  
  145. if not ragdoll:IsValid() then -- Something must have removed it, just spawn
  146. ULib.spawn( ply, true )
  147. else
  148. local pos = ragdoll:GetPos()
  149. pos.z = pos.z + 10 -- So they don't end up in the ground
  150.  
  151. ULib.spawn( ply, true )
  152. ply:SetPos( pos )
  153. ply:SetVelocity( ragdoll:GetVelocity() )
  154. local yaw = ragdoll:GetAngles().yaw
  155. ply:SetAngles( Angle( 0, yaw, 0 ) )
  156. ragdoll:DisallowDeleting( false )
  157. ragdoll:Remove()
  158. end
  159. for k, v in pairs(taseredrags) do
  160. table.remove( taseredrags, k )
  161. end
  162. end
  163.  
  164. function SWEP:SecondaryAttack()
  165.  
  166. if table.Count( taseredrags ) == 0 then return end
  167.  
  168.  
  169.  
  170. self.Owner:EmitSound( "Weapon_Pistol.Empty")
  171.  
  172. self.Owner:EmitSound( "Weapon_SMG1.Empty")
  173.  
  174. if CLIENT then return end
  175.  
  176.  
  177.  
  178. for k, v in pairs(taseredrags) do
  179.  
  180. local shock1 = math.random(-1200, 1200 )
  181. local shock2 = math.random(-1200, 1200 )
  182.  
  183. local shock3 = math.random(-1200, 1200 )
  184.  
  185. if not v:IsValid() then return end
  186. v:GetPhysicsObject():ApplyForceCenter( Vector( shock1, shock2, shock3 ) )
  187. end
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement