function onUse(cid, item, fromPosition, itemEx, toPosition, words, param, channel, item2, topos)
local quest = {
level = 50, -- level mínimo
max_times = 3, -- quantas vezes poderá usar
timetowait = {1, "day"}, -- tempo para usar novamente após atingir o max_times
max_players = 3, -- máximo de players dentro da área
room = {from = {x = 32312, y = 32507, z = 8}, to = {x = 32312, y = 32507, z = 8}},-- posição do canto superior esquerdo, posição do canto inferior direito da sala
newpos = {x = 32327, y = 32528, z = 18}, -- posição para onde o player será teleportado ao entrar
stone = {id = 1304, pos = {x = 32320, y = 32516, z = 8}}, -- id da pedra, posição
timetokick = {2, "min"}, -- tempo para ser kikado da sala
}
local pos = {
{x=32331, y=32526, z=7, stackpos=1},
kickpos = {x = 32331 , y = 32526, z = 7}
} -- quando kikados da área, o player vai para essa posição
local p, inside = getPlayerPosition(cid), getPlayersInArea(quest.room.from, quest.room.to)
if getPlayerStorageValue(cid, 84309) > os.time() then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can use again at " .. os.date("%d %B %Y %X", getPlayerStorageValue(cid, 84309))..".")
return true
else
if getPlayerStorageValue(cid, 84310) == quest.max_times then
setPlayerStorageValue(cid, 84310, -1)
end
end
if #inside >= quest.max_players then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Wait for the team to leave the room.")
doSendMagicEffect(p, CONST_ME_POFF)
return true
end
if getPlayerLevel(cid) < quest.level then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need at least level " .. quest.level .. " to go.")
doSendMagicEffect(p, CONST_ME_POFF)
return true
end
local max_times = getPlayerStorageValue(cid, 84310) > 0 and getPlayerStorageValue(cid, 84310) or 0
if (max_times + 1) == quest.max_times then
setPlayerStorageValue(cid, 84309, mathtime(quest.timetowait) + os.time())
end
local stone = getTileItemById(quest.stone.pos, quest.stone.id).uid
if stone > 0 then
doSendMagicEffect(quest.stone.pos, CONST_ME_POFF)
doRemoveItem(stone)
end
doTeleportThing(cid, quest.room.newpos)
doSendMagicEffect(quest.room.newpos, CONST_ME_TELEPORT)
setPlayerStorageValue(cid, 84310, max_times+1)
addEvent(kickFromArea, mathtime(quest.timetokick) * 1000, cid)
return true
end
function getPlayersInArea(fromPos, toPos)
local players = {}
for _, pid in ipairs(getPlayersOnline()) do
if isInRange(getPlayerPosition(pid), fromPos, toPos) then
table.insert(players, pid)
end
end
return players
end
function mathtime(table) -- by dwarfer
local unit = {"sec", "min", "hour", "day"}
for i, v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end
function kickFromArea(cid)
local stone = getTileItemById(quest.stone.pos, quest.stone.id)
if stone.uid == 0 then
doCreateItem(quest.stone.id, 1, quest.stone.pos)
end
if isPlayer(cid) and isInRange(getPlayerPosition(cid), quest.room.from, quest.room.to) then
doTeleportThing(cid, quest.kickpos)
end
doSendMagicEffect(quest.kickpos, CONST_ME_TELEPORT)
end