Advertisement
Guest User

Untitled

a guest
Mar 12th, 2022
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.42 KB | None | 0 0
  1. ---CTF STATUS TRACKING DONT TOUCH --
  2. CTF_STATUS = 0
  3. CTF_PLAYERS_QUEUE = {}
  4. CTF_GREEN_TEAM_PLAYERS = {}
  5. CTF_RED_TEAM_PLAYERS = {}
  6. CTF_GREEN_SCORE = 0
  7. CTF_RED_SCORE = 0
  8. CTF_GREEN_FLAG_HOLDER = nil
  9. CTF_RED_FLAG_HOLDER = nil
  10. CTF_PLAYER_OUTFITS = {}
  11. ------------------------------------
  12.  
  13. -------------------- CTF MAIN CONFIG --------------------------
  14. CTF_GREEN_FLAGID = 1437 -- Flag itemID of green team
  15. CTF_RED_FLAGID = 1435 -- Flag itemId of red team
  16. CTF_GREEN_CAPTURE_TILE_ID = 415 -- Itemid of tile to capture enemy flag
  17. CTF_RED_CAPTURE_TILE_ID = 415 -- Itemid of tile to capture enemy flag
  18. CTF_ACTIONID = 5675 -- Action id for flags and capture tiles
  19. CTF_REMOVE_GATES_TIME = 2 -- Walls that block players from running around CTF right away. 2 minutes
  20. CTF_WIN_SCORE = 10 -- How many times the flag is captured before the team automatically wins.
  21.  
  22. CTF_AREA = { -- Make sure all tiles in the area in included in this. Its used to reset the field --
  23. min = Position(1008, 977, 7), -- Set to top left tile of CTF area --
  24. max = Position(1038, 995, 7) -- Set to bottom right tile of CTF area --
  25. }
  26.  
  27. CTF_GREEN_FLAG_POSITION = Position(1012, 986, 7) -- Set to position that flag starts at
  28. CTF_RED_FLAG_POSITION = Position(1031, 986, 7) -- Set to position that flag starts at
  29. CTF_GREEN_CAPTURE_TILE_POS = Position(1012, 985, 7) -- Tile player walks on to capture enemy flag
  30. CTF_RED_CAPTURE_TILE_POS = Position(1031, 985, 7) -- Tile player walks on to capture enemy flag
  31.  
  32. CTF_GATES = { -- These will be removed when its time for players to run around in CTF. They should block exits/entrances --
  33. [1] = {itemid = 3766, pos = Position(1016, 986, 7)},
  34. [2] = {itemid = 3766, pos = Position(1028, 986, 7)}
  35. }
  36.  
  37. CTF_TIME_LIMIT = 30 -- End CTF automatically after 30 minutes
  38. CTF_RESTART_TIME = 60 -- Start CTF again after 60 minutes
  39. CTF_CHECK_QUEUE = 5 -- Check CTF queue after 5 minutes
  40. CTF_MIN_PLAYERS = 1 -- How many players must be queued for CTF to start.
  41. CTF_LEVEL_REQ = 1 -- What level do you need to enter CTF.
  42.  
  43. CTF_GREEN_TEAM_START_POSITIONS = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)} -- Green team players are teleported in this area
  44. CTF_RED_TEAM_START_POSITIONS = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)} -- Red team players are teleported in this area
  45.  
  46.  
  47. CTF_RESPAWN_POSITIONS = { -- Multiple respawn points randomly selected for each team. Nice "unique" thing to have.
  48. GREEN_TEAM = {
  49. [1] = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)},
  50. [2] = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)},
  51. [3] = {min = Position(1011, 982, 7), max = Position(1013, 984, 7)}
  52. },
  53. RED_TEAM = {
  54. [1] = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)},
  55. [2] = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)},
  56. [3] = {min = Position(1030, 982, 7), max = Position(1032, 984, 7)}
  57. }
  58. }
  59.  
  60. CTF_WINNER_MESSAGE = "Your team has won capture the flag!"
  61. CTF_LOSER_MESSAGE = "Your team has lost capture the flag!"
  62. CTF_TIE_MESSAGE = "Both teams have tied."
  63. CTF_MSG_FLAG_RETRUNED_GREEN = "The green teams flag has been recovered by the green team."
  64. CTF_MSG_FLAG_RETRUNED_RED = "The red teams flag has been recovered by the green red."
  65. CTF_MSG_FLAG_CAPTURED_GREEN = "The green team has captured the red teams flag!"
  66. CTF_MSG_FLAG_CAPTURED_RED = "The red team has captured the green teams flag!"
  67.  
  68. CTF_TELEPORT_POSITION = Position(1021, 993, 7) -- Where players teleport after CTF is over.
  69.  
  70. CTF_GIVE_ITEM_REWARDS = true -- Set to false for no item rewards.
  71. CTF_REWARD_TIE = true -- Gives rewards to all players if they tie.
  72.  
  73. CTF_ITEMREWARDS = { -- Rewards are given to whole team.
  74. [1] = {itemid = 2160, count = 5, randomAmount = true}, -- Random amount will be 1-count
  75. [2] = {itemid = 2157, count = 1, randomAmount = false} -- Random amount will be 1-count
  76. }
  77.  
  78. CTF_GREEN_OUTFIT = { -- TEAM OUTFITS =D as requested
  79. MALE = {lookType = 128, legs = 82, head = 82, feet = 82, body = 82, addons = 0},
  80. FEMALE = {lookType = 136, legs = 82, head = 82, feet = 82, body = 82, addons = 0}
  81. }
  82.  
  83. CTF_RED_OUTFIT = {
  84. MALE = {lookType = 128, legs = 94, head = 94, feet = 94, body = 94, addons = 0},
  85. FEMALE = {lookType = 136, legs = 94, head = 94, feet = 94, body = 94, addons = 0}
  86. }
  87.  
  88.  
  89. ---------------------------------------------------------------
  90.  
  91. ---------- FUNCTIONS ------------
  92. function isGreenTeam(playerName)
  93. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  94. if CTF_GREEN_TEAM_PLAYERS[i] == playerName then
  95. return true
  96. end
  97. end
  98. return false
  99. end
  100.  
  101. function isRedTeam(playerName)
  102. for i = 1, #CTF_RED_TEAM_PLAYERS do
  103. if CTF_RED_TEAM_PLAYERS[i] == playerName then
  104. return true
  105. end
  106. end
  107. return false
  108. end
  109.  
  110. function broadcastToCTFPlayers(msg)
  111. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  112. local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
  113.  
  114. if player then
  115. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, msg)
  116. end
  117. end
  118.  
  119. for i = 1, #CTF_RED_TEAM_PLAYERS do
  120. local player = Player(CTF_RED_TEAM_PLAYERS[i])
  121.  
  122. if player then
  123. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, msg)
  124. end
  125. end
  126. end
  127.  
  128. function checkCTFPlayers()
  129. for i = 1, #CTF_PLAYERS_QUEUE do
  130. local player = Player(CTF_PLAYERS_QUEUE)
  131.  
  132. if player and player:hasCondition(CONDITION_ISINFIGHT) then
  133. CTF_PLAYERS_QUEUE[i] = nil
  134. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You are in combat and cannot enter capture the flag. You have been removed from the queue.")
  135. end
  136. end
  137.  
  138. if #CTF_PLAYERS_QUEUE < CTF_MIN_PLAYERS then
  139. 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)
  140. addEvent(restartCTF, 30 * 60 * 1000)
  141. else
  142. startCTF()
  143. end
  144. end
  145.  
  146. function restartCTF()
  147. CTF_STATUS = 0
  148. end
  149.  
  150. function startCTF()
  151. for i = 1, #CTF_PLAYERS_QUEUE do
  152. if #CTF_GREEN_TEAM_PLAYERS > #CTF_RED_TEAM_PLAYERS then
  153. CTF_RED_TEAM_PLAYERS[#CTF_RED_TEAM_PLAYERS + 1] = CTF_PLAYERS_QUEUE[i]
  154. else
  155. CTF_GREEN_TEAM_PLAYERS[#CTF_GREEN_TEAM_PLAYERS + 1] = CTF_PLAYERS_QUEUE[i]
  156. end
  157. end
  158.  
  159. CTF_PLAYERS_QUEUE = {}
  160.  
  161. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  162. local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
  163.  
  164. if player then
  165. 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)))
  166. player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
  167. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Welcome to capture the flag. You are on the green team! The gates will open in 2 minutes.")
  168. CTF_PLAYER_OUTFITS[player:getName()] = player:getOutfit()
  169. local newOutfit = player:getOutfit()
  170. if player:getSex() == 0 then
  171. newOutfit.lookType = CTF_GREEN_OUTFIT.FEMALE.lookType
  172. newOutfit.lookLegs = CTF_GREEN_OUTFIT.FEMALE.legs
  173. newOutfit.lookHead = CTF_GREEN_OUTFIT.FEMALE.head
  174. newOutfit.lookFeet = CTF_GREEN_OUTFIT.FEMALE.feet
  175. newOutfit.lookBody = CTF_GREEN_OUTFIT.FEMALE.body
  176. newOutfit.lookAddons = CTF_GREEN_OUTFIT.FEMALE.addons
  177. else
  178. newOutfit.lookType = CTF_GREEN_OUTFIT.MALE.lookType
  179. newOutfit.lookLegs = CTF_GREEN_OUTFIT.MALE.legs
  180. newOutfit.lookHead = CTF_GREEN_OUTFIT.MALE.head
  181. newOutfit.lookFeet = CTF_GREEN_OUTFIT.MALE.feet
  182. newOutfit.lookBody = CTF_GREEN_OUTFIT.MALE.body
  183. newOutfit.lookAddons = CTF_GREEN_OUTFIT.MALE.addons
  184. end
  185. Creature(player):setOutfit(newOutfit)
  186. end
  187. end
  188.  
  189. for i = 1, #CTF_RED_TEAM_PLAYERS do
  190. local player = Player(CTF_RED_TEAM_PLAYERS[i])
  191.  
  192. if player then
  193. 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)))
  194. player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
  195. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Welcome to capture the flag. You are on the green team! The gates will open in 2 minutes.")
  196. CTF_PLAYER_OUTFITS[player:getName()] = player:getOutfit()
  197. local newOutfit = player:getOutfit()
  198. if player:getSex() == 0 then
  199. newOutfit.lookType = CTF_RED_OUTFIT.FEMALE.lookType
  200. newOutfit.lookLegs = CTF_RED_OUTFIT.FEMALE.legs
  201. newOutfit.lookHead = CTF_RED_OUTFIT.FEMALE.head
  202. newOutfit.lookFeet = CTF_RED_OUTFIT.FEMALE.feet
  203. newOutfit.lookBody = CTF_RED_OUTFIT.FEMALE.body
  204. newOutfit.lookAddons = CTF_RED_OUTFIT.FEMALE.addons
  205. else
  206. newOutfit.lookType = CTF_RED_OUTFIT.MALE.lookType
  207. newOutfit.lookLegs = CTF_RED_OUTFIT.MALE.legs
  208. newOutfit.lookHead = CTF_RED_OUTFIT.MALE.head
  209. newOutfit.lookFeet = CTF_RED_OUTFIT.MALE.feet
  210. newOutfit.lookBody = CTF_RED_OUTFIT.MALE.body
  211. newOutfit.lookAddons = CTF_RED_OUTFIT.MALE.addons
  212. end
  213. Creature(player):setOutfit(newOutfit)
  214. end
  215. end
  216.  
  217. CTF_STATUS = 2
  218. Game.broadcastMessage("Capture the flag is now closed. Good luck to the participants.", 1)
  219. addEvent(removeGates, CTF_REMOVE_GATES_TIME * 60 * 1000)
  220. addEvent(stopCTF, CTF_TIME_LIMIT * 60 * 1000)
  221. end
  222.  
  223. function removeGates()
  224. for i = 1, #CTF_GATES do
  225. local position = CTF_GATES[i].pos
  226. local tile = Tile(position)
  227. if tile and tile:getItemById(CTF_GATES[i].itemid) then
  228. tile:getItemById(CTF_GATES[i].itemid):remove()
  229. end
  230. end
  231.  
  232. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  233. local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
  234.  
  235. if player then
  236. player:say("CHARGE", TALKTYPE_MONSTER_SAY, 0, 1, player:getPosition())
  237. end
  238. end
  239.  
  240. for i = 1, #CTF_RED_TEAM_PLAYERS do
  241. local player = Player(CTF_RED_TEAM_PLAYERS[i])
  242.  
  243. if player then
  244. player:say("CHARGE", TALKTYPE_MONSTER_SAY, 0, 1, player:getPosition())
  245. end
  246. end
  247. end
  248.  
  249. function stopCTF()
  250. CTF_STATUS = -1
  251. if CTF_GREEN_SCORE == CTF_RED_SCORE then
  252. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  253. local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
  254. if player then
  255. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_TIE_MESSAGE)
  256. Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
  257.  
  258. if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
  259. for i = 1, #CTF_ITEMREWARDS do
  260. if CTF_ITEMREWARDS[i].randomAmount then
  261. player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
  262. else
  263. player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
  264. end
  265. end
  266. end
  267.  
  268. player:teleportTo(CTF_TELEPORT_POSITION)
  269. end
  270. end
  271.  
  272. for i = 1, #CTF_RED_TEAM_PLAYERS do
  273. local player = Player(CTF_RED_TEAM_PLAYERS[i])
  274. if player then
  275. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_TIE_MESSAGE)
  276. Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
  277.  
  278. if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
  279. for i = 1, #CTF_ITEMREWARDS do
  280. if CTF_ITEMREWARDS[i].randomAmount then
  281. player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
  282. else
  283. player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
  284. end
  285. end
  286. end
  287.  
  288. player:teleportTo(CTF_TELEPORT_POSITION)
  289. end
  290. end
  291.  
  292. elseif CTF_GREEN_SCORE > CTF_RED_SCORE then
  293. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  294. local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
  295. if player then
  296. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_WINNER_MESSAGE)
  297. Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
  298.  
  299. if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
  300. for i = 1, #CTF_ITEMREWARDS do
  301. if CTF_ITEMREWARDS[i].randomAmount then
  302. player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
  303. else
  304. player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
  305. end
  306. end
  307. end
  308.  
  309. player:teleportTo(CTF_TELEPORT_POSITION)
  310. end
  311. end
  312.  
  313. for i = 1, #CTF_RED_TEAM_PLAYERS do
  314. local player = Player(CTF_RED_TEAM_PLAYERS[i])
  315. if player then
  316. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_LOSER_MESSAGE)
  317. player:teleportTo(CTF_TELEPORT_POSITION)
  318. Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
  319. end
  320. end
  321.  
  322. else
  323.  
  324. for i = 1, #CTF_RED_TEAM_PLAYERS do
  325. local player = Player(CTF_RED_TEAM_PLAYERS[i])
  326. if player then
  327. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_WINNER_MESSAGE)
  328. Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
  329.  
  330. if CTF_GIVE_ITEM_REWARDS and CTF_REWARD_TIE then
  331. for i = 1, #CTF_ITEMREWARDS do
  332. if CTF_ITEMREWARDS[i].randomAmount then
  333. player:addItem(CTF_ITEMREWARDS[i].itemid, math.random(CTF_ITEMREWARDS[i].count))
  334. else
  335. player:addItem(CTF_ITEMREWARDS[i].itemid, CTF_ITEMREWARDS[i].count)
  336. end
  337. end
  338. end
  339.  
  340. player:teleportTo(CTF_TELEPORT_POSITION)
  341. end
  342. end
  343.  
  344. for i = 1, #CTF_GREEN_TEAM_PLAYERS do
  345. local player = Player(CTF_GREEN_TEAM_PLAYERS[i])
  346. if player then
  347. player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, CTF_LOSER_MESSAGE)
  348. player:teleportTo(CTF_TELEPORT_POSITION)
  349. Creature(player):setOutfit(CTF_PLAYER_OUTFITS[player:getName()])
  350. end
  351. end
  352. end
  353.  
  354. CTF_GREEN_TEAM_PLAYERS = {}
  355. CTF_RED_TEAM_PLAYERS = {}
  356. CTF_PLAYER_OUTFITS = {}
  357. CTF_GREEN_SCORE = 0
  358. CTF_RED_SCORE = 0
  359. CTF_GREEN_FLAG_HOLDER = nil
  360. CTF_RED_FLAG_HOLDER = nil
  361.  
  362. if not Tile(CTF_GREEN_FLAG_POSITION):getItemById(CTF_GREEN_FLAGID) then
  363. local flag = Game.createItem(CTF_GREEN_FLAGID, 1, CTF_GREEN_FLAG_POSITION)
  364. flag:setAttribute('aid', CTF_ACTIONID)
  365. end
  366.  
  367. if not Tile(CTF_RED_FLAG_POSITION):getItemById(CTF_RED_FLAGID) then
  368. local flag = Game.createItem(CTF_RED_FLAGID, 1, CTF_RED_FLAG_POSITION)
  369. flag:setAttribute('aid', CTF_ACTIONID)
  370. end
  371.  
  372. for x = CTF_AREA.min.x, CTF_AREA.max.x do
  373. x = x
  374. for y = CTF_AREA.min.y, CTF_AREA.max.y do
  375. y = y
  376. for z = CTF_AREA.min.z, CTF_AREA.max.z do
  377. local position = Position(x, y, z)
  378. local tile = Tile(position)
  379.  
  380. if tile then
  381. if tile:getItemById(CTF_GREEN_FLAGID) and position ~= CTF_GREEN_FLAG_POSITION then
  382. tile:getItemById(CTF_GREEN_FLAGID):remove()
  383. elseif tile:getItemById(CTF_RED_FLAGID) and position ~= CTF_RED_FLAG_POSITION then
  384. tile:getItemById(CTF_RED_FLAGID):remove()
  385. end
  386. end
  387. end
  388. end
  389. end
  390.  
  391. for i = 1, #CTF_GATES do
  392. if Tile(CTF_GATES[i].pos) and not Tile(CTF_GATES[i].pos):getItemById(CTF_GATES[i].itemid) then
  393. Game.createItem(CTF_GATES[i].itemid, 1, CTF_GATES[i].pos)
  394. end
  395. end
  396.  
  397. addEvent(restartCTF, CTF_RESTART_TIME * 60 * 1000)
  398. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement