--- TALKACTION --
local ctfTalk = TalkAction("!ctf", "!CTF")
function ctfTalk.onSay(player, words, param)
if param == "enter" then
for i = 1, #CTF_PLAYERS_QUEUE do
if CTF_PLAYERS_QUEUE[i] == player:getName() then
player:sendCancelMessage("You are already queued for capture the flag.")
return false
end
end
if player:getLevel() < CTF_LEVEL_REQ then
player:sendCancelMessage("You must be level "..CTF_LEVEL_REQ.." to enter capture the flag.")
return false
end
CTF_PLAYERS_QUEUE[#CTF_PLAYERS_QUEUE + 1] = player:getName()
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You are now queued for capture the flag. You may type !ctf leave to leave the queue.")
elseif param == "leave" then
for i = 1, #CTF_PLAYERS_QUEUE do
if CTF_PLAYERS_QUEUE[i] == player:getName() then
CTF_PLAYERS_QUEUE[i] = nil
player:sendCancelMessage("You have left the capture the flag queue.")
return false
end
end
player:sendCancelMessage("You are not queued in capture the flag.")
return false
elseif param == "start" then
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return true
end
if CTF_STATUS > 0 then
player:sendCancelMessage("Capture the flag is already started.")
return false
end
Game.broadcastMessage("Capture the flag is now open. Type !ctf enter to join the queue. It will start in " ..CTF_CHECK_QUEUE.. " minutes.")
CTF_STATUS = 1
CTF_GREEN_TEAM_PLAYERS = {}
CTF_RED_TEAM_PLAYERS = {}
CTF_PLAYER_OUTFITS = {}
CTF_GREEN_SCORE = 0
CTF_RED_SCORE = 0
CTF_GREEN_FLAG_HOLDER = nil
CTF_RED_FLAG_HOLDER = nil
addEvent(checkCTFPlayers, CTF_CHECK_QUEUE * 60 * 1000)
elseif param == "cancel" or param == "stop" then
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return true
end
stopCTF()
end
return false
end
ctfTalk:separator(" ")
ctfTalk:register()
-- GLOBALEVENT --
local ctfGlobal = GlobalEvent("CTF_GLOBAL")
function ctfGlobal.onThink(...)
if CTF_STATUS == 0 then
Game.broadcastMessage("Capture the flag is now open. Type !ctf enter to join the queue. It will start in 5 minutes.", 1)
addEvent(checkCTFPlayers, 1 * 60 * 1000)
end
if CTF_GREEN_FLAG_HOLDER then
local player = Player(CTF_GREEN_FLAG_HOLDER)
if player then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
if CTF_RED_FLAG_HOLDER then
local player = Player(CTF_RED_FLAG_HOLDER)
if player then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
return true
end
ctfGlobal:interval(1000)
ctfGlobal:register()
-- ACTION --
local ctfAction = Action()
function ctfAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid == CTF_GREEN_FLAGID then
if isGreenTeam(player:getName()) then
if item:getPosition() == CTF_GREEN_FLAG_POSITION then
return player:sendCancelMessage("You cannot pick up your own flag.")
else
item:moveTo(CTF_GREEN_FLAG_POSITION)
broadcastToCTFPlayers(CTF_MSG_FLAG_RETRUNED_GREEN)
end
else
CTF_GREEN_FLAG_HOLDER = player:getName()
item:remove()
broadcastToCTFPlayers("The green flag has been taken by "..player:getName().."!")
end
elseif item.itemid == CTF_RED_FLAGID then
if isRedTeam(player:getName()) then
if item:getPosition() == CTF_RED_FLAG_POSITION then
return player:sendCancelMessage("You cannot pick up your own flag.")
else
item:moveTo(CTF_RED_FLAG_POSITION)
broadcastToCTFPlayers(CTF_MSG_FLAG_RETRUNED_RED)
end
else
CTF_RED_FLAG_HOLDER = player:getName()
item:remove()
broadcastToCTFPlayers("The red flag has been taken by "..player:getName().."!")
end
end
return true
end
ctfAction:aid(CTF_ACTIONID)
ctfAction:register()
-- Moveevent --
local ctfMovement = MoveEvent()
function ctfMovement.onStepIn(creature, item, position, fromPosition)
local player = Player(creature)
if not player then return true end
if item.itemid == CTF_GREEN_CAPTURE_TILE_ID and item.actionid == CTF_ACTIONID and item:getPosition() == CTF_GREEN_CAPTURE_TILE_POS then
if isGreenTeam(player:getName()) then
if CTF_RED_FLAG_HOLDER ~= player:getName() then
player:teleportTo(fromPosition, true)
player:sendCancelMessage("You cannot stand on your capture tile.")
return false
else
player:teleportTo(fromPosition, true)
CTF_RED_FLAG_HOLDER = nil
CTF_GREEN_SCORE = CTF_GREEN_SCORE + 1
local flag = Game.createItem(CTF_RED_FLAGID, 1, CTF_RED_FLAG_POSITION)
flag:setAttribute('aid', CTF_ACTIONID)
if CTF_GREEN_SCORE == CTF_WIN_SCORE then
stopCTF()
return true
end
broadcastToCTFPlayers(CTF_MSG_FLAG_CAPTURED_GREEN.." The green team now has "..CTF_GREEN_SCORE.." point(s).")
end
else
player:teleportTo(fromPosition, true)
player:sendCancelMessage("You cannot stand on the green teams capture tile.")
return false
end
elseif item.itemid == CTF_RED_CAPTURE_TILE_ID and item.actionid == CTF_ACTIONID and item:getPosition() == CTF_RED_CAPTURE_TILE_POS then
if isRedTeam(player:getName()) then
if CTF_GREEN_FLAG_HOLDER ~= player:getName() then
player:teleportTo(fromPosition, true)
player:sendCancelMessage("You cannot stand on your capture tile.")
return false
else
player:teleportTo(fromPosition, true)
CTF_GREEN_FLAG_HOLDER = nil
CTF_RED_SCORE = CTF_RED_SCORE + 1
local flag = Game.createItem(CTF_GREEN_FLAGID, 1, CTF_GREEN_FLAG_POSITION)
flag:setAttribute('aid', CTF_ACTIONID)
if CTF_RED_SCORE == CTF_WIN_SCORE then
stopCTF()
return true
end
broadcastToCTFPlayers(CTF_MSG_FLAG_CAPTURED_RED.." The red team now has "..CTF_RED_SCORE.." point(s).")
end
else
player:teleportTo(fromPosition, true)
player:sendCancelMessage("You cannot stand on the red teams capture tile.")
return false
end
end
return true
end
ctfMovement:aid(CTF_ACTIONID)
ctfMovement:register()
-- CreatureEvents --
local ctfPrepareDeath = CreatureEvent("CTF_PREPAREDEATH")
function ctfPrepareDeath.onPrepareDeath(creature, killer)
if not creature:isPlayer() then return true end
local player = Player(creature)
if isGreenTeam(player:getName()) then
if CTF_RED_FLAG_HOLDER and CTF_RED_FLAG_HOLDER == player:getName() then
CTF_RED_FLAG_HOLDER = nil
local flag = Game.createItem(CTF_RED_FLAGID, 1, player:getPosition())
flag:setAttribute('aid', CTF_ACTIONID)
end
player:addHealth(999999)
player:addMana(999999)
local randSpawn = math.random(3)
local posMin = CTF_RESPAWN_POSITIONS.GREEN_TEAM[randSpawn].min
local posMan = CTF_RESPAWN_POSITIONS.GREEN_TEAM[randSpawn].max
local spawnPos = Position(math.random(posMin.x, posMax.x), math.random(posMin.y, posMax.y), math.random(posMin.z, posMax.z))
player:teleportTo(spawnPos)
return false
elseif isRedTeam(player:getName()) then
if CTF_GREEN_FLAG_HOLDER and CTF_GREEN_FLAG_HOLDER == player:getName() then
CTF_GREEN_FLAG_HOLDER = nil
local flag = Game.createItem(CTF_GREEN_FLAGID, 1, player:getPosition())
flag:setAttribute('aid', CTF_ACTIONID)
end
player:addHealth(999999)
player:addMana(999999)
local randSpawn = math.random(3)
local posMin = CTF_RESPAWN_POSITIONS.RED_TEAM[randSpawn].min
local posMax = CTF_RESPAWN_POSITIONS.RED_TEAM[randSpawn].max
local spawnPos = Position(math.random(posMin.x, posMax.x), math.random(posMin.y, posMax.y), math.random(posMin.z, posMax.z))
player:teleportTo(spawnPos)
return false
end
return true
end
ctfPrepareDeath:register()