• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X [LUA] Casino - Item Roulette

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello guys, how are you?

I have this script bellow to roll items in a casino, works fine, but i guess can be improved. When roll finishes, person needs to wait few more seconds before roll again, i want to put exaust just during items rolling. I find some unused variables too, i guess this script can me improved and have cooldown fixed.
Can u guys help me to fix code?

Lua:
local config = {
    effect = 27, -- efeito em cima do jogador
    effectReward = 28, -- efeito em cima do premio
    effectLever = 2, -- efeito em cima da alavanca
    eventCoin = 5221, -- valor para jogar
    qtdCoin = 1, -- quantidade do coin para jogar.
    lose = false, -- se ira ter a opção de não ganhar nada
    itemLose = 2638, -- id do item que representara a perca (Obs: não se esqueça de adiciona-lo a lista de items)
    effectLose = 29, -- efeito em cima do premio quando perder
    exaust = 10.0, -- Segundos de exaust
    storage = 23111, -- Storage do exaust
    used = 10, -- Tempo da duração da roleta
    used_storage = 23112, -- Storage pra verificar se a roleta esta sendo usada
    used = 10,
    poss = {
        [1] = {x = 123, y = 29, z = 6}, -- Coloque a coordenada da POS1 no Map Editor
        [2] = {x = 124, y = 29, z = 6}, -- Coloque a coordenada da POS2 no Map Editor
        [3] = {x = 125, y = 29, z = 6}, -- Coloque a coordenada da POS3 no Map Editor - local do premio
        [4] = {x = 126, y = 29, z = 6}, -- Coloque a coordenada da POS4 no Map Editor
        [5] = {x = 127, y = 29, z = 6} -- Coloque a coordenada da POS5 no Map Editor
    },
    items = { -- id = id do item - chance = chance de aparecer o item - count = a quantidade de item que a pessoa ira ganhar
        [1] = {id = 5363, chance = 10, count = 1},
        [2] = {id = 5161, chance = 30, count = 1},
        [3] = {id = 5114, chance = 60, count = 1},
        [4] = {id = 2236, chance = 30, count = 1},
        [5] = {id = 5626, chance = 65, count = 1},
        [6] = {id = 5355, chance = 50, count = 1},
        [7] = {id = 5892, chance = 15, count = 1},
        [8] = {id = 5356, chance = 70, count = 1},
        [9] = {id = 2160, chance = 45, count = 30},
        [10] = {id = 5114, chance = 40, count = 1},
        [11] = {id = 6018, chance = 3, count = 1},
        [12] = {id = 5805, chance = 3, count = 20},
        [13] = {id = 5625, chance = 3, count = 1},
        [14] = {id = 5596, chance = 10, count = 1},
        [15] = {id = 5108, chance = 3, count = 1},
        [16] = {id = 5115, chance = 3, count = 1},
        [17] = {id = 5110, chance = 3, count = 1},
        [18] = {id = 5109, chance = 3, count = 1},
        [19] = {id = 5112, chance = 3, count = 1},
        [20] = {id = 2453, chance = 3, count = 1},
        [21] = {id = 2281, chance = 90, count = 100},
        [22] = {id = 6038, chance = 15, count = 1},
        [23] = {id = 6039, chance = 15, count = 1},
        [24] = {id = 5358, chance = 95, count = 1}
    }
}
 
local slot1, slot2, slot3, slot4, slot5
 
local function cleanTile(item, i)
    doCleanTile(config.poss[i], true)
    doCreateItem(item, 1, config.poss[i])
end
 
local function raffle(item)
    if slot4 ~= nil then
        slot5 = slot4
        cleanTile(1617, 5)
        doCreateItem(slot5.id, slot5.count, config.poss[5])
    end
    if slot3 ~= nil then
        slot4 = slot3
        cleanTile(1617, 4)
        doCreateItem(slot4.id, slot4.count, config.poss[4])
    end
    if slot2 ~= nil then
        slot3 = slot2
        cleanTile(1485, 3)
        doCreateItem(slot3.id, slot3.count, config.poss[3])
    end
    if slot1 ~= nil then
        slot2 = slot1
        cleanTile(1617, 2)
        doCreateItem(slot2.id, slot2.count, config.poss[2])
    end
    slot1 = {id = item.id, count = item.count}
    cleanTile(1617, 1)
    doCreateItem(slot1.id, slot1.count, config.poss[1])
end
 
local function result(uid)
    if isPlayer(uid) then
        if config.lose and slot3.id == config.itemLose then
            doSendMagicEffect(getCreaturePosition(uid), CONST_ME_POFF)
            doSendMagicEffect(config.poss[3], config.effectLose)
            doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE,
                                    "[ROULETTE] What bad luck, try again!")
        else
            doSendMagicEffect(getCreaturePosition(uid), config.effect)
            doSendMagicEffect(config.poss[3], config.effectReward)
            doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE,
                                    "[ROULETTE] You won " .. slot3.count .. " " .. getItemNameById(slot3.id) .. ". Congratulations!")
            doPlayerAddItem(uid, slot3.id, slot3.count)
        end
    end
end
 
function onUse(cid, item, pos, itemEx, posEx)
    if item.itemid == 1945 then doTransformItem(item.uid, item.itemid + 1) end
    if item.itemid == 1946 then doTransformItem(item.uid, item.itemid - 1) end
 
    if getGlobalStorageValue(config.used_storage) <= os.time() then
        if not exhaustion.check(cid, config.storage) then
            if getPlayerItemCount(cid, config.eventCoin) >= config.qtdCoin then
                local rand = math.random(10, 30)
                doSendMagicEffect(pos, config.effectLever)
                setGlobalStorageValue(config.used_storage, rand + os.time())
                exhaustion.set(cid, config.storage, rand)
                doPlayerRemoveItem(cid, config.eventCoin, config.qtdCoin)
                local loop = 0
                slot1 = nil
                slot2 = nil
                slot3 = nil
                slot4 = nil
                slot5 = nil
 
                for i = 1, #config.poss do
                    if i == 3 then
                        cleanTile(1485, i)
                    else
                        cleanTile(1617, i)
                    end
                end
 
                while rand >= loop do
                    local roll = math.random(1, 100)
                    index = math.random(#config.items)
                    if roll <= config.items[index].chance then
                        local item = config.items[index]
                        loop = loop + 1
                        addEvent(raffle, loop * 500, item)
                    end
                end
                addEvent(result, (rand + 2) * 500, cid)
            else
                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                                        "[ROULETTE] You must have " .. config.qtdCoin .. " " .. getItemNameById(config.eventCoin) .. " with you in backup to use roulette.")
            end
        else
            doSendMagicEffect(fromPosition, CONST_ME_POFF)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,
                                    "You can not do it that fast, wait " .. exhaustion.get(cid, config.storage) .. " seconds to use roulette again!")
            return false
        end
        return true
    else
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[ROULETTE] Roulette is still hot! Wait a while to roll it again.")
    end
end
 
Solution
Didn't like the script at all and how it was written + the (general, server) cooldown on roulette can by handled at the moment of setting the result of roulette.

Here, an improved version of that (though I also removed things I deemed unnecessary like a loss on roulette - even though you can lose IRL, in-game to a player that earned the casino coin its better to give him atleast bad reward than nothing at all lol).
Remember to register in actions.xml a lever that will have action id to spin the roulette. And also add more items to roulette in config, atm there is 1 item I included to spawn.

Also, the script was spawning the item holders (I mean the basin and the wood counters) on the ground (wtf???) each time item appeared. So new...
exaust = 10.0, -- Segundos de exaust
? what is the problem? just change that it seems the script takes around 3-4 seconds? so just change it to 4.
 
Didn't like the script at all and how it was written + the (general, server) cooldown on roulette can by handled at the moment of setting the result of roulette.

Here, an improved version of that (though I also removed things I deemed unnecessary like a loss on roulette - even though you can lose IRL, in-game to a player that earned the casino coin its better to give him atleast bad reward than nothing at all lol).
Remember to register in actions.xml a lever that will have action id to spin the roulette. And also add more items to roulette in config, atm there is 1 item I included to spawn.

Also, the script was spawning the item holders (I mean the basin and the wood counters) on the ground (wtf???) each time item appeared. So new initial setup: (the lever position doesn't matter)
1694430625771.png
 

Attachments

  • rouletteSystemUpgradedByTofame.lua
    3.9 KB · Views: 44 · VirusTotal
Solution
Back
Top