Postado Fevereiro 24, 2015 10 anos Hm, troca por esse código: local price = {itemid, count} --Troque itemid pelo ID do item que será cobrado, e count pela quantia. local items = { --[itemid] = {chance, count}, >> Onde itemid é o ID do item, chance, obviamente, a chance dele ser sorteado, e count, a quantidade. --Exemplo: >> Para adicionar mais items, siga o modelo indicado acima. [itemid] = {chance, count}, --[2160] = {50, 10}, >> Assim, o item de ID 2160 teria 50% de chance de ser sorteado. Quantidade -> 10. [8303] = {70, 5}, [8302] = {70, 5}, [7422] = {30, 1}, } function onUse(cid) local _table = {} local number = math.random(1, 100) local item = 0 if doPlayerRemoveItem(cid, price[1], price[2]) then for itemid, chance in pairs(items) do if item == 0 then table.insert(_table, itemid) item = itemid else local new_chance = math.abs(chance[1] - number) local old_chance = math.abs(items[item][1] - number) if new_chance < old_chance then if #_table > 0 then _table = {} end table.insert(_table, itemid) item = itemid elseif new_chance == old_chance then table.insert(_table, itemid) end end end if item ~= 0 then if #_table > 1 then item = _table[math.random(1, #_table)] end local count = items[item][2] if not isItemStackable(item) then if count > 1 then for i = 1, count do doPlayerAddItem(cid, item, 1) end else doPlayerAddItem(cid, item, 1) end else doPlayerAddItem(cid, item, count) end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: "..count.."x "..getItemNameById(item)..(count > 1 and "s" or "")..".") end else return doPlayerSendCancel(cid, "You do not have "..price[2].." "..getItemNameById(price[1])..".") end return true end não respondo pms solicitando suporte em programação/scripting
Postado Fevereiro 25, 2015 10 anos Autor Deu certinho valeu! Rep+ A unica coisa é que eu deixei 30% um item e na maioria das vezes vem de primeira, mas isso depois eu tento arrumar. @Edit Então ta funcionando tudo certinho 100%, só gostaria de saber se é possível quando a pessoa apostar aparecer para todo mundo assim no meio da tela e no chat default. Fulano apostou e ganhou (Rare staff). Editado Fevereiro 25, 2015 10 anos por Kd meu arrozz (veja o histórico de edições)
Postado Fevereiro 25, 2015 10 anos A mensagem só vai aparecer com o item raro, ou com todos os items? não respondo pms solicitando suporte em programação/scripting
Postado Fevereiro 26, 2015 10 anos Solução local price = {itemid, count} --Troque itemid pelo ID do item que será cobrado, e count pela quantia. local items = { --[itemid] = {chance, count}, >> Onde itemid é o ID do item, chance, obviamente, a chance dele ser sorteado, e count, a quantidade. --Exemplo: >> Para adicionar mais items, siga o modelo indicado acima. [itemid] = {chance, count}, --[2160] = {50, 10}, >> Assim, o item de ID 2160 teria 50% de chance de ser sorteado. Quantidade -> 10. [8303] = {70, 5}, [8302] = {70, 5}, [7422] = {30, 1}, } function onUse(cid) local _table = {} local number = math.random(1, 100) local item = 0 if doPlayerRemoveItem(cid, price[1], price[2]) then for itemid, chance in pairs(items) do if item == 0 then table.insert(_table, itemid) item = itemid else local new_chance = math.abs(chance[1] - number) local old_chance = math.abs(items[item][1] - number) if new_chance < old_chance then if #_table > 0 then _table = {} end table.insert(_table, itemid) item = itemid elseif new_chance == old_chance then table.insert(_table, itemid) end end end if item ~= 0 then if #_table > 1 then item = _table[math.random(1, #_table)] end local count = items[item][2] if not isItemStackable(item) then if count > 1 then for i = 1, count do doPlayerAddItem(cid, item, 1) end else doPlayerAddItem(cid, item, 1) end else doPlayerAddItem(cid, item, count) end broadcastMessage(getCreatureName(cid).." apostou e ganhou "..getItemNameById(item)..".") doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: "..count.."x "..getItemNameById(item)..(count > 1 and "s" or "")..".") end else return doPlayerSendCancel(cid, "You do not have "..price[2].." "..getItemNameById(price[1])..".") end return true end não respondo pms solicitando suporte em programação/scripting
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.