Guest User

Untitled

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