local THRONE_POS = {x = 2561, y = 2446, z = 5}
local STORAGE_EVENT = 83902
local STORAGE_PLAYER = 73289
local DUR = 15 -- in minutes
function OpenEvent()
for _, tid in ipairs(getPlayersOnline()) do
setPlayerStorageValue(tid, STORAGE_PLAYER, 1)
end
setGlobalStorageValue(STORAGE_EVENT, 1)
doBroadcastMessage("O Evento castle foi aberto.", 25)
end
function getWinnerCastle(cid)
CastleWalls()
local player = getTopCreature(THRONE_POS).uid
if getGlobalStorageValue(STORAGE_EVENT) < 0 then
return true
end
if (isPlayer(player)) then
if (getPlayerStorageValue(player, STORAGE_PLAYER) > 0) then
pid = getPlayerGUID(cid)
setHouseOwner(6257, pid)
doPlayerAddPremiumDays(player, 7)
for _, cid in ipairs(getPlayersOnline()) do
setPlayerStorageValue(cid, STORAGE_PLAYER, 0)
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
end
doBroadcastMessage(getCreatureName(player) .. " ganhou o evento.", 25)
doTeleportThing(player, {x = 2531, y = 2460, z = 7})
doCreateItem(391, 1, {x = 2561, y = 2446, z = 5})
end
else
doBroadcastMessage("Ningúem ganhou o evento.", 27)
for _, pid in ipairs(getPlayersOnline()) do
setPlayerStorageValue(pid, STORAGE_PLAYER, 0)
doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
end
end
setGlobalStorageValue(STORAGE_EVENT, 0)
return db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. STORAGE_PLAYER)
end
function CastleWalls()
local pedra = getTileItemById({ x = 2539, y = 2474, z = 7}, 1285)
local escada = getTileItemById({ x = 2539, y = 2474, z = 7}, 3687)
if pedra.uid > 0 then
return doRemoveItem(pedra.uid)
else
return doCreateItem(1285, 1, { x = 2539, y = 2474, z = 7})
end
if escada.uid > 0 then
return doRemoveItem(escada.uid)
else
return doCreateItem(3687, 1, {x = 2539, y = 2474, z = 7})
end
end
function onSay(cid, words, param, channel)
if ((param == "abrir") and (getGlobalStorageValue(STORAGE_EVENT) == 1)) then
doPlayerSendTextMessage(cid, 27, "O evento já esta aberto.") return true
elseif ((param == "fechar") and (getGlobalStorageValue(STORAGE_EVENT) == 1)) then
getWinnerCastle()
CastleWalls()
return true
end
doCreateItem(3687, 1, {x = 2539, y = 2474, z = 7})
OpenEvent()
CastleWalls()
addEvent(getWinnerCastle, DUR * 60 * 1000)
return true
end