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

Sharing knowledge on Lua possibilities

I can't edit the first message but just a disclaimer that I forgot to add:
The reason for this topic is to show a few possibilities, it's to share ideas rather than code tricks, code style or code efficiency.
Some of the things here are just "detail-oriented"adjustments on existing functions/systems, they don't bring anything new except to remind us all to pay attention to small details.
Most of the scripts were created several years ago, when we just had TFS 1.0 (6 years ago, maybe?). By then we didn't had the architecture that we have today and I wasn't so familiar with metamethods either, so lots of functions are compat based (tfs 0.x).

Of course some of the npcs/actions/spells here will work if you copy/paste in your server and adjust the XML tags, however I highly advise you to remake the idea considering cleaner cone and better code styles. Some redundancies can be eliminated.

I don't have a server anymore but I'll try to add screenshots/gifs later.
 
@Night Wolf
Is it possible to create an item with teleport positions when a specific raid starts with this script?
OTServBR / Canary

Code:
local fuse = 0 -- +1
local raids = {
    -- Weekly
    ['Monday'] = {
        ['06:30'] = {raidName = 'The Snapper'}
    },
    ['Tuesday'] = {
        ['04:00'] = {raidName = 'White Pale'},
        ['18:00'] = {
            raidName = 'The Horned Fox',
            removeItem = {
                {1543, {x = 1529, y = 1851, z = 12}, effect = 16}
            }
        }
    },
    ['Wednesday'] = {
        ['12:50'] = {raidName = 'Rotworm Queen'},
        ['17:00'] = {raidName = 'Black Sheep'}
    },
    ['Thursday'] = {
        ['07:15'] = {
            raidName = 'Kraknaknork',
            createItem = {
                {5070, {x = 1576, y = 2436, z = 9}},
                {1487, {x = 1576, y = 2438, z = 9}, effect = 16}, --f1
            }
        },
function onThink(interval, lastExecution, thinkInterval)
    local day, date, dia = os.date('%A'), os.date("%d/%m"), tonumber(os.date('%d'))
    local raidDays = {}
    if raids[day] then
        raidDays[#raidDays + 1] = raids[day]
    end
    if raids[date] then
        raidDays[#raidDays + 1] = raids[date]
    end
    if raids[dia] then
        raidDays[#raidDays + 1] = raids[dia]
    end
    if #raidDays == 0 then
        return true
    end

    local hours = tonumber(os.date("%H"))
    local minutes = tonumber(os.date("%M"))

    hours = hours + fuse
    if hours >= 24 then
        hours = hours - 24
    elseif hours < 0 then
        hours = hours + 24
    end

    local formatedHour = string.format("%02d:%02d", hours, minutes)
    for i = 1, #raidDays do
        local settings = raidDays[i][formatedHour]
        if settings and not settings.alreadyExecuted then
            Game.startRaid(settings.raidName)
            if (settings.createItem) then -- Create Item
                local tabela = settings.createItem
                for i = 1, #tabela do
                    Game.createItem(tabela[i][1], 1, tabela[i][2])
                    if tabela[i].effect then
                        Position(tabela[i][2]):sendMagicEffect(tabela[i].effect)
                    end
                end
            elseif (settings.removeItem) then -- Remove Item
                local tabela = settings.removeItem
                for i = 1, #tabela do
                    local pos = Position(tabela[i][2])                
                    if pos and Tile(pos) then
                        local tile = Tile(pos)
                        local item = tile:getItemById(tabela[i][1])
                        if item then item:remove() end
                    end
                        if tabela[i].effect then
                        Position(tabela[i][2]):sendMagicEffect(tabela[i].effect)
                    end
                end
            end
            settings.alreadyExecuted = true
        end
    end

    return true
end
 
Back
Top