Ir para conteúdo
  • Cadastre-se

(Resolvido)[PEDIDO] Adicionar chances


Ir para solução Resolvido por Snowsz,

Posts Recomendados

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á!

Link para o post
Compartilhar em outros sites

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
Editado por Ceos (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
  • Solução

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)
                              _
                          .-'` `}
                  _./)   /       }
                .'o   \ |       }
                '.___.'`.\    {`
                /`\_/  , `.    }                                      ME DA UMA NOZ!
                \=' .-'   _`\  {
                 `'`;/      `,  }
                    _\   @   ;  }
                   /__`;-...'--'

Cluck!

Link para o post
Compartilhar em outros sites

 

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

Link para o post
Compartilhar em outros sites
local config = {
	[1] = {item = 2160, count = 10, msg = "blablabla."}, -- 60%
	[2] = {item = 2160, count = 10, msg = "blablabla."}, -- 15%
	[3] = {item = 2160, count = 10, msg = "blablabla."}, -- 14%
	[4] = {item = 2160, count = 10, msg = "blablabla."}, -- 5%
	[5] = {item = 2160, count = 10, msg = "blablabla."}, -- 3%
	[6] = {item = 2160, count = 10, msg = "blablabla."}, -- 2%
	[7] = {item = 2160, count = 10, msg = "blablabla."}, -- 1%
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
	
	local x, vetor = math.random(1, 100), 0
	
	if x <= 60 then
		vetor = 1
	elseif x > 60 and x <= 75 then
		vetor = 2
	elseif x > 75 and x <= 89 then
		vetor = 3
	elseif x > 89 and x <= 94 then
		vetor = 4
	elseif x > 94 and x <= 97 then
		vetor = 5
	elseif x > 97 and x <= 99 then
		vetor = 6
	elseif x == 100 then
		vetor = 7
	end
	
	local reward = config[vetor]
	if reward then
		doCreatureSay(cid, reward.msg, TALKTYPE_ORANGE_1)
		doPlayerAddItem(cid, reward.item, reward.count)
		doRemoveItem(cid, item.uid, 1)
	end
	
	return true
end
Link para o post
Compartilhar em outros sites

biel.stocco, Desculpe eu estava sem tempo, eu ia fazer o script mais snowsz já fez At+

tudo bem manin, agradeço a intenção e obg mesmo, fico muito grato quando pelo menos tentam ajudar de bom coração!

 

 

 

local config = {

    [1] = {item = 2160, count = 10, msg = "blablabla."}, -- 60%

    [2] = {item = 2160, count = 10, msg = "blablabla."}, -- 15%

    [3] = {item = 2160, count = 10, msg = "blablabla."}, -- 14%

    [4] = {item = 2160, count = 10, msg = "blablabla."}, -- 5%

    [5] = {item = 2160, count = 10, msg = "blablabla."}, -- 3%

    [6] = {item = 2160, count = 10, msg = "blablabla."}, -- 2%

    [7] = {item = 2160, count = 10, msg = "blablabla."}, -- 1%

}

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

    

    local x, vetor = math.random(1, 100), 0

    

    if x <= 60 then

        vetor = 1

    elseif x > 60 and x <= 75 then

        vetor = 2

    elseif x > 75 and x <= 89 then

        vetor = 3

    elseif x > 89 and x <= 94 then

        vetor = 4

    elseif x > 94 and x <= 97 then

        vetor = 5

    elseif x > 97 and x <= 99 then

        vetor = 6

    elseif x == 100 then

        vetor = 7

    end

    

    local reward = config[vetor]

    if reward then

        doCreatureSay(cid, reward.msg, TALKTYPE_ORANGE_1)

        doPlayerAddItem(cid, reward.item, reward.count)

        doRemoveItem(cid, item.uid, 1)

    end

    

    return true

end

 

Nesse sistema eu teria que, por exemplo:

o baú terá chance de 15 itens diferentes, então terei de configurar a porcentagem dos 15 itens completando 100% ao todo, é isso?

 

Link para o post
Compartilhar em outros sites

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.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo