Advertisement
Guest User

Untitled

a guest
Aug 7th, 2022
64
0
67 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.30 KB | None | 0 0
  1. ---- DONT TOUCH ---
  2. MW_STATUS = 0
  3. MW_PLAYERS = {}
  4. MW_MONSTERS = {}
  5. local MW_WAVE = 1
  6. -------------------
  7.  
  8. --- CONFIG ----
  9. MW_minLevel = 50 -- Player must be this level to enter event --
  10. MW_positionEnter = Position(559, 788, 7) -- Wait area for event to start position --
  11. MW_positionLeave = Position(84, 158, 4) -- Exit waiting area position --
  12. local MW_minPlayersToStart = 1 -- How many people are required for event to start --
  13. local MW_firstWaveStart = 30 -- 30 seconds for the first wave to start --
  14. local MW_reTryEvent = 60 -- Time in minutes to retry the event if there are not enough players --
  15. local MW_startEventAgain = 60 -- Start the event again after 60 minutes --
  16. ---------------
  17.  
  18. local MW_PLAYER_TELEPORT_TO = { -- Teleport players to this area for event --
  19.     min = Position(542, 775, 7), -- Top left square of area --
  20.     max = Position(580, 806, 7) -- bottom right square of area --
  21. }
  22.  
  23. local MONSTER_WAVES = {
  24.     [1] = {exp = 20000, waitTimeBoss = 60,
  25.         monsters = {
  26.             {"Bandit Lvl 1", Position(565, 785, 7)},
  27.             {"Bandit Lvl 2", Position(553, 788, 7)},
  28.             {"Bandit Lvl 3", Position(571, 793, 7)},
  29.             {"Bandit Lvl 4", Position(553, 783, 7)},
  30.             {"Bandit Lvl 5", Position(561, 787, 7)}
  31.         },
  32.         boss = { -- Boss is spawned after waitTimeBoss seconds after the wave is stated --
  33.             {"Bandit Lvl 10", Position(564, 788, 7)},
  34.         },
  35.         itemRewards = { -- Items rewarded for completing the wave. --
  36.             {2160, 50},
  37.             {14319, 1}
  38.         },
  39.         --outfitReward = {male = 260, female = 261, addons = 0, name = "Citizen"}, -- outfit rewards for completing the wave --
  40.         --mountReward = {126, "Horse"}
  41.     } -- You can delete any of the values to remove it from the wave. exp, itemreward, boss, outfitreward, mountreward (DO NOT DELETE THE monsters TABLE) --
  42.  
  43.     --  [2]
  44.  
  45. }
  46.  
  47. function MW_sendMessage(msgType, msg)
  48.     for i = 1, #MW_PLAYERS do
  49.         local player = Player(MW_PLAYERS[i])
  50.         if player then
  51.             player:sendTextMessage(msgType, msg)
  52.         end
  53.     end
  54. end
  55.  
  56. function MW_teleportPlayers()
  57.     for i = 1, #MW_PLAYERS do
  58.         local player = Player(MW_PLAYERS[i])
  59.         if player then
  60.             local position = Position(math.random(MW_PLAYER_TELEPORT_TO.min.x, MW_PLAYER_TELEPORT_TO.max.x),math.random(MW_PLAYER_TELEPORT_TO.min.y, MW_PLAYER_TELEPORT_TO.max.y), MW_PLAYER_TELEPORT_TO.min.z)
  61.             player:teleportTo(position)
  62.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Welcome to monster wave event. It will begin in "..MW_firstWaveStart.." seconds.")
  63.         end
  64.     end
  65. end
  66.  
  67. function MW_tryEvent()
  68.     if #MW_PLAYERS < MW_minPlayersToStart then
  69.         MW_sendMessage(MESSAGE_STATUS_CONSOLE_RED, "There are not enough players for the event to start. The event will try again after "..MW_reTryEvent.." minutes.")
  70.         addEvent(MW_tryEvent, MW_reTryEvent * 60 * 1000)
  71.         return true
  72.     end
  73.  
  74.     MW_teleportPlayers()
  75.     MW_STATUS = 2
  76.     addEvent(MW_startWave, MW_firstWaveStart * 1000)
  77. end
  78.  
  79. function MW_checkMonsters()
  80.     for i = 1, #MW_MONSTERS do
  81.         local monster = Monster(MW_MONSTERS[i])
  82.         if monster then
  83.             return true
  84.         end
  85.     end
  86.     return false
  87. end
  88.  
  89. function MW_removeMonsters()
  90.     for i = 1, #MW_MONSTERS do
  91.         local monster = Monster(MW_MONSTERS[i])
  92.         if monster then
  93.             monster:remove()
  94.         end
  95.         MW_MONSTERS[i] = nil
  96.     end
  97. end
  98.  
  99. function MW_startWave()
  100.     local WAVE = MONSTER_WAVES[MW_WAVE]
  101.  
  102.     for i = 1, #WAVE.monsters do
  103.         local MONS = Game.createMonster(WAVE.monsters[i][1], WAVE.monsters[i][2])
  104.         if not MW_MONSTERS[1] then
  105.             MW_MONSTERS[1] = MONS:getId()
  106.         else
  107.             MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
  108.         end
  109.     end
  110.  
  111.     MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The wave has spawned. Kill all monsters for the next wave to begin.")
  112.  
  113.     if WAVE.boss then
  114.         addEvent(spawnBosses, WAVE.waitTimeBoss * 1000, WAVE)
  115.         MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This waves bosses will spawn in "..WAVE.waitTimeBoss.." seconds.")
  116.     end
  117.  
  118.     addEvent(MW_proccessWave, 60 * 1000)
  119. end
  120.  
  121. function MW_spawnBosses(waveTable)
  122.     for i = 1, #waveTable.boss do
  123.         local MONS = Game.createMonster(waveTable[i].boss[1], waveTable[i].boss[2])
  124.         MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
  125.     end
  126. end
  127.  
  128. function MW_addOutfitReward(WAVE, player)
  129.     if player:getSex() == 0 then
  130.         player:addOutfit(WAVE.outfitReward.female)
  131.         if addons > 0 then
  132.             for x = 1, addons do
  133.                 player:addOutfitAddons(WAVE.outfitReward.female, x)
  134.             end
  135.         end
  136.     else
  137.         player:addOutfit(WAVE.outfitReward.male)
  138.         if addons > 0 then
  139.             for x = 1, addons do
  140.                 player:addOutfitAddons(WAVE.outfitReward.male, x)
  141.             end
  142.         end
  143.     end
  144. end
  145.  
  146. function MW_proccessWave()
  147.     if MW_checkMonsters() then
  148.         MW_sendMessage(MESSAGE_STATUS_CONSOLE_RED, "There are still monsters left to kill. Kill them to start the next wave.")
  149.         addEvent(MW_proccessWave, 60 * 1000)
  150.         return true
  151.     end
  152.  
  153.     local WAVE = MONSTER_WAVES[MW_WAVE]
  154.  
  155.     local text = "[WAVE REWARD]:"
  156.  
  157.     if WAVE.exp then
  158.         for i = 1, #MW_PLAYERS do
  159.             local player = Player(MW_PLAYERS[i])
  160.             if player then
  161.                 if i == 1 then
  162.                     text = text.." "..WAVE.exp.." experience."
  163.                 end
  164.                 player:addExperience(WAVE.exp)
  165.             end
  166.         end
  167.     end
  168.  
  169.     if WAVE.outfitReward then
  170.         for i = 1, #MW_PLAYERS do
  171.             local player = Player(MW_PLAYERS[i])
  172.             if player then
  173.                 if i == 1 then
  174.                     text = text.." "..WAVE.outfitReward.name.." outfit."
  175.                 end
  176.                 MW_addOutfitReward(WAVE, player)  
  177.             end
  178.         end
  179.     end
  180.  
  181.     if WAVE.mountReward then
  182.         for i = 1, #MW_PLAYERS do
  183.             local player = Player(MW_PLAYERS[i])
  184.             if player then
  185.                 if i == 1 then
  186.                     text = text.." "..WAVE.mountReward[2].." mount."
  187.                 end
  188.                 player:addMount(WAVE.mountReward[1])
  189.             end
  190.         end
  191.     end
  192.  
  193.     MW_sendMessage(MESSAGE_STATUS_CONSOLE_RED, text)
  194.     MW_WAVE = MW_WAVE + 1
  195.     MW_removeMonsters()
  196.  
  197.     if not MONSTER_WAVES[MW_WAVE] then
  198.         MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Well done. You completed all waves. The event will end in 30 seconds!")
  199.         MW_STATUS = 3
  200.         addEvent(MW_endEvent, 30 * 1000)
  201.         return true
  202.     end
  203.  
  204.     MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The next wave will spawn in 1 minute.")
  205.     addEvent(MW_startWave, 60 * 1000)
  206.     addEvent(MW_CleanFields, 5 * 1000)
  207. end
  208.  
  209. function MW_endEvent()
  210.     for i = 1, #MW_PLAYERS do
  211.         local player = Player(MW_PLAYERS[i])
  212.         if player then
  213.             player:teleportTo(MW_positionLeave)
  214.         end
  215.         MW_PLAYERS[i] = nil
  216.     end
  217.  
  218.     MW_removeMonsters()
  219.     addEvent(MW_restartEvent, MW_startEventAgain * 60 * 1000)
  220. end
  221.  
  222. function MW_restartEvent()
  223.     MW_STATUS = 0
  224. end
  225.  
  226. function MW_CleanFields()
  227. local area = {
  228.       fromPos = {x = 32470, y = 32315, z = 9},
  229.       toPos = {x = 32479, y = 32322, z = 9}
  230.   }
  231.  
  232. local tileCache = {}
  233.  
  234. local itemIds = {1487, 1486,1485,1490,1491,1497}
  235.     -- initialize tiles we need to clean, store all tiles in a cache to avoid reconstructing them in the future
  236.     if #tileCache == 0 then
  237.         for x = area.fromPos.x, area.toPos.x do
  238.             for y = area.fromPos.y, area.toPos.y do
  239.                 for z = area.fromPos.z, area.toPos.z do
  240.                     tileCache[#tileCache+1] = Tile(x, y, z)
  241.                 end
  242.             end
  243.         end
  244.     end
  245.     -- clean based off of cache
  246.     for i = 1, #tileCache do
  247.         local items = tileCache[i]:getItems()
  248.         if items and next(items) then
  249.             for index = 1, #items do
  250.                 local item = items[index]
  251.                 if table.contains(itemIds, item:getId()) then
  252.                     item:remove()
  253.                 end
  254.             end
  255.         end
  256.     end
  257.     return true
  258. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement