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
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())
"Aaaah...", TEXTCOLOR_ORANGE)
doPlayerAddMana(cid, math.random(80, 160))
doRemoveItem(item.uid,1)
doSendMagicEffect(topos, 12)
elseif item.type == 10 then
doSendAnimatedText(getPlayerPosition(cid),
doRemoveItem(item.uid,1)
In fluids you will find lots of things like this for manapotion:
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 addCode:"Aaaah...", TEXTCOLOR_ORANGE) doPlayerAddMana(cid, math.random(80, 160)) doRemoveItem(item.uid,1) doSendMagicEffect(topos, 12) elseif item.type == 10 then doSendAnimatedText(getPlayerPosition(cid),
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
that still doesnt support the 8.1 potions.......