--everything below are executed only once --changes health bar mode --1 = Sonic, 2 = Amy mode = 1 HPLayerIndicators = { HealthBar.HPLayer1, HealthBar.HPLayer2, HealthBar.HPLayer3, HealthBar.HPLayer4 } HPTopBars = { HealthBar.HPTop, HealthBar.HPMiddle } HealingTopBars = { HealthBar.HealingTop, HealthBar.HealingMiddle } HPTopCritical = createPicture() HPTopWarning = createPicture() HPTopNormal = createPicture() HPMiddleCritical = createPicture() HPMiddleWarning = createPicture() HPMiddleNormal = createPicture() HPBottomCritical = createPicture() HPBottomWarning = createPicture() HPBottomNormal = createPicture() EnergyBottom = createPicture() EnergyMiddle = createPicture() EnergyTop = createPicture() SpeedNormal = createPicture() SpeedWarning = createPicture() SpeedDanger = createPicture() defeatedEmblem = createPicture() normalEmblem = createPicture() superEmblem = createPicture() OxygenDanger = createPicture() OxygenNormal = createPicture() HPLayer1DMG = createPicture() HPLayer1Heal = createPicture() HPLayer1Red = createPicture() HPLayer1Yellow = createPicture() HPLayer1Green = createPicture() HPLayer2DMG = createPicture() HPLayer2Heal = createPicture() HPLayer2Red = createPicture() HPLayer2Yellow = createPicture() HPLayer2Green = createPicture() icon = createPicture() imgDir = "D://Documents//Sonic HP Bar//" HPTopCritical.loadFromFile(imgDir.."HP top red.png") HPTopWarning.loadFromFile(imgDir.."HP top yellow.png") HPTopNormal.loadFromFile(imgDir.."HP top green.png") HPMiddleCritical.loadFromFile(imgDir.."HP middle red.png") HPMiddleWarning.loadFromFile(imgDir.."HP middle yellow.png") HPMiddleNormal.loadFromFile(imgDir.."HP middle green.png") HPBottomCritical.loadFromFile(imgDir.."HP bottom red.png") HPBottomWarning.loadFromFile(imgDir.."HP bottom yellow.png") HPBottomNormal.loadFromFile(imgDir.."HP bottom green.png") SpeedNormal.loadFromFile(imgDir.."Speed middle.png") SpeedWarning.loadFromFile(imgDir.."Speed middle warning.png") SpeedDanger.loadFromFile(imgDir.."Speed middle danger.png") OxygenDanger.loadFromFile(imgDir.."Oxygen danger.png") OxygenNormal.loadFromFile(imgDir.."Oxygen.png") HPLayer1DMG.loadFromFile(imgDir.."HP layer 1 damage.png") HPLayer1Heal.loadFromFile(imgDir.."HP layer 1 heal bright.png") HPLayer1Red.loadFromFile(imgDir.."HP layer 1 red.png") HPLayer1Yellow.loadFromFile(imgDir.."HP layer 1 yellow.png") HPLayer1Green.loadFromFile(imgDir.."HP layer 1 green.png") HPLayer2DMG.loadFromFile(imgDir.."HP layer 2 damage.png") HPLayer2Heal.loadFromFile(imgDir.."HP layer 2 heal bright.png") HPLayer2Red.loadFromFile(imgDir.."HP layer 2 red.png") HPLayer2Yellow.loadFromFile(imgDir.."HP layer 2 yellow.png") HPLayer2Green.loadFromFile(imgDir.."HP layer 2 green.png") if mode == 1 then --Sonic EnergyBottom.loadFromFile(imgDir.."Energy bottom.png") EnergyMiddle.loadFromFile(imgDir.."Energy middle.png") EnergyTop.loadFromFile(imgDir.."Energy top.png") defeatedEmblem.loadFromFile(imgDir.."Defeated Sonic emblem.png") normalEmblem.loadFromFile(imgDir.."Sonic emblem.png") superEmblem.loadFromFile(imgDir.."Super Sonic emblem.png") icon.loadFromFile(imgDir.."Sonic icon.png") HealthBar.Emblem.Hint = "Change mode in Lua script to 2 and execute script if you want Amy instead." HealthBar.Emblem.Top = 23 HealthBar.HPOverlay.Hint = "Sonic's health points" HealthBar.EnergyOverlay.Hint = "Sonic's boost energy\nFill to boost for longer." HealthBar.SpeedOverlay.Hint = "Sonic's current speed" HealthBar.OxygenOverlay.Hint = "Sonic's oxygen reserve\nQuickly resurface before this bar empties, else he will drown." elseif mode == 2 then --Amy EnergyBottom.loadFromFile(imgDir.."Amy variant//Energy bottom.png") EnergyMiddle.loadFromFile(imgDir.."Amy variant//Energy middle.png") EnergyTop.loadFromFile(imgDir.."Amy variant//Energy top.png") defeatedEmblem.loadFromFile(imgDir.."Amy variant//Defeated Amy emblem.png") normalEmblem.loadFromFile(imgDir.."Amy variant//Amy emblem.png") superEmblem.loadFromFile(imgDir.."Amy variant//Super Amy emblem.png") icon.loadFromFile(imgDir.."Amy variant//Amy icon.png") HealthBar.Emblem.Hint = "Change mode in Lua script to 1 and execute script if you want Sonic instead." HealthBar.Emblem.Top = 10 HealthBar.HPOverlay.Hint = "Amy's health points" HealthBar.EnergyOverlay.Hint = "Amy's boost energy\nFill to boost for longer." HealthBar.SpeedOverlay.Hint = "Amy's current speed" HealthBar.OxygenOverlay.Hint = "Amy's oxygen reserve\nQuickly resurface before this bar empties, else she will drown." end HealthBar.Emblem.Picture = normalEmblem HealthBar.EnergyBottom.Picture = EnergyBottom HealthBar.EnergyMiddle.Picture = EnergyMiddle HealthBar.EnergyTop.Picture = EnergyTop HealthBar.Icon = icon.getBitmap() HPColors = { {HPTopCritical, HPTopWarning, HPTopNormal}, {HPMiddleCritical, HPMiddleWarning, HPMiddleNormal} } HPBottomColors = { HPBottomCritical, HPBottomWarning, HPBottomNormal } HPLayerColors = { {HPLayer1DMG, HPLayer1Heal, HPLayer1Red, HPLayer1Yellow, HPLayer1Green}, {HPLayer2DMG, HPLayer2Heal, HPLayer2Red, HPLayer2Yellow, HPLayer2Green} } al = getAddressList() function fmod (a,b) c = a % b if c == 0 and a > 0 then c = b end return c end function secondsToTimeFormat(t) local negative = "" if t < 0 then negative = "-" end if t ~= t then return "-:--:--.--" elseif t == math.huge then return "∞" else t = math.abs(t) local hours = math.floor(t/3600) local minutes = math.floor((t%3600)/60) local seconds = t % 60 if minutes == 0 then return string.format("%s%.2f",negative,seconds) elseif hours == 0 then return string.format("%s%d%s%05.2f",negative,minutes,":",seconds) else return string.format("%s%d%s%02d%s%05.2f",negative,hours,":",minutes,":",seconds) end end end damage = 0 damageDelay = 0 healing = 0 healingDelay = 0 oldHealth = 0 function HealthBar_UpdateTimerTimer(sender) checkFPS() --everything below are executed continuously character = al["Current Character"].NumericalValue or 0 vitals = 0 oxygen = 32 - (al["Underwater time (limit = 32 seconds)"].NumericalValue or 0) energy = al["Boost Gauge"].NumericalValue or 0 speed = math.sqrt((al["X Velocity"].NumericalValue or 0)^2 + (al["Y Velocity"].NumericalValue or 0)^2 + (al["Z Velocity"].NumericalValue or 0)^2) progress = al["Progress"].NumericalValue or 0 environment = al["Atmosphere type"].NumericalValue or 1 --0 == water, 1 == air xCoord = al["X Coordinates"].NumericalValue or 0 yCoord = al["Y Coordinates"].NumericalValue or 0 zCoord = al["Z Coordinates"].NumericalValue or 0 time = al["Time"].NumericalValue or 0 Locator.XCoord.Caption = string.format("%.2f",xCoord) Locator.YCoord.Caption = string.format("%.2f",yCoord) Locator.ZCoord.Caption = string.format("%.2f",zCoord) if progress ~= 0 then eta = time/progress else eta = math.huge end Locator.ETA.Caption = string.format("ETA %s",secondsToTimeFormat(eta)) if mode == 1 then charName = "Sonic" elseif mode == 2 then charName = "Amy" end if character == 2 then health = al["Current Rings"].NumericalValue or 0 elseif vitals == 0 and oxygen > 0 then health = (al["Current Rings"].NumericalValue or 0) + 1 else health = 0 end if health > 0 then if character == 2 then HealthBar.Emblem.Picture = superEmblem else HealthBar.Emblem.Picture = normalEmblem end else HealthBar.Emblem.Picture = defeatedEmblem end --removes absurd values if health > 1000 then health = 1000 elseif health < 0 then health = 0 end HealthBar.HPNumeric.Caption = string.format("%d",health) HealthBar.SpeedNumeric.Caption = string.format("%.2f",speed) HealthBar.ProgressNumeric.Caption = string.format("%.2f%s",100*progress,"%") HealthBar.Progress.Width = 1000*progress) if environment == 0 or oxygen < 32 then HealthBar.OxygenBackground.Visible = true HealthBar.Oxygen.Visible = true HealthBar.OxygenNumeric.Visible = true HealthBar.OxygenOverlay.Visible = true HealthBar.Oxygen.Width = 10*oxygen HealthBar.OxygenNumeric.Caption = string.format("%.2f %s", oxygen, "s") if oxygen > 10 then HealthBar.Oxygen.Picture = OxygenNormal HealthBar.OxygenNumeric.Font.Color = 0xffffff else HealthBar.Oxygen.Picture = OxygenDanger HealthBar.OxygenNumeric.Font.Color = 0x0000ff end else HealthBar.OxygenBackground.Visible = false HealthBar.Oxygen.Visible = false HealthBar.OxygenNumeric.Visible = false HealthBar.OxygenOverlay.Visible = false end if speed > 90 then HealthBar.SpeedTop.Visible = true HealthBar.SpeedMiddle.Visible = false HealthBar.SpeedBottom.Visible = true HealthBar.SpeedTop.Width = 10*(speed-90) else HealthBar.SpeedTop.Visible = false HealthBar.SpeedMiddle.Visible = true HealthBar.SpeedBottom.Visible = false HealthBar.SpeedMiddle.Width = 10*speed --[[ if speed > 30 then HealthBar.SpeedMiddle.Picture = SpeedNormal elseif speed > 10 then HealthBar.SpeedMiddle.Picture = SpeedWarning else HealthBar.SpeedMiddle.Picture = SpeedDanger end --]] end if character == 0 then HealthBar.EnergyBackground.Visible = true HealthBar.EnergyOverlay.Visible = true HealthBar.EnergyNumeric.Visible = true HealthBar.EnergyNumeric.Caption = string.format("%.02f",energy) if energy <= 0 then HealthBar.EnergyOverlay.Hint = "Out of energy -- refill to boost again." else HealthBar.EnergyOverlay.Hint = string.format("%s's boost energy\nFill to boost for longer.",charName end if energy > 200 then HealthBar.EnergyTop.Visible = true HealthBar.EnergyMiddle.Visible = false HealthBar.EnergyBottom.Visible = true HealthBar.EnergyTop.Width = 4*(energy-200) else HealthBar.EnergyTop.Visible = false HealthBar.EnergyMiddle.Visible = true HealthBar.EnergyBottom.Visible = false HealthBar.EnergyMiddle.Width = 4*energy end else HealthBar.EnergyOverlay.Visible = false HealthBar.EnergyBackground.Visible = false HealthBar.EnergyNumeric.Visible = false HealthBar.EnergyTop.Visible = false HealthBar.EnergyMiddle.Visible = false HealthBar.EnergyBottom.Visible = false end healthLayer = math.ceil(health/200) healthTop = fmod(health,200) damageChange = 1 healingChange = 1 if 4*health - healingChange - math.abs(healing - 4*health)^(3/4)/5 < healing then healing = 4*health healingDelay = 0 elseif health > oldHealth then healingDelay = 20 elseif healingDelay > 0 then healingDelay = healingDelay - 1 else healing = healing + healingChange + math.abs(healing - 4*health)^(3/4)/5 end if 4*health + damageChange + math.abs(damage - 4*health)^(3/4)/5 > damage then damage = 4*health damageDelay = 0 elseif health < oldHealth then damageDelay = 20 elseif damageDelay > 0 then damageDelay = damageDelay - 1 else damage = damage - damageChange - math.abs(damage - 4*health)^(3/4)/5 end oldHealth = health damageLayer = math.ceil(damage/800) damageTop = fmod(damage,800) healingLayer = math.ceil(healing/800) healingTop = fmod(healing,800) if character == 2 then dangerHealth = 29 warningHealth = 49 else dangerHealth = 1 warningHealth = 50 end dangerHealthLayer = math.floor(dangerHealth/200) warningHealthLayer = math.floor(warningHealth/200) --------------------------------------------------------------------------------Healing section, var healing controls HP elements if health <= dangerHealth then status = 1 HealthBar.HPNumeric.Font.Color = 0x0000ff elseif health <= warningHealth then status = 2 HealthBar.HPNumeric.Font.Color = 0x00ffff else status = 3 HealthBar.HPNumeric.Font.Color = 0xffffff end if healingLayer > 4 then HPTopBar = 1 else HPTopBar = 2 end if healingLayer >= damageLayer then HPTopBarVisible = true HealthBar.HPBottom.Visible = true) HealthBar.HPBottom.Width = 800) if healingLayer - 1 > warningHealthLayer then HealthBar.HPBottom.Picture = HPBottomColors[3] elseif healingLayer - 1 > dangerHealthLayer then HealthBar.HPBottom.Picture = HPBottomColors[2] else HealthBar.HPBottom.Picture = HPBottomColors[1] end elseif healingLayer == damageLayer - 1 then HPTopBarVisible = false HealthBar.HPBottom.Visible = true) HealthBar.HPBottom.Width = healingTop) if healing > 4*warningHealth then HealthBar.HPBottom.Picture = HPBottomColors[3] elseif healing > 4*dangerHealth then HealthBar.HPBottom.Picture = HPBottomColors[2] else HealthBar.HPBottom.Picture = HPBottomColors[1] end else HPTopBarVisible = false HealthBar.HPBottom.Visible = false end for selection,bar in ipairs(HPTopBars) do if selection == HPTopBar and healingLayer > 0 then bar.Visible = true and HPTopBarVisible bar.Width = healingTop bar.Picture = HPColors[selection][status] else bar.Visible = false) end end --------------------------------------------------------------------------------HP section, var health controls healing elements if healthLayer > 4 then HealingTopBar = 1 else HealingTopBar = 2 end if healthLayer >= damageLayer then HealingTopBarVisible = true HealthBar.HealingBottom.Visible = true HealthBar.HealingBottom.Width = 800 elseif healthLayer == damageLayer - 1 then HealingTopBarVisible = false HealthBar.HealingBottom.Visible = true HealthBar.HealingBottom.Width = 4*healthTop else HealingTopBarVisible = false HealthBar.HealingBottom.Visible = false end for selection,bar in ipairs(HealingTopBars) do if selection == HealingTopBar and healthLayer > 0 then bar.Visible = true and HealingTopBarVisible bar.Width = 4*healthTop else bar.Visible = false end end -------------------------------------------------------------------------------- if status == 1 and health > 0 then --HealthBar.AnimateTimer.Enabled = true HealthBar.HPOverlay.Hint = string.format("Watch it! Any more damage taken and %s is toast!",charName) else --HealthBar.AnimateTimer.Enabled = false --HealthBar.DangerGlow.Visible = false if health <= 0 then HealthBar.HPOverlay.Hint = string.format("%s is wasted",charName) else HealthBar.HPOverlay.Hint = string.format("%s's health points",charName) end end if damageLayer > 1 then HealthBar.HPBottom.Visible = true and HealthBar.HPBottom.Visible HealthBar.HealingBottom.Visible = true and HealthBar.HealingBottom.Visible HealthBar.DMGBottom.Visible = true else HealthBar.HPBottom.Visible = false HealthBar.HealingBottom.Visible = false HealthBar.DMGBottom.Visible = false end if damageLayer > 4 then HealthBar.DMGTop.Visible = true HealthBar.DMGTop.Width = damageTop HealthBar.DMGMiddle.Visible = false else HealthBar.DMGTop.Visible = false if damageLayer > 0 then HealthBar.DMGMiddle.Visible = true HealthBar.DMGMiddle.Width = damageTop else HealthBar.DMGMiddle.Visible = false end end for layer,indicator in ipairs(HPLayerIndicators) do if damageLayer > layer then indicator.Visible = true if layer > 1 then firstOffset = 2 else firstOffset = 1 end if healingLayer > layer then secondOffset = 3 if dangerHealthLayer >= layer then thirdOffset = 0 elseif warningHealthLayer >= layer then thirdOffset = 1 else thirdOffset = 2 end else if healthLayer > layer then secondOffset = 2 else secondOffset = 1 end thirdOffset = 0 end indicator.Picture = HPLayerColors[firstOffset][secondOffset+thirdOffset] else indicator.Visible = false end end end function HealthBar_AnimateTimerTimer(sender) HealthBar.DangerGlow.Visible = not HealthBar.DangerGlow.Visible end