Advertisement
Guest User

TTT Defib

a guest
May 18th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.71 KB | None | 0 0
  1. SWEP.Base = "weapon_tttbase"
  2.  
  3. SWEP.HoldType = "slam"
  4.  
  5. SWEP.ViewModel = Model("models/weapons/v_c4.mdl")
  6. SWEP.WorldModel = Model("models/weapons/w_c4.mdl")
  7.  
  8. SWEP.Kind = WEAPON_EQUIP2
  9. SWEP.AutoSpawnable = false
  10. SWEP.CanBuy = { ROLE_TRAITOR }
  11. SWEP.LimitedStock = true
  12.  
  13.  
  14. if CLIENT then
  15. SWEP.PrintName = "Defibrillator"
  16. SWEP.Slot = 7
  17.  
  18. SWEP.ViewModelFOV = 10
  19. --SWEP.ViewModelFlip = true
  20.  
  21. SWEP.Icon = "VGUI/ttt/icon_rg_defibrillator"
  22.  
  23. SWEP.EquipMenuData = {
  24. type = "item_weapon",
  25. name = "Defibrillator",
  26. desc = "Resurrect dead mates with this one!"
  27. };
  28.  
  29. usermessage.Hook("_resurrectbody", function(um)
  30. local ply = um:ReadEntity()
  31. ply.was_resurrected = true
  32. ply.was_found = um:ReadBool()
  33. end)
  34.  
  35. usermessage.Hook("_resetresurrectedbody", function(um)
  36. for _, p in pairs(player.GetAll()) do
  37. p.was_resurrected = nil
  38. p.was_found = nil
  39. end
  40. end)
  41.  
  42. function ScoreGroup(p)
  43. if !IsValid(p) then return -1 end --because of reasons
  44. if p.was_resurrected then
  45. if LocalPlayer():Alive() then
  46. if !LocalPlayer():IsActiveTraitor() then
  47. return p.was_found and GROUP_FOUND or GROUP_TERROR
  48. else
  49. return GROUP_TERROR
  50. end
  51. end
  52. end
  53. if p.was_resurrected and LocalPlayer() == p then
  54. return GROUP_TERROR
  55. end
  56. if DetectiveMode() then
  57. if p:IsSpec() and (not p:Alive()) then
  58. if p:GetNWBool("body_found", false) then
  59. return GROUP_FOUND
  60. else
  61. local client = LocalPlayer()
  62. -- To terrorists, missing players show as alive
  63. if client:IsSpec() or
  64. client:IsActiveTraitor() or
  65. ((GAMEMODE.round_state != ROUND_ACTIVE) and client:IsTerror()) then
  66. return GROUP_NOTFOUND
  67. else
  68. return GROUP_TERROR
  69. end
  70. end
  71. end
  72. end
  73.  
  74. return p:IsTerror() and GROUP_TERROR or GROUP_SPEC
  75. end
  76.  
  77.  
  78. function SWEP:PrimaryAttack()
  79. local tr = util.TraceLine({start = self.Owner:EyePos(), endpos = self.Owner:EyePos() + self.Owner:EyeAngles():Forward() * 80, filter = self.Owner})
  80. if tr.HitNonWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and CORPSE.GetPlayerNick(tr.Entity) ~= "" then
  81. self.StartTime = CurTime()
  82. self.EndTime = CurTime() + 5
  83. self.Started = true
  84. end
  85. end
  86.  
  87. function SWEP:DrawHUD()
  88. if self.Started then
  89. --print("1")
  90. if self.Owner:KeyDown(IN_ATTACK) then
  91. --print("2")
  92. local tr = util.TraceLine({start = self.Owner:EyePos(), endpos = self.Owner:EyePos() + self.Owner:EyeAngles():Forward() * 80, filter = self.Owner})
  93. if tr.HitNonWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and CORPSE.GetPlayerNick(tr.Entity) ~= "" then
  94. local mins, maxs = self.Owner:OBBMins(), self.Owner:OBBMaxs()
  95. local tr2 = util.TraceHull({start = tr.Entity:LocalToWorld(tr.Entity:OBBCenter()) + vector_up, endpos = tr.Entity:LocalToWorld(tr.Entity:OBBCenter()) + Vector(0, 0, 80), filter = {tr.Entity, self.Owner}, mins = Vector(mins.x * 1.6, mins.y * 1.6, 0), maxs = Vector(maxs.x * 1.6, maxs.y * 1.6, 0), mask = MASK_PLAYERSOLID})
  96. if tr2.Hit then
  97. local w, h = surface.GetTextSize("THERE'S NO ROOM TO RESURRECT HERE")
  98. surface.SetTextPos(ScrW() / 2 - (w / 2), ScrH() / 2 - h)
  99. surface.SetTextColor(Color(255, 0, 0, 255))
  100. surface.DrawText("THERE'S NO ROOM TO RESURRECT HERE")
  101. self.StartTime = CurTime()
  102. self.EndTime = CurTime() + 5
  103. else
  104. fract = math.TimeFraction(self.StartTime, self.EndTime, CurTime())
  105. surface.SetDrawColor(Color(255, 0, 0, 255))
  106. surface.SetDrawColor(Color(120, 120, 120, 130))
  107. surface.DrawRect(ScrW() / 2 - (160 / 2), ScrH() / 2 + 10, 160, 10)
  108. surface.SetFont("TabLarge")
  109. local w, h = surface.GetTextSize("RESURRECTING")
  110. surface.SetTextPos(ScrW() / 2 - (w / 2), ScrH() / 2 - h)
  111. surface.SetTextColor(Color(255, 0, 0, 255))
  112. surface.DrawText("RESURRECTING")
  113. surface.SetDrawColor(Color(255, 0, 0, 255))
  114. surface.DrawRect(ScrW() / 2 - (160 / 2), ScrH() / 2 + 10, math.Clamp(160 * fract, 0, 160), 10)
  115. end
  116. else
  117. self.StartTime = CurTime()
  118. self.EndTime = CurTime() + 5
  119. end
  120. end
  121. end
  122. end
  123. end
  124.  
  125. if SERVER then
  126. resource.AddFile("materials/vgui/ttt/icon_rg_defibrillator.vmt")
  127. AddCSLuaFile("shared.lua")
  128.  
  129. function SWEP:Deploy()
  130. self.Started = false
  131. end
  132.  
  133. function ResurrectHandler(rag)
  134. if IsValid(rag) and rag:GetClass() == "prop_ragdoll" and rag.player_ragdoll then
  135. local ply = player.GetByUniqueID(rag.uqid)
  136. local credits = CORPSE.GetCredits(rag, 0)
  137. ply:SpawnForRound(true)
  138. ply:SetCredits(credits)
  139. ply:SetPos(rag:LocalToWorld(rag:OBBCenter()) + vector_up / 2) --Just in case he gets stuck somewhere
  140. ply:SetEyeAngles(Angle(0, rag:GetAngles().y, 0))
  141. ply:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  142. timer.Simple(2, function() ply:SetCollisionGroup(COLLISION_GROUP_PLAYER) end)
  143. umsg.Start("_resurrectbody")
  144. umsg.Entity(ply)
  145. umsg.Bool(CORPSE.GetFound(rag, false))
  146. umsg.End()
  147. rag:Remove()
  148. end
  149. end
  150.  
  151. function SWEP:PrimaryAttack()
  152. local tr = util.TraceLine({start = self.Owner:EyePos(), endpos = self.Owner:EyePos() + self.Owner:EyeAngles():Forward() * 80, filter = self.Owner})
  153. if tr.HitNonWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and tr.Entity.player_ragdoll then
  154. self.StartTime = CurTime()
  155. self.Started = true
  156.  
  157. end
  158. end
  159.  
  160. function SWEP:Think()
  161. if self.Started then
  162. --print("1")
  163. if self.Owner:KeyDown(IN_ATTACK) then
  164. --print("2")
  165. local tr = util.TraceLine({start = self.Owner:EyePos(), endpos = self.Owner:EyePos() + self.Owner:EyeAngles():Forward() * 80, filter = self.Owner})
  166. if tr.HitNonWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and tr.Entity.player_ragdoll then
  167. --print("3")
  168. local mins, maxs = self.Owner:OBBMins(), self.Owner:OBBMaxs()
  169. local tr2 = util.TraceHull({start = tr.Entity:LocalToWorld(tr.Entity:OBBCenter()) + vector_up, endpos = tr.Entity:LocalToWorld(tr.Entity:OBBCenter()) + Vector(0, 0, 80), filter = {tr.Entity, self.Owner}, mins = Vector(mins.x * 1.6, mins.y * 1.6, 0), maxs = Vector(maxs.x * 1.6, maxs.y * 1.6, 0), mask = MASK_PLAYERSOLID})
  170. if !tr2.Hit then
  171. --print(CurTime() - self.StartTime)
  172. if CurTime() - self.StartTime >= 5 then
  173. ResurrectHandler(tr.Entity)
  174. self:Remove()
  175. end
  176. else
  177. self.StartTime = CurTime()
  178. end
  179. else
  180. self.StartTime = CurTime()
  181. end
  182. else
  183. self.StartTime = CurTime()
  184. self.Started = false
  185. end
  186. end
  187. end
  188.  
  189. hook.Add("TTTEndRound", "_resetresurrectedbody", function()
  190. umsg.Start("_resetresurrectedbody")
  191. umsg.End()
  192. end)
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement