-- Forkz
local COOLDOWN_TIME = 3600 -- Defina o tempo de espera em segundos (3600 segundos = 1 hora)
local topic = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local function formatTime(seconds)
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
return string.format("%dh %dm", hours, minutes)
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
local lastExchangeTime = player:getStorageValue(Storage.kala) or 0
local currentTime = os.time()
if msgcontains(msg, "boots of haste") then
if currentTime - lastExchangeTime < COOLDOWN_TIME then
local remainingTime = COOLDOWN_TIME - (currentTime - lastExchangeTime)
npcHandler:say("You already switched, you need to wait " .. formatTime(remainingTime) .. " to change again.", cid)
return true
end
npcHandler:say("Do you really want to exchange 20 hydra eggs for boots of haste?", cid)
topic[cid] = 1
return true
end
if msgcontains(msg, "yes") then
if player:getItemCount(4850) >= 20 then -- Verifica se o jogador tem pelo menos 20 hydra eggs
player:removeItem(4850, 20)
player:addItem(2195, 1)
player:setStorageValue(Storage.kala, os.time()) -- Adiciona o momento da troca à storage
npcHandler:say("Here are your boots of haste. Have a good day!", cid)
else
npcHandler:say("You don't have enough hydra eggs.", cid)
end
else
npcHandler:say("Maybe at another time then.", cid)
end
topic[cid] = 0 -- Esta linha deve estar fora do bloco "if msgcontains(msg, "yes") then"
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "People are so stupid these days.")
npcHandler:addModule(FocusModule:new())