Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. local players = {}
  2. local config = {
  3. teleporter = {{x = 160, y = 54, z = 7}, {x = 227, y = 118, z = 14}}, -- location, destination
  4. teleportOpenTime = 1000 * 10, -- 1000 * 5 = 5 seconds
  5. arena_location = {{x = 221, y = 112, z = 14}, {x = 233, y = 124, z = 14}}, -- top_left_corner, bottom_right_corner
  6. minimum_participants = 2,
  7. time_between_rounds = 10,
  8. random_time_for_rounds = {5, 15},
  9. outfits = {{lookType = 128, lookHead = 79, lookBody = 79, lookLegs = 79, lookFeet = 79}, {lookType = 128, lookHead = 77, lookBody = 77, lookLegs = 77, lookFeet = 77}, {lookType = 128, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}}
  10. }
  11.  
  12. local function countParticipants()
  13. local count = 0
  14. for _ in pairs(players) do count = count + 1 end
  15. return count
  16. end
  17.  
  18. local function countParticipantsRemaining()
  19. local count = 0
  20. for index, index_ in pairs(players) do
  21. if index_[2] > 0 and index_[2] < 4 then
  22. count = count + 1
  23. end
  24. end
  25. return count
  26. end
  27.  
  28. local function changeParticipantsOutfits()
  29. for index, index_ in pairs(players) do
  30. if isPlayer(index_[1]) then
  31. if index_[2] < 4 then
  32. doSetCreatureOutfit(index_[1], config.outfits[index_[2]], -1)
  33. end
  34. end
  35. end
  36. end
  37.  
  38. local function checkEventWinners()
  39. if countParticipantsRemaining() > 2 then
  40. addEvent(eventRoundsIdle, 0)
  41. elseif countParticipantsRemaining() == 1 then
  42. for index, index_ in pairs(players) do
  43. if isPlayer(index_[1]) then
  44. doBroadcastMessage("" .. getCreatureName(index_[1]) .. " won the event!")
  45. addEvent(doTeleportThing, 5000, index_[1], getTownTemplePosition(getPlayerTown(index_[1])))
  46. doSetCreatureOutfit(index_[1], index_[3], -1)
  47. end
  48. end
  49. players = {}
  50. else
  51. doBroadcastMessage("Nobody won the event! All participants were eliminated.")
  52. players = {}
  53. end
  54. end
  55.  
  56. local function checkEventLosers()
  57. for index, index_ in pairs(players) do
  58. if isPlayer(index_[1]) then
  59. if index_[2] == 4 then
  60. index_[2] = index_[2] + 1
  61. doTeleportThing(index_[1], getTownTemplePosition(getPlayerTown(index_[1])))
  62. doSetCreatureOutfit(index_[1], index_[3], -1)
  63. end
  64. end
  65. end
  66. addEvent(checkEventWinners, 0)
  67. end
  68.  
  69. local function eventRoundsFinish()
  70. for index, index_ in pairs(players) do
  71. if isPlayer(index_[1]) then
  72. if index_[2] < 4 then
  73. print(index_[2])
  74. if getTileThingByPos(getThingPosition(index_[1])).itemid == 407 then
  75. index_[2] = index_[2] + 1
  76. print(index_[2])
  77. end
  78. end
  79. end
  80. end
  81. changeParticipantsOutfits()
  82. addEvent(checkEventLosers, 0)
  83. end
  84.  
  85. local function eventRoundsStart()
  86. -- set random tiles
  87. addEvent(eventRoundsFinish, (math.random(config.random_time_for_rounds[1], config.random_time_for_rounds[2]) * 1000))
  88. end
  89.  
  90. local function eventRoundsIdle()
  91. addEvent(eventRoundsStart, config.time_between_rounds)
  92. end
  93.  
  94. local function checkParticipants()
  95. local text = "Players"
  96. local playerCount = countParticipants()
  97. if playerCount >= config.minimum_participants then
  98. for index, index_ in pairs(players) do
  99. if isPlayer(index_[1]) then
  100. if text ~= "Players" then
  101. text = text .. ","
  102. end
  103. text = text .. " " .. getCreatureName(index_[1]) .. ""
  104. end
  105. end
  106. text = text .. " have entered the event."
  107. end
  108. if text == "Players" then
  109. doBroadcastMessage("Event cancelled. Not enough participants.")
  110. if playerCount > 0 then
  111. for index, index_ in pairs(players) do
  112. if isPlayer(index_[1]) then
  113. doTeleportThing(index_[1], getTownTemplePosition(getPlayerTown(index_[1])))
  114. doSetCreatureOutfit(index_[1], index_[3], -1)
  115. end
  116. end
  117. players = {}
  118. end
  119. else
  120. doBroadcastMessage(text)
  121. addEvent(doBroadcastMessage, 5000, "Event will start in " .. config.time_between_rounds .. " seconds.")
  122. changeParticipantsOutfits()
  123. addEvent(eventRoundsIdle, 5000)
  124. end
  125. return
  126. end
  127.  
  128. local function removeTeleporter()
  129. doRemoveItem(getTileItemById(config.teleporter[1], 1387).uid)
  130. for _, pid in ipairs(getPlayersOnline()) do
  131. if isPlayer(pid) then
  132. local pos = getThingPosition(pid)
  133. if pos.z <= config.arena_location[1].z and pos.z >= config.arena_location[2].z then
  134. if pos.x >= config.arena_location[1].x and pos.x <= config.arena_location[2].x then
  135. if pos.y >= config.arena_location[1].y and pos.y <= config.arena_location[2].y then
  136. local pid_outfit = getCreatureOutfit(pid)
  137. players[pid] = {pid, 1, pid_outfit}
  138. end
  139. end
  140. end
  141. end
  142. end
  143. doBroadcastMessage("Starting event..")
  144. addEvent(checkParticipants, 5000)
  145. return
  146. end
  147.  
  148. function onTime()
  149. doCreateTeleport(1387, config.teleporter[2], config.teleporter[1])
  150. addEvent(removeTeleporter, config.teleportOpenTime)
  151. doBroadcastMessage("Event in Progress..")
  152. return true
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement