• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Script - tool that gives npc selling/buying list in desired format!

Yassate

New Member
Joined
Mar 26, 2011
Messages
13
Reaction score
0
I wanted to make my npcs to have list of sellable/buyable items like in real tibia. First I downloaded a few packs but these NPC didn't have full lists (or I downloaded wrong packs) : D
As you know, in xml file of npc that list have to be in "itemname,itemid,price;itemname,itemid,price" format
I'm not a expert in lua but I came up with an idea to make a script to do this for me.

Scripts:

Add this:
XML:
<talkaction log="yes" words="/buysell" access="3" event="script" value="buysell.lua"/>
to talkactions.xml


Create file called "buysell.lua" in talkactions/scripts and paste this:

LUA:
function onSay(cid, words, param, channel)
	if(param ~= '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "No command param required.")
		return true
	end

			tabelka1 ={
"Axe",20,
"Battle Axe",235,
"Battle Hammer",350,
"Wrong Item",51,
}	
			tabelka2 ={
"Axe",20,
"Battle Axe",235,
"Battle Hammer",350,
"Wrong Item",51,
}

tabelka3={}
tabelka4={}

		for i=1,(#tabelka1/2) do
			if not(getItemIdByName(tabelka1[2*i-1])) then
				table.insert(tabelka3,tabelka1[2*i-1])
				table.insert(tabelka4,i)
			end
		end
		
		for i=1,#tabelka3 do
			if i==1 then
				table.remove(tabelka2,(tabelka4[i])*2-1)
				table.remove(tabelka2,(tabelka4[i])*2-1)
				table.remove(tabelka1,(tabelka4[i])*2-1)
				table.remove(tabelka1,(tabelka4[i])*2-1)
			else
				table.remove(tabelka2,(tabelka4[i])*2-2*i+1)
				table.remove(tabelka2,(tabelka4[i])*2-2*i+1)
				table.remove(tabelka1,(tabelka4[i])*2-2*i+1)
				table.remove(tabelka1,(tabelka4[i])*2-2*i+1)
			end
		end
			
		for i=1,((#tabelka1)/2) do
			if not(getItemIdByName(tabelka1[2*i-1])) then
			else
			smth = getItemIdByName(tabelka1[2*i-1])
			table.insert(tabelka2,3*i-1,smth)
			end
		end
		
		msg=""
		a=4
		for i=1,#tabelka2 do
			if msg~="" then
				if i==a	then
					msg="" .. msg .. ";" .. tabelka2[i] .. ""
					a=i+3
				else
					msg="" .. msg .. "," .. tabelka2[i] .. ""
				end
			else
			msg="" .. tabelka2[i] .. ""
			end
		end
		msg="" .. msg .. " ; Can\'t find items: "
		if tabelka3~=nil then

			for i=1,#tabelka3 do
				msg="" .. msg .. "" .. tabelka3[i] .. ","
			end
		end
print(msg)
	return true
end

In that "tabelka1" and "tabelka2" you have to paste your items in table(read down). Tabelka1 and tabelka2 have to be the same.

Now when you use command "/buysell" console/gui will give you smth like this:

Code:
"Axe,2386,20;Battle Axe,2378,235;Battle Hammer,2417,350 ; Can't find items: Wrong Item,"

Now you can just simply copy it and paste in your npc.xml file =)

To fast create table with items and prices you can copy them from tibia.wikia.com and use macros in notepad++ or word or smth ; d
If you did it right It shouldn't take more than 30 sec to create table : )



I don't know that smth like that was posted somewhere on OTLand, and I don' know that there is program to do that without running your OT. If there is something similar and easier just don't use it : P

I think that script can be much shorter and simpler but I can't do this ;d
Tested on TFS 0.3.6
 
Any error in console or something? Or it works in bad way?
In talkactions.xml you have to add only one line, script should be in new file called "buysell.lua" =P
 
You type command /buysell and there is no message in console yepp? If you did everything in right way I don't know why it doesn't work, sorry : P
 
Well i dont undastand this part

Now when you use command "/buysell" console/gui will give you smth like this:

Code:
"Axe,2386,20;Battle Axe,2378,235;Battle Hammer,2417,350 ; Can't find items: Wrong Item

and yea i got error in talk~
 
You should paste your itemlist in that script in tabelka1 and tabelka2. When you have it, you have to run OT and type on your god character "/buysell" and then in your console should be text in format: itemname,itemid,price;item2name,item2id,price2; etc
Then just copy ( without " Cant find item:~ " ) and paste it to your npc.xml file in line about buyable or sellable.
" Cant find item " tells you which items you have to find manually because script cant find itemid with given name ; p
I cant explain it better ; P

Im writing from phone so I cant give ya examples, if you will still have problem tommorow just send me pm.
 
Back
Top