Step 1: You need to remember to change the width of the process picture to 0
Step 2: Also, you need to remember the first width of the process picture
local loading_picture = nil
local ratio = nil
local the_first_width_value = nil
-- Define the game function to update the UI
function game(obj)
repeat
-- Set the size of the UI element
Customui:setSize(obj.eventobjid, loading_picture[1], loading_picture[2], width_value, 86)
-- Increment the width value by a random number between 0 and 5
width_value = width_value + math.random(6)
--Calculate the percentage of the current width relative to the initial width
local percentage = (width_value / the_first_width_value) * 100
-- Set the text with the calculated percentage (formatted with no decimal places)
Customui:setText(obj.eventobjid, ratio[1], ratio[2], string.format("%.0f%%", percentage))
-- Wait for 0.01 seconds before the next iteration
Trigger:wait(0.01)
-- If the width value exceeds the initial width, set it to the initial width
if width_value > the_first_width_value then
width_value = the_first_width_value
end
-- Repeat until the width value reaches the initial width
until width_value == the_first_width_value
end
-- Register the game function to be triggered when the UI is shown
ScriptSupportEvent:registerEvent("UI.Show", game)
local loading_picture = nil local ratio = nil local the_first_width_value = nil loading_picture = nil -- Replace with your picture IDs ratio = nil -- Replace with your ratio IDs
These lines initialize some variables:
function game(obj)
repeat
-- Set the size of the UI element
Customui:setSize(obj.eventobjid, loading_picture[1], loading_picture[2], width_value, 86)
-- Increment the width value by a random number between 0 and 5
width_value = width_value + math.random(6)
-- Calculate the percentage of the current width relative to the initial width
local percentage = (width_value / the_first_width_value) * 100
-- Set the text with the calculated percentage (formatted with no decimal places)
Customui:setText(obj.eventobjid, ratio[1], ratio[2], string.format("%.0f%%", percentage))
-- Wait for 0.01 seconds before the next iteration
Trigger:wait(0.01)
-- If the width value exceeds the initial width, set it to the initial width
if width_value > the_first_width_value then
width_value = the_first_width_value
end
-- Repeat until the width value reaches the initial width
until width_value == the_first_width_value
end
ScriptSupportEvent:registerEvent("UI.Show", game)
ScriptSupportEvent:registerEvent(“UI.Show”, game): Registers the game function to be called when the UI.Show event occurs.
This script initializes variables and defines a function (game) that simulates a loading bar increasing over time by updating the width and percentage text of UI elements. The function runs in a loop, increasing the width incrementally until it reaches a specified initial width. The function is triggered by the UI.Show event.