CẤU HÌNH NHÂN VẬT & TỶ LỆ XUẤT HIỆN
local charactor = {“10359”, “10361”, “10363”, “10365”, “10368”, “10369”, “10370”, “10376”} local select_button = {
"7466769901929621097_58", "7466769901929621097_59", "7466769901929621097_60", "7466769901929621097_65", "7466769901929621097_30", "7466769901929621097_61", "7466769901929621097_64", "7466769901929621097_63"
} local phantramra = {13.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5}
– Các element của kho lưu trữ (hiển thị kết quả chưa ghép) local kho_du_tru = {
"7466769901929621097_18", "7466769901929621097_19", "7466769901929621097_20", "7466769901929621097_21", "7466769901929621097_22", "7466769901929621097_23", "7466769901929621097_51", "7466769901929621097_52"
}
– Biến tích lũy số lần trúng “con nguyện vọng” của vòng hiện tại local round_nguyen = 0
– XỬ LÝ THAY ĐỔI TỶ LỆ CHỌN NGUYỆN VỌNG –
function xulyphantram(e)
if e.uielement == select_button[1] then
phantramra = {13.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5}
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == select_button[2] then
phantramra = {12.5, 13.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == select_button[3] then
phantramra = {12.5, 12.5, 13.5, 12.5, 12.5, 12.5, 12.5, 12.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == select_button[4] then
phantramra = {12.5, 12.5, 12.5, 13.5, 12.5, 12.5, 12.5, 12.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == "7466769901929621097_62" then
phantramra = {12.5, 12.5, 12.5, 12.5, 13.5, 12.5, 12.5, 12.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == select_button[6] then
phantramra = {12.5, 12.5, 12.5, 12.5, 12.5, 13.5, 12.5, 12.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == select_button[7] then
phantramra = {12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 13.5, 12.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
elseif e.uielement == select_button[8] then
phantramra = {12.5, 12.5, 12.5, 12.5, 13.5, 12.5, 12.5, 13.5}
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_42")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_44")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_45")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_46")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_47")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_48")
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_49")
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_50")
end
if e.uielement == "7466769901929621097_66" then
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_32")
for i, v in ipairs(phantramra) do
print("Phần tử " .. i .. ": " .. v)
end
end
end ScriptSupportEvent:registerEvent(“UI.Button.Click”, xulyphantram)
– HÀM CHỌN NHÂN VẬT THEO TỶ LỆ & NGUYỆN VỌNG –
local function get_random_character()
local rand = math.random() * 100 -- Random từ 0 đến 100
local cumulative = 0
for i = 1, #phantramra do
cumulative = cumulative + phantramra[i]
if rand <= cumulative then
local chosen = charactor[i]
if chosen == "10376" then
round_nguyen = round_nguyen + 1
Player:notifyGameInfo2Self(nil, "Trúng con nguyện vọng! Điểm +1. Tổng điểm vòng này: " .. round_nguyen)
phantramra[i] = math.max(phantramra[i] * 0.8, 1)
end
return chosen
end
end
local chosen = charactor[#charactor]
if chosen == "10376" then
round_nguyen = round_nguyen + 1
print("Trúng con nguyện vọng! Điểm +1. Tổng điểm vòng này: " .. round_nguyen)
phantramra[#phantramra] = math.max(phantramra[#phantramra] * 0.8, 1)
end
return chosen
end
– CẤU HÌNH VỚI “TÚI QUAY” & “DỰ PHÒNG” –
local spin_slots = { – Danh sách các slot quay (theo thứ tự)
"7466769901929621097_24", "7466769901929621097_25", "7466769901929621097_26", "7466769901929621097_27", "7466769901929621097_28", "7466769901929621097_29", "7466769901929621097_30", "7466769901929621097_31"
}
local tui_status = {} for i, slot in ipairs(spin_slots) do
tui_status[slot] = 0
end
local bangnv_du = {
"7466769901929621097_18", "7466769901929621097_19", "7466769901929621097_20", "7466769901929621097_21", "7466769901929621097_22", "7466769901929621097_23"
}
– tui_list lưu các nhân vật quay được (bao gồm “con đơn” từ các vòng trước) local tui_list = {} local total_pairs = 0 – Tổng số cặp tích lũy qua các vòng
– solandcquay: số lượt quay của vòng hiện tại (vòng đầu = 8) local solandcquay = 8 – solan: số lượt đã thực hiện trong vòng hiện tại local solan = 0
– HÀM QUAY “TÚI” VÀ CẬP NHẬT GIAO DIỆN –
function boctuimu(e)
if tui_status[e.uielement] == 0 and solan < solandcquay then
local selected_char = get_random_character()
Customui:setTexture(e.eventobjid, "7466769901929621097", e.uielement, selected_char)
solan = solan + 1
print("Số lần mở túi (vòng này): " .. solan .. " / " .. solandcquay)
table.insert(tui_list, {id = selected_char, slot = e.uielement})
tui_status[e.uielement] = 1
if solan == solandcquay then
print("Đã đủ lượt quay của vòng, bắt đầu xử lý ghép cặp.")
-- Sau khi bốc full, reset texture của kho lưu trữ (hiển thị các spin chưa ghép)
reset_kho_du_tru(e)
Trigger:wait(0.1)
process_duplicates(e)
end
end
end
– HÀM XỬ LÝ GHÉP CẶP VÀ TÍNH LẠI LƯỢT QUAY VÒNG MỚI –
function process_duplicates(e)
local found_pairs = {}
local round_pairs = 0 -- Số cặp ghép được (tính từ toàn bộ tui_list)
for _, data in ipairs(tui_list) do
found_pairs[data.id] = (found_pairs[data.id] or 0) + 1
end
for char, count in pairs(found_pairs) do
local pairs_for_char = math.floor(count / 2)
round_pairs = round_pairs + pairs_for_char
total_pairs = total_pairs + pairs_for_char
print("🔹 Ghép được " .. pairs_for_char .. " cặp của nhân vật ID: " .. char)
end
Trigger:wait(0.1)
update_ui()
local next_round_spins = (round_pairs) + round_nguyen
if next_round_spins < 0 then next_round_spins = 0 end
print("Vòng này: " .. round_pairs .. " cặp ghép, " .. round_nguyen .. " lần trúng nguyện vọng.")
print("=> Lượt quay cho vòng mới: " .. next_round_spins)
solandcquay = next_round_spins
print("Tổng số cặp tích lũy: " .. total_pairs)
Trigger:wait(2)
Customui:showElement(e.eventobjid, "7466769901929621097", "7466769901929621097_69")
Customui:setText(e.eventobjid, "7466769901929621097", "7466769901929621097_70",
"Vòng này: " .. round_pairs .. " cặp ghép, " .. round_nguyen .. " lần trúng nguyện vọng.")
-- Loại bỏ các spin đã ghép khỏi tui_list (chỉ giữ lại những spin chưa ghép)
local new_tui_list = {}
for spin, count in pairs(found_pairs) do
local remainder = count % 2
for i = 1, remainder do
table.insert(new_tui_list, {id = spin})
end
end
tui_list = new_tui_list
-- Reset lại giao diện kho lưu trữ với danh sách tui_list mới
reset_kho_du_tru(e)
xulyui(e)
if solandcquay > 0 then
solan = 0
round_nguyen = 0
for i, slot in ipairs(spin_slots) do
if i <= solandcquay then
tui_status[slot] = 0
Customui:showElement(e.eventobjid, "7466769901929621097", slot)
else
tui_status[slot] = 1
Customui:hideElement(e.eventobjid, "7466769901929621097", slot)
end
end
print("Bắt đầu vòng mới với " .. solandcquay .. " lượt quay.")
else
print("Trò chơi kết thúc. Không còn lượt quay.")
Player:hideUIView(e.eventobjid,"7466769901929621097")
Chat:sendSystemMsg("Hết lượt quay")
end
end
– CẬP NHẬT GIAO DIỆN “CON ĐƠN” (dành cho slot dự phòng) –
function update_ui()
for i = 1, solandcquay do
local texture = "10041"
if tui_list[i] then
texture = tui_list[i].id
end
Customui:setTexture(nil, "7466769901929621097", "7466769901929621097_" .. tostring(17 + i), texture)
end
end
– HÀM RESET TEXTURE CHO KHO LƯU TRỮ –
– Ở đây, kho lưu trữ sẽ được cập nhật với dữ liệu của tui_list (chỉ chứa spin chưa ghép) function reset_kho_du_tru(e)
for i, slot in ipairs(kho_du_tru) do
local texture = "10041"
if tui_list[i] then
texture = tui_list[i].id
end
Customui:setTexture(e.eventobjid, "7466769901929621097", slot, texture)
end
end
– XỬ LÝ UI: Ẩn các túi chưa được bốc (hoặc reset giao diện) –
function xulyui(e)
if e.uielement == "7466769901929621097_71" then
Customui:hideElement(e.eventobjid, "7466769901929621097", "7466769901929621097_69")
for i, slot in ipairs(spin_slots) do
Customui:setTexture(e.eventobjid, "7466769901929621097", slot, "20040")
end
end
if e.uielement == "7466769901929621097_71" and next_round_spins == 0 then
end end
– ĐĂNG KÝ SỰ KIỆN CHO NÚT –
ScriptSupportEvent:registerEvent(“UI.Button.Click”, boctuimu) ScriptSupportEvent:registerEvent(“UI.Button.Click”, xulyui)