• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Avesta] NPC buying vials

Veterana

Oldschool Player
Joined
May 4, 2010
Messages
194
Reaction score
7
I need help to make a NPC buy all vials, when you say "vials".
It should only take the empty vials and not the ones filled with mana or other liquid.

Anyone got skills to make this?
 
Hi,

data/global.lua
LUA:
PLAYERSLOT_FIRST = 1
PLAYERSLOT_LAST = 10
function removePlayerItemsWithCharges(cid, itemid, charges)
    if(isItemRune(itemid) ~= TRUE and isItemFluidContainer(itemid) ~= TRUE) then
        error('[Error] removePlayerItemsWithCharges: Item ' .. itemid .. ' is not a rune or fluid container.', 2)
        return 0
    end
 
    local n = 0
 
    for slot = PLAYERSLOT_FIRST, PLAYERSLOT_LAST, 1 do
        local item = getPlayerSlotItem(cid, slot)
        if(item.itemid > 0) then
            if(item.itemid == itemid and item.type == charges) then
                if(doRemoveItem(item.uid, -1) == LUA_NO_ERROR) then
                    n = n + 1
                else
                    print('[Warning] removePlayerItemsWithCharges: ', 'Could not remove item with uid ' .. item.uid)
                end
            elseif(isContainer(item.uid) == TRUE) then
                n = n + removeContainerItemsWithCharges(item.uid, itemid, charges)
            end
        end
    end
 
    return n
 
end
 
function removeContainerItemsWithCharges(uid, itemid, charges)
    if(isItemRune(itemid) ~= TRUE and isItemFluidContainer(itemid) ~= TRUE) then
        error('[Error] removeContainerItemsWithCharges: Item ' .. itemid .. ' is not a rune or fluid container.', 2)
        return 0
    end
 
    local n = 0
 
    local slot = 0
    local cap = getContainerCap(uid)
    while(slot <= cap) do
        local item = getContainerItem(uid, slot)
        if(item.itemid > 0) then
            if(item.itemid == itemid and item.type == charges) then
                if(doRemoveItem(item.uid, -1) == LUA_NO_ERROR) then
                    n = n+1
                    slot = slot-1
                else
                    print('[Warning] removeContainerItemsWithCharges: ', 'Could not remove item with uid ' .. item.uid)
                end
            elseif(isContainer(item.uid) == TRUE) then
                n = n + removeContainerItemsWithCharges(item.uid, itemid, charges)
            end
        end
        slot = slot+1
    end
 
    return n
end

data/npcs/scripts/runes.lua:

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
 
 
-- OTServ event handling functions start
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
-- OTServ event handling functions end
 
 
function returnVials(cid, message, keywords, parameters, node)
    if(npcHandler.focus ~= cid) then
        return false
    end
 
    local amount = removePlayerItemsWithCharges(cid, parameters.itemid, parameters.charges)
    if(amount <= 0) then
        npcHandler:say('You do not have any.')
    else
        local price = amount*parameters.cost
        if(doPlayerAddMoney(cid, price) == LUA_NO_ERROR) then
            npcHandler:say('Here are your reward of ' .. price .. ' gold coins. It was a pleasure doing business with you.')
        else
            error('[Error] returnVials:', 'Could not give ' .. price .. ' gold coins to player ' .. getPlayerName(cid))
        end
    end
    npcHandler:resetNpc()
    return true
end
 
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
 
shopModule:addBuyableItem({'light wand', 'lightwand'},         2163, 500,     1,    'magic light wand')
shopModule:addBuyableItem({'mana fluid', 'manafluid'},         2006, 100,     7,     'mana fluid')
shopModule:addBuyableItem({'life fluid', 'lifefluid'},         2006, 80,     10,    'life fluid')
shopModule:addBuyableItem({'heavy magic missile', 'hmm'},     2311, 125,     10,    'heavy magic missile rune')
shopModule:addBuyableItem({'great fireball', 'gfb'},             2304, 180,     4,     'great fireball rune')
shopModule:addBuyableItem({'explo', 'xpl'},                     2313, 250,     6,     'explosion rune')
shopModule:addBuyableItem({'ultimate healing', 'uh'},         2273, 175,     2,     'ultimate healing rune')
shopModule:addBuyableItem({'sudden death', 'sd'},             2268, 325,     2,     'sudden death rune')
shopModule:addBuyableItem({'blank', 'rune'},                     2260, 10,     1,    'blank rune')
 
 
local node = keywordHandler:addKeyword({'flask'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you wish to return all your empty vials for 5 gold coins each?'})
    node:addChildKeyword({'yes'}, returnVials, {itemid = 2006, charges = 0, cost = 5})
    node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Allright then.'})
 
npcHandler:addModule(FocusModule:new())
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local topic = 0
 
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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'life fluid'}, 2006, 60, 10)
 
function greetCallback(cid)
	topic = 0
	return true
end
 
npcHandler:setMessage(MESSAGE_GREET, "Greetings, traveller |PLAYERNAME|.") 
npcHandler:setMessage(MESSAGE_WALKAWAY, "May Crunor bless you.")
npcHandler:setMessage(MESSAGE_FAREWELL, "May Crunor bless you.")
npcHandler:setMessage(MESSAGE_IDLETIMEOUT, "Good bye.")
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "Wait, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_ONBUY, "Thank you. Here it is.")
npcHandler:setMessage(MESSAGE_ONSELL, "Ok. Here is your money.")
npcHandler:setMessage(MESSAGE_NEEDMOREMONEY, "Sorry, you do not have enough gold.")
npcHandler:setMessage(MESSAGE_NOTHAVEITEM, "Sorry, you do not have one.")
npcHandler:setMessage(MESSAGE_DECLINE, "Maybe next time.")
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)

keywordHandler:addKeyword({'how are you'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Thanks to the gods, I am fine."})
keywordHandler:addKeyword({'sell'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I just sell some revitalizing life fluids."})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am a druid and healer, a follower of Crunor."})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am Hyacinth."})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Time does not matter to me."})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I can only sell life fluids, ask Cipfried for further help."})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Most of the so called monsters of this isle are just creatures of the gods. On the mainland there are some beasts that truly are monstrous."})
keywordHandler:addKeyword({'dungeon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The dungeons are dangerous for unexperienced adventurers."})
keywordHandler:addKeyword({'sewer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I rarely visit the town."})
keywordHandler:addKeyword({'god'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "As far as I know there is a library in the village. Teach yourself about the gods."})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I don't care about kings, queens, and the like."})
keywordHandler:addKeyword({'obi'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "A greedy and annoying person as most people are."})
keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He has some inner devils that torture him."})
keywordHandler:addKeyword({'dallheim'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "A man of the sword."})
keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "His healing powers equal even mine."})
keywordHandler:addKeyword({'amber'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I never talked to her longer."})
keywordHandler:addKeyword({'weapon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I don't care much about weapons."})
keywordHandler:addKeyword({'magic'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am one of the few magic users on this isle. But I sense a follower of the dark path of magic hiding somewhere in the depths of the dungeons."})
keywordHandler:addKeyword({'spell'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I can't teach you magic. On the mainland you will learn your spells soon enough."})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It is shaped by the will of the gods, so we don't have to question it."})
 
function creatureSayCallback(cid, type, msg)
	if npcHandler.focus ~= cid then
		return false
	end
	
	msg = msg:lower()
	
	if msgcontains(msg, "flask") or msgcontains(msg, "vial") or msgcontains(msg, "deposit") then
		npcHandler:say("I will pay you 5 gold for every empty vial. Ok?")
		topic = 3
	elseif topic == 3 then
		if msgcontains(msg, "yes") then
			local money = 0
			while doPlayerRemoveItem(cid, 2006, 1, 0) == 1 do
					money = money + 5
			end
			if money ~= 0 then
				npcHandler:say("Here you are ... ".. money.." gold.")
				doPlayerAddMoney(cid, money)
			else
				npcHandler:say("You don't have any empty vials.")
			end
		else
			npcHandler:say("Hmm, but please keep Tibia litter free.")
		end
		topic = 0	
end
	return TRUE
end
	
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top