Ir para conteúdo

Featured Replies

Postado

Olá, preciso adicionar exhausted no meu system de cave exclusiva, onde o player só podera usar o item novamente depois de algumas horas. segue o meu item que da use pra entrar na cave.

 

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




function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, 13540) > os.time() then
	horaextra = 1800
	else
	horaextra = 0
	end
		if getPlayerLevel(cid) > 500 then
		tempohunt = (5400 + horaextra)
		else
		tempohunt = (10800 + horaextra)
		end
			tempominutos = (tempohunt / 60)
		numerodacave = 0
		cr = getCreaturePosition(cid)
	if cr.x == 2321 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822081
			numerodacave = 1
	elseif cr.x == 2324 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822082
			numerodacave = 2
	elseif cr.x == 2327 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822083
			numerodacave = 3
	elseif cr.x == 2330 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822084
			numerodacave = 4
	elseif cr.x == 2333 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822085
			numerodacave = 5
	elseif cr.x == 2321 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822086
			numerodacave = 6
	elseif cr.x == 2324 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822087
			numerodacave = 7
	elseif cr.x == 2327 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822088
			numerodacave = 8
	elseif cr.x == 2330 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822089
			numerodacave = 9
	elseif cr.x == 2333 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822090
			numerodacave = 10
	elseif cr.x == 2336 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822091
			numerodacave = 11	
	elseif cr.x == 2339 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822092
			numerodacave = 12
	elseif cr.x == 2336 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822093
			numerodacave = 13
	elseif cr.x == 2339 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822094
			numerodacave = 14
	elseif cr.x == 2343 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822095
			numerodacave = 15
	elseif cr.x == 2346 and cr.y == 488 and cr.z == 7 then
			storageglobal = 822096
			numerodacave = 16
	elseif cr.x == 2342 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822097
			numerodacave = 17
	elseif cr.x == 2345 and cr.y == 482 and cr.z == 7 then
			storageglobal = 822098
			numerodacave = 18					
	end

if numerodacave > 0 then
		
    if tonumber(filtrateString(getGlobalStorageValue(storageglobal))[2]) < os.time() then
    	if getPlayerStorageValue(cid, 77657) ~= numerodacave then
    	doPlayerPopupFYI(cid, "[CAVE EXCLUSIVA]: Seu personagem estará alugando a Cave ["..numerodacave.."] por "..tempominutos.." minutos.\n[LEVEL 500+]: 90 Minutos.\n[LEVEL 499-]: 180 Minutos.\n[VIP CHARACTER]: +30 Minutos --Personagens VIP tem + 30 Minutos de CAVE EXCLUSIVA\nTOTAL de Tempo de Cave: "..tempominutos.." Minutos\n\nPara confirmar e alugar a Hunt basta usar o item novamente.")
		setPlayerStorageValue(cid, 77657, numerodacave)
		else  
		doRemoveItem(item.uid)
		setGlobalStorageValue(storageglobal, "a "..getPlayerGUID(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "[CAVE EXCLUSIVA]: Seu Personagem agora é dono da Cave ["..numerodacave.."] e pode upar lá por "..tempominutos.." minutos.")
		setPlayerStorageValue(cid, 77657, 0)
		end

	else
	doPlayerSendTextMessage(cid, 25, "[CAVE EXCLUSIVA]: Desculpe, A Cave ["..numerodacave.."] não está disponivel.\nEscolha outra CAVE ou aguarde até ela ser liberada.")
	end			
else
doPlayerSendTextMessage(cid, 25, "[CAVE EXCLUSIVA]: Para usar uma Cave Exclusiva voce precisa usar esse item na frente da porta da [CAVE EXCLUSIVA].")
setPlayerStorageValue(cid, 77657, 0)
end
--[[	elseif tonumber(filtrateString(getGlobalStorageValue(822082))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822082, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 2 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822083))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822083, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 3 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822084))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822084, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 4 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822085))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822085, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 5 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822086))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822086, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 6 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822087))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822087, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 7 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822088))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822088, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 8 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822089))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822089, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 9 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822090))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822090, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 10 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822091))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822091, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 11 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822092))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822092, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 12 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822093))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822093, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 13 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822094))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822094, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 14 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822095))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822095, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 15 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822096))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822096, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 16 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822097))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822097, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 17 e pode upar lá por 4 horas.")
	elseif tonumber(filtrateString(getGlobalStorageValue(822098))[2]) < os.time() then
		doRemoveItem(item.uid)
		setGlobalStorageValue(822098, "a "..getPlayerAccountId(cid).." b ".. os.time() + tempohunt)
		doPlayerSendTextMessage(cid, 25, "Agora você é o dono da cave 18 e pode upar lá por 4 horas.")
	
	else
		doPlayerSendCancel(cid, "Todas as caves já estão com dono no momento. Tente mais tarde.")
	end


	]]--


	return true
end

 

Postado

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.

 

Dark Souls Bonfire GIF - Dark Souls Bonfire Rest - Discover & Share GIFs

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo