@Arthasz Walker,
Desculpa, fiz um erro besta, nem lembrei que prices era um array kkk. Acho que dessa vez vai, desculpa mesmo não estar podendo testar no momento estou sem meu desktop com os arquivos de otserver
Tenta essa versão:
-- Configuracoes necessarias para o script
local config = {
quest = { -- Precisa fazer quest? (Nao mexa caso negativo)
necessaria = false, -- Eh necessario fazer uma quest para liberar o sistema?
storageID = 10001, -- Qual o storageID dessa quest? (caso true, anteriormente)
},
chestPos = {x = 92, y = 114, z = 7, stackpos = 1}, -- Posicao do Bau (certifique-se que nao tenha nada encima dele)
-- Tenha atencao para que a soma das chances dos helds em cada tier seja igual a 100
prices = {
["tier_1"] = 60000,
["tier_2"] = 150000,
["tier_3"] = 300000,
["tier_4"] = 700000,
["tier_5"] = 1000000,
["tier_6"] = 1500000,
},
helds = { -- Item IDs e chance de vir o held
[1] = { -- Array Tier 1
{ID = 2159, chance = 10},
{ID = 2160, chance = 80},
{ID = 2158, chance = 10},
},
[2] = { -- Array Tier 2
{ID = 2000, chance = 20},
{ID = 2001, chance = 20},
{ID = 2002, chance = 20},
{ID = 2003, chance = 20},
{ID = 2004, chance = 20},
},
[3] = { -- Array Tier 3
},
[4] = { -- Array Tier 4
},
[5] = { -- Array Tier 5
},
[6] = { -- Array Tier 6
},
[7] = { -- Array Tier 7
},
},
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if config.quest.necessaria and getPlayerStorageValue (cid, config.quest.storageID) == 0 then
-- Erro caso a pessoa use a maquina sem ter feito a quest
-- Valido apenas quando a opcao esta ativada
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don\'t have permission to use this machine.")
return false
end
items = {nil, nil, nil}
container = getThingFromPos(config.chestPos)
for i = 0, 2 do
items[i + 1] = getContainerItem (container.uid, i)
if items [i + 1].itemid == 0 or items [i + 1].itemid == nil then
-- Erro quando tem menos de 3 itens no bau
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need 3 held items to fuse.")
return false
end
end
heldType = {nil, nil, nil}
for j=1, 3 do
for i=1, 7 do
for k = 1, #config.helds[i] do
if config.helds[i][k].ID == items[j].itemid then
heldType[j] = i
end
end
end
if heldType [j] == nil then
-- Erro a ser exibido caso o jogador coloque algum item que nao seja um held na maquina
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "This machine works only to held items.")
return false
end
end
if heldType[1] ~= heldType[2] or heldType[2] ~= heldType[3] then
-- Erro a ser exibido caso o jogador coloque helds de tiers diferentes
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need helds with the same tier.")
return false
elseif heldType[1] == 7 or heldType[2] == 7 or heldType[3] == 7 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot fuse tier 7 held items.")
return false
end
if not doPlayerRemoveMoney(cid, config.prices["tier_"..heldType[1]]) then -- Se nao for possivel retirar a quantia de dinheiro do jogador, finalizar script
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need " .. config.prices.tier_..heldType[1] .. " gold to fuse tier ".. heldType[1].. " held items.")
return false
end
-- Sortear qual held vira
for i = 1, 3 do
doRemoveItem(items[i].uid, 1)
end
tierSorteado = heldType[1] + 1
numeroSorte = math.random(1, 100)
itemIDSorteado = sorteiaValor (tierSorteado, numeroSorte)
doPlayerAddItem(cid, itemIDSorteado, 1)
-- Mensagem exibida ao fundir com sucesso
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received your new held item.")
return true
end
-- Função retirada de https://pt.stackoverflow.com/questions/147884/sorteio-aleat%C3%B3rio-mas-com-diferentes-probabilidades
function sorteiaValor (tierSorteado, numeroSorte)
x = numeroSorte
for i = 1, #config.helds[tierSorteado] do
x = x - config.helds[tierSorteado][i].chance
if x <= 0 then
return config.helds[tierSorteado][i].ID
end
end
end