Ir para conteúdo

Featured Replies

Postado

<img  data-cke-saved-src="/images/5/56/SemImagem.gif" src="/images/5/56/SemImagem.gif" /> Evento Loteria <img  data-cke-saved-src="/images/5/56/SemImagem.gif" src="/images/5/56/SemImagem.gif" />

 

 

Esse evento loteria é diferente dos demais que existem hoje nos servidores, é baseado em cima de um evento que ocorre no CraftLandia (um servidor de Minecraft).

Quando o evento for iniciado o jogador poderá pagar um valor (configurável) para tentar acertar o número premiado (que vai de 1 até o número configurado). O evento tem um tempo de duração (configurável) e o primeiro jogador a acertar qual é o número premiado levará um premio em dinheiro (configurável) e o evento será encerrado.

 

Demonstrações:

 

Spoiler

initlottery.thumb.gif.d9632c0440ea2ca88f6b067535b02f92.gif

 

Spoiler

nowinner.thumb.gif.8d419e4a96b16f62ed5bbe9ba0cdb671.gif

 

Spoiler

win.thumb.gif.c17237340354a09778e416847ea0871f.gif

 

Comandos:

 

Spoiler

!lottery start - Inicia o evento a qualquer momento durante o jogo.

!lottery forcestop - Faz o evento loteria ativo ser cancelado a força. Recomendável usar apenas quando o servidor travar.

!lottery info - Exibe o valor do premio da loteria e a valor de cada tentativa.

!lottery X - Faz uma tentativa, onde X é o número desejado.

 

Configuração:

 

Spoiler

LOTTERY_REWARD_TYPE_ONLYMONEY    -- Prêmio somente em dinheiro
LOTTERY_REWARD_TYPE_ONLYITEM     -- Prêmio somente em item
LOTTERY_REWARD_TYPE_MONEYANDITEM -- Prêmio em dinheiro E item
LOTTERY_REWARD_TYPE_MONEYORITEM  -- Prêmio em dinheiro OU item

Lottery.config = {
    bet = 1,                                   -- Valor pago por cada aposta
    reward = LOTTERY_REWARD_TYPE_MONEYORITEM,  -- Tipo da recompensa para o ganhador
    range = 1000,                              -- Quantidade máxima de números
    duration = 2                               -- Duração do evento em minutos
}

Lottery.rewards = {
    money = 5000,    -- Dinheiro a ser entregue ao jogador
    items = {        -- Itens a serem entregues ao jogados (aleatoriamente)
        {id = 2147, count = 59}, -- Count só ira funcionar para itens não acumuláveis
        {id = 10521, count = 3},
        {id = 9692, count = 4}
    }
}

 

 

Caso queira implementar este evento em seu servidor, crie os arquivos abaixo.

 

data/lib/lottery/event.lua (as configurações ficam neste arquivo)

 

Spoiler

LOTTERY_MESSAGE_START = 1
LOTTERY_MESSAGE_FINISH = 2
LOTTERY_MESSAGE_TRY_AGAIN = 3
LOTTERY_MESSAGE_WINNER_MONEY = 4
LOTTERY_MESSAGE_WINNER_ITEM = 5
LOTTERY_MESSAGE_WINNER_MONEY_AND_ITEM = 6
LOTTERY_MESSAGE_CONGRATULATION_MONEY = 7
LOTTERY_MESSAGE_CONGRATULATION_ITEM = 8
LOTTERY_MESSAGE_CONGRATULATION_MONEY_AND_ITEM = 9
LOTTERY_MESSAGE_NOTICE = 10
LOTTERY_MESSAGE_INSUFFICIENT_MONEY = 11
LOTTERY_MESSAGE_INFO = 12
LOTTERY_MESSAGE_ERROR_ACTIVE = 13
LOTTERY_MESSAGE_ERROR_NO_ACTIVE = 14
LOTTERY_MESSAGE_NUMBER_TOO_BIG = 15
LOTTERY_MESSAGE_NUMBER_NOT_FOUND = 16
LOTTERY_REWARD_TYPE_ONLYMONEY = 17
LOTTERY_REWARD_TYPE_ONLYITEM = 18
LOTTERY_REWARD_TYPE_MONEYANDITEM = 19
LOTTERY_REWARD_TYPE_MONEYORITEM = 20

Lottery = {}
Lottery.__index = Lottery

Lottery.config = {
    bet = 1,                                   -- Valor pago por cada aposta
    reward = LOTTERY_REWARD_TYPE_MONEYORITEM,  -- Tipo da recompensa para o ganhador
    range = 1000,                              -- Quantidade máxima de números
    duration = 2                               -- Duração do evento em minutos
}

Lottery.rewards = {
    money = 5000,    -- Dinheiro a ser entregue ao jogador
    items = {        -- Items a serem entregues ao jogados (aleatoriamente)
        {id = 2147, count = 59},
        {id = 10521, count = 3},
        {id = 9692, count = 4}
    }
}

Lottery.storages = {
    started = 172836
}

Lottery.messages = {
    prefix = "[LOTTERY]",
    start  = "The event has started, type '!lottery X', where X is a number from 1 to %d. Good luck!",
    finish = "The event ended without winners.",
    try_again = "Not this time, try again!",
    winner_money = "Congratulations, %s won %s gold coins!",
    winner_item = "Congratulations, %s won %d %s!",
    winner_money_and_item = "Congratulations, %s won %d gold coins and %s %s!",
    congratulation_money = "Congratulations, you won %d gold coins!",
    congratulation_item = "Congratulations, you won %s %s!",
    congratulation_money_and_item = "Congratulations, you won %d gold coins and %s %s!",
    notice = "The event ends in %d minute(s).",
    insufficient_money = "You do not have enough money.",
    info = "Info:\nBet: %s gold coins\nRewards: %s",
    error_active = "The Lottery is active.",
    error_no_active = "The Lottery is not active.",
    error_number_too_big = "Sorry, you can bet from 1 to %d.",
    error_number_not_found = "Sorry, you need to enter a number between 1 and %d."
}

function Lottery:start()
    print("> [LOTTERY] Event started.")
    Lottery:turnOn()
    Lottery:reset()
    Lottery:setWinningNumber()
    print("> [LOTTERY] Number: " .. Lottery:getWinningNumber())
    local message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_START), Lottery:getRange())
    Lottery:broadcast(message)
    Lottery:notice(Lottery.config.duration - 1, 1)

    addEvent(function()
        if Lottery:isStarted() then
            Lottery:finish()
        end
    end, Lottery:getDurationInMS())
end

function Lottery:finish()
    print("> [LOTTERY] Event finalized.")
    Lottery:turnOff()
    local message

    if Lottery:getWinner() then
        print("> [LOTTERY] Winner: " .. Lottery:getWinner())

        if Lottery:getRewardType() == LOTTERY_REWARD_TYPE_ONLYMONEY then
            message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_WINNER_MONEY), Lottery:getWinner(), Lottery:getReward())
        elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_ONLYITEM then
            message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_WINNER_ITEM), Lottery:getWinner(), Lottery:getReward():getCount(), Lottery:getReward():getName())
        elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_MONEYANDITEM then
            message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_WINNER_MONEY_AND_ITEM), Lottery:getWinner(), Lottery:getReward()[1], Lottery:getReward()[2]:getCount(), Lottery:getReward()[2]:getName())
        elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_MONEYORITEM then
            if tonumber(reward) then
                message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_WINNER_MONEY), Lottery:getWinner(), Lottery:getReward())
            else
                message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_WINNER_ITEM), Lottery:getWinner(), Lottery:getReward():getCount(), Lottery:getReward():getName())
            end
        end
    else
        print("> [LOTTERY] Winner: Nobody")
        message = Lottery:getMsg(LOTTERY_MESSAGE_FINISH)
    end

    Lottery:broadcast(message)
end

function Lottery:isStarted()
    if Game.getStorageValue(Lottery.storages.started) ~= -1 then
        return true
    end
    return false
end

function Lottery:getRange()
    return Lottery.config.range
end

function Lottery:getDurationInMS()
    return Lottery.config.duration * 60 * 1000
end

function Lottery:getBetPrice()
    return Lottery.config.bet
end

function Lottery:broadcast(message)
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendTextMessage(MESSAGE_STATUS_WARNING, message)
    end
end

function Lottery:bet(player, number)
    if tonumber(number) == nil then
        local message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_NUMBER_NOT_FOUND), Lottery:getRange())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
        return false
    end

    if tonumber(number) > Lottery:getRange() then
        local message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_NUMBER_TOO_BIG), Lottery:getRange())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
        return false
    end

    if Lottery:getBetPrice() > 0 then
        if not player:removeMoney(Lottery:getBetPrice()) then
            local message = Lottery:getMsg(LOTTERY_MESSAGE_INSUFFICIENT_MONEY)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
            return false
        end
    end

    if tonumber(number) == Lottery:getWinningNumber() then
        local reward = Lottery:getReward()
        local message

        if Lottery:getRewardType() == LOTTERY_REWARD_TYPE_ONLYMONEY then
            message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_CONGRATULATION_MONEY), reward)
        elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_ONLYITEM then
            message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_CONGRATULATION_ITEM), reward:getCount(), reward:getName())
        elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_MONEYANDITEM then
            message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_CONGRATULATION_MONEY_AND_ITEM), reward[1], reward[2]:getCount(), reward[2]:getName())
        elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_MONEYORITEM then
            if tonumber(reward) then
                message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_CONGRATULATION_MONEY), reward)
            else
                message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_CONGRATULATION_ITEM), reward:getCount(), reward:getName())
            end
        end
        
        Lottery:addReward(player, reward)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
        Lottery:setWinner(player:getName())
        Lottery:finish()
    else
        local message = Lottery:getMsg(LOTTERY_MESSAGE_TRY_AGAIN)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    end
end

function Lottery:setWinner(name)
    Lottery.winner = name
end

function Lottery:addReward(player, reward)
    if tonumber(reward) then
        player:addMoney(reward)
    elseif reward[1] ~= nil and reward[2] ~= nil then
        player:addMoney(reward[1])
        player:addItemEx(reward[2])
    else
        player:addItemEx(reward)
    end
end

function Lottery:getRewardType()
    return Lottery.config.reward
end

function Lottery:getWinner()
    return Lottery.winner
end

function Lottery:getReward()
    if Lottery.reward then
        return Lottery.reward
    else
        Lottery:setReward()
        return Lottery.reward
    end
end

function Lottery:getRewardsName()
    local rewards = ""

    if Lottery.rewards.money ~= nil then
        rewards = rewards .. Lottery.rewards.money .. " gold coins"
    end

    for i = 1, #Lottery.rewards.items do
        if i ~= #Lottery.rewards.items then
            rewards = rewards .. ", " .. Lottery.rewards.items[i].count .. "x " .. ItemType(Lottery.rewards.items[i].id):getName()
        else
            rewards = rewards .. ", " .. Lottery.rewards.items[i].count .. "x " .. ItemType(Lottery.rewards.items[i].id):getName() .. "."
        end
    end

    return rewards
end

function Lottery:setReward()
    if Lottery:getRewardType() == LOTTERY_REWARD_TYPE_ONLYMONEY then
        reward = Lottery.rewards.money
    elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_ONLYITEM then
        print(#Lottery.rewards.items)
        local rand = math.random(1, #Lottery.rewards.items)
        print(rand)
        reward = Game.createItem(Lottery.rewards.items[rand].id, Lottery.rewards.items[rand].count)
    elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_MONEYANDITEM then
        local rand = math.random(1, #Lottery.rewards.items)
        reward = {Lottery.rewards.money, Game.createItem(Lottery.rewards.items[rand].id, Lottery.rewards.items[rand].count)}
    elseif Lottery:getRewardType() == LOTTERY_REWARD_TYPE_MONEYORITEM then
        local rand = math.random(1, 2)

        if rand == 1 then
            reward = Lottery.rewards.money
        else
            rand = math.random(1, #Lottery.rewards.items)
            reward = Game.createItem(Lottery.rewards.items[rand].id, Lottery.rewards.items[rand].count)
        end
    end

    Lottery.reward = reward
end

function Lottery:setWinningNumber()
    Lottery.number = math.random(1, Lottery:getRange())
end

function Lottery:getWinningNumber()
    return Lottery.number
end

function Lottery:reset()
    Lottery.reward = nil
    Lottery.winner = nil
    Lottery.number = nil
end

function Lottery:notice(minutes, i)
    if minutes == 0 then
        return false
    end

    addEvent(function()
        if Lottery:isStarted() then
            local message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_NOTICE), Lottery.config.duration - i)
            Lottery:broadcast(message)
            Lottery:notice(minutes - 1, i + 1)
        end
    end, i * 60 * 1000)
end

function Lottery:turnOn()
    Game.setStorageValue(Lottery.storages.started, 1)
end

function Lottery:turnOff()
    Game.setStorageValue(Lottery.storages.started, -1)
end

function Lottery:getMsg(TYPE)
    if TYPE == LOTTERY_MESSAGE_START then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.start
    elseif TYPE == LOTTERY_MESSAGE_FINISH then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.finish
    elseif TYPE == LOTTERY_MESSAGE_TRY_AGAIN then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.try_again
    elseif TYPE == LOTTERY_MESSAGE_WINNER_MONEY then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.winner_money
    elseif TYPE == LOTTERY_MESSAGE_WINNER_ITEM then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.winner_item
    elseif TYPE == LOTTERY_MESSAGE_WINNER_MONEY_AND_ITEM then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.winner_money_and_item
    elseif TYPE == LOTTERY_MESSAGE_CONGRATULATION_MONEY then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.congratulation_money
    elseif TYPE == LOTTERY_MESSAGE_CONGRATULATION_ITEM then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.congratulation_item
    elseif TYPE == LOTTERY_MESSAGE_CONGRATULATION_MONEY_AND_ITEM then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.congratulation_money_and_item
    elseif TYPE == LOTTERY_MESSAGE_NOTICE then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.notice
    elseif TYPE == LOTTERY_MESSAGE_INSUFFICIENT_MONEY then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.insufficient_money
    elseif TYPE == LOTTERY_MESSAGE_INFO then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.info
    elseif TYPE == LOTTERY_MESSAGE_ERROR_ACTIVE then
        return Lottery.messages.error_active
    elseif TYPE == LOTTERY_MESSAGE_ERROR_NO_ACTIVE then
        return Lottery.messages.error_no_active
    elseif TYPE == LOTTERY_MESSAGE_NUMBER_TOO_BIG then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.error_number_too_big
    elseif TYPE == LOTTERY_MESSAGE_NUMBER_NOT_FOUND then
        return Lottery.messages.prefix .. ' ' .. Lottery.messages.error_number_not_found
    end
end

 

 

data/globalevents/scripts/lottery.lua

 

Spoiler

dofile('data/lib/lottery/event.lua')

function onTime(interval)
    Lottery:start()
    return true
end

 

 

data/globalevents/globalevents.xml

 

você pode por com um intervalo de tempo

 

Spoiler

<globalevent name="Lottery" interval="3600000" script="lottery.lua" />

 

 

ou horário fixo

 

Spoiler

<globalevent name="Lottery" time="19:00:00" script="lottery.lua" />

 

 

data/talkactions/scripts/lottery.lua

 

Spoiler

dofile('data/lib/lottery/event.lua')

function onSay(player, words, param)
    if param == 'start' then
        if not verifyPermissions(player) then 
            return true
        end
        
        if Lottery:isStarted() then
            player:sendCancelMessage(Lottery:getMsg(LOTTERY_MESSAGE_ERROR_ACTIVE))
        else
            Lottery:start()
        end
    elseif param == 'forcestop' then
        if not verifyPermissions(player) then 
            return true 
        end
        
        Lottery:turnOff()
    elseif param == 'info' then
        local message = string.format(Lottery:getMsg(LOTTERY_MESSAGE_INFO), Lottery:getBetPrice(), Lottery:getRewardsName())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    else
        if Lottery:isStarted() then
            Lottery:bet(player, param)
        else
            player:sendCancelMessage(Lottery:getMsg(LOTTERY_MESSAGE_ERROR_NO_ACTIVE))
        end
    end
    
    return false
end

function verifyPermissions(player)
    if not player:getGroup():getAccess() then
        return false
    end
    
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    
    return true
end

 

 

data/talkactions/talkactions.xml

 

Spoiler

<talkaction words="!lottery" separator=" " script="lottery.lua" hidden="yes" />

 

 

Tradução para PT-BR!

 

Caso deseje traduzir o evento, substitua o Lottery.messages inteiro em data/lib/lottery/event.lua por este

 

Spoiler

Lottery.messages = {
    prefix = "[LOTERIA]",
    start  = "O evento acaba de começar, digite '!lottery X', onde X é um número de 1 a %d. Boa sorte!",
    finish = "O evento acabou sem nenhum vencedor.",
    try_again = "Não foi dessa vez, tente novamente!",
    winner_money = "Parabéns, %s ganhou %s moedas de ouro!",
    winner_item = "Parabéns, %s ganhou %s %s!",
    winner_money_and_item = "Parabéns, %s ganhou %s moedas de ouro e %s %s!",
    congratulation_money = "Parabéns, você ganhou %s moedas de ouro!",
    congratulation_item = "Parabéns, você ganhou %s %s!",
    congratulation_money_and_item = "Parabéns, você ganhou %s moedas de ouro e %s %s!",
    notice = "O evento acaba em %d minuto(s).",
    insufficient_money = "Você não possui dinheiro suficiente.",
    info = "Info:\nAposta: %d moedas de ouro\nPrêmio: %s",
    error_active = "A Loteria está ativa.",
    error_no_active = "A Loteria não está ativa.",
    error_number_too_big = "Desculpe, você só pode apostar de 1 a %d.",
    error_number_not_found = "Desculpe, você precisa entrar com um número entre 1 e %d."
}

 

 

Qualquer problema, sugestão, bug ou dúvida utilize este tópico!!!

Editado por Leohige
Buf (veja o histórico de edições)

  • Respostas 11
  • Visualizações 2.5k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

Posted Images

Postado

Parabéns, seu tópico de conteúdo foi aprovado!
Muito obrigado pela sua contribuição, nós do Tibia King agradecemos.
Seu conteúdo com certeza ajudará à muitos outros, você recebeu +1 REP.

Spoiler

Congratulations, your content has been approved!
Thank you for your contribution, we of Tibia King we are grateful.
Your content will help many other users, you received +1 REP.

 

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Postado

Poderia deixara opção para outros items na loteria fora dinheiro tambem. Ou uma forma randomica entre items e dinheiro. Pois se for analisar nos dias de hoje dinheiro em OT é quase valido de nada.

Postado
  • Autor
3 horas atrás, Andreeyyy disse:

Poderia deixara opção para outros items na loteria fora dinheiro tambem. Ou uma forma randomica entre items e dinheiro. Pois se for analisar nos dias de hoje dinheiro em OT é quase valido de nada.

 

Adicionado a sua sugestão no evento.

Postado
Em 05/01/2018 em 21:34, Leohige disse:

 

Adicionado a sua sugestão no evento.

 

Agora ficou show e mais próximo da realidade dos servidores atuais! Parabéns pelo script! 

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

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo