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

Bridge Script from 0.4 to TFS 1.3

Salvus

Well-Known Member
Joined
Feb 7, 2019
Messages
102
Solutions
1
Reaction score
69
Can someone help me to rebuild this script to TFS 1.3?
And to remove guild and just put players will get that not "Guilds"

Lua:
local tiles = {
    {x = 1282, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1283, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1284, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1285, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1286, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1287, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1288, y = 995, z = 7, stackpos = STACKPOS_TOP_CREATURE},
}

-- [gid] = score
local guildScores = nil

-- gid, time
local counter = nil

local function addBridgeScore(gid, amount)
    local amount = amount or 1
    db.query(string.format("UPDATE `guilds` SET `bridge` = `bridge` + %i WHERE `id` = %i;", amount, gid))
    if guildScores[gid] then
        guildScores[gid] = guildScores[gid] + amount
    else
        guildScores[gid] = amount
    end
end

local function finishCurrentCounter()
    if not(counter) then return true end

    local amount = math.floor(counter[2] / 60)
    if amount > 0 then
        addBridgeScore(counter[1], amount)
    end
    counter = nil
end

local config = {
    convertCounter = function(t) return math.floor(t / 60) end,
    convertScore = function(t) return t end,
  
    color = COLOR_TEAL,
  
    showNoGuild = true
}

local function showCounter(cid, gid)
    local pos = getThingPos(cid)
    local t = config.convertCounter(counter[2])
    if guildScores[gid] then
        t = t + config.convertScore(guildScores[gid])
    end
  
    if t > 0 then
        doSendAnimatedText(pos, t, config.color)
    end
end

function onThink(interval)
    if not guildScores then
        guildScores = { }
      
        local res = db.getResult("SELECT `id`, `bridge` FROM `guilds`;")
        if res:getID() ~= -1 then
            repeat
                guildScores[res:getDataInt("id")] = res:getDataInt("bridge")             
            until not(res:next())
      
            res:free()
        end
    end
  
    local things = { }
    for i = 1, #tiles do
        local thing = getThingFromPos(tiles[i])
        if thing.uid > 0 and isPlayer(thing.uid) then
            thing = thing.uid
        else
            thing = nil
        end
        table.insert(things, thing)
    end
  
    local lastThing = nil
    for i = #things, 1, -1 do
        local tmp = things[i]
        if tmp then
            lastThing = tmp
            break         
        end
    end
  
    if not lastThing then
        finishCurrentCounter()
        return true
    end
  
    local gid = getPlayerGuildId(lastThing)
    if gid <= 0 then
        finishCurrentCounter()
        if config.showNoGuild then
            doSendAnimatedText(getThingPos(lastThing), "No Guild", config.color)
        end     
        return true
    end
  
    if not(counter) then
        counter = {gid, 0}
        showCounter(lastThing, gid)
        return true
    end
  
    if gid ~= counter[1] then
        finishCurrentCounter()
        counter = {gid, 0}
    else
        counter[2] = counter[2] + 1
    end
  
    showCounter(lastThing, gid)
    return true
end
 
Last edited by a moderator:
It should count minutes for each time the player is on the bridge. It should be saved all the time so every time the player leave bridge and and step on the bridge aigen it will need to count from the last time he step on it., the old minutes should be counted as well. And the minuts need to show up near the character namn so the others can see

Like this @Itutorial

34557
 
Last edited:
Back
Top