-- This script is part of Snow Ball War
-- Copyright by Ciroc Developer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- //
SnowBall_Configurations = {
Event_Duration = 1, -- Minutes of duration of the game.
Event_WaitGame = 1, -- Minutes waiting for the beginning of the game, inside the room.
Event_MinPlayers = 2, -- Minimum of players for the game start, otherwise the game is canceled.
Event_GainPoint = 1, -- Gain points for each hit in the game.
Event_LostPoints = 1, -- Lose points with every death in the game. // To disable, value = 0.
Event_Days = {1, 2, 3, 4, 5, 6, 7}, -- Days that will occur the event (following the order of 1 = Sunday, 7 = Saturday)
Area_Configurations = {
Area_Arena = {{x = 2219, y = 2364, z = 7}, {x = 2258, y = 2403, z = 7}}, -- Area of ??the game arena, ({Upper Left Corner}, {Lower Right Corner})
Position_WaitRoom = {x = 2236, y = 2383, z = 6}, -- Position of the waiting room of the game
Position_ExitWaitRoom = {x = 2239, y = 2380, z = 6}, -- Position of the teleport that will leave the waiting room of the game
Position_EventTeleport = {x = 2438, y = 2491, z = 7}, -- Position where the teleport will be created for the participants to go to the waiting room.
},
Ammo_Configurations = {
Ammo_Price = 1, -- Price of the game in points of the game.
Ammo_Ammount = 100, -- Amount of gain on each purchase.
Ammo_Start = 100, -- Amount of each player's ammo at the beginning of the game.
Ammo_Restart = 100, -- Amount of player's ammunition in case he dies. // If you want to disable, value = 0.
Ammo_Speed = 150, -- Speed of each shot
Ammo_Infinity = false, -- Whether the ammunition will be infinite or not (True / False)
Ammo_Exhaust = 1, -- Seconds waiting to re-use the command !snowball atirar
Ammo_Distance = 5, -- Amount of tiles the shot will reach
},
Positions_Rewards = {
[1] = { -- First place awards
[2160] = 100,
[2152] = 1,
},
[2] = { -- Second place awards
[2160] = 50,
},
[3] = { -- Third place awards
[2160] = 10,
},
},
}
-- ################# SnowBall Functions -- Please do not mess with it. Developed entirely by Tony Araújo (OrochiElf) ################# --
CACHE_GAMEPLAYERS = {}
CACHE_GAMEAREAPOSITIONS = {}
function loadEvent()
print("[SnowBall Event]: Loading the arena area.")
for newX = SnowBall_Configurations.Area_Configurations.Area_Arena[1].x, SnowBall_Configurations.Area_Configurations.Area_Arena[2].x do
for newY = SnowBall_Configurations.Area_Configurations.Area_Arena[1].y, SnowBall_Configurations.Area_Configurations.Area_Arena[2].y do
local AreaPos = {x = newX, y = newY, z = SnowBall_Configurations.Area_Configurations.Area_Arena[1].z}
if getTileThingByPos(AreaPos).itemid == 0 then
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.")
return false
elseif isWalkable(AreaPos) then
table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
end
end
end
print("[SnowBall Event]: Loading the arena area successfully completed.")
if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_WaitRoom).itemid == 0 then
print("[SnowBall Event]: There was a problem verifying the existence of the waiting room position, please check the conditions.")
return false
end
if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom).itemid == 0 then
print("[SnowBall Event]: There was a problem verifying the existence of the teleport position of the waiting room, please check the conditions.")
return false
end
if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_EventTeleport).itemid == 0 then
print("[SnowBall Event]: There was a problem verifying the existence of the position to create the event teleport, please check the conditions.")
return false
end
print("[SnowBall Event]: Event loading completed successfully.")
return true
end
local sampleConfigs = {
[0] = {dirPos = {x = 0, y = -1}},
[1] = {dirPos = {x = 1, y = 0}},
[2] = {dirPos = {x = 0, y = 1}},
[3] = {dirPos = {x = -1, y = 0}},
}
local iced_Corpses = {
[0] = {
[0] = {7303},
[1] = {7306},
[2] = {7303},
[3] = {7306},
},
[1] = {
[0] = {7305, 7307, 7309, 7311},
[1] = {7308, 7310, 7312},
[2] = {7305, 7307, 7309, 7311},
[3] = {7308, 7310, 7312},
},
}
function Event_sendSnowBall(cid, pos, rounds, dir)
local player = Player(cid)
if rounds == 0 then
return true
end
if player then
local sampleCfg = sampleConfigs[dir]
if sampleCfg then
local newPos = Position(pos.x + sampleCfg.dirPos.x, pos.y + sampleCfg.dirPos.y, pos.z)
if isWalkable(newPos) then
if Tile(newPos):getTopCreature() then
local killed = Tile(newPos):getTopCreature()
if Player(killed:getId()) then
if iced_Corpses[killed:getSex()] then
local killed_corpse = iced_Corpses[killed:getSex()][killed:getDirection()][math.random(1, #iced_Corpses[killed:getSex()][killed:getDirection()])]
Game.createItem(killed_corpse, 1, killed:getPosition())
local item = Item(getTileItemById(killed:getPosition(), killed_corpse).uid)
addEvent(function() item:remove(1) end, 3000)
end
killed:getPosition():sendMagicEffect(3)
killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
killed:getPosition():sendMagicEffect(50)
killed:setStorageValue(10109, killed:getStorageValue(10109) - SnowBall_Configurations.Event_LostPoints)
killed:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Restart)
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")
player:setStorageValue(10109, player:getStorageValue(10109) + SnowBall_Configurations.Event_GainPoint)
player:sendTextMessage(29, "You just hit the player " .. killed:getName() .. " and won +" .. SnowBall_Configurations.Event_GainPoint .." points.\nTotal of: " .. player:getStorageValue(10109) .. " points")
if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
player:getPosition():sendMagicEffect(7)
player:sendTextMessage(29, "You are now the leader of the SnowBall ranking, congratulations!")
Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, "You just lost the first place!")
end
table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
else
newPos:sendMagicEffect(3)
end
return true
end
pos:sendDistanceEffect(newPos, 13)
pos = newPos
return addEvent(Event_sendSnowBall, SnowBall_Configurations.Ammo_Configurations.Ammo_Speed, player:getId(), pos, rounds - 1, dir)
end
newPos:sendMagicEffect(3)
return true
end
end
return true
end
function Event_endGame()
local str = " ## -> SnowBall Ranking <- ##\n\n"
for rank, players in ipairs(CACHE_GAMEPLAYERS) do
if SnowBall_Configurations.Positions_Rewards[rank] then
for item_id, item_ammount in pairs(SnowBall_Configurations.Positions_Rewards[rank]) do
Player(players):addItem(item_id, item_ammount)
end
end
str = str .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " points\n"
Player(players):teleportTo(Player(players):getTown():getTemplePosition())
end
for _, cid in ipairs(CACHE_GAMEPLAYERS) do
Player(cid):showTextDialog(2111, str)
end
broadcastMessage("[Snowball Event]: The event ended.")
return true
end
function isWalkable(pos) --- New Function by Tony Araújo (OrochiElf)
for i = 0, 255 do
pos.stackpos = i
local item = Item(getTileThingByPos(pos).uid)
if item ~= nil then
if item:hasProperty(2) or item:hasProperty(3) or item:hasProperty(7) then
return false
end
end
end
return true
end
function isInArena(player)
local pos = player:getPosition()
if pos.z == SnowBall_Configurations.Area_Configurations.Area_Arena[1].z then
if pos.x >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].x and pos.y >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].y then
if pos.x <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].x and pos.y <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].y then
return true
end
end
end
return false
end