Bom dia, estou utilizando um sistema de roleta em meu servidor, está funcionando perfeitamente porém estou com um pouco de problema na hora de configurar as porcentagens de chance de ganho de cada item, gostaria de entender melhor a parte de chance desse script.
local tiles = {
Position(32163, 32295, 6),
Position(32164, 32295, 6),
Position(32165, 32295, 6),
Position(32166, 32295, 6), -- Center Tile is winning Tile --
Position(32167, 32295, 6),
Position(32168, 32295, 6),
Position(32169, 32295, 6)
}
local items = {
-- Chance Win / itemid / amount / chance amount (out of 100000)
[{1, 10001}] = {itemid = 3079, amount = 1, amountChance = 80000}, -- 1, 10001 = 10000 (100000/10000 = 10% chance to win) [100000 / 80000 = 80% chance for amount to increase]
[{10002, 20002}] = {itemid = 3388, amount = 1, amountChance = 70000},
[{20003, 30003}] = {itemid = 43869, amount = 1, amountChance = 60000},
[{30004, 40004}] = {itemid = 43886, amount = 1, amountChance = 50000},
[{40005, 50005}] = {itemid = 43880, amount = 1, amountChance = 40000},
[{50006, 60006}] = {itemid = 43878, amount = 1, amountChance = 30000},
[{60007, 70007}] = {itemid = 3389, amount = 1, amountChance = 25000},
[{70008, 80008}] = {itemid = 3387, amount = 1, amountChance = 15000},
[{80009, 90009}] = {itemid = 5903, amount = 1, amountChance = 10000}
}
-- local items = {
-- -- Chance Win / itemid / amount / chance amount (out of 100000)
-- [{1, 80001}] = {itemid = 3387, amount = 5, amountChance = 80000}, -- 1, 10001 = 10000 (100000/10000 = 10% chance to win) [100000 / 80000 = 80% chance for amount to increase]
-- [{80002, 85002}] = {itemid = 3388, amount = 5, amountChance = 50000},
-- [{85003, 88003}] = {itemid = 2160, amount = 5, amountChance = 25000}
-- }
local itemsList = {3387, 3388, 3389, 43869, 43886, 43880, 43878, 3079, 5903}
local canGetNoItem = false -- If true players can get nothing at all. --
local autoWin = {itemid = 3043, amount = 100, amountChance = 99999999} -- Item that is always won if they have to get something. --
local leverAID = 53452 -- AID in map for item that is used to roll --
local leverItemID = 1723 -- itemid for item that is used to roll --
-- Item required to spin activate roulette --
local itemRequired = 23681
local itemAmount = 1
local roulette = Action()
function roulette.onUse(player, item, fromPosition, target, toPosition, isHotkey)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
if not player:removeItem(itemRequired, itemAmount) then
return player:sendCancelMessage("Você não tem "..itemAmount.." "..ItemType(itemRequired):getName()..".")
end
local rand = math.random(100000)
local win = false
for i, v in pairs(items) do
if rand >= i[1] and rand <= i[2] then
win = items[i]
break
end
end
if not canGetNoItem and not win then
win = autoWin
end
local winAmount = 0
if win then
for i = 1, win.amount do
local rand = math.random(100000)
if rand <= win.amountChance then
winAmount = winAmount + 1
end
end
end
rollItems(win, winAmount, 30, player:getName())
return true
end
function rollItems(winTable, winAmount, spins, name)
moveItems()
if spins == 3 then
if not winTable then
spins = spins - 1
addEvent(rollItems, 200, winTable, winAmount, spins, name)
return true
end
Game.createItem(winTable.itemid, winAmount, tiles[1])
spins = spins - 1
addEvent(rollItems, 200, winTable, winAmount, spins, name)
return true
end
if spins >= 1 and spins ~= 3 then
local randEmpty = math.random(6)
if randEmpty == 1 then
spins = spins - 1
addEvent(rollItems, 200, winTable, winAmount, spins, name)
return true
end
local randomItem = itemsList[math.random(#itemsList)]
local itemType = ItemType(randomItem)
if itemType:isStackable() then
Game.createItem(randomItem, math.random(5), tiles[1])
else
Game.createItem(randomItem, 1, tiles[1])
end
spins = spins - 1
addEvent(rollItems, 200, winTable, winAmount, spins, name)
return true
end
if spins == 0 then
giveReward(winTable, winAmount, name)
end
end
function moveItems()
local tileItems = {}
for i = 1, #tiles do
local tile = Tile(tiles[i])
if tile and tile:getTopDownItem() then
tileItems[i] = tile:getTopDownItem()
elseif tile and not tile:getTopDownItem() then
tileItems[i] = false
end
end
for i = 1, #tileItems do
if i == 7 and tileItems[i] ~= false then
tileItems[i]:remove()
return true
elseif tileItems[i] ~= false then
tileItems[i]:moveTo(tiles[i + 1])
end
end
end
function giveReward(winTable, winAmount, name)
local player = Player(name)
if not player then return true end
if not winTable then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "TESTE")
return true
end
player:addItem(winTable.itemid, winAmount)
player:getPosition():sendMagicEffect(CONST_ME_FIREAREA)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Parabéns! Você recebeu um(a) "..ItemType(winTable.itemid):getName()..".")
-- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You won "..winAmount.." "..ItemType(winTable.itemid):getName()..".")
end
roulette:id(leverItemID)
roulette:register()
Pergunta
olimpiamarkin 16
Bom dia, estou utilizando um sistema de roleta em meu servidor, está funcionando perfeitamente porém estou com um pouco de problema na hora de configurar as porcentagens de chance de ganho de cada item, gostaria de entender melhor a parte de chance desse script.
local tiles = { Position(32163, 32295, 6), Position(32164, 32295, 6), Position(32165, 32295, 6), Position(32166, 32295, 6), -- Center Tile is winning Tile -- Position(32167, 32295, 6), Position(32168, 32295, 6), Position(32169, 32295, 6) } local items = { -- Chance Win / itemid / amount / chance amount (out of 100000) [{1, 10001}] = {itemid = 3079, amount = 1, amountChance = 80000}, -- 1, 10001 = 10000 (100000/10000 = 10% chance to win) [100000 / 80000 = 80% chance for amount to increase] [{10002, 20002}] = {itemid = 3388, amount = 1, amountChance = 70000}, [{20003, 30003}] = {itemid = 43869, amount = 1, amountChance = 60000}, [{30004, 40004}] = {itemid = 43886, amount = 1, amountChance = 50000}, [{40005, 50005}] = {itemid = 43880, amount = 1, amountChance = 40000}, [{50006, 60006}] = {itemid = 43878, amount = 1, amountChance = 30000}, [{60007, 70007}] = {itemid = 3389, amount = 1, amountChance = 25000}, [{70008, 80008}] = {itemid = 3387, amount = 1, amountChance = 15000}, [{80009, 90009}] = {itemid = 5903, amount = 1, amountChance = 10000} } -- local items = { -- -- Chance Win / itemid / amount / chance amount (out of 100000) -- [{1, 80001}] = {itemid = 3387, amount = 5, amountChance = 80000}, -- 1, 10001 = 10000 (100000/10000 = 10% chance to win) [100000 / 80000 = 80% chance for amount to increase] -- [{80002, 85002}] = {itemid = 3388, amount = 5, amountChance = 50000}, -- [{85003, 88003}] = {itemid = 2160, amount = 5, amountChance = 25000} -- } local itemsList = {3387, 3388, 3389, 43869, 43886, 43880, 43878, 3079, 5903} local canGetNoItem = false -- If true players can get nothing at all. -- local autoWin = {itemid = 3043, amount = 100, amountChance = 99999999} -- Item that is always won if they have to get something. -- local leverAID = 53452 -- AID in map for item that is used to roll -- local leverItemID = 1723 -- itemid for item that is used to roll -- -- Item required to spin activate roulette -- local itemRequired = 23681 local itemAmount = 1 local roulette = Action() function roulette.onUse(player, item, fromPosition, target, toPosition, isHotkey) player:getPosition():sendMagicEffect(CONST_ME_POFF) if not player:removeItem(itemRequired, itemAmount) then return player:sendCancelMessage("Você não tem "..itemAmount.." "..ItemType(itemRequired):getName()..".") end local rand = math.random(100000) local win = false for i, v in pairs(items) do if rand >= i[1] and rand <= i[2] then win = items[i] break end end if not canGetNoItem and not win then win = autoWin end local winAmount = 0 if win then for i = 1, win.amount do local rand = math.random(100000) if rand <= win.amountChance then winAmount = winAmount + 1 end end end rollItems(win, winAmount, 30, player:getName()) return true end function rollItems(winTable, winAmount, spins, name) moveItems() if spins == 3 then if not winTable then spins = spins - 1 addEvent(rollItems, 200, winTable, winAmount, spins, name) return true end Game.createItem(winTable.itemid, winAmount, tiles[1]) spins = spins - 1 addEvent(rollItems, 200, winTable, winAmount, spins, name) return true end if spins >= 1 and spins ~= 3 then local randEmpty = math.random(6) if randEmpty == 1 then spins = spins - 1 addEvent(rollItems, 200, winTable, winAmount, spins, name) return true end local randomItem = itemsList[math.random(#itemsList)] local itemType = ItemType(randomItem) if itemType:isStackable() then Game.createItem(randomItem, math.random(5), tiles[1]) else Game.createItem(randomItem, 1, tiles[1]) end spins = spins - 1 addEvent(rollItems, 200, winTable, winAmount, spins, name) return true end if spins == 0 then giveReward(winTable, winAmount, name) end end function moveItems() local tileItems = {} for i = 1, #tiles do local tile = Tile(tiles[i]) if tile and tile:getTopDownItem() then tileItems[i] = tile:getTopDownItem() elseif tile and not tile:getTopDownItem() then tileItems[i] = false end end for i = 1, #tileItems do if i == 7 and tileItems[i] ~= false then tileItems[i]:remove() return true elseif tileItems[i] ~= false then tileItems[i]:moveTo(tiles[i + 1]) end end end function giveReward(winTable, winAmount, name) local player = Player(name) if not player then return true end if not winTable then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "TESTE") return true end player:addItem(winTable.itemid, winAmount) player:getPosition():sendMagicEffect(CONST_ME_FIREAREA) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Parabéns! Você recebeu um(a) "..ItemType(winTable.itemid):getName()..".") -- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You won "..winAmount.." "..ItemType(winTable.itemid):getName()..".") end roulette:id(leverItemID) roulette:register()
Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados