Skymagnum

Untitled

May 17th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. local THRONE_POS = {x = 1, y = 2, z = 3}
  2. local STORAGE_EVENT = 83902
  3. local STORAGE_PLAYER = 73289
  4. local REWARDS = {{2160, 10}, {2159, 30}}
  5. local DUR = 30 -- in minutes
  6.  
  7. function OpenEvent()
  8.  
  9.  
  10.     for _, tid in ipairs(getPlayersOnline()) do
  11.         setPlayerStorageValue(tid, STORAGE_PLAYER, 1)
  12.     end
  13.  
  14.     setGlobalStorageValue(STORAGE_EVENT, 1)
  15.     doBroadcastMessage("O Evento castle foi aberto.", 25)
  16. end
  17.  
  18.  
  19. function getWinnerCastle()
  20.  
  21. local player = getTopCreature(THRONE_POS).uid
  22.  
  23. if getGlobalStorageValue(STORAGE_EVENT) < 0 then return true end
  24.  
  25.     if (isPlayer(player)) then
  26.         if (getPlayerStorageValue(player, STORAGE_PLAYER) > 0) then
  27.             for _, T in pairs(REWARDS) do
  28.                 doPlayerAddItem(player, T[1], T[2])
  29.             end
  30.             for _, cid in ipairs(getPlayersOnline()) do
  31.                 setPlayerStorageValue(cid, STORAGE_PLAYER, 0)
  32.                 doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  33.             end
  34.         doBroadcastMessage(getCreatureName(player) .. " ganhou o evento.", 25)
  35.         end
  36.     else
  37.         doBroadcastMessage("Ningúem ganhou o evento.", 27)
  38.         for _, pid in ipairs(getPlayersOnline()) do
  39.             doPlayerAddItem(pid, 2160, 100)
  40.             setPlayerStorageValue(pid, STORAGE_PLAYER, 0)
  41.             doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
  42.         end
  43.     end
  44.  
  45.     setGlobalStorageValue(STORAGE_EVENT, 0)
  46.     return db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. STORAGE_PLAYER)
  47. end
  48.  
  49. function CastleWalls()
  50.  
  51. local walls = {
  52.     {ID, POS},
  53.     {ID, POS},
  54. }
  55.  
  56.     for _, K in pairs(walls) do
  57.         local wall = getTileItemById(K[2], K[1])
  58.         if (wall.uid > 0) then
  59.             doRemoveItem(wall.uid)
  60.         else
  61.             doCreateItem(K[1], 1, K[2])
  62.         end
  63.     end
  64.  
  65. end
  66.  
  67. function onSay(cid, words, param, channel)
  68.  
  69.     if ((param == "abrir") and (getGlobalStorageValue(STORAGE_EVENT) == 1)) then
  70.         doPlayerSendTextMessage(cid, 27, "O evento já esta aberto.") return true
  71.     elseif ((param == "fechar") and (getGlobalStorageValue(STORAGE_EVENT) == 1)) then
  72.         getWinnerCastle()
  73.         CastleWalls() return true
  74.     end
  75.  
  76.     OpenEvent()
  77.     CastleWalls()
  78.     addEvent(getWinnerCastle(), DUR * 60 * 1000)
  79.  
  80.     return true
  81. end
Advertisement
Add Comment
Please, Sign In to add comment