developer_center:developer_editor:rotation_luck
Table of Contents
ROTATION LUCK
I. Design UI
You can change items
II. Diagram
III. Script
local display_number = {1, 2, 3, 4} local items = {12499, 11600, 11667, 11668} -- fill your items here local pictures = {"1012499", "1011600", "1011667", '1011668'} -- fill your pictures following the items here here function spin(e) if e.uielement == '7369828431314806377_12' then --- change your button local repeat_time = 0 local random_number local items_spin local picture_spin repeat random_number = display_number[math.random(#display_number)] items_spin = items[random_number] picture_spin = pictures[random_number] repeat_time = repeat_time + 1 Customui:setTexture(e.eventobjid, [[7369828431314806377]],[[7369828431314806377_10]], picture_spin) --- change your element Trigger:wait(0.1) until repeat_time == nil --- fill your time here Player:gainItems(e.eventobjid, items_spin, 1, 1) end end ScriptSupportEvent:registerEvent('UI.Button.Click', spin)
IV. Explaination
1. Initialization of Arrays:
local display_number = {1, 2, 3, 4} local items = {12499, 11600, 11667, 11668} -- fill your items here local pictures = {"1012499", "1011600", "1011667", '1011668'} -- fill your pictures following the items here here
- display_number is an array that holds indices (1 to 4). These are used to randomly pick an item and its corresponding picture.
- items is an array holding item IDs.
- pictures is an array holding picture IDs corresponding to the items.
2. Spin Function
function spin(e) if e.uielement == '7369828431314806377_12' then local repeat_time = 0 local random_number local items_spin local picture_spin repeat random_number = display_number[math.random(#display_number)] items_spin = items[random_number] picture_spin = pictures[random_number] repeat_time = repeat_time + 1 Customui:setTexture(e.eventobjid, [[7369828431314806377]],[[7369828431314806377_10]], picture_spin) Trigger:wait(0.1) until repeat_time == nil --- fill your time here Player:gainItems(e.eventobjid, items_spin, 1, 1) end end
- spin(e) is the function that handles the spinning and item reward process.
- It checks if the clicked UI element (e.uielement) matches the specified ID (7369828431314806377_12).
- It initializes repeat_time to 0, which will count how many times the loop runs.
- Inside the repeat loop:
- random_number is assigned a random value from display_number.
- items_spin is set to the item ID at the random_number index in the items array.
- picture_spin is set to the picture ID at the random_number index in the pictures array.
- The texture of the UI element is set to picture_spin using Customui:setTexture.
- The script waits for 0.1 seconds before the next iteration.
- The loop continues until repeat_time reaches a certain value (which is not specified here, you need to set it appropriately).
- After the loop, the player is given the selected item using Player:gainItems.
3. Event Registration:
ScriptSupportEvent:registerEvent('UI.Button.Click', spin)
This line registers the spin function to be called whenever the UI.Button.Click event occurs.
V. Summary of the Script
Initialization:
- Arrays for display numbers, item IDs, and picture IDs are defined.
Spin Function:
- When a specific UI button is clicked, the function starts a loop.
- It randomly selects an item and its picture, updates the UI texture, and waits 0.1 seconds in each iteration.
- The loop runs for a specified number of times (you need to fill in the appropriate condition for repeat_time).
- After the loop, the player is rewarded with the randomly selected item.
Event Registration:
- The spin function is registered to handle button click events.
Adjustments Needed Define Loop End Condition: Replace until repeat_time == nil with a proper condition, such as until repeat_time == 10 (or any other number based on how many spins you want). Ensure UI Element IDs are Correct: Verify that the UI element IDs match those in your actual project.
If you have any questions about Developer Tools, feel free to join our official discord server Mini World Global DEV discord
developer_center/developer_editor/rotation_luck.txt · Last modified: 2024/05/17 10:27 by don