Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. if SERVER then return end
  2. local scrx, scry = ScrW(), ScrH()
  3. local chargeActive = false
  4. include("shared.lua")
  5. function drawcharge(isCharge)
  6. local globalwep = weapons.GetStored("weapon_defibrillator")
  7. local activewep = LocalPlayer():GetActiveWeapon()
  8. if isCharge then
  9. if CurTime() >= globalwep.CanUse and !chargeActive then
  10. frame = vgui.Create("DPanel")
  11. frame:SetSize(400, 60)
  12. frame:SetPos(scrx/2-200, 55)
  13. function frame:Paint(w, h) draw.RoundedBox(30, 0, 0, w, h, Color(80, 80, 80, 200)) end
  14. local bar = vgui.Create("DShape", frame)
  15. bar:SetType("Rect")
  16. bar:SetColor(Color(0, 200, 0, 245))
  17. bar:SetSize(350, 30)
  18. bar:SetPos(scrx/2-200, scry/2-30)
  19. bar:Center()
  20. local repeats = math.Round(globalwep.ChargeTime*30)
  21. local i = 1
  22. timer.Create("fadethething", 0.01, 0, function()
  23. local colstep = math.Min(200, i*(200/repeats))
  24. function bar:Paint(w,h) draw.RoundedBox(8, 0, 0, w, h, Color(-5+colstep, 205-colstep, 0, 245)) end
  25. local num = math.Min(350, i*(350/repeats))
  26. bar:SetSize(350 - num, 30)
  27. i = i + 1
  28. if num >= 350 then frame:Remove(); timer.Destroy("fadethething"); end
  29. end)
  30. end
  31. else
  32. if frame != nil then
  33. frame:Remove()
  34. if timer.Exists("fadethething") then timer.Destroy("fadethething") end
  35. end
  36. end
  37. end
  38. local hasswep = false
  39. net.Receive("defibfx", function(len)
  40. local globalwep = weapons.GetStored("weapon_defibrillator")
  41. local ent = net.ReadEntity()
  42. local entpos = net.ReadVector()
  43. local fx = net.ReadString()
  44. local ply = net.ReadEntity()
  45. if fx == "spark" then
  46. local sparkData = EffectData()
  47. sparkData:SetStart(LocalPlayer():GetShootPos()+LocalPlayer():GetForward(50))
  48. sparkData:SetEntity(LocalPlayer())
  49. sparkData:SetOrigin(entpos)
  50. util.Effect("StunstickImpact", sparkData)
  51. elseif fx == "tracer" then
  52. local traceData = EffectData()
  53. traceData:SetStart(ply:GetShootPos())
  54. traceData:SetOrigin(ply:GetEyeTrace().HitPos)
  55. util.Effect("ToolTracer", traceData)
  56. elseif fx == "sound" then
  57. surface.PlaySound(globalwep.DeathSound)
  58. elseif fx == "charge" then
  59. drawcharge(true)
  60. elseif fx == "decharge" then
  61. drawcharge(false)
  62. elseif fx == "toolongdead" then
  63. if entpos == Vector(1, 1, 1) then notification.AddLegacy("He's dead. Really dead.", 1, 6)
  64. else notification.AddLegacy("You're dead. Really dead.", 1, 6) end
  65. elseif fx == "timedied" then
  66. ply.TimeDied = CurTime()
  67. end
  68. end)
  69. net.Receive("defibgetents", function(len)
  70. local globalwep = weapons.GetStored("weapon_defibrillator")
  71. local ply = LocalPlayer()
  72. local isRevive, otherPly, pos
  73. for k,v in pairs(ents.FindInSphere(ply:GetPos(), 164)) do
  74. if v:GetClass() == "prop_ragdoll" or v:GetClass() == "class C_HL2MPRagdoll" and ply:GetPos():Distance(v:GetPos()) <= globalwep.ReviveDistance and ply:GetEyeTrace().HitPos:Distance(v:GetPos()) < globalwep.ReviveDistance and IsValid(v:GetRagdollOwner()) then
  75. isRevive = true
  76. otherPly = v:GetRagdollOwner()
  77. pos = v:GetPos()
  78. end
  79. end
  80. if !isRevive then
  81. local lookatent = ply:GetEyeTrace().Entity
  82. if lookatent:IsPlayer() and ply:GetPos():Distance(lookatent:GetPos()) <= globalwep.HitDistance then
  83. isRevive = false
  84. otherPly = lookatent
  85. pos = lookatent:GetPos()
  86. end
  87. end
  88. if pos == nil then return end
  89. net.Start("defibgiveents")
  90. net.WriteBool(isRevive)
  91. net.WriteEntity(otherPly)
  92. net.WriteVector(pos)
  93. net.SendToServer()
  94. end)
  95. hook.Add("HUDPaint", "DrawDefibGUI", function()
  96. local globalwep = weapons.GetStored("weapon_defibrillator")
  97. local isDefib = LocalPlayer():GetActiveWeapon().PrintName == "Defibrillator"
  98. local medicsOnly = globalwep.ReviveHeartMedicsOnly
  99. if isDefib and medicsOnly or !medicsOnly then
  100. for k,v in pairs(ents.GetAll()) do
  101. local otherply = v:GetRagdollOwner()
  102. if v:GetClass() == "class C_HL2MPRagdoll" and otherply.TimeDied != nil and (otherply.TimeDied+globalwep.TimeToRevive)-CurTime() > 0 then
  103. local dist = LocalPlayer():GetPos():Distance(v:GetPos())
  104. if dist <= globalwep.ReviveHeartDistance then
  105. cam.Start2D()
  106. local bodyPos = v:GetPos()
  107. local heartPos = (bodyPos + Vector(0, 0, 30+dist/20)):ToScreen()
  108. heartPos.x = heartPos.x - (28-(dist/100))
  109. surface.SetDrawColor(255, 255, 255, 255)
  110. surface.SetMaterial(Material("vgui/revive.png"))
  111. local size = math.Round(math.max(80 - (dist/100)*4.2, 5))
  112. surface.DrawTexturedRect(heartPos.x, heartPos.y, size, size)
  113. cam.End2D()
  114. end
  115. end
  116. end
  117. end
  118. end)
  119. hook.Add("PostPlayerDraw", "DefibTwoHanded", function(ply)
  120. local model = ply.Defib
  121. local attach = ply:GetAttachment(ply:LookupAttachment("anim_attachment_LH"))
  122. if !ply or !ply:Alive() or ply:GetActiveWeapon() == NULL or ply:GetActiveWeapon():GetClass() != "weapon_defibrillator" or !attach then
  123. if ply.Defib then ply.Defib:Remove(); ply.Defib = nil; end
  124. return
  125. end
  126. local color = Color(255, 255, 255)
  127. if model == nil then
  128. ply.Defib = ClientsideModel("models/weapons/custom/defib2.mdl")
  129. model = ply.Defib
  130. end
  131. local pos, ang = attach.Pos, attach.Ang
  132. ang:RotateAroundAxis(ang:Up(), 90)
  133. ang:RotateAroundAxis(ang:Right(), -60)
  134. ang:RotateAroundAxis(ang:Forward(), 45)
  135. pos = attach.Pos + ang:Forward()*0 + ang:Right()*1.5 + ang:Up()*2
  136. model:SetColor(color)
  137. model:SetRenderOrigin(pos)
  138. model:SetRenderAngles(ang)
  139. model:SetupBones()
  140. model:DrawModel()
  141. model:SetRenderOrigin()
  142. model:SetRenderAngles()
  143. end)
  144.  
  145. GLUATIMELEFTBEFORESPAWN = 20
  146.  
  147. timer.Create("TimerViewTimeGmodTimeLua", 1.5, timeLeft, function()
  148. GLUATIMELEFTBEFORESPAWN = GLUATIMELEFTBEFORESPAWN-1
  149. end)
  150.  
  151. hook.Add("HUDPaint", "ViewTime", function()
  152. if !LocalPlayer():Alive() then
  153. draw.RoundedBox(0,0,0,ScrW(),ScrH(),Color(200,0,0,200))
  154. draw.SimpleText("Attendez le médecin...", "Trebuchet24", ScrW() / 2, ScrH() / 2.05, Color(255,255,255), 1, 1)
  155. if GLUATIMELEFTBEFORESPAWN <= 0 then
  156. draw.SimpleText("Appuyez sur une touche pour respawn.", "Trebuchet24", ScrW() / 2, ScrH() / 1.95, Color(255,255,255), 1, 1)
  157. else
  158. draw.SimpleText("Temps restant: " ..GLUATIMELEFTBEFORESPAWN, "Trebuchet24", ScrW() / 2, ScrH() / 1.95, Color(255,255,255), 1, 1)
  159. end
  160. end
  161. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement