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:
to talkactions.xml
Create file called "buysell.lua" in talkactions/scripts and paste this:
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:
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
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"/>
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