Salve man!, testa ai
local config = {
cooldownHours = 6, -- tempo em horas para usar novamente
level = 100,
storage = 30015, -- armazena o timestamp da última vez que usou
requiredItem = 6527,
playerPositions = {
{x = 247, y = 659, z = 13},
{x = 247, y = 660, z = 13},
{x = 247, y = 661, z = 13},
{x = 247, y = 662, z = 13}
},
teleportPositions = {
{x = 189, y = 650, z = 13},
{x = 189, y = 651, z = 13},
{x = 189, y = 652, z = 13},
{x = 189, y = 653, z = 13}
}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == 1946 then
doTransformItem(item.uid, 1945)
return true
end
local players = {}
for i, pos in ipairs(config.playerPositions) do
local creature = getTopCreature(pos).uid
if creature > 0 and isPlayer(creature) then
-- Verificações individuais
if getPlayerLevel(creature) < config.level then
doPlayerSendCancel(cid, "Todos os jogadores precisam ter level " .. config.level .. " ou mais.")
return true
end
if getPlayerItemCount(creature, config.requiredItem) < 1 then
doPlayerSendCancel(cid, "Todos os jogadores precisam ter o item necessário (ID: " .. config.requiredItem .. ").")
return true
end
local lastUse = getPlayerStorageValue(creature, config.storage)
if lastUse ~= -1 and os.time() - lastUse < (config.cooldownHours * 3600) then
local remaining = math.ceil(((lastUse + config.cooldownHours * 3600) - os.time()) / 60)
doPlayerSendCancel(cid, "Todos os jogadores devem esperar " .. remaining .. " minutos para usar novamente.")
return true
end
table.insert(players, creature)
else
doPlayerSendCancel(cid, "Todos os quadrados precisam estar ocupados por jogadores.")
return true
end
end
-- Tudo ok, teleporta e consome o item
for i, player in ipairs(players) do
doTeleportThing(player, config.teleportPositions[i], false)
doSendMagicEffect(config.playerPositions[i], CONST_ME_POFF)
doSendMagicEffect(config.teleportPositions[i], CONST_ME_ENERGYAREA)
doPlayerRemoveItem(player, config.requiredItem, 1)
setPlayerStorageValue(player, config.storage, os.time())
end
doTransformItem(item.uid, 1946)
return true
end
Por
Darcio Antonio, · Postado