Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------------
  2. -- Tranq Gun v1.5 --
  3. -- Special thanks to Mahalis for his crate maker --
  4. -- and Adrian Leuzzi for his ragdoll gun --
  5. -- as well as everyone who helped to document the GMod wiki -- --
  6. --------------------------------------------------------------------------------------------------------
  7.  
  8. --Ported by Charles445
  9.  
  10. if SERVER then
  11. AddCSLuaFile( "shared.lua" )
  12. end
  13.  
  14. SWEP.HoldType = "ar2"
  15.  
  16. if CLIENT then
  17. SWEP.PrintName = "Tranquilizer"
  18. SWEP.Slot = 7
  19.  
  20. SWEP.ViewModelFlip = false
  21. SWEP.ViewModelFOV = 54
  22.  
  23. SWEP.EquipMenuData = {
  24. type = "item_weapon",
  25. desc = "Used on suspects that won't comply."
  26. };
  27.  
  28. SWEP.Icon = "VGUI/ttt/icon_polter"
  29. end
  30.  
  31. SWEP.Base = "weapon_tttbase"
  32. SWEP.Kind = WEAPON_EQUIP2
  33. SWEP.CanBuy = {ROLE_DETECTIVE}
  34. SWEP.WeaponID = AMMO_TRANQ -- What does this do?
  35. SWEP.ViewModel = "models/weapons/v_IRifle.mdl"
  36. SWEP.WorldModel = "models/weapons/w_IRifle.mdl"
  37.  
  38. -- THESE VARIABLES CAN BE CHANGED
  39. SWEP.RateOfFire = 5 -- pause between shots
  40. SWEP.SetTime = 10 -- YOU CAN CHANGE THIS TO SET THE DURATION OF THE SLEEP
  41. -- That's it for variables you should change
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. -- Basic SWEP Settings
  49. SWEP.Author = "Elwaywitvac"
  50. SWEP.PrintName = "Tranquilizer Gun"
  51. SWEP.Contact = "Elwaywitvac@gmail.com"
  52. SWEP.Purpose = "Knocks Players/NPCs unconcious"
  53. SWEP.Instructions = "Rate of Fire: " .. SWEP.RateOfFire .. " secs \nPrimary: Sleep\nSecondary: Revive\nReload: Change Mode(permanent/temporary)"
  54.  
  55. SWEP.Primary.ClipSize = 3
  56. SWEP.Primary.DefaultClip = 3
  57. SWEP.Primary.ClipMax = 3
  58. SWEP.Primary.Automatic = false
  59. SWEP.Primary.Ammo = "none"
  60.  
  61.  
  62. SWEP.Secondary.ClipSize = -1
  63. SWEP.Secondary.DefaultClip = -1
  64. SWEP.Secondary.Automatic = false
  65. SWEP.Secondary.Ammo = "none"
  66.  
  67. local ShootSound = Sound( "Weapon_crossbow.Single" )
  68. if SERVER then sleeping = {} end
  69.  
  70. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  71. ----------- SWEP FUNCTIONS -----------
  72. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  73.  
  74. -- Make ply/npc sleep
  75. function SWEP:PrimaryAttack()
  76. -- Fire the weapon
  77. self.Weapon:SetNextPrimaryFire( CurTime() + self.RateOfFire )
  78. if not self:CanPrimaryAttack() then return end
  79. self.Weapon:EmitSound(ShootSound)
  80.  
  81. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  82.  
  83. self:TakePrimaryAmmo(1)
  84. -- Only server handles ragdolls
  85. if(!SERVER) then return end
  86.  
  87. local tr = self.Owner:GetEyeTrace()
  88. if ( (SinglePlayer() && SERVER) || CLIENT ) then
  89. self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
  90. end
  91. -- if there isn't anything there quit
  92. if ( tr.HitWorld ) then return end
  93.  
  94. -- tranq Player
  95. if tr.Entity:IsPlayer() then
  96. tranqPlayer(tr.Entity, self.SetTime)
  97. end
  98. end
  99.  
  100. -- Revive
  101. function SWEP:SecondaryAttack( )
  102. -- Fire the weapon
  103. self.Weapon:EmitSound(ShootSound)
  104. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  105.  
  106. -- Only server handles ragdolls
  107. if(!SERVER) then return end
  108.  
  109. local tr = self.Owner:GetEyeTrace()
  110.  
  111. -- if there isn't anything there quit
  112. if ( tr.HitWorld ) then return end
  113.  
  114. -- revive what you hit
  115. revive(tr.Entity)
  116. end
  117.  
  118. function SWEP:Reload()
  119. --Reload does absolutely nothing! Hooray!
  120. end
  121.  
  122. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  123. ----------- TRANQ FUNCTIONS ---------
  124. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  125.  
  126. -------------- Revive
  127. function revive(ent)
  128. -- revive player
  129. if !ent then return end
  130.  
  131. if ent.ply then
  132. local phy = ent:GetPhysicsObject()
  133. phy:EnableMotion(false)
  134. ent:SetSolid(SOLID_NONE)
  135. ent.ply:DrawViewModel(true)
  136. ent.ply:DrawWorldModel(true)
  137. ent.ply:Spawn()
  138. ent.ply:SetPos(ent:GetPos())
  139. ent.ply:SetVelocity(ent:GetPhysicsObject():GetVelocity())
  140. end
  141. -- remove ragdoll
  142. ent:Remove()
  143. end
  144.  
  145. function tranqPlayer(ply, t)
  146. -- create ragdoll
  147. local rag = ents.Create( "prop_ragdoll" )
  148. if not rag:IsValid() then return end
  149.  
  150. -- build rag
  151. rag:SetModel( ply:GetModel() )
  152. rag:SetKeyValue( "origin", ply:GetPos().x .. " " .. ply:GetPos().y .. " " .. ply:GetPos().z )
  153. rag:SetAngles(ply:GetAngles())
  154.  
  155. -- player vars
  156. rag.ply = ply
  157.  
  158. -- "remove" player
  159. ply:StripWeapons()
  160. ply:DrawViewModel(false)
  161. ply:DrawWorldModel(false)
  162. ply:Spectate(OBS_MODE_CHASE)
  163. ply:SpectateEntity(rag)
  164.  
  165. -- finalize ragdoll
  166. rag:Spawn()
  167. rag:Activate()
  168.  
  169. -- make ragdoll fall
  170. rag:GetPhysicsObject():SetVelocity(4*ply:GetVelocity())
  171.  
  172. --Timed sleep
  173. local key = (t + CurTime())
  174. sleeping[key] = rag
  175. return rag
  176. end
  177.  
  178. -- Watch for temporary revives (hook on think)
  179. function checkSleeping()
  180. for t, ent in pairs(sleeping) do
  181. if CurTime() > t then
  182. revive(ent)
  183. sleeping[t] = nil
  184. end
  185. end
  186. end
  187.  
  188. hook.Add("Think", "checksleeping", checkSleeping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement