Как сделать в донате товар например: Случайный донат и он будет выдать случайный донат который указан ниже по шансам.
Например:
Пушка - 0.1%
100 руб. - 0.5%
$10.000.000 - 1%
$1.000.000 - 5%
15 руб. - 15%
$500.000 - 30%
Нечего не выпадет - 48.4%
ЧТОБЫ НЕ ПРОСТО РАНДОМНАЯ ПУШКИ ВЫПАЛА, А ПО ШАНСАМ ОНА БЫЛА!
Я тут полусонный, так что мог где-то ошибиться, но вроде должно работать
local numbers = {}
local AddNumber = function(number, chance)
table.insert(numbers, {number = number, chance = chance*10})
end
local GetRandomNumber = function()
local totalChance = 0
for _, data in ipairs(numbers) do
totalChance = totalChance + data.chance
end
local randomValue = math.random(1, totalChance)
local currentChance = 0
for _, data in ipairs(numbers) do
currentChance = currentChance + data.chance
if randomValue <= currentChance then
return data.number
end
end
return nil
end
local test = {
[1] = function()
print(":Р")
end,
[2] = function(pl)
print(pl:Nick()..", how are you?")
end,
[3] = function()
print("meow.")
end,
}
AddNumber(1, 0.1)
AddNumber(2, 0.5)
AddNumber(3, 15)
IGS("Новогодний рандомный набор","new_year2023")
:SetPrice(125)
:SetCategory("Наборы")
:SetDescription("бублик")
:SetIcon("https://i.imgur.com/TWBTnK6.png")
:SetPremiumPoints(10000)
:SetOnActivate(function(pl)
test[GetRandomNumber()](pl)
table.Empty(numbers)
IGS.NotifyAll(pl:Name() .. " приобрёл новогодний рандомный набор.")
IGS.Notify(pl, "С наступающим 2023 годом!")
end)