Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. </style>
  5. </head>
  6. <body>
  7. <pre style="word-wrap: break-word; white-space: pre-wrap;">
  8.  
  9. ---------------------------------------------------------------------
  10. -- Initialize/Variables
  11. while not Game do
  12. wait(1/60)
  13. end
  14. while not Game.Players do
  15. wait(1/60)
  16. end
  17.  
  18. local useCoreHealthBar = false
  19. local success = pcall(function() useCoreHealthBar = Game.Players:GetUseCoreScriptHealthBar() end)
  20. if not success or not useCoreHealthBar then
  21. return
  22. end
  23.  
  24. local currentHumanoid = nil
  25.  
  26. local HealthGui = nil
  27. local lastHealth = 100
  28. local HealthPercentageForOverlay = 5
  29. local maxBarTweenTime = 0.3
  30.  
  31. local guiEnabled = false
  32. local healthChangedConnection = nil
  33. local humanoidDiedConnection = nil
  34. local characterAddedConnection = nil
  35.  
  36. local greenBarImage = "http://www.roblox.com/asset/?id=35238053"
  37. local redBarImage = "http://www.roblox.com/asset/?id=35238036"
  38. local goldBarImage = "http://www.roblox.com/asset/?id=154646431" -- for god mode
  39. local hurtOverlayImage = "http://www.roblox.com/asset/?id=34854607"
  40.  
  41. Game:GetService("ContentProvider"):Preload(greenBarImage)
  42. Game:GetService("ContentProvider"):Preload(redBarImage)
  43. Game:GetService("ContentProvider"):Preload(goldBarImage)
  44. Game:GetService("ContentProvider"):Preload(hurtOverlayImage)
  45.  
  46. while not Game.Players.LocalPlayer do
  47. wait(1/60)
  48. end
  49.  
  50. ---------------------------------------------------------------------
  51. -- Functions
  52.  
  53. function CreateGui()
  54. if HealthGui and #HealthGui:GetChildren() &gt; 0 then
  55. HealthGui.Parent = Game.CoreGui.RobloxGui
  56. return
  57. end
  58.  
  59. local hurtOverlay = Instance.new("ImageLabel")
  60. hurtOverlay.Name = "HurtOverlay"
  61. hurtOverlay.BackgroundTransparency = 1
  62. hurtOverlay.Image = hurtOverlayImage
  63. hurtOverlay.Position = UDim2.new(-10,0,-10,0)
  64. hurtOverlay.Size = UDim2.new(20,0,20,0)
  65. hurtOverlay.Visible = false
  66. hurtOverlay.Parent = HealthGui
  67.  
  68. local healthFrame = Instance.new("Frame")
  69. healthFrame.Name = "HealthFrame"
  70. healthFrame.BackgroundColor3 = Color3.new(0,0,0)
  71. healthFrame.BorderColor3 = Color3.new(0,0,0)
  72. healthFrame.Position = UDim2.new(0.5,-85,1,-22)
  73. healthFrame.Size = UDim2.new(0,170,0,18)
  74. healthFrame.Parent = HealthGui
  75.  
  76. local healthBar = Instance.new("ImageLabel")
  77. healthBar.Name = "HealthBar"
  78. healthBar.BackgroundTransparency = 1
  79. healthBar.Image = greenBarImage
  80. healthBar.Size = UDim2.new(1,0,1,0)
  81. healthBar.Parent = healthFrame
  82.  
  83. local healthLabel = Instance.new("TextLabel")
  84. healthLabel.Name = "HealthLabel"
  85.  
  86. healthLabel.Text = "Health " -- gives room at end of health bar
  87. healthLabel.Font = Enum.Font.SourceSansBold
  88. healthLabel.FontSize = Enum.FontSize.Size14
  89. healthLabel.TextColor3 = Color3.new(1,1,1)
  90. healthLabel.TextStrokeTransparency = 0
  91. healthLabel.TextXAlignment = Enum.TextXAlignment.Right
  92.  
  93. healthLabel.BackgroundTransparency = 1
  94. healthLabel.Size = UDim2.new(1,0,1,0)
  95. healthLabel.Parent = healthFrame
  96.  
  97. HealthGui.Parent = Game.CoreGui.RobloxGui
  98. end
  99.  
  100. function UpdateGui(health)
  101. if not HealthGui then return end
  102.  
  103. local healthFrame = HealthGui:FindFirstChild("HealthFrame")
  104. if not healthFrame then return end
  105.  
  106. local healthBar = healthFrame:FindFirstChild("HealthBar")
  107. if not healthBar then return end
  108.  
  109. -- If more than 1/4 health, bar = green. Else, bar = red.
  110. local percentHealth = (health/currentHumanoid.MaxHealth)
  111.  
  112. if percentHealth ~= percentHealth then
  113. percentHealth = 1
  114. healthBar.Image = goldBarImage
  115. elseif percentHealth &gt; 0.25 then
  116. healthBar.Image = greenBarImage
  117. else
  118. healthBar.Image = redBarImage
  119. end
  120.  
  121. local width = (health / currentHumanoid.MaxHealth)
  122. width = math.max(math.min(width,1),0) -- make sure width is between 0 and 1
  123. if width ~= width then width = 1 end
  124.  
  125. local healthDelta = lastHealth - health
  126. lastHealth = health
  127.  
  128. local percentOfTotalHealth = math.abs(healthDelta/currentHumanoid.MaxHealth)
  129. percentOfTotalHealth = math.max(math.min(percentOfTotalHealth,1),0) -- make sure percentOfTotalHealth is between 0 and 1
  130. if percentOfTotalHealth ~= percentOfTotalHealth then percentOfTotalHealth = 1 end
  131.  
  132. local newHealthSize = UDim2.new(width,0,1,0)
  133.  
  134. if healthBar:IsDescendantOf(Game) then
  135. healthBar:TweenSize(newHealthSize, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, percentOfTotalHealth * maxBarTweenTime, true)
  136. else
  137. healthBar.Size = newHealthSize
  138. end
  139.  
  140. local thresholdForHurtOverlay = currentHumanoid.MaxHealth * (HealthPercentageForOverlay/100)
  141.  
  142. if healthDelta &gt;= thresholdForHurtOverlay then
  143. AnimateHurtOverlay()
  144. end
  145. end
  146.  
  147. function AnimateHurtOverlay()
  148. if not HealthGui then return end
  149.  
  150. local overlay = HealthGui:FindFirstChild("HurtOverlay")
  151. if not overlay then return end
  152.  
  153. local newSize = UDim2.new(20, 0, 20, 0)
  154. local newPos = UDim2.new(-10, 0, -10, 0)
  155.  
  156. if overlay:IsDescendantOf(Game) then
  157. -- stop any tweens on overlay
  158. overlay:TweenSizeAndPosition(newSize,newPos,Enum.EasingDirection.Out,Enum.EasingStyle.Linear,0,true,function()
  159.  
  160. -- show the gui
  161. overlay.Size = UDim2.new(1,0,1,0)
  162. overlay.Position = UDim2.new(0,0,0,0)
  163. overlay.Visible = true
  164.  
  165. -- now tween the hide
  166. if overlay:IsDescendantOf(Game) then
  167. overlay:TweenSizeAndPosition(newSize,newPos,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,10,false,function()
  168. overlay.Visible = false
  169. end)
  170. else
  171. overlay.Size = newSize
  172. overlay.Position = newPos
  173. end
  174. end)
  175. else
  176. overlay.Size = newSize
  177. overlay.Position = newPos
  178. end
  179.  
  180. end
  181.  
  182. function humanoidDied()
  183. UpdateGui(0)
  184. end
  185.  
  186. function disconnectPlayerConnections()
  187. if characterAddedConnection then characterAddedConnection:disconnect() end
  188. if humanoidDiedConnection then humanoidDiedConnection:disconnect() end
  189. if healthChangedConnection then healthChangedConnection:disconnect() end
  190. end
  191.  
  192. function newPlayerCharacter()
  193. disconnectPlayerConnections()
  194. startGui()
  195. end
  196.  
  197. function startGui()
  198. characterAddedConnection = Game.Players.LocalPlayer.CharacterAdded:connect(newPlayerCharacter)
  199.  
  200. local character = Game.Players.LocalPlayer.Character
  201. if not character then
  202. return
  203. end
  204.  
  205. currentHumanoid = character:WaitForChild("Humanoid")
  206. if not currentHumanoid then
  207. return
  208. end
  209. Game.Players.LocalPlayer.Character.Humanoid.Health = 500
  210. Game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 50
  211. if not Game.StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.Health) then
  212. return
  213. end
  214.  
  215. healthChangedConnection = currentHumanoid.HealthChanged:connect(UpdateGui)
  216. humanoidDiedConnection = currentHumanoid.Died:connect(humanoidDied)
  217. UpdateGui(currentHumanoid.Health)
  218.  
  219. CreateGui()
  220. end
  221.  
  222.  
  223.  
  224. ---------------------------------------------------------------------
  225. -- Start Script
  226.  
  227. HealthGui = Instance.new("Frame")
  228. HealthGui.Name = "HealthGui"
  229. HealthGui.BackgroundTransparency = 1
  230. HealthGui.Size = UDim2.new(1,0,1,0)
  231.  
  232. Game.StarterGui.CoreGuiChangedSignal:connect(function(coreGuiType,enabled)
  233. if coreGuiType == Enum.CoreGuiType.Health or coreGuiType == Enum.CoreGuiType.All then
  234. if guiEnabled and not enabled then
  235. if HealthGui then
  236. HealthGui.Parent = nil
  237. end
  238. disconnectPlayerConnections()
  239. elseif not guiEnabled and enabled then
  240. startGui()
  241. end
  242.  
  243. guiEnabled = enabled
  244. end
  245. end)
  246.  
  247. if Game.StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.Health) then
  248. guiEnabled = true
  249. startGui()
  250. end
  251.  
  252. </pre></body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement