• 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 1.3] Rewrite a system (learning) Roulette system

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,121
Solutions
7
Reaction score
117
Location
YurOTS Land
Im triying to make a similar system from scratch (learning) but i cant make the items move, sometimes i got a infinite loop and other thing is moveTo function recieve a nil position, this is my current code using TFS 1.3 what i can do to make this code better? any tips? thanks have good day/night where you are ;D

Script that im using to remake [Tf 1x+] Event Roulette (https://otland.net/threads/tf-1x-event-roulette.270958/)

How it would work, but items not need be re-created when reach the end just use pre-made (im current using random ones)

ruleta.gif


Lua:
local winning_tile = Position(463, 468, 8)
local tile_items = {
    Position(457, 468, 8),
    Position(458, 468, 8),
    Position(459, 468, 8),
    Position(460, 468, 8),
    Position(461, 468, 8),
    Position(462, 468, 8),
    Position(463, 468, 8),
    Position(464, 468, 8),
    Position(465, 468, 8),
    Position(466, 468, 8),
    Position(467, 468, 8),
    Position(468, 468, 8),
    Position(469, 468, 8)
}

local times = 0    

function moveItem(item, pos)
    if(item) then
        item:moveTo(pos)
    end
end
function getItemIndex(item)
    local index = 0
    for i = 1, #tile_items - 1 do
        if tile_items[i] == item:getPosition() then
            index = i
            break
        end
    end
    return index
end


local items = {}
function moveAll()
    for _, item in ipairs(items) do
        if((getItemIndex(item) + 1) == #tile_items - 1) then
            item:moveTo(tile_items[1])
        else
            item:moveTo(tile_items[getItemIndex(item) + 1])
        end
    end
    if(times == 30) then
        return true
    else
        addEvent(moveAll, 1000)
    end
    times = times + 1
end
function generateItems()
    for i = 1, #tile_items - 1 do
        local item = Tile(tile_items[i]):getTopDownItem()
        if(item) then
           item:remove()
           items[i] = nil
        end
        Game.createItem(math.random(2268, 2273), 1, tile_items[i])
    end
   
  
    for i = 1, #tile_items - 1 do
        local item = Tile(tile_items[i]):getTopDownItem()
        if(item) then
            table.insert(items, item)
        end
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
    generateItems()
    moveAll()
    return true
end

Current problems:

Infinite loop and some items dissapear when items got moved.

1618384825418.png
 
Last edited:
Top