Advertisement
Guest User

Untitled

a guest
Dec 30th, 2015
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.40 KB | None | 0 0
  1. -- Store player kills
  2. if zombieKillCount == nil then
  3.     zombieKillCount = {}
  4. end
  5.  
  6. -- Zombie Variables
  7. ze_zombieName = "Zombie Event" -- Zombie name
  8. ze_timeToStartInvasion = 30 -- When should the first zombie be summoned [seconds]
  9. ze_zombieSpawnInerval = 5 -- The interval of each zombie that will get summoned
  10. ze_zombieMaxSpawn = 20 -- Max zombies in the arena
  11. ze_zombieCountGlobalStorage = 100 -- Use empty global storage
  12.  
  13. -- Player Variables
  14. ze_joinStorage = 1000 -- Storage that will be added, when player join
  15. ze_minPlayers = 1 -- Minimum players that have to join
  16. ze_maxPlayers = 10 -- Maxnimum players that can join
  17. ze_joinCountGlobalStorage = 101 -- Use empty global storage
  18.  
  19. -- States
  20. ze_stateGlobalStorage = 102 -- Use empty global storage
  21. ze_EVENT_CLOSED = 0
  22. ze_EVENT_STATE_STARTUP = 1
  23. ze_EVENT_STARTED = 2
  24.  
  25. -- Waiting room
  26. ze_WaitingRoomStartPosition = Position(138, 373, 6) -- Where should player be teleport in waiting room
  27. ze_waitingRoomCenterPosition = Position(138, 373, 6) -- Center of the waiting room
  28. ze_waitingRoomRadiusX = 25 -- Depends how big the arena room is 25sqm to x
  29. ze_waitingRoomRadiusY = 25 -- Depends how big the arena room is 25sqm to y
  30.  
  31. -- Zombie arena
  32. ze_zombieArenaStartPosition = Position(162, 374, 5) -- When even start where should player be teleported in the zombie arena?
  33. ze_arenaCenterPosition = Position(162, 374, 5) -- Center position of the arena
  34. ze_arenaFromPosition = Position(154, 368, 5) -- Pos of top left corner
  35. ze_arenaToPosition = Position(168, 379, 5) -- Pos of bottom right corner
  36. ze_arenaRoomRadiusX = 50 -- Depends how big the arena room is 50sqm to x
  37. ze_arenaRoomRadiusY = 50 -- Depends how big the arena room is 50sqm to y
  38. ze_arenaRoomMultifloor = false -- Does the arena have more floors than one?
  39.  
  40. -- Other variables
  41. ze_waitTime = 10 -- How long until the event begin?
  42. ze_createTeleportPosition = Position(158, 387, 6) -- Where should the teleport be created?
  43. ze_teleportActionId = 7000 -- Actionid of the teleport
  44. ze_trophiesTable = {
  45.     [1] = {itemid = 7369, description = "won first place on Zombie Event."},
  46.     [2] = {itemid = 7370, description = "won second place on Zombie Event."},
  47.     [3] = {itemid = 7371, description = "won third place on Zombie Event."}
  48. }
  49.  
  50. -- Get methods
  51. function getZombieEventZombieCount()
  52.     return Game.getStorageValue(ze_zombieCountGlobalStorage)
  53. end
  54.  
  55. function getZombieEventJoinedCount()
  56.     return Game.getStorageValue(ze_joinCountGlobalStorage)
  57. end
  58.  
  59. function setZombieEventState(value)
  60.     Game.setStorageValue(ze_stateGlobalStorage, value)
  61. end
  62.  
  63. function getZombieEventState()
  64.     return Game.getStorageValue(ze_stateGlobalStorage) or ze_EVENT_CLOSED
  65. end
  66.  
  67. function resetZombieEvent()
  68.     -- Reset variables
  69.     Game.setStorageValue(ze_zombieCountGlobalStorage, 0)
  70.     Game.setStorageValue(ze_joinCountGlobalStorage, 0)
  71.     setZombieEventState(ze_EVENT_CLOSED)
  72.  
  73.     -- Clear the arena from zombies
  74.     local spectator = Game.getSpectators(ze_arenaCenterPosition, ze_arenaRoomMultifloor, false, 0, ze_arenaRoomRadiusX, 0, ze_arenaRoomRadiusY)
  75.     for i = 1, #spectator do
  76.         if spectator[i]:isMonster() then
  77.             spectator[i]:remove()
  78.         end
  79.     end
  80. end
  81.  
  82. function startZombieEvent()
  83.     local spectator = Game.getSpectators(ze_waitingRoomCenterPosition, ze_arenaRoomMultifloor, false, 0, ze_waitingRoomRadiusX, 0, ze_waitingRoomRadiusY)
  84.     if getZombieEventJoinedCount() < ze_minPlayers then
  85.         for i = 1, #spectator do
  86.             spectator[i]:teleportTo(spectator[i]:getTown():getTemplePosition())
  87.             spectator[i]:setStorageValue(ze_joinStorage, 0)
  88.         end
  89.  
  90.         resetZombieEvent()
  91.         Game.broadcastMessage("Zombie event failed to start, due to not enough of participants.")
  92.     else
  93.         for i = 1, #spectator do
  94.             spectator[i]:teleportTo(ze_zombieArenaStartPosition)
  95.             spectator[i]:registerEvent("ZombiePlayerDeath")
  96.         end
  97.  
  98.         Game.broadcastMessage("Zombie Event has started, good luck to all participants.")
  99.         setZombieEventState(ze_EVENT_STARTED)
  100.         addEvent(startZombieInvasion, ze_timeToStartInvasion * 1000)
  101.     end
  102.  
  103.     -- Remove Teleport
  104.     local item = Tile(ze_createTeleportPosition):getItemById(1387)
  105.     if item:isTeleport() then
  106.         item:remove()
  107.     end
  108. end
  109.  
  110. function startZombieInvasion()
  111.     if getZombieEventState() == ze_EVENT_STARTED then
  112.         local random = math.random
  113.         local zombie = Game.createMonster(ze_zombieName, Position(random(ze_arenaFromPosition.x, ze_arenaToPosition.x), random(ze_arenaFromPosition.y, ze_arenaToPosition.y), random(ze_arenaFromPosition.z, ze_arenaToPosition.z)))
  114.         if zombie then
  115.             Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() + 1)
  116.         end
  117.  
  118.         addEvent(startZombieInvasion, ze_zombieSpawnInerval * 1000)
  119.     end
  120. end
  121.  
  122. function Player.joinZombieEvent(self)
  123.     -- Set storage and teleport
  124.     self:teleportTo(ze_WaitingRoomStartPosition)
  125.     ze_WaitingRoomStartPosition:sendMagicEffect(CONST_ME_TELEPORT)
  126.     self:setStorageValue(ze_joinStorage, 1)
  127.  
  128.     -- Add count and broadcast
  129.     local count = getZombieEventJoinedCount()
  130.     Game.setStorageValue(ze_joinCountGlobalStorage, count + 1)
  131.     Game.broadcastMessage(string.format("%s has joined the Zombie Event! [%d/%d].", self:getName(), count + 1, ze_maxPlayers))
  132. end
  133.  
  134. function setupZombieEvent(minPlayers, maxPlayers, waitTime)
  135.     -- Event is not closed, then stop from start new one
  136.     if getZombieEventState() ~= ze_EVENT_CLOSED then
  137.         return
  138.     end
  139.  
  140.     -- Create teleport and set the respective action id
  141.     local item = Game.createItem(1387, 1, ze_createTeleportPosition)
  142.     if item:isTeleport() then
  143.         item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, ze_teleportActionId)
  144.     end
  145.  
  146.     -- Change the variables, to the new ones
  147.     ze_minPlayers = minPlayers
  148.     ze_maxPlayers = maxPlayers
  149.     ze_waitTime = waitTime
  150.  
  151.     -- Set the counts, state, broadcast and delay the start of the event.
  152.     Game.setStorageValue(ze_zombieCountGlobalStorage, 0)
  153.     Game.setStorageValue(ze_joinCountGlobalStorage, 0)
  154.     setZombieEventState(ze_EVENT_STATE_STARTUP)
  155.     Game.broadcastMessage(string.format("The Zombie Event has started! The event require atleast %d and max %d players, you have %d minutes to join.", minPlayers, maxPlayers, waitTime))
  156.     addEvent(startZombieEvent, waitTime * 60 * 1000)
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement