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

Lua Capture the flag - TFS 0.3.6

Carlitos Flow

Developer (lvl*1)
Joined
Mar 2, 2011
Messages
156
Solutions
4
Reaction score
10
Good day, i have a problem , i was testing the event and when it start all players go to the team blue. And the second time it divide 50% for each teams. Itried solve it, but i can't. Thank you! (Mode)
LUA:
function eventStart()
        doSetStorage(Event_Tile_Close,-1)
        setGlobalStorageValue(Event_timeend,1)
        setGlobalStorageValue(Timer, os.time() + Event_MaxTime*60)
        addEvent(eventEnd,Event_MaxTime*60*1000)



                        for v = frompos.x , topos.x do
                                for k = frompos.y , topos.y do
                                        for i = 1, 200 do
                                                position = {x = v, y = k, z = 7, stackpos = i}
                                                pid = getThingfromPos(position).uid
                                                        if(pid ~= nil and isPlayer(pid)) then
                                                                table.insert(players, pid)
                                                        end
                                        end
                                end
                        end
                        if math.mod(#players, 2) ~= 0 then
                                doTeleportThing(players[#players],getTownTemplePosition(getPlayerTown(players[#players])),false)
                                doSendMagicEffect(getThingPosition(players[#players]),10)
                                doPlayerSendTextMessage(players[#players], 19, "Sorry, you have been kicked from event to balance teams.")
                                table.remove(players)
                        end
                        if #players < Players_Least_Number then
                                doBroadcastMessage("Capture The Flag event was cancelled because less than "..Players_Least_Number.." players joined")
              doRemoveItem(getTileItemById(Tp_Place, 1387).uid, 1)
                                resetTheStorage()
                                        if #players > 0 then
                                                for i = 1,#players do
                                                        doTeleportThing(players[i],getTownTemplePosition(getPlayerTown(players[i])),false)
                                                        doSendMagicEffect(getThingPos(players[i]), 10)
                                                end
                                        end
                        else
                                        doBroadcastMessage("CTF started")
                                                for i = 1, math.floor(#players/2) do
                                                        setFirstTeam(players[i])
                                                end
                                                for i = math.floor(#players/2)+1 , #players do
                                                        setSecondTeam(players[i])
                                                end
                                                for _,cid in ipairs(getPlayersOnline()) do
                                                        if isTeamOne(cid) then
                                                                if getPlayerSex(cid) == 1 then
                                                                        doAddCondition(cid, bmale)
                                                                elseif getPlayerSex(cid) ~= 1 then
                                                                        doAddCondition(cid, bfemale)
                                                                end
                                                                doAddCondition(cid, fight)
                                                                doTeleportThing(cid,Blue_Position,false)
                                                                doSendMagicEffect(Blue_Position, 10)
                                                                doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid))
                                                        elseif  isTeamTwo(cid) then
                                                                if getPlayerSex(cid) == 1 then
                                                                        doAddCondition(cid, rmale)
                                                                elseif getPlayerSex(cid) ~= 1 then
                                                                        doAddCondition(cid, rfemale)
                                                                end
                                                                doAddCondition(cid, fight)
                                                                doTeleportThing(cid,Red_Position,false)
                                                                doSendMagicEffect(Red_Position, 10)
                                                                doChangeSpeed(cid, getTheSpeed(Players_Speed) - getCreatureSpeed(cid))
                                                        end
                                                end
                                                players = {}

                        end
end
function onThink(interval)
  if getGlobalStorageValue(Event_Start) < 0 then
                setGlobalStorageValue(Event_Start,1)
                doSetStorage(Event_Tile_Close,1)
                doBroadcastMessage("Event Notice! Capture The Flag event has been opened and a teleport has been created in the Temple. It will begin in "..Event_WaitTime.." minutes!")
                players = {}
                if getTileItemById(Tp_Place, 1387).uid < 1 then
                        doItemSetAttribute(doCreateItem(1387,1, Tp_Place), "aid", 3435)
                end

                f= Event_WaitTime - 1
                        for i = 1,Event_WaitTime-1 do
                                addEvent(doBroadcastMessage,i*60*1000,"Capture The Flag event has been opened and the teleport is created in the Temple. It will begin in "..f.." minutes.")
                                f= f-1
                        end
                addEvent(eventStart,Event_WaitTime*60*1000)
        end
return true
end
]]></globalevent>
  <event type="think" name="ctff" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')

local bl = GREEN_FLAG
local re = RED_FLAG
function onThink(interval)
        if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
                if redStolen() < 0 then
                        doSendAnimatedText(re,"FLAG!",TEXTCOLOR_DARKRED)
                        doSendMagicEffect(re, CONST_ME_SOUND_RED)
                end
                if blueStolen() < 0 then
                        doSendAnimatedText(bl,"FLAG!",TEXTCOLOR_GREEN)
                        doSendMagicEffect(bl, CONST_ME_SOUND_GREEN)
                end
                for _, cid in ipairs(getPlayersOnline()) do
                        if flagOwner(cid) then
                                if isTeamOne(cid) or isTeamTwo(cid) then
                                        if hasCondition(cid,CONDITION_HASTE) then
                                                doRemoveCondition(cid,CONDITION_HASTE)
                                        end
                                end
                                pl = getThingPos(cid)
                                        if isTeamTwo(cid) then
                                                if getPlayerStorageValue(cid,103) < os.time() then
                                                        releaseBF(cid)
                                                                for _,cid in ipairs(getPlayersOnline()) do
                                                                        if isTeamOne(cid) or isTeamTwo(cid) then
                                                                                doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " wasted 5 minutes with FLAG."..TEAM2_NAME.." flag is again on spawn!")
                                                                        end
                                                                end
                                                else
                                                        doSendAnimatedText(pl,"FLAG!",TEXTCOLOR_GREEN)
                                                        doSendMagicEffect(pl, CONST_ME_SOUND_GREEN)
                                                end
                                        elseif isTeamOne(cid) then
                                                if getPlayerStorageValue(cid,103) < os.time() then
                                                        releaseRF(cid)
                                                                for _,cid in ipairs(getPlayersOnline()) do
                                                                        if isTeamOne(cid) or isTeamTwo(cid) then
                                                                                doPlayerSendTextMessage(cid,22,getCreatureName(cid) .. " wasted 5 minutes with FLAG."..TEAM1_NAME.." flag is again on spawn!")
                                                                        end
                                                                end
                                                else
                                                        doSendAnimatedText(pl,"FLAG!",COLOR_RED)
                                                        doSendMagicEffect(pl, CONST_ME_SOUND_RED)
                                                end
                                        end
                        end
                end
        end
  return true
end
]]></event>
  <globalevent name="timer" interval="0.4" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')

function onThink(interval)
        for _,cid in ipairs(getPlayersOnline()) do
                if isTeamOne(cid) or isTeamTwo(cid) then
                        if getGlobalStorageValue(Event_Start) > 0 and getGlobalStorageValue(Event_timeend) > 0 then
                                if getGlobalStorageValue(Timer)- os.time() >= 0 then
                                        doPlayerSendCancel(cid, "Time -> ".. os.date("%M:%S ",getGlobalStorageValue(Timer)- os.time()) .. "  |  ".. TEAM1_NAME.." Score : "..getBlueScore(cid).."/"..FLAG_SCORE.." captures  |  ".. TEAM2_NAME.." Score : "..getRedScore(cid).."/"..FLAG_SCORE.." captures")
                                end
                        end
                end
        end
return true
end
]]></globalevent>
  <globalevent name="starting" type="startup" event="script"><![CDATA[
domodlib('toto')
domodlib('CTF-lib')
function onStartup()
        resetTheStorage()

return true
end
]]></globalevent>
</mod>
 
Back
Top