Advertisement
Guest User

SnowBall_Configurations

a guest
Aug 7th, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.30 KB | None | 0 0
  1. -- This script is part of Snow Ball War
  2. -- Copyright by Ciroc Developer
  3. --
  4. -- This program is free software: you can redistribute it and/or modify
  5. -- it under the terms of the GNU General Public License as published by
  6. -- the Free Software Foundation, either version 3 of the License, or
  7. -- (at your option) any later version.
  8. --
  9. -- This program is distributed in the hope that it will be useful,
  10. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. -- GNU General Public License for more details.
  13. --
  14. -- You should have received a copy of the GNU General Public License
  15. -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.  
  17. -- //
  18.  
  19. SnowBall_Configurations = {
  20.     Event_Duration = 1, -- Minutes of duration of the game.
  21.     Event_WaitGame = 1, -- Minutes waiting for the beginning of the game, inside the room.
  22.     Event_MinPlayers = 2, -- Minimum of players for the game start, otherwise the game is canceled.
  23.     Event_GainPoint = 1, -- Gain points for each hit in the game.
  24.     Event_LostPoints = 1, -- Lose points with every death in the game. // To disable, value = 0.
  25.     Event_Days = {1, 2, 3, 4, 5, 6, 7}, -- Days that will occur the event (following the order of 1 = Sunday, 7 = Saturday)
  26.  
  27.     Area_Configurations = {
  28.         Area_Arena = {{x = 32099, y = 30863, z = 7}, {x = 32191, y = 30920, z = 7}}, -- Area of ??the game arena, ({Upper Left Corner}, {Lower Right Corner})
  29.         Position_WaitRoom = {x = 32164, y = 30854, z = 7}, -- Position of the waiting room of the game
  30.         Position_ExitWaitRoom = {x = 32160, y = 30851, z = 7}, -- Position of the teleport that will leave the waiting room of the game
  31.         Position_EventTeleport = {x = 32378, y = 32239, z = 7}, -- Position where the teleport will be created for the participants to go to the waiting room.
  32.     },
  33.  
  34.     Ammo_Configurations = {
  35.         Ammo_Price = 1, --  Price of the game in points of the game.
  36.         Ammo_Ammount = 100, -- Amount of gain on each purchase.
  37.         Ammo_Start = 100, --  Amount of each player's ammo at the beginning of the game.
  38.         Ammo_Restart = 100, -- Amount of player's ammunition in case he dies. // If you want to disable, value = 0.
  39.         Ammo_Speed = 150, -- Speed of each shot
  40.         Ammo_Infinity = false, --  Whether the ammunition will be infinite or not (True / False)
  41.         Ammo_Exhaust = 1, -- Seconds waiting to re-use the command !snowball atirar
  42.         Ammo_Distance = 5, -- Amount of tiles the shot will reach
  43.     },
  44.  
  45.     Positions_Rewards = {
  46.         [1] = { -- First place awards
  47.             [2160] = 100,
  48.             [2152] = 1,
  49.         },
  50.         [2] = { -- Second place awards
  51.             [2160] = 50,
  52.         },
  53.         [3] = { -- Third place awards
  54.             [2160] = 10,
  55.         },
  56.        
  57.     },
  58. }
  59.  
  60. -- ################# SnowBall Functions -- Please do not mess with it. Developed entirely by Tony Araújo (OrochiElf) ################# --
  61. CACHE_GAMEPLAYERS = {}
  62. CACHE_GAMEAREAPOSITIONS = {}
  63.  
  64. function loadEvent()
  65.     print("[SnowBall Event]: Loading the arena area.")
  66.     for newX = SnowBall_Configurations.Area_Configurations.Area_Arena[1].x, SnowBall_Configurations.Area_Configurations.Area_Arena[2].x do
  67.         for newY = SnowBall_Configurations.Area_Configurations.Area_Arena[1].y, SnowBall_Configurations.Area_Configurations.Area_Arena[2].y do
  68.             local AreaPos = {x = newX, y = newY, z = SnowBall_Configurations.Area_Configurations.Area_Arena[1].z}
  69.             if getTileThingByPos(AreaPos).itemid == 0 then
  70.                 print("[SnowBall Event]: There was a problem loading the location (x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. ") Of the event arena, please check the conditions.")
  71.                 return false
  72.             elseif isWalkable(AreaPos) then
  73.                 table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
  74.             end
  75.         end
  76.     end
  77.     print("[SnowBall Event]: Loading the arena area successfully completed.")
  78.  
  79.     if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_WaitRoom).itemid == 0 then
  80.         print("[SnowBall Event]: There was a problem verifying the existence of the waiting room position, please check the conditions.")
  81.         return false
  82.     end
  83.  
  84.     if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom).itemid == 0 then
  85.         print("[SnowBall Event]: There was a problem verifying the existence of the teleport position of the waiting room, please check the conditions.")
  86.         return false
  87.     end
  88.  
  89.     if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_EventTeleport).itemid == 0 then
  90.         print("[SnowBall Event]: There was a problem verifying the existence of the position to create the event teleport, please check the conditions.")
  91.         return false
  92.     end
  93.  
  94.     print("[SnowBall Event]: Event loading completed successfully.")
  95.     return true
  96. end
  97.  
  98. local sampleConfigs = {
  99.     [0] = {dirPos = {x = 0, y = -1}},
  100.     [1] = {dirPos = {x = 1, y = 0}},
  101.     [2] = {dirPos = {x = 0, y = 1}},
  102.     [3] = {dirPos = {x = -1, y = 0}},
  103. }
  104.  
  105. local iced_Corpses = {
  106.     [0] = {
  107.         [0] = {7303},
  108.         [1] = {7306},
  109.         [2] = {7303},
  110.         [3] = {7306},
  111.     },
  112.     [1] = {
  113.         [0] = {7305, 7307, 7309, 7311},
  114.         [1] = {7308, 7310, 7312},
  115.         [2] = {7305, 7307, 7309, 7311},
  116.         [3] = {7308, 7310, 7312},
  117.     },
  118. }
  119.  
  120. function Event_sendSnowBall(cid, pos, rounds, dir)
  121.     local player = Player(cid)
  122.  
  123.     if rounds == 0 then
  124.         return true
  125.     end
  126.  
  127.     if player then
  128.         local sampleCfg = sampleConfigs[dir]
  129.  
  130.         if sampleCfg then
  131.             local newPos = Position(pos.x + sampleCfg.dirPos.x, pos.y + sampleCfg.dirPos.y, pos.z)
  132.  
  133.             if isWalkable(newPos) then
  134.                 if Tile(newPos):getTopCreature() then
  135.                     local killed = Tile(newPos):getTopCreature()
  136.  
  137.                     if Player(killed:getId()) then
  138.                         if iced_Corpses[killed:getSex()] then
  139.                             local killed_corpse = iced_Corpses[killed:getSex()][killed:getDirection()][math.random(1, #iced_Corpses[killed:getSex()][killed:getDirection()])]
  140.  
  141.                             Game.createItem(killed_corpse, 1, killed:getPosition())
  142.                             local item = Item(getTileItemById(killed:getPosition(), killed_corpse).uid)
  143.                             addEvent(function() item:remove(1) end, 3000)
  144.                         end
  145.  
  146.                         killed:getPosition():sendMagicEffect(3)
  147.                         killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
  148.                         killed:getPosition():sendMagicEffect(50)
  149.                         killed:setStorageValue(10109, killed:getStorageValue(10109) - SnowBall_Configurations.Event_LostPoints)
  150.                         killed:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Restart)
  151.                         killed:sendTextMessage(29, "You've been hit by the player " .. player:getName() .. " And lost -" .. SnowBall_Configurations.Event_LostPoints .." points.\nTotal of: " .. killed:getStorageValue(10109) .. " points")
  152.  
  153.                         player:setStorageValue(10109, player:getStorageValue(10109) + SnowBall_Configurations.Event_GainPoint)
  154.                         player:sendTextMessage(29, "You just hit the player " .. killed:getName() .. " and won +" .. SnowBall_Configurations.Event_GainPoint .." points.\nTotal of: " .. player:getStorageValue(10109) .. " points")
  155.  
  156.                         if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
  157.                             player:getPosition():sendMagicEffect(7)
  158.                             player:sendTextMessage(29, "You are now the leader of the SnowBall ranking, congratulations!")
  159.                             Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
  160.                             Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, "You just lost the first place!")
  161.                         end
  162.  
  163.                         table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
  164.                     else
  165.  
  166.                         newPos:sendMagicEffect(3)
  167.                     end
  168.                     return true
  169.                 end
  170.  
  171.                 pos:sendDistanceEffect(newPos, 13)
  172.                 pos = newPos
  173.                 return addEvent(Event_sendSnowBall, SnowBall_Configurations.Ammo_Configurations.Ammo_Speed, player:getId(), pos, rounds - 1, dir)
  174.             end
  175.  
  176.             newPos:sendMagicEffect(3)
  177.             return true
  178.         end
  179.     end
  180.     return true
  181. end
  182.  
  183. function Event_endGame()
  184.     local str = "       ## -> SnowBall Ranking <- ##\n\n"
  185.  
  186.     for rank, players in ipairs(CACHE_GAMEPLAYERS) do
  187.         if SnowBall_Configurations.Positions_Rewards[rank] then
  188.             for item_id, item_ammount in pairs(SnowBall_Configurations.Positions_Rewards[rank]) do
  189.  
  190.                 Player(players):addItem(item_id, item_ammount)
  191.             end
  192.         end
  193.  
  194.         str = str .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " points\n"
  195.         Player(players):teleportTo(Player(players):getTown():getTemplePosition())
  196.     end
  197.  
  198.     for _, cid in ipairs(CACHE_GAMEPLAYERS) do
  199.         Player(cid):showTextDialog(2111, str)
  200.     end
  201.  
  202.     broadcastMessage("[Snowball Event]: The event ended.")
  203.     return true
  204. end
  205.  
  206. function isWalkable(pos) --- New Function by Tony Araújo (OrochiElf)
  207.     for i = 0, 255 do
  208.         pos.stackpos = i
  209.  
  210.         local item = Item(getTileThingByPos(pos).uid)
  211.         if item ~= nil then
  212.             if item:hasProperty(2) or item:hasProperty(3) or item:hasProperty(7) then
  213.                 return false
  214.             end
  215.         end
  216.     end
  217.     return true
  218. end
  219.  
  220. function isInArena(player)
  221.     local pos = player:getPosition()
  222.  
  223.     if pos.z == SnowBall_Configurations.Area_Configurations.Area_Arena[1].z then
  224.         if pos.x >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].x and pos.y >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].y then
  225.             if pos.x <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].x and pos.y <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].y then
  226.                 return true
  227.             end
  228.         end
  229.     end
  230.     return false
  231. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement