• 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 exchanges tibia gold for tibia coins

Faeyren

Active Member
Joined
Apr 2, 2009
Messages
11
Reaction score
28
NPC Will sell 1 tibia coin for 1250 gold. Ratio is adjustable at the top.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local count = {}
local transfer = {}
local ratio = 1250
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 creatureSayCallback(cid, type, msg)


    if not npcHandler:isFocused(cid) then
        return false
    end


    local player = Player(cid)


if msgcontains(msg, "balance") then
    npcHandler:say('Your balance is ' .. player:getCoinsBalance() .. ' tibia coins.', cid)


    elseif msgcontains(msg, "purchase") or msgcontains(msg, "exchange") or msgcontains(msg, "tibia coins")then
    count[cid] = player:getBankBalance()
        if count[cid] < 1 then
            npcHandler:say('You need to have gold in your bank to {exchange} currency.', cid)
            npcHandler.topic[cid] = 0
            return false
        end
        
            if string.match(msg,'%d+') then
                count[cid] = getMoneyCount(msg)
                if count[cid] < 1 then
                    npcHandler:say('You do not have enough money {in your bank} to make this exchange.', cid)
                    npcHandler.topic[cid] = 0
                    return false
                end
                amount = getMoneyCount(msg)
                cost = amount * ratio
                npcHandler:say('Would you really like to purchase ' .. count[cid] .. ' tibia coins for ' .. cost .. ' gold coins?', cid)
                npcHandler.topic[cid] = 2
                return true
            else
                npcHandler:say('How many tibia coins would you like to purchase?', cid)
                npcHandler.topic[cid] = 1
                return true
            end


        if not isValidMoney(count[cid]) then
            npcHandler:say('I\'m sorry. I can\'t do that.', cid)
            npcHandler.topic[cid] = 0
            return false
        end
    elseif npcHandler.topic[cid] == 1 then
        count[cid] = getMoneyCount(msg)
        amount = getMoneyCount(msg)
        cost = amount * ratio
    
        if isValidMoney(count[cid]) then
                npcHandler:say('Would you really like to purchase ' .. count[cid] .. ' tibia coins for ' .. cost .. ' gold coins?', cid)
                npcHandler.topic[cid] = 2
            return true
        else
            npcHandler:say('You do not have enough money {in your bank} to make this exchange.', cid)
            npcHandler.topic[cid] = 0
            return true
        end
    elseif npcHandler.topic[cid] == 2 then
        if msgcontains(msg, 'yes') then


            if not player:removeMoneyNpc(cost) then
                npcHandler:say('You do not have enough money {in your bank} to make this exchange.', cid)
                npcHandler.topic[cid] = 0
                return true
            end
            if player:setCoinsBalance(player:getCoinsBalance() + amount) then
                npcHandler:say('Alright, we have added the ' .. count[cid] .. ' tibia coins to your {balance}.', cid)
            else
                npcHandler:say('You do not have enough money {in your bank} to make this exchange.', cid)
            end
        elseif msgcontains(msg, 'no') then
            npcHandler:say('Is there something else I can do for you?', cid)
        end
        npcHandler.topic[cid] = 0
    return true
    end
end




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