<action itemid="8981" script="access.lua"/>
local storageValue = 13741
local itemID = 8981 -- Item utilizado para conceder o acesso de 72 horas
local teleportPosition = {x = 154, y = 51, z = 7} -- Posição de teleporte quando o tempo acabar
local timeInterval = 1 * 60 -- Intervalo de tempo em segundos (30 minutos)
function onUse(cid, item, frompos, item2, topos)
if getPlayerStorageValue(cid, storageValue) ~= -1 then
doPlayerSendCancel(cid, "Você já tem acesso a essa funcionalidade.")
return true
end
if not doPlayerRemoveItem(cid, itemID, 1) then
doPlayerSendCancel(cid, "Você precisa ter o item necessário para usar essa funcionalidade.")
return true
end
local currentTime = os.time()
local accessTime = 72 * 60 * 60 -- Convertendo 72 horas para segundos
local expirationTime = currentTime + accessTime
setPlayerStorageValue(cid, storageValue, expirationTime)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Você ganhou acesso a essa funcionalidade por 72 horas.")
return true
end
function onLogin(cid)
local currentTime = os.time()
local expirationTime = getPlayerStorageValue(cid, storageValue)
if expirationTime ~= -1 and currentTime >= expirationTime then
doTeleportThing(cid, teleportPosition, false)
setPlayerStorageValue(cid, storageValue, -1)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Seu acesso expirou. Você foi teleportado para a posição 154, 51, 7.")
end
local timeDifference = currentTime - getPlayerStorageValue(cid, "lastTimeCheck")
if timeDifference >= timeInterval then
local timeRemaining = expirationTime - currentTime
local hours = math.floor(timeRemaining / 3600)
local minutes = math.floor((timeRemaining % 3600) / 60)
local seconds = timeRemaining % 60
local timeString = string.format("%02d:%02d:%02d", hours, minutes, seconds)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Tempo restante: " .. timeString)
setPlayerStorageValue(cid, "lastTimeCheck", currentTime)
end
return true
end
<movevent type="StepIn" uniqueid="18956" event="script" value="acessoTile.lua"/>
function onStepIn(cid, item, position, fromPosition)
local sto = 13741 -- storage Aqui
if isPlayer(cid) then
if getPlayerStorageValue(cid, sto) >= 1 then
doPlayerSendTextMessage(cid, 25, "Seja bem vindo a area.")
else
doTeleportThing(cid, fromPosition, true)
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
doPlayerSendTextMessage(cid, 25, "Você Não Tem Acesso!")
end
end
return true
end