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

[HELP] NPC who buys flasks

clone

New Member
Joined
Jun 16, 2007
Messages
412
Reaction score
1
The title says it all i need a npc who buys all flasks including the 8.1 vials i have used the search function and have found one and tried scriptingi t to work but it doesnt work help please.
 
Add this at the bottem of data/global.lua:

Code:
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

And change your runes.lua to:

Code:
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())

How it works? hi/flask/yes =)

I hope it help you.
 
In fluids you will find lots of things like this for manapotion:
Code:
"Aaaah...", TEXTCOLOR_ORANGE)
				doPlayerAddMana(cid, math.random(80, 160))
                                doRemoveItem(item.uid,1)
				doSendMagicEffect(topos, 12)
			elseif item.type == 10 then
				doSendAnimatedText(getPlayerPosition(cid),
This is from 8.0, but if you open fluids in data/actions/scripts fluids, you can easily find the lvl 0 potion, lvl 50 potion etc, and you add
Code:
                                doRemoveItem(item.uid,1)

And you won't have any irritating empty flasks anymore. Since when you use the potion, it will dissapear. So you won't have to sell it, or dropp it.

REP me if my post'S come in handy :)
 
In fluids you will find lots of things like this for manapotion:
Code:
"Aaaah...", TEXTCOLOR_ORANGE)
				doPlayerAddMana(cid, math.random(80, 160))
                                doRemoveItem(item.uid,1)
				doSendMagicEffect(topos, 12)
			elseif item.type == 10 then
				doSendAnimatedText(getPlayerPosition(cid),
This is from 8.0, but if you open fluids in data/actions/scripts fluids, you can easily find the lvl 0 potion, lvl 50 potion etc, and you add
Code:
                                doRemoveItem(item.uid,1)

And you won't have any irritating empty flasks anymore. Since when you use the potion, it will dissapear. So you won't have to sell it, or dropp it.

REP me if my post'S come in handy :)

Lol. You cant read? What a piece of shit did you write? :huh:
 
Sorry for beeing noob.

I guess Ronaldino's example will fix the problem.

EDIT:
I wasn't a noob at all. Just you guys who didn't seem to understand me.

This is for TFS!
Enter data\actions\scripts\other and open fluids and potions.lua

Remove
doTransformItem(item.uid, emptyPot)
and add
doRemoveItem(item.uid,1)

Then when you click on the potion, you will drink the potion, and the vial will be removed automatic.
No more vials.

With this, you don't need any npc that buys vials at all, since there won't exist any vials.
 
Last edited:
Back
Top