[TFS 0.4] NEW LOTTERY SYSTEM

Furabio
em Globalevents e Spells

Furabio

Why be a king.. when you can be a god
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 08/04/15Posts: 962Gênero: Masculino

O evento se resume a cada x horário configurável, é escolhido dentre os player online, 1 pessoa e ela recebe uma surprise bag (com items aleatórios para ganhar também configurável).

 

Globalevents/scripts ---> lottery.lua

local config = {
    lottery_hour = "1 Hours", -- after how many hours should lottery begin, explains itself really...
    reward_count = 4, -- How much items/rewards? so you want 4 random items then write 4...
    website = 1 -- Doesn't need explanation 
    }
function onThink(interval, lastExecution)
    local players = getPlayersOnline()
    local list = {}
    for i, tid in ipairs(players) do
    list[i] = tid
end
    local winner = list[math.random(1, #list)]
    if(config.website == 1) then
        db.executeQuery("INSERT INTO `lottery` (`name`) VALUES ('".. getCreatureName(winner) .."');")
    end
    doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: Suprise Bag' ..'! - Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
    doPlayerAddItem(winner, 6571,config.reward_count)
    return TRUE
end

globalevents.xml

<globalevent name="lottery" interval="4050000" event="script" value="lottery.lua"/>

Actions/scripts --> surprisebag.lua

-- CREATED BY GHETTOBIRD --!
local PRESENT_BLUE = {2494, 2472} -- Add more items if you want just seperate them with an item id...
local PRESENT_RED = {2160, 2514} -- same as above 

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local count = 1
    if(item.itemid == 6570) then
        local randomChance = math.random(1, #PRESENT_BLUE)
        if(randomChance == 1) then
            count = 2
        elseif(randomChance == 2) then
            count = 2
        end
        doPlayerAddItem(cid, PRESENT_BLUE[randomChance], count)
    elseif(item.itemid == 6571) then
        local randomChance = math.random(1, #PRESENT_RED)
        if randomChance > 0 and randomChance < 4 then
            count = 2
        end
        doPlayerAddItem(cid, PRESENT_RED[randomChance], count)
    end

    doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
    doRemoveItem(item.uid, 1)
    return true
end

actions.xml

<action fromid="6570" toid="6571" event="script" value="surprisebag.lua"/>

Créditos : ghetobird

EQD4Qy4.gif

 

zipter98

avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 20/09/12Posts: 2553Gênero: Masculino

Iterar os jogadores online, insertando-os numa tabela para depois pegar um elemento aleatório dela, na minha opinião, é desnecessário, visto que você poderia somente usar:

 

local players = getPlayersOnline()
local winner = players[math.random(#players)]

Mas, de resto, o código tá legal, especialmente o segundo. xD

Não respondo PMs solicitando suporte. Já existem seções no fórum para isto.

patrick323

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/03/08Posts: 20

e para TFS 1.0 tem algum sistema de loteria que funcione?

www.global-nirlha.com

 

Ajudei? Agradeça, use add.png