Tenta esse código:
FONTE: Chat-GPT
-- Função para filtrar a string
local function filtrateString(str)
if type(str) ~= "string" then
return false
end
local _, first = string.find(str, "a ")
local _, last = string.find(str, " ", first + 1)
local _, second = string.find(str, "b ")
return {str:sub(first + 1, last - 1), str:sub(second + 1)}
end
-- Tabelas para armazenar as caves exclusivas
local caveExclusiva = {
{pos = {x = 2321, y = 482, z = 7}, storage = 822081},
{pos = {x = 2324, y = 482, z = 7}, storage = 822082},
-- Adicione as demais caves exclusivas aqui
}
-- Verifica se a posição é uma cave exclusiva
local function isCaveExclusiva(position)
for i = 1, #caveExclusiva do
if caveExclusiva[i].pos.x == position.x and caveExclusiva[i].pos.y == position.y and caveExclusiva[i].pos.z == position.z then
return caveExclusiva[i]
end
end
return nil
end
-- Função para checar a disponibilidade da cave
local function checkCaveAvailability(cid, fromPosition, numerodacave)
local storageGlobal = numerodacave + 900000
-- Filtra a string para obter o tempo restante de exaustão
local remainingTime = tonumber(filtrateString(getGlobalStorageValue(storageGlobal))[2])
if remainingTime and remainingTime > os.time() then
local currentTime = os.time()
local timeDiff = os.difftime(remainingTime, currentTime)
if timeDiff > 0 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, a Cave ["..numerodacave.."] não está disponível. Escolha outra CAVE ou aguarde até ela ser liberada.")
return true
end
end
local player = Player(cid)
local isVIP = player:getPremiumDays() > 0
local exhaustionTime = 10800 -- Tempo de exaustão padrão para jogadores não VIP
if isVIP then
exhaustionTime = 12600 -- Tempo de exaustão para jogadores VIP
end
-- Restante do código para verificar a exaustão e permitir acesso à cave
return false
end
-- Exemplo de uso
local playerID = 123 -- ID do jogador
local playerPosition = {x = 2321, y = 482, z = 7} -- Posição do jogador
local caveNumber = 1 -- Número da cave
checkCaveAvailability(playerID, playerPosition, caveNumber)
Se der erro, tente esse outro:
local function filtrateString(str)
if type(str) ~= "string" then
return false
end
local first, last = 0, 0
local second, final = 0, #str
for i = 1, #str do
if string.byte(str:sub(i,i)) == string.byte('a') then
first = i + 2
for t = first, #str do
if string.byte(str:sub(t,t)) == string.byte(' ') then
last = t - 1
break
end
end
end
if string.byte(str:sub(i,i)) == string.byte('b') then
second = i + 2
end
end
return {str:sub(first, last), str:sub(second, final)}
end
local function getPlayerHuntExhaustion(cid)
local exhaustStorage = 13540
local exhaustionTime = 1800 -- Tempo de exaustão em segundos (padrão: 30 minutos)
local lastTime = getPlayerStorageValue(cid, exhaustStorage)
if lastTime and lastTime > os.time() then
local remainingTime = lastTime - os.time()
return remainingTime
else
setPlayerStorageValue(cid, exhaustStorage, os.time() + exhaustionTime)
return 0
end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local playerLevel = getPlayerLevel(cid)
local isVIP = false -- Defina como verdadeiro se o jogador for VIP
local caveExclusiva = {
{pos = {x = 2321, y = 482, z = 7}, storage = 822081},
{pos = {x = 2324, y = 482, z = 7}, storage = 822082},
-- Adicione as demais caves exclusivas aqui
}
local cave = nil
for i = 1, #caveExclusiva do
if caveExclusiva[i].pos.x == fromPosition.x and caveExclusiva[i].pos.y == fromPosition.y and caveExclusiva[i].pos.z == fromPosition.z then
cave = caveExclusiva[i]
break
end
end
if not cave then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Para usar uma Cave Exclusiva, você precisa usar esse item na frente da porta da Cave Exclusiva.")
return true
end
local storageGlobal = cave.storage
local remainingTime = tonumber(filtrateString(getGlobalStorageValue(storageGlobal))[2])
if remainingTime and remainingTime > os.time() then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, a Cave ["..numerodacave.."] não está disponível. Escolha outra CAVE ou aguarde até ela ser liberada.")
return true
end
local tempohunt = 0
if playerLevel > 500 then
tempohunt = 5400
else
tempohunt = 10800
end
if isVIP then
tempohunt = tempohunt + 1800 -- Adiciona 30 minutos extras para.