• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

CTF Event after event player dont get teleported to temple

Saint Spear

Veteran OT User
Joined
Jun 22, 2016
Messages
1,547
Solutions
18
Reaction score
379
Elo people, I tried fix on rare ways this but I couldnt , so i went to make thread on otland ..
I'm using tfs 0.4 and the problem is After CTF Event ends , 1-2 players of 5-6 dont get teleported back to temple , and other players do. So what should be the problem? here's lib file
Code:
--[[
]]

CTF_LIB = {
    waitpos = {x = 1250, y = 2093, z =7}, -- Posição da sala de espera
    tppos = {x = 1383, y = 1997, z =7}, -- Onde o TP vai aparecer

    days = {1, 2, 3, 4, 5, 6, 7}, -- Dias que o evento vai abrir
    xp_percent = 0.2, -- Porcentagem de exp que o player vai ganhar
    timeclose = 5, -- Tempo, em minutos, para iniciar o CTF
    winp = 3, -- Quantos pontos uma equipe precisa marcar para vencer

    teams = {
        ["Red Team"] = {
            temple = 6, -- TownID da equipe vermelha
            outfit = {lookHead = 0, lookBody = 132, lookLegs = 113, lookFeet = 94},

            flag = {
                id = 1435,
                flag_pos = {x = 1435, y = 2112, z =7}, -- Posição onde a bandeira vermelha vai ser criada
                gnd_pos = {x = 1435, y = 2110, z =7}, -- Onde os players da equipe vermelha entregarão a bandeira.
            },
        },

        ["Green Team"] = {
            temple = 5, -- TownID da equipe verde
            outfit = {lookHead = 0, lookBody = 121, lookLegs = 101, lookFeet = 101},

            flag = {
                id = 1437,
                flag_pos = {x = 1379, y = 2112, z =7}, -- Posição onde a bandeira verde vai ser criada
                gnd_pos = {x = 1379, y = 2110, z =7}, -- Onde os players da equipe verde entregarão a bandeira.
            },
        },
    },
}

local CTF = CTF_LIB

function CTF.getMembers()
    local members = {}

    for _, cid in pairs(getPlayersOnline()) do
        if getPlayerStorageValue(cid, 16700) ~= -1 then
            table.insert(members, cid)
        end
    end

    return members
end

function CTF.getTeamMembers(team)
    local members = {}

    for _, cid in pairs(CTF.getMembers()) do
        if getPlayerStorageValue(cid, 16700) == team then
            table.insert(members, cid)
        end
    end

    return members
end

function CTF.removePlayer(uid)
    setPlayerStorageValue(uid, 16700, -1)
    doPlayerSetTown(uid, getPlayerStorageValue(uid, 16701))
    doTeleportThing(uid, getTownTemplePosition(getPlayerStorageValue(uid, 16701)))
    setPlayerStorageValue(uid, 16701, -1)

    doRemoveCondition(uid, CONDITION_OUTFIT)
    doCreatureAddHealth(uid, getCreatureMaxHealth(uid))
    doCreatureAddMana(uid, getCreatureMaxMana(uid))
    return true
end

function CTF.addPlayer(uid)
    local team = CTF.getTeamLivre()
    local n_team = CTF.teams[team]

    setPlayerStorageValue(uid, 16700, team)
    setPlayerStorageValue(uid, 16701, getPlayerTown(uid))

    doPlayerSetTown(uid, n_team.temple)
    doTeleportThing(uid, CTF.waitpos)

    doPlayerSendTextMessage(uid, 22, "You are now part of the team. ".. team .. ".")

    local outfit = getCreatureOutfit(uid)

    for i, v in pairs(n_team.outfit) do
        outfit[i] = v
    end

    registerCreatureEvent(uid, "CTFLogout")
    registerCreatureEvent(uid, "CTFAttack")
    registerCreatureEvent(uid, "CTFCombat")
    registerCreatureEvent(uid, "CTFDeath")
    doSetCreatureOutfit(uid, outfit, -1)
    return true
end

function CTF.getTeamLivre()
    local teams = {}

    for i, _ in pairs(CTF.teams) do
        table.insert(teams, {i, #CTF.getTeamMembers(i)})
    end

    if (teams[1][2] < teams[2][2]) then
        return teams[1][1]
    elseif (teams[1][2] > teams[2][2]) then
        return teams[2][1]
    end

    return teams[math.random(2)][1]
end

function CTF.broadCast(msg, class)
    for _, uid in pairs(CTF.getMembers()) do
        doPlayerSendTextMessage(uid, class or 20, msg)
    end

    return true
end

function CTF.getFlagTeam(flag)
    for i, v in pairs(CTF.teams) do
        if v.flag.id == flag then
            return i
        end
    end

    return ""
end

local score_sto = {}
local a = 0
for i, _ in pairs(CTF.teams) do
    score_sto[i] = 42314 + a
    a = a + 1
end

function CTF.createFlags()
    for i, v in pairs(CTF.teams) do
        local flag = doCreateItem(v.flag.id, 1, v.flag.flag_pos)
        doItemSetAttribute(flag, "aid", 63218)

        v.flag.gnd_pos.stackpos = 0
        local gnd = getThingFromPos(v.flag.gnd_pos).uid
        doItemSetAttribute(gnd, "aid", 63200)
        doItemSetAttribute(gnd, "team", i)

        setGlobalStorageValue(score_sto[i], 0)
    end

    return true
end

function CTF.removeFlags()
    for i, v in pairs(CTF.teams) do
        local flag = doFindItemInPos({v.flag.id}, v.flag.flag_pos)[1]
        if flag then
            doRemoveItem(flag.uid, 1)
        end

        v.flag.gnd_pos.stackpos = 0
        local gnd = getThingFromPos(v.flag.gnd_pos).uid
        doItemSetAttribute(gnd, "aid", 0)
    end

    return true
end

function CTF.start()
    doRemoveItem(doFindItemInPos({1387}, CTF.tppos)[1].uid, 1)
    setGlobalStorageValue(16705, -1)

    if #CTF.getMembers() < 2 then
        doBroadcastMessage("The CTF could not be started due to lack of players.")

        for _, cid in pairs(CTF.getMembers()) do
            CTF.removePlayer(cid)
        end

        return false
    end

    CTF.broadCast("The CTF has started. Have Fun!")

    for _, uid in pairs(CTF.getMembers()) do
        doTeleportThing(uid, getTownTemplePosition(getPlayerTown(uid)))
    end

    CTF.createFlags()
    return true
end

function CTF.returnFlag(uid, status)
    local team = getPlayerStorageValue(uid, 16702)

    if status then
        local msg = "Player ".. getCreatureName(uid) .. " Had Team Flag ".. team .. " "

        if status == 1 then
            msg = msg .. "But he died. "
        elseif status == 2 then
            msg = "You have been removed from event. "
        end

        msg = msg .. "The ".. team .. " flag has been retured."
        CTF.broadCast(msg)
    end

    if CTF.teams[team] then
        local flag = doCreateItem(CTF.teams[team].flag.id, 1, CTF.teams[team].flag.flag_pos)
        doItemSetAttribute(flag, "aid", 63218)

        setPlayerStorageValue(uid, 16702, -1)
    end

    return true
end

function CTF.addPoint(uid)
    local finish
    local msg = "Capture The Flag:"

    setGlobalStorageValue(score_sto[getPlayerStorageValue(uid, 16700)], getGlobalStorageValue(score_sto[getPlayerStorageValue(uid, 16700)]) + 1)

    for i, _ in pairs(CTF.teams) do
        msg = msg .. "\nTeam ".. i .. ": ".. getGlobalStorageValue(score_sto[i])

        if getGlobalStorageValue(score_sto[i]) >= CTF.winp then
            finish = i
        end
    end

    CTF.broadCast(getCreatureName(uid) .. " Scored a point for the Team ".. getPlayerStorageValue(uid, 16700) .. ".", 22)
    CTF.broadCast(msg)
    if finish then
        CTF.close(finish)
    end

    return true
end

function CTF.close(win)
    for i, _ in pairs(CTF.teams) do
        setGlobalStorageValue(score_sto[i], 0)
    end

    if not win then
        doBroadcastMessage("The CTF ended up with no winners.")
    else
        CTF.broadCast("The team ".. win .. " marked ".. CTF.winp .. " points and won the event.")
    end

for _, cid in pairs(CTF.getMembers()) do
        if getPlayerStorageValue(cid, 16700) == win then
            local xp = math.ceil(getPlayerExperience(cid) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(cid, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doPlayerAddExperience(cid, xp)
   doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end

        if getPlayerStorageValue(cid, 16702) ~= -1 then
            CTF.returnFlag(cid)
        end

        CTF.removePlayer(cid)
    end

    CTF.removeFlags()
    return true
end

local function Alert(uid)
    if (isCreature(uid)) then
        if getPlayerStorageValue(uid, 16702) == -1 or getPlayerStorageValue(uid, 16700) == -1 then
            return false
        end

        doSendAnimatedText(getThingPos(uid), "Flag!", math.random(50, 200))

        local bla = {18, 19, 21, 22, 23, 24}
        doSendMagicEffect(getThingPos(uid), bla[math.random(#bla)])

        if (os.time() - getPlayerStorageValue(uid, 16703) >= 60) then
            CTF.returnFlag(uid)
            return setPlayerStorageValue(uid, 16703, -1)
        end

        addEvent(Alert, 500, uid)
        return true
    end

    return false
end

function CTF.stealFlag(uid, team)
    setPlayerStorageValue(uid, 16702, team)
    setPlayerStorageValue(uid, 16703, os.time())

    CTF.broadCast(getCreatureName(uid) .. " Stole the Teams Flag from ".. team .. "!")
    Alert(uid)
    return true
end

function doFindItemInPos(ids, pos) -- By Undead Slayer
    local results = {}

    for _ = 0, 255 do
        local findPos = {x = pos.x, y = pos.y, z = pos.z, stackpos = _}
        if isInArray(ids, getThingFromPos(findPos).itemid) then
            table.insert(results, getThingFromPos(findPos))
        end
    end

    return results
end

Bump !

Bump

BUMP

bump

bump !

Well, you should first read all the code. After reading the code you should think what and when is failing.

If you do that you realise that this part is the affected one:
Code:
function CTF.close(win)
    for i, _ in pairs(CTF.teams) do
        setGlobalStorageValue(score_sto[i], 0)
    end
    if not win then
        doBroadcastMessage("The CTF ended up with no winners.")
    else
        CTF.broadCast("The team ".. win .. " marked ".. CTF.winp .. " points and won the event.")
    end
for _, cid in pairs(CTF.getMembers()) do
        if getPlayerStorageValue(cid, 16700) == win then
            local xp = math.ceil(getPlayerExperience(cid) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(cid, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doPlayerAddExperience(cid, xp)
   doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end
        if getPlayerStorageValue(cid, 16702) ~= -1 then
            CTF.returnFlag(cid)
        end
        CTF.removePlayer(cid)
    end
    CTF.removeFlags()
    return true
end

As you can see on this part of the code "CTF.close(win)", it happens when the CTF match ends.
Now if you check this part with more detail, you'll see that doTeleportThing() ONLY happens once
IF and ONLY IF the player got the storage (win).. that means that if the player lose which means he will have
"getPlayerStorageValue(cid,16700) ~= win", will not get teleported.

All you need to do is add a storage for losers or use a storage the player already have, and teleport those players with
that storage.

Something like this.

Code:
if getPlayerStorageValue(cid, 16700) == win then
            local xp = math.ceil(getPlayerExperience(cid) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(cid, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doPlayerAddExperience(cid, xp)
   doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
else
 
doPlayerSendTextMessage(cid, 22, "You lost, now exp for you loser!")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end

I did not test this, nor have seen the whole code, so i am just making assumptions with the info you gave.

Wish it helps.

Well, you should first read all the code. After reading the code you should think what and when is failing.

If you do that you realise that this part is the affected one:
Code:
function CTF.close(win)
    for i, _ in pairs(CTF.teams) do
        setGlobalStorageValue(score_sto[i], 0)
    end
    if not win then
        doBroadcastMessage("The CTF ended up with no winners.")
    else
        CTF.broadCast("The team ".. win .. " marked ".. CTF.winp .. " points and won the event.")
    end
for _, cid in pairs(CTF.getMembers()) do
        if getPlayerStorageValue(cid, 16700) == win then
            local xp = math.ceil(getPlayerExperience(cid) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(cid, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doPlayerAddExperience(cid, xp)
   doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end
        if getPlayerStorageValue(cid, 16702) ~= -1 then
            CTF.returnFlag(cid)
        end
        CTF.removePlayer(cid)
    end
    CTF.removeFlags()
    return true
end

As you can see on this part of the code "CTF.close(win)", it happens when the CTF match ends.
Now if you check this part with more detail, you'll see that doTeleportThing() ONLY happens once
IF and ONLY IF the player got the storage (win).. that means that if the player lose which means he will have
"getPlayerStorageValue(cid,16700) ~= win", will not get teleported.

All you need to do is add a storage for losers or use a storage the player already have, and teleport those players with
that storage.

Something like this.

Code:
if getPlayerStorageValue(cid, 16700) == win then
            local xp = math.ceil(getPlayerExperience(cid) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(cid, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doPlayerAddExperience(cid, xp)
   doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
else
 
doPlayerSendTextMessage(cid, 22, "You lost, now exp for you loser!")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end

I did not test this, nor have seen the whole code, so i am just making assumptions with the info you gave.

Wish it helps.
Hey , @Pretx already did it , but in private messages , he made as you said new storage and that all but i still have an bug in movements and dont want to teleport the players here you are :

[Error - MoveEvents Interface]
data/movements/scripts/CTFMax.lua:OnStepIn
Description:
<LuaInterface::LuaDoCreatureSetStorage> Creature not found


And also heres the lib which Pretx configured it to me :
Code:
--[[
]]
CTF_LIB = {
    waitpos = {x = 1250, y = 2093, z =7}, -- Posição da sala de espera
    tppos = {x = 1383, y = 1997, z =7}, -- Onde o TP vai aparecer
    days = {1, 2, 3, 4, 5, 6, 7}, -- Dias que o evento vai abrir
    xp_percent = 0.2, -- Porcentagem de exp que o player vai ganhar
    timeclose = 5, -- Tempo, em minutos, para iniciar o CTF
    winp = 3, -- Quantos pontos uma equipe precisa marcar para vencer
    teams = {
        ["Red Team"] = {
            temple = 6, -- TownID da equipe vermelha
            outfit = {lookHead = 0, lookBody = 132, lookLegs = 113, lookFeet = 94},
            flag = {
                id = 1435,
                flag_pos = {x = 1435, y = 2112, z =7}, -- Posição onde a bandeira vermelha vai ser criada
                gnd_pos = {x = 1435, y = 2110, z =7}, -- Onde os players da equipe vermelha entregarão a bandeira.
            },
        },
        ["Green Team"] = {
            temple = 5, -- TownID da equipe verde
            outfit = {lookHead = 0, lookBody = 121, lookLegs = 101, lookFeet = 101},
            flag = {
                id = 1437,
                flag_pos = {x = 1379, y = 2112, z =7}, -- Posição onde a bandeira verde vai ser criada
                gnd_pos = {x = 1379, y = 2110, z =7}, -- Onde os players da equipe verde entregarão a bandeira.
            },
        },
    },
}
local CTF = CTF_LIB
function CTF.getMembers()
    local members = {}
    for _, cid in pairs(getPlayersOnline()) do
        if getPlayerStorageValue(cid, 16700) ~= -1 then
            setPlayerStorageValue(cid, 55555, 1)
            table.insert(members, cid)
        end
    end
    return members
end
function CTF.teleport()
    for _, cid in pairs(getPlayersOnline()) do
        if getPlayerStorageValue(cid, 55555) == 1 then
            doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))         
            setPlayerStorageValue(cid, 55555, 0)
        end
    end
    return true
end
function CTF.getTeamMembers(team)
    local members = {}
    for _, cid in pairs(CTF.getMembers()) do
        if getPlayerStorageValue(cid, 16700) == team then
            table.insert(members, cid)
        end
    end
    return members
end
function CTF.removePlayer(uid)
    setPlayerStorageValue(uid, 16700, -1)
    doPlayerSetTown(uid, getPlayerStorageValue(uid, 16701))
    doTeleportThing(uid, getTownTemplePosition(getPlayerStorageValue(uid, 16701)))
    setPlayerStorageValue(uid, 16701, -1)
    setPlayerStorageValue(cid, 55555, 0)
    doRemoveCondition(uid, CONDITION_OUTFIT)
    doCreatureAddHealth(uid, getCreatureMaxHealth(uid))
    doCreatureAddMana(uid, getCreatureMaxMana(uid))
    return true
end
function CTF.addPlayer(uid)
    local team = CTF.getTeamLivre()
    local n_team = CTF.teams[team]
    setPlayerStorageValue(uid, 16700, team)
    setPlayerStorageValue(uid, 16701, getPlayerTown(uid))
    doPlayerSetTown(uid, n_team.temple)
    doTeleportThing(uid, CTF.waitpos)
    doPlayerSendTextMessage(uid, 22, "You are now part of the team. ".. team .. ".")
    local outfit = getCreatureOutfit(uid)
    for i, v in pairs(n_team.outfit) do
        outfit[i] = v
    end
    registerCreatureEvent(uid, "CTFLogout")
    registerCreatureEvent(uid, "CTFAttack")
    registerCreatureEvent(uid, "CTFCombat")
    registerCreatureEvent(uid, "CTFDeath")
    doSetCreatureOutfit(uid, outfit, -1)
    return true
end
function CTF.getTeamLivre()
    local teams = {}
    for i, _ in pairs(CTF.teams) do
        table.insert(teams, {i, #CTF.getTeamMembers(i)})
    end
    if (teams[1][2] < teams[2][2]) then
        return teams[1][1]
    elseif (teams[1][2] > teams[2][2]) then
        return teams[2][1]
    end
    return teams[math.random(2)][1]
end
function CTF.broadCast(msg, class)
    for _, uid in pairs(CTF.getMembers()) do
        doPlayerSendTextMessage(uid, class or 20, msg)
    end
    return true
end
function CTF.getFlagTeam(flag)
    for i, v in pairs(CTF.teams) do
        if v.flag.id == flag then
            return i
        end
    end
    return ""
end
local score_sto = {}
local a = 0
for i, _ in pairs(CTF.teams) do
    score_sto[i] = 42314 + a
    a = a + 1
end
function CTF.createFlags()
    for i, v in pairs(CTF.teams) do
        local flag = doCreateItem(v.flag.id, 1, v.flag.flag_pos)
        doItemSetAttribute(flag, "aid", 63218)
        v.flag.gnd_pos.stackpos = 0
        local gnd = getThingFromPos(v.flag.gnd_pos).uid
        doItemSetAttribute(gnd, "aid", 63200)
        doItemSetAttribute(gnd, "team", i)
        setGlobalStorageValue(score_sto[i], 0)
    end
    return true
end
function CTF.removeFlags()
    for i, v in pairs(CTF.teams) do
        local flag = doFindItemInPos({v.flag.id}, v.flag.flag_pos)[1]
        if flag then
            doRemoveItem(flag.uid, 1)
        end
        v.flag.gnd_pos.stackpos = 0
        local gnd = getThingFromPos(v.flag.gnd_pos).uid
        doItemSetAttribute(gnd, "aid", 0)
    end
    return true
end
function CTF.start()
    doRemoveItem(doFindItemInPos({1387}, CTF.tppos)[1].uid, 1)
    setGlobalStorageValue(16705, -1)
    if #CTF.getMembers() < 2 then
        doBroadcastMessage("The CTF could not be started due to lack of players.")
        for _, cid in pairs(CTF.getMembers()) do
            CTF.removePlayer(cid)
        end
        return false
    end
    CTF.broadCast("The CTF has started. Have Fun!")
    for _, uid in pairs(CTF.getMembers()) do
        doTeleportThing(uid, getTownTemplePosition(getPlayerTown(uid)))
    end
    CTF.createFlags()
    return true
end
function CTF.returnFlag(uid, status)
    local team = getPlayerStorageValue(uid, 16702)
    if status then
        local msg = "Player ".. getCreatureName(uid) .. " Had Team Flag ".. team .. " "
        if status == 1 then
            msg = msg .. "But he died. "
        elseif status == 2 then
            msg = "You have been removed from event. "
        end
        msg = msg .. "The ".. team .. " flag has been retured."
        CTF.broadCast(msg)
    end
    if CTF.teams[team] then
        local flag = doCreateItem(CTF.teams[team].flag.id, 1, CTF.teams[team].flag.flag_pos)
        doItemSetAttribute(flag, "aid", 63218)
        setPlayerStorageValue(uid, 16702, -1)
    end
    return true
end
function CTF.addPoint(uid)
    local finish
    local msg = "Capture The Flag:"
    setGlobalStorageValue(score_sto[getPlayerStorageValue(uid, 16700)], getGlobalStorageValue(score_sto[getPlayerStorageValue(uid, 16700)]) + 1)
    for i, _ in pairs(CTF.teams) do
        msg = msg .. "\nTeam ".. i .. ": ".. getGlobalStorageValue(score_sto[i])
        if getGlobalStorageValue(score_sto[i]) >= CTF.winp then
            finish = i
        end
    end
    CTF.broadCast(getCreatureName(uid) .. " Scored a point for the Team ".. getPlayerStorageValue(uid, 16700) .. ".", 22)
    CTF.broadCast(msg)
    if finish then
        CTF.close(finish)
    end
    return true
end
function CTF.close(win)
    for i, _ in pairs(CTF.teams) do
        setGlobalStorageValue(score_sto[i], 0)
    end
    if not win then
        doBroadcastMessage("The CTF ended up with no winners.")
    else
        CTF.broadCast("The team ".. win .. " marked ".. CTF.winp .. " points and won the event.")
    end
    CTF.teleport()
for _, cid in pairs(CTF.getMembers()) do
        if getPlayerStorageValue(cid, 16700) == win then
            local xp = math.ceil(getPlayerExperience(cid) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(cid, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(cid), xp, 215)
            doPlayerAddExperience(cid, xp)
            --doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end
        if getPlayerStorageValue(cid, 16702) ~= -1 then
            CTF.returnFlag(cid)
        end
        CTF.removePlayer(cid)
    end
    CTF.removeFlags()
    return true
end
local function Alert(uid)
    if (isCreature(uid)) then
        if getPlayerStorageValue(uid, 16702) == -1 or getPlayerStorageValue(uid, 16700) == -1 then
            return false
        end
        doSendAnimatedText(getThingPos(uid), "Flag!", math.random(50, 200))
        local bla = {18, 19, 21, 22, 23, 24}
        doSendMagicEffect(getThingPos(uid), bla[math.random(#bla)])
        if (os.time() - getPlayerStorageValue(uid, 16703) >= 60) then
            CTF.returnFlag(uid)
            return setPlayerStorageValue(uid, 16703, -1)
        end
        addEvent(Alert, 500, uid)
        return true
    end
    return false
end
function CTF.stealFlag(uid, team)
    setPlayerStorageValue(uid, 16702, team)
    setPlayerStorageValue(uid, 16703, os.time())
    CTF.broadCast(getCreatureName(uid) .. " Stole the Teams Flag from ".. team .. "!")
    Alert(uid)
    return true
end
function doFindItemInPos(ids, pos) -- By Undead Slayer
    local results = {}
    for _ = 0, 255 do
        local findPos = {x = pos.x, y = pos.y, z = pos.z, stackpos = _}
        if isInArray(ids, getThingFromPos(findPos).itemid) then
            table.insert(results, getThingFromPos(findPos))
        end
    end
    return results
end

And also here you got movements/ctfmax.lua
Code:
--[[
    Capture The Flag System
    Author: Maxwell Denisson(MaXwEllDeN)
    Version: 2.0
    Contact: [email protected]
]]

local CTF = CTF_LIB

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    local team = getItemAttribute(item.uid, "team")

    if team ~= getPlayerStorageValue(cid, 16700) then
        return doTeleportThing(cid, fromPosition)
    end

    if getPlayerStorageValue(cid, 16702) == -1 then
        doPlayerSendCancel(cid, "You do not have the flag.")
        return doTeleportThing(cid, fromPosition)
    end

    CTF.addPoint(cid)
    doTeleportThing(cid, fromPosition)

    CTF.returnFlag(cid)
    return true
end
Also thank you for answer !

Bump
 
Last edited by a moderator:
Honestly, even though it's badly coded and has multiple errors, everything looks like if should be working.
You'll need to test the event with like 2 players only, and add prints all over the place.
LUA:
print(001)
print(002)
print(003)
Do the event once, and post code + console messages after the event get's to the point of erroring.
 
Where right i should write Code print(001) ?
also as i told in previous , an guy already made me new lib , just the problem is in CTFMax.lua theres bug <LuaInterface::LuaDoCreatureSetStorage> Creature not found
i think i need add storage in script ctfmax.lua , am I right?
 
Based on the comment that you think the mistake are on CTF.close(win), why no check this, I have not a server 0.4 to test it, but I always use this kind of code and works:

LUA:
function CTF.close(win)
    for i, _ in pairs(CTF.teams) do
        setGlobalStorageValue(score_sto[i], 0)
    end
    if not win then
        doBroadcastMessage("The CTF ended up with no winners.")
    else
        CTF.broadCast("The team ".. win .. " marked ".. CTF.winp .. " points and won the event.")
    end
    local players = CTF.getMembers()
    for i = 1, #players() do
        local player = players[i]
        if getPlayerStorageValue(player, 16700) == win then
            local xp = math.ceil(getPlayerExperience(player) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(player, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(player), xp, 215)
            doPlayerAddExperience(player, xp)
            doTeleportThing(player, getTownTemplePosition(getPlayerTown(player)))
        else
            doPlayerSendTextMessage(player, 22, "You lost, now exp for you loser!")
            doSendAnimatedText(getThingPos(player), xp, 215)
            doTeleportThing(player, getTownTemplePosition(getPlayerTown(player)))
        end
        if getPlayerStorageValue(player, 16702) ~= -1 then
            CTF.returnFlag(cid)
        end
        CTF.removePlayer(player)
    end
    CTF.removeFlags()
    return true
end
 
Based on the comment that you think the mistake are on CTF.close(win), why no check this, I have not a server 0.4 to test it, but I always use this kind of code and works:

LUA:
function CTF.close(win)
    for i, _ in pairs(CTF.teams) do
        setGlobalStorageValue(score_sto[i], 0)
    end
    if not win then
        doBroadcastMessage("The CTF ended up with no winners.")
    else
        CTF.broadCast("The team ".. win .. " marked ".. CTF.winp .. " points and won the event.")
    end
    local players = CTF.getMembers()
    for i = 1, #players() do
        local player = players[i]
        if getPlayerStorageValue(player, 16700) == win then
            local xp = math.ceil(getPlayerExperience(player) * (CTF.xp_percent / 100), 215)
            doPlayerSendTextMessage(player, 22, "Congratulations! You won the event and got ".. CTF.xp_percent .."% of your total experience(".. xp ..").")
            doSendAnimatedText(getThingPos(player), xp, 215)
            doPlayerAddExperience(player, xp)
            doTeleportThing(player, getTownTemplePosition(getPlayerTown(player)))
        else
            doPlayerSendTextMessage(player, 22, "You lost, now exp for you loser!")
            doSendAnimatedText(getThingPos(player), xp, 215)
            doTeleportThing(player, getTownTemplePosition(getPlayerTown(player)))
        end
        if getPlayerStorageValue(player, 16702) ~= -1 then
            CTF.returnFlag(cid)
        end
        CTF.removePlayer(player)
    end
    CTF.removeFlags()
    return true
end

Added your script , now it dont even tp any of players here is image
Screenshot

Bump
 
Last edited by a moderator:
If its too hard to make script to work , can someone make me a script that will create 3 teleportts there and tp will stay for 1h , and than close i means every time ctf has been ended than tp should be created, :p
 
Back
Top