• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua TFS 1.5 - Downgrade Nekiro - NPC Exchange x items for y items.

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hi otlanders,

I need an NPC that exchanges configurable items, example, the player will give items id 4850 quantity 20 and item id 2160 quantity 50 and will receive item 2195 quantity 2.

And the player can only make this exchange within a 1-day interval.

Can anyone help me?
 
Solution
Lua:
-- 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 =...
Lua:
-- 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())
 
Lua:
-- 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())
Lua:
    if topic[cid] == 1 and 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)
            topic[cid] = 0
        end
    else
        npcHandler:say("Maybe at another time then.", cid)
        topic[cid] = 0
    end
 
Solution
Back
Top