• 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!

NPC that converts items after 60 seconds

Candlejack

Don't hug me I'm scared
Joined
Jun 20, 2012
Messages
87
Reaction score
38
Location
nowhere
Is this possible? I need an NPC that would convert x number of item id xxxx to x number of item id yyyy. But I need the player to wait based on the number of items that were given

For example.

Player: Hi
Npc: Hello
Player: Convert 10 Branches
<Player gives NPC 10 branches>
NPC: Thank you. Check back in 2 minutes 30 seconds.
...
Player: Hi
NPC: I am still processing your branches. Please check back in 30 seconds...
...
Player: Hi
NPC: I have converted your 10 branches to 10 pieces of wood!
<NPC Gives player 10 wood>

If someone could help me with this I would be extremely grateful!
 
flOCopL.png


In my example script I used Wood (5901) and Honeycombs (5902). Change those values to your desired items. You can also easily adjust the delay time. You can also change lines like this:
Code:
npcHandler:say("Would you like to convert {item1} into {item2}?", cid)
To be worded better to your needs.

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

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 config = {
    item1 = 5901,
    item2 = 5902,
    timeX = 10,    -- Seconds per item
    delayStorage = 50530, -- empty storage value delay time
    branchCount = 50531, -- empty storage value for branch count
}
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
local itemCount = getPlayerItemCount(cid, config.item1)
   
    if msgcontains(msg, "convert") then
        npcHandler:say("Would you like to convert {item1} into {item2}?", cid)
        Topic[cid] = 1
    elseif msgcontains(msg, "pickup") then
        if getPlayerStorageValue(cid, config.branchCount) > 0 then
            if getPlayerStorageValue(cid, config.delayStorage) > os.time() then
                npcHandler:say("Please come back later I need more time. Come back in ".. (getPlayerStorageValue(cid, config.delayStorage) - os.time()) .." seconds.", cid)
                Topic[cid] = 0
            else
                npcHandler:say("Ah yes here are your ".. getPlayerStorageValue(cid, config.branchCount) .." branches.", cid)
                doPlayerAddItem(cid, config.item2,  getPlayerStorageValue(cid, config.branchCount))
                setPlayerStorageValue(cid, config.branchCount, 0)
            end
        else
            npcHandler:say("I'm sorry you don't have any items to be picked up.", cid)
            Topic[cid] = 0
        end
    elseif msgcontains(msg, "yes") then
        if itemCount < 1 then
            npcHandler:say("I'm sorry you don't have any items to convert.", cid)
            Topic[cid] = 0
        else
            npcHandler:say("It will take ".. (itemCount * 10) .." seconds to convert these items. Please check back later.", cid)
            doPlayerRemoveItem(cid, config.item1, itemCount)
            setPlayerStorageValue(cid, config.delayStorage, os.time() + (itemCount * 10))
            setPlayerStorageValue(cid, config.branchCount, itemCount)
            Topic[cid] = 0
        end
    elseif msgcontains(msg, "no") then
        if Topic[cid] > 1 then
            npcHandler:say("Then no.", cid)
            Topic[cid] = 0
        end
       
    return true
    end
end

npcHandler:setMessage(MESSAGE_GREET, "Welcome to my adventurer shop, |PLAYERNAME|! Would you like to {convert} or {pickup} any items?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top