samuel157
/root
- Joined
- Mar 19, 2010
- Messages
- 447
- Solutions
- 3
- Reaction score
- 49
- Location
- São Paulo, Brazil
- GitHub
- Samuel10M
Lua:
local storageValue = 13741
local itemID = 8981 -- Item utilizado para conceder o acesso de 30 minutos
local teleportPosition = {x = 154, y = 51, z = 7} -- Posição de teleporte quando o tempo acabar
local cooldownTime = 30 * 60 -- Tempo de cooldown em segundos (30 minutos)
local timeInterval = 60 -- Intervalo de verificação de tempo em segundos (exemplo: 1 minuto)
function onUse(cid, item, frompos, item2, topos)
local lastUsageTime = getPlayerStorageValue(cid, "lastUsageTime")
local currentTime = os.time()
if lastUsageTime ~= -1 and currentTime < lastUsageTime + cooldownTime then
local remainingTime = (lastUsageTime + cooldownTime) - currentTime
local minutes = math.floor(remainingTime / 60)
local seconds = remainingTime % 60
doPlayerSendCancel(cid, "Aguarde mais " .. minutes .. " minutos e " .. seconds .. " segundos antes de usar novamente.")
return true
end
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 expirationTime = currentTime + (30 * 60) -- Convertendo 30 minutos para segundos
setPlayerStorageValue(cid, storageValue, expirationTime)
setPlayerStorageValue(cid, "lastUsageTime", currentTime)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Você ganhou acesso a essa funcionalidade por 30 minutos.")
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 lastTimeCheck = getPlayerStorageValue(cid, "lastTimeCheck")
local timeDifference = currentTime - lastTimeCheck
if timeDifference >= timeInterval then
local timeRemaining = expirationTime - currentTime
if timeRemaining > 0 then
local minutes = math.floor(timeRemaining / 60)
local seconds = timeRemaining % 60
local timeString = string.format("%02d:%02d", minutes, seconds)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Tempo restante: " .. timeString)
end
setPlayerStorageValue(cid, "lastTimeCheck", currentTime)
end
return true
end