RevScript NPC Sell Store Coin (tibia coins) for Gold (money)

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
Hola a todos,

Aqui encontraran el script.lua que deben de integrar a su NPC si desean vender ' Store Coins ' ( tibia coins ) por Gold Coins, pueden anadir el precio que desean,

Código:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local coinId = 24774
local coinCost = 42 -- gold coins
local coinsAmount = {}

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 greetCallback(cid)
    npcHandler.topic[cid] = 0
    coinsAmount[cid] = 0
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local player = Player(cid)

    if msgcontains(msg, "buy") then
        npcHandler:say("How many store coins would you want to buy?", cid)
        npcHandler.topic[cid] = 1
       
    elseif npcHandler.topic[cid] == 1 then
        local amount = tonumber(msg) ~= nil
        if not amount then
            npcHandler:say("I'm unfamiliar with that number. How many store coins do you want to buy?", cid)
            return true
        end
        amount = tonumber(msg)
        if amount < 0 or amount > 1000000 then
            npcHandler:say("I'm unfamiliar with that number. How many store coins do you want to buy?", cid)
            return true
        end
        npcHandler:say("Would you like to purchase " .. amount .. " store coins for " .. (amount * coinCost) .. " gold coins?", cid)
        npcHandler.topic[cid] = 2
        coinsAmount[cid] = amount
       
    elseif npcHandler.topic[cid] == 2 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("Another time then.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        local cost = coinsAmount[cid] * coinCost
        if player:getMoney() < cost then
            npcHandler:say("You do not have enough gold coins to make this purchase. Another time, maybe?", cid)
            npcHandler.topic[cid] = 0
            coinsAmount[cid] = 0
            return true
        end
        player:removeMoney(cost)
        player:addItem(coinId, coinsAmount[cid], true)
        npcHandler:say("I appreciate your business.", cid)
        npcHandler.topic[cid] = 0
        coinsAmount[cid] = 0
       
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Arriba