• 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/help] buy with back packs

renancs

New Member
Joined
Jul 8, 2008
Messages
252
Reaction score
3
Hello, A has been searching arround for the "BUY WITH BACKPACK" feature congiguration, but I cant find nothing to guide me,
When Im using this Function, the NPC sells me just ONE BACKPACK with a SINGLE ITEM inside, can anyone show me how this noobs NPCs SELL those BACKPACKS FULL of BOUGHT ITENS.

Tahnk for the Help.
Im waiting!
=D
 
^_^
shopModule:addBuyableItemContainer({'bp sd'}, 2003, 2268, 2000, 100, 'backpack of sudden death runes')

values= backpackID, itemIDinside, costs, charges

doesnt work, look mines archives:
NPC RACHEL.XML - who sells runes in carlin
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Rachel" script="mods/npc/scripts/global_magic_shop.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="136" head="58" body="84" legs="86" feet="114" addons="0"/>
    <parameters>
        <parameter key="message_greet" value="Welcome |PLAYERNAME|! Whats your need? Im selling potions, runes and wands and {backpack} of runes and {backpack} of potions."/>
        <parameter key="message_farewell" value="Good bye, |PLAYERNAME|."/>
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="job;" />
        <parameter key="keyword_reply1" value="I am the head alchemist of Carlin. I keep the secret recipies of our ancestors. Besides, I {trade} mana and health potions, spellbooks, wands, rods and runes." />
		</parameters>
</npc>

SCRIPT global_magic_shop.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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)

keywordHandler:addKeyword({'backpack'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I have backpacks of blank runes({bp blank}), ultimate healing runes ({bp uh}), sudden death runes({bp sd}), health potions({bp slhp}, {bp hp}, {bp shp}, {bp ghp}, {bp uthp}), mana potions({bp mp}, {bp smp}, {bp gmp}), spirit potions({bp gsp}) and antidote potions({bp ap}). to buy say: {buy [quantify] bp xxx}.'})

shopModule:addBuyableItemContainer({'bp uh'}, 	2002, 2273, 3500,  4, 'backpack of ultimate healing runes')
shopModule:addBuyableItemContainer({'bp sd'}, 	2003, 2268, 6500,  6, 'backpack of sudden death runes')
shopModule:addBuyableItemContainer({'bp mw'}, 	2004, 2293, 7000,  6, 'backpack of magic wall runes')
shopModule:addBuyableItemContainer({'bp blank'}, 	1988, 2260, 200,  1, 'backpack of blank runes')

shopModule:addBuyableItemContainer({'bp slhp'}, 	2000, 8704, 400,  1, 'backpack of small health potions')
shopModule:addBuyableItemContainer({'bp hp'}, 		2000, 7618, 900,  1, 'backpack of health potions')
shopModule:addBuyableItemContainer({'bp shp'}, 		2000, 7588, 2000, 1, 'backpack of strong health potions')
shopModule:addBuyableItemContainer({'bp ghp'}, 		2000, 7591, 3800, 1, 'backpack of great health potions')
shopModule:addBuyableItemContainer({'bp uthp'}, 	2000, 8473, 6200, 1, 'backpack of ultimate health potions')
shopModule:addBuyableItemContainer({'bp mp'}, 		2001, 7620, 1000, 1, 'backpack of mana potions')
shopModule:addBuyableItemContainer({'bp smp'}, 		2001, 7589, 1600, 1, 'backpack of strong mana potions')
shopModule:addBuyableItemContainer({'bp gmp'}, 		2001, 7590, 2400, 1, 'backpack of great mana potions')
shopModule:addBuyableItemContainer({'bp gsp'}, 		1999, 8472, 3800, 1, 'backpack of great spirit potions')
shopModule:addBuyableItemContainer({'bp ap'}, 		2002, 8474, 2000, 1, 'backpack of antidote potions')


shopModule:addBuyableItem({'spellbook'}, 2175, 150, 'spellbook')
shopModule:addBuyableItem({'magic lightwand'}, 2163, 400, 'magic lightwand')

shopModule:addSellableItem({'normal potion flask', 'empty potion flask'}, 	7636, 	5, 	'empty potion flask')
shopModule:addSellableItem({'strong potion flask', 'empty potion flask'}, 	7634, 	10, 'empty potion flask')
shopModule:addSellableItem({'great potion flask', 'empty potion flask'}, 	7635, 	15, 'empty potion flask')

shopModule:addBuyableItem({'small health'},		8704,	 20,	 1,	 'small health potion')
shopModule:addBuyableItem({'health potion'},	7618,	 45,	 1,	 'health potion')
shopModule:addBuyableItem({'mana potion'},	 	7620,	 50,	 1,	 'mana potion')
shopModule:addBuyableItem({'strong health'},	7588,	 100,	 1,	 'strong health potion')
shopModule:addBuyableItem({'strong mana'},	 	7589,	 80,	 1,	 'strong mana potion')
shopModule:addBuyableItem({'great health'},	 	7591,	 190,	 1,	 'great health potion')
shopModule:addBuyableItem({'great mana'},		7590,	 120,	 1,	 'great mana potion')
shopModule:addBuyableItem({'great spirit'},	 	8472,	 190,	 1,	 'great spirit potion')
shopModule:addBuyableItem({'ultimate health'},	8473,	 310,	 1,	 'ultimate health potion')
shopModule:addBuyableItem({'antidote potion'},	8474,	 50,	 1,	 'antidote potion')

shopModule:addBuyableItem({'fire field'}, 		2301, 85, 	6,	'fire field rune')
shopModule:addBuyableItem({'firebomb'}, 	 	2305, 235, 	4,	'firebomb rune')
shopModule:addBuyableItem({'fire wall'}, 		2303, 245, 	8,	'fire wall rune')
shopModule:addBuyableItem({'poison field'}, 	2285, 65, 	6,	'poison field rune')
shopModule:addBuyableItem({'poisonbomb'}, 		2286, 170 ,	4,	'poison bomb rune')
shopModule:addBuyableItem({'poison wall'}, 		2289, 210, 	8,	'poison wall rune')
shopModule:addBuyableItem({'energy field'}, 	2277, 115, 	6,	'energy field rune')
shopModule:addBuyableItem({'energybomb'},	 	2262, 325, 	4,	'energybomb rune')
shopModule:addBuyableItem({'energy wall'}, 		2279, 340, 	8,	'energy wall rune')
shopModule:addBuyableItem({'destroy field'}, 	2261, 45, 	6,	'destroy field rune')
shopModule:addBuyableItem({'light magic missile'}, 	2287, 40, 	20,	'light magic missile rune')
shopModule:addBuyableItem({'heavy magic missile'}, 	2311, 120, 	20,	'heavy magic missile rune')
shopModule:addBuyableItem({'stalagmite'}, 		2292, 120, 	20,	'stalagmite rune')
shopModule:addBuyableItem({'fireball'}, 		2302, 120, 	20,	'fireball rune')
shopModule:addBuyableItem({'icicle'},	 		2271, 120, 	20,	'Icicle rune')
shopModule:addBuyableItem({'stone shower'}, 	2288, 180, 	8,	'stone shower rune')
shopModule:addBuyableItem({'thunderstorm'},	 	2315, 180, 	8,	'thunderstorm rune')
shopModule:addBuyableItem({'avalanche'}, 		2274, 180, 	8,	'avalanche rune')
shopModule:addBuyableItem({'great'}, 			2304, 180, 	8, 	'great fireball rune')
shopModule:addBuyableItem({'explosion'}, 		2313, 190, 	12, 	'explosion rune')
shopModule:addBuyableItem({'sudden death'}, 	2268, 325, 	6, 	'sudden death rune')
shopModule:addBuyableItem({'intense'}, 			2265, 95, 	4, 	'intense healing rune')
shopModule:addBuyableItem({'ultimate'}, 		2273, 175, 	4, 	'ultimate healing rune')
shopModule:addBuyableItem({'convince creature'},	2290, 80, 	2, 	'convince creature rune')
shopModule:addBuyableItem({'animate dead'}, 	2316, 375, 	2, 	'animate dead rune')
shopModule:addBuyableItem({'desintegrate'}, 	2310, 80, 	6, 	'desintegrate rune')
shopModule:addBuyableItem({'chameleon'}, 		2291, 210, 	2, 	'chameleon rune')
shopModule:addBuyableItem({'magic wall'}, 		2293, 350, 	6, 	'magic wall rune')
shopModule:addBuyableItem({'soulfire'}, 		2308, 140, 	4, 	'soulfire rune')
shopModule:addBuyableItem({'blank rune'}, 		2260, 10,	1,	'blank rune')

shopModule:addBuyableItemContainer({'bp uh'}, 	2002, 2273, 3500,  4, 'backpack of ultimate healing runes')
shopModule:addBuyableItemContainer({'bp sd'}, 	2003, 2268, 6500,  6, 'backpack of sudden death runes')
shopModule:addBuyableItemContainer({'bp mw'}, 	2004, 2293, 7000,  6, 'backpack of magic wall runes')
shopModule:addBuyableItemContainer({'bp blank'},	1988, 2260, 200,  1, 'backpack of blank runes')

shopModule:addBuyableItemContainer({'bp slhp'}, 	2000, 8704, 400,  1, 'backpack of small health potions')
shopModule:addBuyableItemContainer({'bp hp'}, 		2000, 7618, 900,  1, 'backpack of health potions')
shopModule:addBuyableItemContainer({'bp shp'}, 		2000, 7588, 2000, 1, 'backpack of strong health potions')
shopModule:addBuyableItemContainer({'bp ghp'}, 		2000, 7591, 3800, 1, 'backpack of great health potions')
shopModule:addBuyableItemContainer({'bp uhp'}, 		2000, 8473, 6200, 1, 'backpack of ultimate health potions')
shopModule:addBuyableItemContainer({'bp mp'}, 		2001, 7620, 1000, 1, 'backpack of mana potions')
shopModule:addBuyableItemContainer({'bp smp'}, 		2001, 7589, 1600, 1, 'backpack of strong mana potions')
shopModule:addBuyableItemContainer({'bp gmp'}, 		2001, 7590, 2400, 1, 'backpack of great mana potions')
shopModule:addBuyableItemContainer({'bp gsp'}, 		1999, 8472, 3800, 1, 'backpack of great spirit potions')
shopModule:addBuyableItemContainer({'bp ap'}, 		2002, 8474, 2000, 1, 'backpack of antidote potions')

shopModule:addBuyableItem({'wand of vortex', 'vortex'},			 2190, 500, 'wand of vortex')
shopModule:addBuyableItem({'wand of dragonbreath', 'dragonbreath'},	 2191, 1000, 'wand of dragonbreath')
shopModule:addBuyableItem({'wand of decay', 'decay'},			 2188, 5000, 'wand of decay')
shopModule:addBuyableItem({'wand of draconia', 'draconia'},		 8921, 7500, 'wand of draconia')
shopModule:addBuyableItem({'wand of cosmic energy', 'cosmic energy'},	 2189, 10000, 'wand of cosmic energy')
shopModule:addBuyableItem({'wand of inferno', 'inferno'},		 2187, 15000, 'wand of inferno')
shopModule:addBuyableItem({'wand of starstorm', 'starstorm'},		 8920, 18000, 'wand of starstorm')
shopModule:addBuyableItem({'wand of voodoo', 'voodoo'},			 8922, 22000, 'wand of voodoo')

shopModule:addBuyableItem({'snakebite rod', 'snakebite'},		 2182, 500, 'snakebite rod')
shopModule:addBuyableItem({'moonlight rod', 'moonlight'},		 2186, 1000, 'moonlight rod')
shopModule:addBuyableItem({'necrotic rod', 'necrotic'},			 2185, 5000, 'necrotic rod')
shopModule:addBuyableItem({'northwind rod', 'northwind'},		 8911, 7500, 'northwind rod')
shopModule:addBuyableItem({'terra rod', 'terra'},			 2181, 10000, 'terra rod')
shopModule:addBuyableItem({'hailstorm rod', 'hailstorm'},		 2183, 15000, 'hailstorm rod')
shopModule:addBuyableItem({'springsprout rod', 'springsprout'},		 912, 18000, 'springsprout rod')
shopModule:addBuyableItem({'underworld rod', 'underworld'},		 8910, 22000, 'underworld rod')

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

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	local items = {[1] = 2190, [2] = 2182, [5] = 2190, [6] = 2182}

	if(msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand')) then
		if(isSorcerer(cid) or isDruid(cid)) then
			if(getPlayerStorageValue(cid, 30002) == -1) then
				selfSay('So you ask me for a {' .. getItemName(items[getPlayerVocation(cid)]) .. '} to begin your advanture?', cid)
				talkState[talkUser] = 1
			else
				selfSay('What? I have already gave you one {' .. getItemName(items[getPlayerVocation(cid)]) .. '}!', cid)
			end
		else
			selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
		end
	elseif(msgcontains(msg, 'yes')) then
		if(talkState[talkUser] == 1) then
			doPlayerAddItem(cid, items[getPlayerVocation(cid)], 1)
			selfSay('Here you are young adept, take care yourself.', cid)
			setPlayerStorageValue(cid, 30002, 1)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		selfSay('Ok then.', cid)
		talkState[talkUser] = 0
	end

	return true
end

its like the line of code that you pass to me, but it keep not working!
When i set in the CLIENT the trade function "BUY WITH BACKPACKS"
the NPC keep selling me just an ITEM inside a backpack, and the cost its just for ONE item.

Can you still help me =D
Thank you in add!
 
rune.jpg


I just added your {'bp uh'} line and it worked very well.

In data/npc/lib/npc.lua make sure this phrase is in it:

LUA:
	local a = 0
	if(inBackpacks) then
		local container = doCreateItemEx(backpack, 1)
		local b = 1
		for i = 1, amount do
			item = doAddContainerItem(container, itemid, subType)
			if(itemid == ITEM_PARCEL) then
				doAddContainerItem(item, ITEM_LABEL)
			end

			if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
				if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
					b = b - 1
					break
				end

				a = i
				if(amount > i) then
					container = doCreateItemEx(backpack, 1)
					b = b + 1
				end
			end
		end

		return a, b
	end
 
holy sh1t, i think its the same
look at mine NPC.lib

Code:
-- Include the Advanced NPC System
dofile(getDataDir() .. 'npc/lib/npcsystem/npcsystem.lua')

function selfIdle()
	following = false
	attacking = false

	selfAttackCreature(0)
	target = 0
end

function selfSayChannel(cid, message)
	return selfSay(message, cid, false)
end

function selfMoveToCreature(id)
	if(not id or id == 0) then
		return
	end

	local t = getCreaturePosition(id)
	if(not t.x or t.x == nil) then
		return
	end

	selfMoveTo(t.x, t.y, t.z)
	return
end

function getNpcDistanceToCreature(id)
	if(not id or id == 0) then
		selfIdle()
		return nil
	end

	local c = getCreaturePosition(id)
	if(not c.x or c.x == 0) then
		return nil
	end

	local s = getCreaturePosition(getNpcId())
	if(not s.x or s.x == 0 or s.z ~= c.z) then
		return nil
	end

	return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
end

function doMessageCheck(message, keyword)
	if(type(keyword) == "table") then
		return table.isStrIn(keyword, message)
	end

	local a, b = message:lower():find(keyword:lower())
	if(a ~= nil and b ~= nil) then
		return true
	end

	return false
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
	local amount = amount or 1
	local subType = subType or 1
	local ignoreCap = ignoreCap and true or false

	local item = 0
	if(isItemStackable(itemid)) then
		item = doCreateItemEx(itemid, amount)
		if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
			return 0, 0
		end

		return amount, 0
	end

	local a = 0
	if(inBackpacks) then
		local container = doCreateItemEx(backpack, 1)
		local b = 1
		for i = 1, amount do
			item = doAddContainerItem(container, itemid, subType)
			if(itemid == ITEM_PARCEL) then
				doAddContainerItem(item, ITEM_LABEL)
			end

			if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
				if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
					b = b - 1
					break
				end

				a = i
				if(amount > i) then
					container = doCreateItemEx(backpack, 1)
					b = b + 1
				end
			end
		end

		return a, b
	end

	for i = 1, amount do
		item = doCreateItemEx(itemid, subType)
		if(itemid == ITEM_PARCEL) then
			doAddContainerItem(item, ITEM_LABEL)
		end

		if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
			break
		end

		a = i
	end

	return a, 0
end

function doRemoveItemIdFromPos (id, n, position)
	local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
	if(thing.itemid == id) then
		doRemoveItem(thing.uid, n)
		return true
	end

	return false
end

function getNpcName()
	return getCreatureName(getNpcId())
end

function getNpcPos()
	return getCreaturePosition(getNpcId())
end

function selfGetPosition()
	local t = getNpcPos()
	return t.x, t.y, t.z
end

msgcontains = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToCreature
selfMoveToPosition = selfMoveTo
selfGotoIdle = selfIdle
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPos
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceToCreature


What you whink about i grance all LIB folder from the NPCS?
to a new one?
Im using the 0.3.5, but i can try change it to the 0.3.6 LIB, try make a try.

or have you another adivice before?
 
Before we do that:

Your NPC (in data/npc) NAME.xml open it up and check if he's really
executing the right script:

e.g.
LUA:
<npc name="Eryn" nameDescription="Eryn, the rune vendor" script="runes.lua" walkinterval="2000" floorchange="0" skull="green">

check the line script="runes.lua"

now insert this line in your NPC:

LUA:
<npc name="Rachel" script="global_magic_shop.lua" walkinterval="2000" floorchange="0">

and put your script into the data/npc/scripts folder
 
I just remember one thing, before o do this,
Is that Im loading alll mines NPC of the MODS directory:
MODS/NPC/SCRIPT

Maybe this causing some problem?

and i will take a look at the NPC file, but im thinging that is all OK, I back in a sec to reawnser!

thank for your help mate.
 
Before we do that:

Your NPC (in data/npc) NAME.xml open it up and check if he's really
executing the right script:

e.g.
LUA:
<npc name="Eryn" nameDescription="Eryn, the rune vendor" script="runes.lua" walkinterval="2000" floorchange="0" skull="green">

check the line script="runes.lua"

now insert this line in your NPC:

LUA:
<npc name="Rachel" script="global_magic_shop.lua" walkinterval="2000" floorchange="0">

and put your script into the data/npc/scripts folder

omg, i tried to change the script directory from mods/npc/script to data/npc/script, but it keep doesnt working, i tried to add the LIB dir, into mods/npc directory, but keep doesnt working.
I tryed to change the whole lib data, from the 0.3.6 repository, but it doest work.
it keep selling me just a Backpack with a single item inside, and say "14:56 Bought 1x ultimate healing rune for 195 gold."

='(
 
Dont you need som thing like custommonsters.xml in the mod folder.
Like customnpc.xml and whit this code.

PHP:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Custom NPC" version="1.0" author="The Forgotten Server" contact="otland.net" enabled="yes">
	<!-- Shop NPC -->
	<npc name="NPC_NAME" file="Custom/NPC_FILE.xml"/>
</mod>

I just edited custommonsters.xml
Dont know if this works.
 
Dont you need som thing like custommonsters.xml in the mod folder.
Like customnpc.xml and whit this code.

PHP:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Custom NPC" version="1.0" author="The Forgotten Server" contact="otland.net" enabled="yes">
	<!-- Shop NPC -->
	<npc name="NPC_NAME" file="Custom/NPC_FILE.xml"/>
</mod>

I just edited custommonsters.xml
Dont know if this works.

this is not exactly what im looking for, but will be very usevul to me organize the NPCs in the folder. thank you mate.

But mine problem is this follow "When im tring to use the "BUY WITH BACKPACKS" feature, in the CLIENT, the noob NPC sell me a BACKPACK with a SINGLE rune, and says that he solds just a RUNE, not a BACKPACK of runes"

did you get it?

but thank you for the advice! realy!!
 
Why do you use a mod npc?

I thought you use the normal ones.

Put the npc Rachel.xml into the standard data/npc directory and the
.lua script into the data/npc/scripts directory.

Or do you have any special reason to use the mod npc?
I don't know just asking.
 
Im puting all mine custom files in the MODS folder, just to organize! to keep easy to UPDATE when i need to.

Not for a especial reason
=D
I got all mine quests, and NPCs in the MODS folder, like some itens too.

Im thinking that maybe is this the problem to this funciton doenst work properly.
=/
have you another adivece mate?

thank you for the help!
 
Well, copy ALL NPCs.
Clear the old data/npc (all the .xml files)
Add only your NPCs which you are actually using.

All scripts can stay in the data/npc/scripts folder.

Easy overview, all scripts should work properly and easy updating.

But again, I'm not sure if that's the problem.
Could be a wrong line also in an .xml file in your mod folder...

Check the other .xml NPCs in your MOD folder.

EDIT: Did you copy the data/npc/lib into your mod/npc directory?
 
I tried to make a copy of the DATA/NPC/LIB, and paste it in MODS/NPC/LIB, but it keep doest work.

did you say to me empty the data/npc/lib and put ALL files in the folder?
or empty the MODS/NPC and put ALL files in the data/npc/lib folder?
 
Back
Top