Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---CTF STATUS TRACKING DONT TOUCH --
- CTF_STATUS = 0
- CTF_PLAYERS_QUEUE = {}
- CTF_GREEN_TEAM_PLAYERS = {}
- CTF_RED_TEAM_PLAYERS = {}
- CTF_GREEN_SCORE = 0
- CTF_RED_SCORE = 0
- CTF_GREEN_FLAG_HOLDER = nil
- CTF_RED_FLAG_HOLDER = nil
- CTF_PLAYER_OUTFITS = {}
- ------------------------------------
- -------------------- CTF MAIN CONFIG --------------------------
- CTF_GREEN_FLAGID = 1437 -- Flag itemID of green team
- CTF_RED_FLAGID = 1435 -- Flag itemId of red team
- CTF_GREEN_CAPTURE_TILE_ID = 415 -- Itemid of tile to capture enemy flag
- CTF_RED_CAPTURE_TILE_ID = 415 -- Itemid of tile to capture enemy flag
- CTF_ACTIONID = 5675 -- Action id for flags and capture tiles
- CTF_REMOVE_GATES_TIME = 2 -- Walls that block players from running around CTF right away. 2 minutes
- CTF_WIN_SCORE = 10 -- How many times the flag is captured before the team automatically wins.
- CTF_AREA = { -- Make sure all tiles in the area in included in this. Its used to reset the field --
- min = Position(1008, 977, 7), -- Set to top left tile of CTF area --
- max = Position(1038, 995, 7) -- Set to bottom right tile of CTF area --
- }
- CTF_GREEN_FLAG_POSITION = Position(1012, 986, 7) -- Set to position that flag starts at
- CTF_RED_FLAG_POSITION = Position(1031, 986, 7) -- Set to position that flag starts at
- CTF_GREEN_CAPTURE_TILE_POS = Position(1012, 985, 7) -- Tile player walks on to capture enemy flag
- CTF_RED_CAPTURE_TILE_POS = Position(1031, 985, 7) -- Tile player walks on to capture enemy flag
- CTF_GATES = { -- These will be removed when its time for players to run around in CTF. They should block exits/entrances --
- [1] = {itemid = 3766, pos = Position(1016, 986, 7)},
- [2] = {itemid = 3766, pos = Position(1028, 986, 7)}
- }
- CTF_TIME_LIMIT = 30 -- End CTF automatically after 30 minutes
- CTF_RESTART_TIME = 60 -- Start CTF again after 60 minutes
- CTF_CHECK_QUEUE = 5 -- Check CTF queue after 5 minutes
- CTF_MIN_PLAYERS = 1 -- How many players must be queued for CTF to start.
- CTF_LEVEL_REQ = 1 -- What level do you need to enter CTF.
- CTF_GREEN_TEAM_START_POSITIONS = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)} -- Green team players are teleported in this area
- CTF_RED_TEAM_START_POSITIONS = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)} -- Red team players are teleported in this area
- CTF_RESPAWN_POSITIONS = { -- Multiple respawn points randomly selected for each team. Nice "unique" thing to have.
- GREEN_TEAM = {
- [1] = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)},
- [2] = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)},
- [3] = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)}
- },
- RED_TEAM = {
- [1] = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)},
- [2] = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)},
- [3] = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)}
- }
- }
- CTF_WINNER_MESSAGE = "Your team has won capture the flag!"
- CTF_LOSER_MESSAGE = "Your team has lost capture the flag!"
- CTF_TIE_MESSAGE = "Both teams have tied."
- CTF_MSG_FLAG_RETRUNED_GREEN = "The green teams flag has been recovered by the green team."
- CTF_MSG_FLAG_RETRUNED_RED = "The red teams flag has been recovered by the green red."
- CTF_MSG_FLAG_CAPTURED_GREEN = "The green team has captured the red teams flag!"
- CTF_MSG_FLAG_CAPTURED_RED = "The red team has captured the green teams flag!"
- CTF_TELEPORT_POSITION = Position(1021, 993, 7) -- Where players teleport after CTF is over.
- CTF_GIVE_ITEM_REWARDS = true -- Set to false for no item rewards.
- CTF_REWARD_TIE = true -- Gives rewards to all players if they tie.
- CTF_ITEMREWARDS = { -- Rewards are given to whole team.
- [1] = {itemid = 2160, count = 5, randomAmount = true}, -- Random amount will be 1-count
- [2] = {itemid = 2157, count = 1, randomAmount = false} -- Random amount will be 1-count
- }
- CTF_GREEN_OUTFIT = { -- TEAM OUTFITS =D as requested
- MALE = {lookType = 128, legs = 82, head = 82, feet = 82, body = 82, addons = 0},
- FEMALE = {lookType = 136, legs = 82, head = 82, feet = 82, body = 82, addons = 0}
- }
- CTF_RED_OUTFIT = {
- MALE = {lookType = 128, legs = 94, head = 94, feet = 94, body = 94, addons = 0},
- FEMALE = {lookType = 136, legs = 94, head = 94, feet = 94, body = 94, addons = 0}
- }
- ---------------------------------------------------------------
- ---------- FUNCTIONS ------------
- function isGreenTeam(playerName)
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- if CTF_GREEN_TEAM_PLAYERS[i] == playerName then
- return true
- end
- end
- return false
- end
- function isRedTeam(playerName)
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- if CTF_RED_TEAM_PLAYERS[i] == playerName then
- return true
- end
- end
- return false
- end
- function broadcastToCTFPlayers(msg)
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, msg)
- end
- end
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- local player = Player(CTF_RED_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, msg)
- end
- end
- end
- function checkCTFPlayers()
- for i = 1, #CTF_PLAYERS_QUEUE do
- local player = Player(CTF_PLAYERS_QUEUE)
- if player and player:hasCondition(CONDITION_ISINFIGHT) then
- CTF_PLAYERS_QUEUE[i] = nil
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You are in combat and cannot enter capture the flag. You have been removed from the queue.")
- end
- end
- if #CTF_PLAYERS_QUEUE < CTF_MIN_PLAYERS then
- Game.broadcastMessage("There are not enough players for CTF to start. CTF will try again in 30 minutes. You do not need to requeue.", 1)
- addEvent(restartCTF, 30 * 60 * 1000)
- else
- startCTF()
- end
- end
- function restartCTF()
- CTF_STATUS = 0
- end
- function startCTF()
- for i = 1, #CTF_PLAYERS_QUEUE do
- if #CTF_GREEN_TEAM_PLAYERS > #CTF_RED_TEAM_PLAYERS then
- CTF_RED_TEAM_PLAYERS[#CTF_RED_TEAM_PLAYERS + 1] = CTF_PLAYERS_QUEUE[i]
- else
- CTF_GREEN_TEAM_PLAYERS[#CTF_GREEN_TEAM_PLAYERS + 1] = CTF_PLAYERS_QUEUE[i]
- end
- end
- CTF_PLAYERS_QUEUE = {}
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
- if player then
- player:teleportTo(Position(math.random(CTF_GREEN_TEAM_START_POSITIONS.min.x, CTF_GREEN_TEAM_START_POSITIONS.max.x), math.random(CTF_GREEN_TEAM_START_POSITIONS.min.y, CTF_GREEN_TEAM_START_POSITIONS.max.y), math.random(CTF_GREEN_TEAM_START_POSITIONS.min.z, CTF_GREEN_TEAM_START_POSITIONS.max.z)))
- player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Welcome to capture the flag. You are on the green team! The gates will open in 2 minutes.")
- CTF_PLAYER_OUTFITS[player:getName()] = player:getOutfit()
- local newOutfit = player:getOutfit()
- if player:getSex() == 0 then
- newOutfit.lookType = CTF_GREEN_OUTFIT.FEMALE.lookType
- newOutfit.lookLegs = CTF_GREEN_OUTFIT.FEMALE.legs
- newOutfit.lookHead = CTF_GREEN_OUTFIT.FEMALE.head
- newOutfit.lookFeet = CTF_GREEN_OUTFIT.FEMALE.feet
- newOutfit.lookBody = CTF_GREEN_OUTFIT.FEMALE.body
- newOutfit.lookAddons = CTF_GREEN_OUTFIT.FEMALE.addons
- else
- newOutfit.lookType = CTF_GREEN_OUTFIT.MALE.lookType
- newOutfit.lookLegs = CTF_GREEN_OUTFIT.MALE.legs
- newOutfit.lookHead = CTF_GREEN_OUTFIT.MALE.head
- newOutfit.lookFeet = CTF_GREEN_OUTFIT.MALE.feet
- newOutfit.lookBody = CTF_GREEN_OUTFIT.MALE.body
- newOutfit.lookAddons = CTF_GREEN_OUTFIT.MALE.addons
- end
- Creature(player):setOutfit(newOutfit)
- end
- end
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- local player = Player(CTF_RED_TEAM_PLAYERS[i])
- if player then
- player:teleportTo(Position(math.random(CTF_RED_TEAM_START_POSITIONS.min.x, CTF_RED_TEAM_START_POSITIONS.max.x), math.random(CTF_RED_TEAM_START_POSITIONS.min.y, CTF_RED_TEAM_START_POSITIONS.max.y), math.random(CTF_RED_TEAM_START_POSITIONS.min.z, CTF_RED_TEAM_START_POSITIONS.max.z)))
- player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Welcome to capture the flag. You are on the green team! The gates will open in 2 minutes.")
- CTF_PLAYER_OUTFITS[player:getName()] = player:getOutfit()
- local newOutfit = player:getOutfit()
- if player:getSex() == 0 then
- newOutfit.lookType = CTF_RED_OUTFIT.FEMALE.lookType
- newOutfit.lookLegs = CTF_RED_OUTFIT.FEMALE.legs
- newOutfit.lookHead = CTF_RED_OUTFIT.FEMALE.head
- newOutfit.lookFeet = CTF_RED_OUTFIT.FEMALE.feet
- newOutfit.lookBody = CTF_RED_OUTFIT.FEMALE.body
- newOutfit.lookAddons = CTF_RED_OUTFIT.FEMALE.addons
- else
- newOutfit.lookType = CTF_RED_OUTFIT.MALE.lookType
- newOutfit.lookLegs = CTF_RED_OUTFIT.MALE.legs
- newOutfit.lookHead = CTF_RED_OUTFIT.MALE.head
- newOutfit.lookFeet = CTF_RED_OUTFIT.MALE.feet
- newOutfit.lookBody = CTF_RED_OUTFIT.MALE.body
- newOutfit.lookAddons = CTF_RED_OUTFIT.MALE.addons
- end
- Creature(player):setOutfit(newOutfit)
- end
- end
- CTF_STATUS = 2
- Game.broadcastMessage("Capture the flag is now closed. Good luck to the participants.", 1)
- addEvent(removeGates, CTF_REMOVE_GATES_TIME * 60 * 1000)
- addEvent(stopCTF, CTF_TIME_LIMIT * 60 * 1000)
- end
- function removeGates()
- for i = 1, #CTF_GATES do
- local position = CTF_GATES[i].pos
- local tile = Tile(position)
- if tile and tile:getItemById(CTF_GATES[i].itemid) then
- tile:getItemById(CTF_GATES[i].itemid):remove()
- end
- end
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
- if player then
- player:say("CHARGE", TALKTYPE_MONSTER_SAY, 0, 1, player:getPosition())
- end
- end
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- local player = Player(CTF_RED_TEAM_PLAYERS[i])
- if player then
- player:say("CHARGE", TALKTYPE_MONSTER_SAY, 0, 1, player:getPosition())
- end
- end
- end
- function stopCTF()
- CTF_STATUS = -1
- if CTF_GREEN_SCORE == CTF_RED_SCORE then
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_TIE_MESSAGE)
- Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
- if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
- for i = 1, #CTF_ITEMREWARDS do
- if CTF_ITEMREWARDS[i].randomAmount then
- player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
- else
- player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
- end
- end
- end
- player:teleportTo(CTF_TELEPORT_POSITION)
- end
- end
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- local player = Player(CTF_RED_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_TIE_MESSAGE)
- Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
- if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
- for i = 1, #CTF_ITEMREWARDS do
- if CTF_ITEMREWARDS[i].randomAmount then
- player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
- else
- player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
- end
- end
- end
- player:teleportTo(CTF_TELEPORT_POSITION)
- end
- end
- elseif CTF_GREEN_SCORE > CTF_RED_SCORE then
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_WINNER_MESSAGE)
- Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
- if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
- for i = 1, #CTF_ITEMREWARDS do
- if CTF_ITEMREWARDS[i].randomAmount then
- player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
- else
- player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
- end
- end
- end
- player:teleportTo(CTF_TELEPORT_POSITION)
- end
- end
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- local player = Player(CTF_RED_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_LOSER_MESSAGE)
- player:teleportTo(CTF_TELEPORT_POSITION)
- Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
- end
- end
- else
- for i = 1, #CTF_RED_TEAM_PLAYERS do
- local player = Player(CTF_RED_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_WINNER_MESSAGE)
- Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
- if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
- for i = 1, #CTF_ITEMREWARDS do
- if CTF_ITEMREWARDS[i].randomAmount then
- player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
- else
- player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
- end
- end
- end
- player:teleportTo(CTF_TELEPORT_POSITION)
- end
- end
- for i = 1, #CTF_GREEN_TEAM_PLAYERS do
- local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
- if player then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_LOSER_MESSAGE)
- player:teleportTo(CTF_TELEPORT_POSITION)
- Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
- end
- end
- end
- 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
- if not Tile(CTF_GREEN_FLAG_POSITION):getItemById(CTF_GREEN_FLAGID) then
- local flag = Game.createItem(CTF_GREEN_FLAGID, 1, CTF_GREEN_FLAG_POSITION)
- flag:setAttribute('aid', CTF_ACTIONID)
- end
- if not Tile(CTF_RED_FLAG_POSITION):getItemById(CTF_RED_FLAGID) then
- local flag = Game.createItem(CTF_RED_FLAGID, 1, CTF_RED_FLAG_POSITION)
- flag:setAttribute('aid', CTF_ACTIONID)
- end
- for x = CTF_AREA.min.x, CTF_AREA.max.x do
- x = x
- for y = CTF_AREA.min.y, CTF_AREA.max.y do
- y = y
- for z = CTF_AREA.min.z, CTF_AREA.max.z do
- local position = Position(x, y, z)
- local tile = Tile(position)
- if tile then
- if tile:getItemById(CTF_GREEN_FLAGID) and position ~= CTF_GREEN_FLAG_POSITION then
- tile:getItemById(CTF_GREEN_FLAGID):remove()
- elseif tile:getItemById(CTF_RED_FLAGID) and position ~= CTF_RED_FLAG_POSITION then
- tile:getItemById(CTF_RED_FLAGID):remove()
- end
- end
- end
- end
- end
- for i = 1, #CTF_GATES do
- if Tile(CTF_GATES[i].pos) and not Tile(CTF_GATES[i].pos):getItemById(CTF_GATES[i].itemid) then
- Game.createItem(CTF_GATES[i].itemid, 1, CTF_GATES[i].pos)
- end
- end
- addEvent(restartCTF, CTF_RESTART_TIME * 60 * 1000)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement