Ir para conteúdo

(Resolvido)[PEDIDO] Adicionar chances


Ir para solução Resolvido por Snowsz,

Posts Recomendados

Postado

Olá pessoal!
 

Estou usando o sistema(action) do shumagora, que funciona como um baú que ao abrir pode vir os itens configurados..

baualeatorio.lua

function onUse(cid, item, fromPosition, itemEx, toPosition)

local rand = math.random(0, 11)
local lotteryid = 4850

  if item.itemid == lotteryid then
if rand == 0 then
   doCreatureSay(cid, "Abriu e ganhou 15x HANDGUN AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11389,15)
doRemoveItem(cid, item.uid, 1)
elseif rand == 1 then
   doCreatureSay(cid, "Abriu e ganhou 15x MAGNUM AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11390,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 2 then
   doCreatureSay(cid, "Abriu e ganhou 15x SHOTGUN AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11391,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 3 then
   doCreatureSay(cid, "Abriu e ganhou 15x RIFLE AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11392,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 4 then
   doCreatureSay(cid, "Abriu e ganhou 15x MACHINEGUN AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11394,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 5 then
   doCreatureSay(cid, "Abriu e ganhou 15x ACID AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11395,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 6 then
   doCreatureSay(cid, "Abriu e ganhou 15x EXPLOSIVE AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11396,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 7 then
   doCreatureSay(cid, "Abriu e ganhou 15x NITROGEN AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11397,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 8 then
   doCreatureSay(cid, "Abriu e ganhou 15x FLASH AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11398,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 9 then
   doCreatureSay(cid, "Abriu e ganhou 15x ELETRIC AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11399,15)
doRemoveItem(cid, item.uid, 1)
   elseif rand == 10 then
   doCreatureSay(cid, "Abriu e ganhou 15x FLAME AMMO!", TALKTYPE_ORANGE_1)
      doPlayerAddItem(cid, 11400,15)
doRemoveItem(cid, item.uid, 1)
            --! se quiser que quebra -->
   elseif rand == 11 then
   doCreatureSay(cid, "BROKE!", TALKTYPE_ORANGE_1)
    doRemoveItem(cid, item.uid, 1)
    end
  end
return TRUE
end

 

Action TAG

     <action itemid="4850" event="script" value="baualeatorio.lua"/> 


Vim ao suporte pedir que adicionem uma chance de cada item, pq do jeito que tá é uma chancezinha aleatória.. queria tipo assim:

ITEM 1 -  67% de chance

ITEM 2 - 12% de chance

ITEM 3 - 5% de chance

ITEM 4 - 15% de chance

ITEM 5 - 1% de chance

ITEM 6 - 3% de chance

ITEM 7 - 0.5% de chance       (se possível.. ficaria legal tbm mas não é tão necessário euehuehe)


espero que consigam entender o que to falando.. cada item com uma porcentagem de chances de vir ao invés de aleatória.


grato desde já!

  • Solução
Postado (editado)

function onUse(cid, item, fromPosition, itemEx, toPosition)

local rand = math.random(1, 120)

    if rand <= 10 then
        doCreatureSay(cid, "Abriu e ganhou 15x HANDGUN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11389,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 20 then
        doCreatureSay(cid, "Abriu e ganhou 15x MAGNUM AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11390,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 30 then
        doCreatureSay(cid, "Abriu e ganhou 15x SHOTGUN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11391,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 40 then
        doCreatureSay(cid, "Abriu e ganhou 15x RIFLE AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11392,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 50 then
        doCreatureSay(cid, "Abriu e ganhou 15x MACHINEGUN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11394,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 60 then
        doCreatureSay(cid, "Abriu e ganhou 15x ACID AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11395,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 70 then
        doCreatureSay(cid, "Abriu e ganhou 15x EXPLOSIVE AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11396,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 80 then
        doCreatureSay(cid, "Abriu e ganhou 15x NITROGEN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11397,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 90 then
        doCreatureSay(cid, "Abriu e ganhou 15x FLASH AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11398,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 100 then
        doCreatureSay(cid, "Abriu e ganhou 15x ELETRIC AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11399,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 110 then
        doCreatureSay(cid, "Abriu e ganhou 15x FLAME AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11400,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand >= 110 then
        doCreatureSay(cid, "BROKE!", TALKTYPE_ORANGE_1)
        doRemoveItem(cid, item.uid, 1)
    end
    
    return true
end

Sua explicação ficou confusa, então, use isso e teste, pois não são 7 items, são mais que isso, coloquei chances de 10% até 100% de pegar tal item, bom, veja se está bom para você.

 

Acima de "elseif rand == 1 then", Você coloca isso onde ta 75 e a %.

if math.random(1, 100) >= 1 and math.random(1, 100) <= 75 then

E você está errado.

Editado por Snowsz (veja o histórico de edições)
Postado

 

Acima de "elseif rand == 1 then", Você coloca isso onde ta 75 e a %.

if math.random(1, 100) >= 1 and math.random(1, 100) <= 75 then

agradeço por tentar ajudar

 

 

function onUse(cid, item, fromPosition, itemEx, toPosition)

local rand = math.random(1, 120)

    if rand <= 10 then
        doCreatureSay(cid, "Abriu e ganhou 15x HANDGUN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11389,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 20 then
        doCreatureSay(cid, "Abriu e ganhou 15x MAGNUM AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11390,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 30 then
        doCreatureSay(cid, "Abriu e ganhou 15x SHOTGUN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11391,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 40 then
        doCreatureSay(cid, "Abriu e ganhou 15x RIFLE AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11392,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 50 then
        doCreatureSay(cid, "Abriu e ganhou 15x MACHINEGUN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11394,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 60 then
        doCreatureSay(cid, "Abriu e ganhou 15x ACID AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11395,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 70 then
        doCreatureSay(cid, "Abriu e ganhou 15x EXPLOSIVE AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11396,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 80 then
        doCreatureSay(cid, "Abriu e ganhou 15x NITROGEN AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11397,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 90 then
        doCreatureSay(cid, "Abriu e ganhou 15x FLASH AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11398,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 100 then
        doCreatureSay(cid, "Abriu e ganhou 15x ELETRIC AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11399,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand <= 110 then
        doCreatureSay(cid, "Abriu e ganhou 15x FLAME AMMO!", TALKTYPE_ORANGE_1)
        doPlayerAddItem(cid, 11400,15)
        doRemoveItem(cid, item.uid, 1)
    elseif rand >= 110 then
        doCreatureSay(cid, "BROKE!", TALKTYPE_ORANGE_1)
        doRemoveItem(cid, item.uid, 1)
    end
    
    return true
end

Sua explicação ficou confusa, então, use isso e teste, pois não são 7 items, são mais que isso, coloquei chances de 10% até 100% de pegar tal item, bom, veja se está bom para você.

 

E você está errado.

 

Snowsz novamente, melhor resposta e REP+, obg pela ajuda novamente :D

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.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
  • Estatísticas dos Fóruns

    96.9k
    Tópicos
    519.6k
    Posts
×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo