Jump to content

Proto Converter | XML 2 SQL | SQL 2 TXT


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

Hi.
I wanna to show you how can you convert item_proto to sql and later to txt files.
XML -> SQL
First we need this program:

This is the hidden content, please

scan:

This is the hidden content, please

Ther is something, but i haven't better program so you download it for your own responsibility

With it, we can convert our xml proto to sql
But first, from our xml file, we need to delete all <!--AddonType="0"--> and <!--AddonType="99"--> easy with notepad++ and ctrl+h :)

and now we run our program and select file to convert.

After moment we'll have a sql file, but if we have a locale_name column in item_proto we need to change also with ctr+h all gb2312name to locale_name, and now we can upload file with "execute sql file" or simpy with query to our database
 
SQL -> TXT
To convert item_proto sql to txt files, you need this script in python

http://pastebin.com/K5EDE4b6

Configuration:

You need MySQLdb on your freebsd

If you haven't it, just install it - it's a mysql library to python

cd /usr/ports/databases/py-MySQLdb/ && make install clean

You need also change the connection properties in script

default it's:

host_mysql = 'localhost'
user_mysql = 'mt2'
passwd_mysql = 'mt2!@#'

And if you want convert also mob_proto in this way, you need onlu change from

#print mob_proto()

to

print mob_proto()

in the end of file.

 

Now script should generate our protos in his directory .

 

These programs are not mine. The python script i found somewhere and just modified it to 40k version

I think that it's all, if you have any better program or any better way or idea you can show it :D

Maybe in the future I will write to that one big script, but now I have no time for this ;/

If there are any problems, I'll try to help :)

 

#Updated python script

 

Regards

Deucalion

  • Metin2 Dev 179
  • Eyes 5
  • Dislove 8
  • Not Good 1
  • Sad 2
  • Think 2
  • Confused 1
  • Scream 2
  • Lmao 1
  • Good 66
  • muscle 2
  • Love 13
  • Love 133
Link to comment
https://metin2.dev/topic/996-proto-converter-xml-2-sql-sql-2-txt/
Share on other sites

  • 4 weeks later...
  • 1 month later...

getting this:

convert_itemm.py:583: SyntaxWarning: name 'errors' is assigned to before global declaration
  global errors
convert_itemm.py:592: SyntaxWarning: name 'errors' is assigned to before global declaration
  global errors
Connecting to database proto...
Connected.
Converting item_proto...
Traceback (most recent call last):
  File "convert_itemm.py", line 867, in <module>
    print item_proto()
  File "convert_itemm.py", line 857, in item_proto
    item_proto_line = "%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%s" % (row[0], """ + row[1] + """, """  + get_item_type(row[3], row[0]) + """ , """  + get_item_subtype(row[3], row[4], row[0]) + """, row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
IndexError: tuple index out of range

and not work for me

hey Deucalion, im at the first step right now and well, i have to say that this converts my xml ind an succesfully query, but sometimes he miss lines, and sometimes lines are double, im i doing soemthing wrong?

i just renamed gb123name or w/e into "local_name" like my itemproto table is, and well, just removed that addontype=0 and 99. nothing else :/

an expample could be this:


<Item vnum="1"  name="돈꾸러미" locale_name="Yang" type="9" subtype="0" weight="0" size="1" antiflag="0" flag="0" wearflag="0" immuneflag="0" gold="0" buy_price="0" limittype0="0" limitvalue0="0" limittype1="0" limitvalue1="0" applytype0="0" applyvalue0="0" applytype1="0" applyvalue1="0" applytype2="0" applyvalue2="0" value0="0" value1="0" value2="0" value3="0" value4="0" value5="0" socket0="0" socket1="0" socket2="0" socket3="0" socket4="0" socket5="0" refine_vnum="0" refine_set="0" magic_pct="0" specular="0" socket_pct="0" />
 
<Item vnum="2"  name="한국무쌍버젼" locale_name="Versi? Espa?la" type="0" subtype="0" weight="0" size="1" antiflag="0" flag="0" wearflag="0" immuneflag="0" gold="0" buy_price="0" limittype0="0" limitvalue0="0" limittype1="0" limitvalue1="0" applytype0="0" applyvalue0="0" applytype1="0" applyvalue1="0" applytype2="0" applyvalue2="0" value0="0" value1="0" value2="0" value3="0" value4="0" value5="0" socket0="0" socket1="0" socket2="0" socket3="0" socket4="0" socket5="0" refine_vnum="0" refine_set="0" magic_pct="0" specular="0" socket_pct="0" />
 
<Item vnum="10"  name="도+0" locale_name="Espada +0" type="1" subtype="0" weight="0" size="2" antiflag="32" flag="1" wearflag="16" immuneflag="0" gold="0" buy_price="0" limittype0="1" limitvalue0="0" limittype1="0" limitvalue1="0" applytype0="7" applyvalue0="22" applytype1="0" applyvalue1="0" applytype2="0" applyvalue2="0" value0="0" value1="15" value2="19" value3="13" value4="15" value5="0" socket0="0" socket1="0" socket2="0" socket3="0" socket4="0" socket5="0" refine_vnum="11" refine_set="1" magic_pct="15" specular="0" socket_pct="1" />
 
<Item vnum="11"  name="도+1" locale_name="Espada +1" type="1" subtype="0" weight="0" size="2" antiflag="32" flag="1" wearflag="16" immuneflag="0" gold="100" buy_price="100" limittype0="1" limitvalue0="0" limittype1="0" limitvalue1="0" applytype0="7" applyvalue0="22" applytype1="0" applyvalue1="0" applytype2="0" applyvalue2="0" value0="0" value1="15" value2="19" value3="13" value4="15" value5="7" socket0="0" socket1="0" socket2="0" socket3="0" socket4="0" socket5="0" refine_vnum="12" refine_set="2" magic_pct="15" specular="0" socket_pct="1" />
 
<Item vnum="12"  name="도+2" locale_name="Espada +2" type="1" subtype="0" weight="0" size="2" antiflag="32" flag="1" wearflag="16" immuneflag="0" gold="100" buy_price="100" limittype0="1" limitvalue0="0" limittype1="0" limitvalue1="0" applytype0="7" applyvalue0="22" applytype1="0" applyvalue1="0" applytype2="0" applyvalue2="0" value0="0" value1="15" value2="19" value3="13" value4="15" value5="14" socket0="0" socket1="0" socket2="0" socket3="0" socket4="0" socket5="0" refine_vnum="13" refine_set="3" magic_pct="15" specular="0" socket_pct="1" />
 
<Item vnum="13"  name="도+3" locale_name="Espada +3" type="1" subtype="0" weight="0" size="2" antiflag="32" flag="1" wearflag="16" immuneflag="0" gold="100" buy_price="150" limittype0="1" limitvalue0="0" limittype1="0" limitvalue1="0" applytype0="7" applyvalue0="22" applytype1="0" applyvalue1="0" applytype2="0" applyvalue2="0" value0="0" value1="15" value2="19" value3="13" value4="15" value5="21" socket0="0" socket1="0" socket2="0" socket3="0" socket4="0" socket5="0" refine_vnum="14" refine_set="4" magic_pct="15" specular="0" socket_pct="1" />
 

 

 

 

and converted;


INSERT INTO `item_proto` VALUES ('2', 'Versi? Espa?la', 'Versi? Espa?la', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
 
INSERT INTO `item_proto` VALUES ('10', 'Espada +0', 'Espada +0', '1', '0', '0', '2', '32', '1', '16', '0', '0', '0', '11', '1', '0', '15', '1', '0', '0', '0', '7', '22', '0', '0', '0', '0', '0', '15', '19', '13', '15', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0');
 
INSERT INTO `item_proto` VALUES ('10', 'Espada +0', 'Espada +0', '1', '0', '0', '2', '32', '1', '16', '0', '0', '0', '11', '1', '0', '15', '1', '0', '0', '0', '7', '22', '0', '0', '0', '0', '0', '15', '19', '13', '15', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0');
 
INSERT INTO `item_proto` VALUES ('12', 'Espada +2', 'Espada +2', '1', '0', '0', '2', '32', '1', '16', '0', '100', '100', '13', '3', '0', '15', '1', '0', '0', '0', '7', '22', '0', '0', '0', '0', '0', '15', '19', '13', '15', '14', '0', '0', '0', '0', '0', '0', '1', '0', '0');
 
INSERT INTO `item_proto` VALUES ('12', 'Espada +2', 'Espada +2', '1', '0', '0', '2', '32', '1', '16', '0', '100', '100', '13', '3', '0', '15', '1', '0', '0', '0', '7', '22', '0', '0', '0', '0', '0', '15', '19', '13', '15', '14', '0', '0', '0', '0', '0', '0', '1', '0', '0');
 
INSERT INTO `item_proto` VALUES ('13', 'Espada +3', 'Espada +3', '1', '0', '0', '2', '32', '1', '16', '0', '100', '150', '14', '4', '0', '15', '1', '0', '0', '0', '7', '22', '0', '0', '0', '0', '0', '15', '19', '13', '15', '21', '0', '0', '0', '0', '0', '0', '1', '0', '0');





some lines missing, and other doubles as i said :/


thanks fro reading and for your work ^^

    item_proto_line = "%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%s" % (row[0], """ + row[1] + """, """  + get_item_type(row[3], row[0]) + """ , """  + get_item_subtype(row[3], row[4], row[0]) + """, row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
TypeError: cannot concatenate 'str' and 'NoneType' objects
 
 
WTF?
  • 2 months later...

getting this:

convert_itemm.py:583: SyntaxWarning: name 'errors' is assigned to before global declaration
  global errors
convert_itemm.py:592: SyntaxWarning: name 'errors' is assigned to before global declaration
  global errors
Connecting to database proto...
Connected.
Converting item_proto...
Traceback (most recent call last):
  File "convert_itemm.py", line 867, in <module>
    print item_proto()
  File "convert_itemm.py", line 857, in item_proto
    item_proto_line = "%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%s" % (row[0], """ + row[1] + """, """  + get_item_type(row[3], row[0]) + """ , """  + get_item_subtype(row[3], row[4], row[0]) + """, row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
IndexError: tuple index out of range

and not work for me

 

 

 

    item_proto_line = "%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%st%s" % (row[0], """ + row[1] + """, """  + get_item_type(row[3], row[0]) + """ , """  + get_item_subtype(row[3], row[4], row[0]) + """, row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
TypeError: cannot concatenate 'str' and 'NoneType' objects
 
 
WTF?

 

 

Take a look here

  • 3 months later...
  • 3 weeks later...
  • 1 year later...

Excellent guide it works good ... 
but i have problem with converting item proto using convertproto.py 
if any1 can correct it will be good 
 

Error while converting

  Hide contents

  File "convert_proto.py", line 857, in item_proto
    item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[1] + "\"", "\""  + get_item_type(row[3], row[0]) + "\"" , "\""  + get_item_subtype(row[3], row[4], row[0]) + "\"", row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
TypeError: cannot concatenate 'str' and 'long' objects
 


I tell you why it is happening normal convert proto the vnum_range will be last so it wont make problem but here we added vnum_range next to vnum that is row 2... so its making problem So any one who correct this will be helpful i tried but it says 

" TypeError: not enough arguments for format string " 

Here is my Convert proto.py 

Error section 
 

  Hide contents

    out_file_itemproto = open("item_proto.txt", "w")
    out_file_itemnames = open("item_names.txt", "w")
    print "Converting item_proto..."
    for row in rows:
        item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[1] + "\"", "\""  + get_item_type(row[3], row[0]) + "\"" , "\""  + get_item_subtype(row[3], row[4], row[0]) + "\"", row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
        item_names_line = "%s\t%s" % (row[0], row[2])
        out_file_itemproto.write(item_proto_line + "\r\n")
        out_file_itemnames.write(item_names_line + "\r\n")
    out_file_itemproto.close()


Thanks in Advance 

  • Good 1
  • 9 years later...
On 3/26/2016 at 4:34 PM, Human said:

Excellent guide it works good ... 
but i have problem with converting item proto using convertproto.py 
if any1 can correct it will be good 
 

Error while converting

  Hide contents

  File "convert_proto.py", line 857, in item_proto
    item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[1] + "\"", "\""  + get_item_type(row[3], row[0]) + "\"" , "\""  + get_item_subtype(row[3], row[4], row[0]) + "\"", row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
TypeError: cannot concatenate 'str' and 'long' objects
 


I tell you why it is happening normal convert proto the vnum_range will be last so it wont make problem but here we added vnum_range next to vnum that is row 2... so its making problem So any one who correct this will be helpful i tried but it says 

" TypeError: not enough arguments for format string " 

Here is my Convert proto.py 

Error section 
 

  Hide contents

    out_file_itemproto = open("item_proto.txt", "w")
    out_file_itemnames = open("item_names.txt", "w")
    print "Converting item_proto..."
    for row in rows:
        item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[1] + "\"", "\""  + get_item_type(row[3], row[0]) + "\"" , "\""  + get_item_subtype(row[3], row[4], row[0]) + "\"", row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])
        item_names_line = "%s\t%s" % (row[0], row[2])
        out_file_itemproto.write(item_proto_line + "\r\n")
        out_file_itemnames.write(item_names_line + "\r\n")
    out_file_itemproto.close()


Thanks in Advance 


The root of your problem is newer Python2.7 versions doesn't support some operators which in older versions where accepted.
I faced the same problem as you, if you want to use this cool script in 2025, I use FreeBSD 13.4 release.
You need to downgrade your Python first. Secondly py-MySQLdb isn't at your ports collection anymore.
So if you installed your server for example from TMP4 guide 

 You was forced to install packages with pkg add (pkg add -f to be exact because force install is needed!) command because for example MySQL 5.6 server cannot be found at FreeBSD 13.4's ports collection.
TMP4's package backup 64 folder contains Python2.7:
python27-2.7.18_2 version
You need an older one because scripts like this:

	def get_flag(flag):
		if flag == "":
			return flag
		else:
			return "\"" + flag + "\""

Causing:

TypeError: cannot concatenate 'str' and 'set' objects

Errors when you run this cool serverside DB to TXT script.
Uninstalling python27-2.7.18_2, installing python27-2.7.11_1 garbaged from FreeBSD 10.3 solved my problem.
I share with you my package backup files which you can install in your newer FreeBSD system:

This is the hidden content, please

The tar file readme instructions file is wrong (/usr/pkg_backup_amd64/ is missing from the pkg add -f commands), please follow these:

Older Python2.7 amd py-MySQLdb extension for higher version FreeBSD's.

-Copy this folder (pkg_backup_amd64) to your /usr folder.
-Uninstall your newer Python2.7 software if needed: pkg remove python27
-Force install these with this commands to your FreeBSD's console:
pkg add -f /usr/pkg_backup_amd64/python27-2.7.11_1.txz
pkg add -f /usr/pkg_backup_amd64/py27-setuptools27-19.2.txz
pkg add -f /usr/pkg_backup_amd64/python2-2_3.txz
pkg add -f /usr/pkg_backup_amd64/py27-MySQLdb-1.2.5.txz

Now if you run: python2.7 convert_test.py hopefully it will run smoothly without errors!


Enjoy your working DB -> TXT converter!

Oh, and a small script for the converter, you noticed that fact of Wild dog and Yang text is missing from your client?
That's because it's the first row in your protos, open your db->txt.py find this:

print "Converting mob_proto..."

Add under:

	mob_proto_line1 = "VNUM	NAME	RANK	TYPE	BATTLE_TYPE	LEVEL	SIZE	AI_FLAG	MOUNT_CAPACITY	SETRACEFLAG	SETIMMUNEFLAG	EMPIRE	FOLDER	ON_CLICK	ST	DX	HT	IQ	DAMAGE_MIN	DAMAGE_MAX	MAX_HP	REGEN_CYCLE	REGEN_PERCENT	GOLD_MIN	GOLD_MAX	EXP	DEF	ATTACK_SPEED	MOVE_SPEED	AGGRESSIVE_HP_PCT	AGGRESSIVE_SIGHT	ATTACK_RANGE	DROP_ITEM	RESURRECTION_VNUM	ENCHANT_CURSE	ENCHANT_SLOW	ENCHANT_POISON	ENCHANT_STUN	ENCHANT_CRITICAL	ENCHANT_PENETRATE	RESIST_SWORD	RESIST_TWOHAND	RESIST_DAGGER	RESIST_BELL	RESIST_FAN	RESIST_BOW	RESIST_FIRE	RESIST_ELECT	RESIST_MAGIC	RESIST_WIND	RESIST_POISON	DAM_MULTIPLY	SUMMON	DRAIN_SP	MOB_COLOR	POLYMORPH_ITEM	SKILL_LEVEL0	SKILL_VNUM0	SKILL_LEVEL1	SKILL_VNUM1	SKILL_LEVEL2	SKILL_VNUM2	SKILL_LEVEL3	SKILL_VNUM3	SKILL_LEVEL4	SKILL_VNUM4	SP_BERSERK	SP_STONESKIN	SP_GODSPEED	SP_DEATHBLOW	SP_REVIVE"
	out_file_mobproto.write(mob_proto_line1 + "\r\n")
	mob_names_line1 = "VNUM	LOCALE_NAME"
	out_file_mobnames.write(mob_names_line1 + "\r\n")

Find this:

print "Converting item_proto..."

Add under:

	item_proto_line1 = "VNUM	NAME	TYPE	SUBTYPE	SIZE	ANTIFLAG	FLAG	WEARFLAG	IMMUNEFLAG	GOLD	SHOP_BUY_PRICE	REFINED_VNUM	REFINE_SET	MAGIC_PCT	LIMITTYPE0	LIMITVALUE0	LIMITTYPE1	LIMITVALUE1	APPLYTYPE0	APPLYVALUE0	APPLYTYPE1	APPLYVALUE1	APPLYTYPE2	APPLYVALUE2	VALUE0	VALUE1	VALUE2	VALUE3	VALUE4	VALUE5	SPECULAR	SOCKET_PCT	ADDON_TYPE"
	out_file_itemproto.write(item_proto_line1 + "\r\n")
	item_names_line1 = "VNUM	LOCALE_NAME"
	out_file_itemnames.write(item_names_line1 + "\r\n")

So the first line skip problem will be fixed with this modification.
Also, there is a # mark at the end of the file which could prevent your mob_proto.txt files to be compiled.

Here is my full converter py file:
 

#!/usr/bin/env python
#-*- coding" utf-8 -*-
#Modified by Deucalion
import MySQLdb
host_mysql = 'localhost'
user_mysql = 'root'
passwd_mysql = ''
def mob_proto():
	rank = {
		1: "S_PAWN",
		2: "KNIGHT",
		3: "S_KNIGHT",
		4: "BOSS",
		5: "KING",
	}
	
	typeee = {
		1: "NPC",
		2: "STONE",
		3: "WARP",
		4: "DOOR",
		5: "BUILDING",
		7: "POLYMORPH_PC",
		8: "HORSE",
		9: "GOTO",
	}
	
	battletype = {
		2: "RANGE",
		3: "MAGIC",
		4: "SPECIAL",
		5: "POWER",
		6: "TANKER",
	}
	
	def get_rank(level):
		if level in rank:
			return "\"" + rank[level] + "\""
		else:
			return "\"PAWN\""
	
	def get_type(typee):
		if typee in typeee:
			return "\"" + typeee[typee] + "\""
		else:
			return "\"MONSTER\""
			
	def get_battletype(battle):
		if battle in battletype:
			return "\"" + battletype[battle] + "\""
		else:
			return "\"MELEE\""
			
	def get_flag(flag):
		if flag == "":
			return flag
		else:
			return "\"" + flag + "\""
			
	def get_race(race):
		if race == "":
			return race
		else:
			return "\"" + race + "\""
			
	def get_immune(immune):
		if immune == "":
			return immune
		else:
			return "\"" + immune + "\""
			
	def get_folder(folder):
		if folder == "":
			return "\"wolf\""
		else:
			return "\"" + folder + "\""
	
	print "Connecting to database proto..."
	data = "player"
	db = MySQLdb.connect(host_mysql,user_mysql,passwd_mysql,data)
	cur = db.cursor()
	print "Connected."
	cur.execute("select * from mob_proto")
	rows = cur.fetchall()
	out_file_mobproto = open("mob_proto.txt", "w")
	out_file_mobnames = open("mob_names.txt", "w")
	print "Converting mob_proto..."
	mob_proto_line1 = "VNUM	NAME	RANK	TYPE	BATTLE_TYPE	LEVEL	SIZE	AI_FLAG	MOUNT_CAPACITY	SETRACEFLAG	SETIMMUNEFLAG	EMPIRE	FOLDER	ON_CLICK	ST	DX	HT	IQ	DAMAGE_MIN	DAMAGE_MAX	MAX_HP	REGEN_CYCLE	REGEN_PERCENT	GOLD_MIN	GOLD_MAX	EXP	DEF	ATTACK_SPEED	MOVE_SPEED	AGGRESSIVE_HP_PCT	AGGRESSIVE_SIGHT	ATTACK_RANGE	DROP_ITEM	RESURRECTION_VNUM	ENCHANT_CURSE	ENCHANT_SLOW	ENCHANT_POISON	ENCHANT_STUN	ENCHANT_CRITICAL	ENCHANT_PENETRATE	RESIST_SWORD	RESIST_TWOHAND	RESIST_DAGGER	RESIST_BELL	RESIST_FAN	RESIST_BOW	RESIST_FIRE	RESIST_ELECT	RESIST_MAGIC	RESIST_WIND	RESIST_POISON	DAM_MULTIPLY	SUMMON	DRAIN_SP	MOB_COLOR	POLYMORPH_ITEM	SKILL_LEVEL0	SKILL_VNUM0	SKILL_LEVEL1	SKILL_VNUM1	SKILL_LEVEL2	SKILL_VNUM2	SKILL_LEVEL3	SKILL_VNUM3	SKILL_LEVEL4	SKILL_VNUM4	SP_BERSERK	SP_STONESKIN	SP_GODSPEED	SP_DEATHBLOW	SP_REVIVE"
	out_file_mobproto.write(mob_proto_line1 + "\r\n")
	mob_names_line1 = "VNUM	LOCALE_NAME"
	out_file_mobnames.write(mob_names_line1 + "\r\n")
	for row in rows:
		mob_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[1] + "\"", get_rank(row[3]), get_type(row[4]), get_battletype(row[5]), row[6], row[7], get_flag(row[8]), row[9], get_race(row[10]), get_immune(row[11]), row[12], get_folder(row[13]), row[14], row[15], row[16], row[17], row[18], row[19], row[20], row[21], row[22], row[23], row[24], row[25], row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[33], row[34], row[35], row[36], row[37], row[38], row[39], row[40], row[41], row[42], row[43], row[44], row[45], row[46], row[47], row[48], row[49], row[50], row[51], row[52], row[53], row[54], row[55], row[56], row[57], row[58], row[59], row[60], row[61], row[62], row[63], row[64], row[65], row[66], row[67], row[68], row[69], row[70], row[71])
		mob_names_line = "%s\t%s" % (row[0], row[2])
		out_file_mobproto.write(mob_proto_line + "\r\n")
		out_file_mobnames.write(mob_names_line + "\r\n")
	out_file_mobproto.close()
	return "Mob proto converted!"
	
def item_proto():
	item_type = {
		0: "ITEM_NONE",
		1: "ITEM_WEAPON",
		2: "ITEM_ARMOR",
		3: "ITEM_USE",
		4: "ITEM_AUTOUSE",
		5: "ITEM_MATERIAL",
		6: "ITEM_SPECIAL",
		7: "ITEM_TOOL",
		8: "ITEM_LOTTERY",
		9: "ITEM_ELK",
		10: "ITEM_METIN",
		11: "ITEM_CONTAINER",
		12: "ITEM_FISH",
		13: "ITEM_ROD",
		14: "ITEM_RESOURCE",
		15: "ITEM_CAMPFIRE",
		16: "ITEM_UNIQUE",
		17: "ITEM_SKILLBOOK",
		18: "ITEM_QUEST",
		19: "ITEM_POLYMORPH",
		20: "ITEM_TREASURE_BOX",
		21: "ITEM_TREASURE_KEY",
		22: "ITEM_SKILLFORGET",
		23: "ITEM_GIFTBOX",
		24: "ITEM_PICK",
		25: "ITEM_HAIR",
		26: "ITEM_TOTEM",
		27: "ITEM_BLEND",
		28: "ITEM_COSTUME",
		29: "ITEM_DS",
		30: "ITEM_SPECIAL_DS",
		31: "ITEM_EXTRACT",
		32: "ITEM_SECONDARY_COIN",
		33: "ITEM_RING",
		34: "ITEM_BELT"
	}

	item_subtype = {
		1: {
			0: "WEAPON_SWORD",
			1: "WEAPON_DAGGER",
			2: "WEAPON_BOW",
			3: "WEAPON_TWO_HANDED",
			4: "WEAPON_BELL",
			5: "WEAPON_FAN",
			6: "WEAPON_ARROW",
			7: "WEAPON_MOUNT_SPEAR",
			8: "WEAPON_NUM_TYPES",
		},
		2: {
			0: "ARMOR_BODY",
			1: "ARMOR_HEAD",
			2: "ARMOR_SHIELD",
			3: "ARMOR_WRIST",
			4: "ARMOR_FOOTS",
			5: "ARMOR_NECK",
			6: "ARMOR_EAR",
			7: "ARMOR_NUM_TYPES",
		},
		3 : {
			0: "USE_POTION",
			1: "USE_TALISMAN",
			2: "USE_TUNING",
			3: "USE_MOVE",
			4: "USE_TREASURE_BOX",
			5: "USE_MONEYBAG",
			6: "USE_BAIT",
			7: "USE_ABILITY_UP",
			8: "USE_AFFECT",
			9: "USE_CREATE_STONE",
			10: "USE_SPECIAL",
			11: "USE_POTION_NODELAY",
			12: "USE_CLEAR",
			13: "USE_INVISIBILITY",
			14: "USE_DETACHMENT",
			15: "USE_BUCKET",
			16: "USE_POTION_CONTINUE",
			17: "USE_CLEAN_SOCKET",
			18: "USE_CHANGE_ATTRIBUTE",
			19: "USE_ADD_ATTRIBUTE",
			20: "USE_ADD_ACCESSORY_SOCKET",
			21: "USE_PUT_INTO_ACCESSORY_SOCKET",
			22: "USE_ADD_ATTRIBUTE2",
			23: "USE_RECIPE",
			24: "USE_CHANGE_ATTRIBUTE2",
			25: "USE_BIND",
			26: "USE_UNBIND",
			27: "USE_TIME_CHARGE_PER",
			28: "USE_TIME_CHARGE_FIX",
			29: "USE_PUT_INTO_BELT_SOCKET",
			30: "USE_PUT_INTO_RING_SOCKET",
		},
		4: {
			0: "AUTOUSE_POTION",
			1: "AUTOUSE_ABILITY_UP",
			2: "AUTOUSE_BOMB",
			3: "AUTOUSE_GOLD",
			4: "AUTOUSE_MONEYBAG",
			5: "AUTOUSE_TREASURE_BOX",
		},
		5: {
			0: "MATERIAL_LEATHER",
			1: "MATERIAL_BLOOD",
			2: "MATERIAL_ROOT",
			3: "MATERIAL_NEEDLE",
			4: "MATERIAL_JEWEL",
			5: "MATERIAL_DS_REFINE_NORMAL",
			6: "MATERIAL_DS_REFINE_BLESSED",
			7: "MATERIAL_DS_REFINE_HOLLY",
		},
		6: {
			0: "SPECIAL_MAP",
			1: "SPECIAL_KEY",
			2: "SPECIAL_DOC",
			3: "SPECIAL_SPIRIT",
		},
		7: {
			0 : "TOOL_FISHING_ROD",
		},
		8: {
			0: "LOTTERY_TICKET",
			1: "LOTTERY_INSTANT",
		},
		10: {
			0: "METIN_NORMAL",
			1: "METIN_GOLD",
		},
		12: {
			0: "FISH_ALIVE",
			1: "FISH_DEAD",
		},
		14: {
			0: "RESOURCE_FISHBONE",
			1: "RESOURCE_WATERSTONEPIECE",
			2: "RESOURCE_WATERSTONE",
			3: "RESOURCE_BLOOD_PEARL",
			4: "RESOURCE_BLUE_PEARL",
			5: "RESOURCE_WHITE_PEARL",
			6: "RESOURCE_BUCKET",
			7: "RESOURCE_CRYSTAL",
			8: "RESOURCE_GEM",
			9: "RESOURCE_STONE",
			10: "RESOURCE_METIN",
			11: "RESOURCE_ORE",
		},
		16: {
			0: "UNIQUE_NONE",
			1: "UNIQUE_BOOK",
			2: "UNIQUE_SPECIAL_RIDE",
			3: "UNIQUE_3",
			4: "UNIQUE_4",
			5: "UNIQUE_5",
			6: "UNIQUE_6",
			7: "UNIQUE_7",
			8: "UNIQUE_8",
			9: "UNIQUE_9",
			10: "USE_SPECIAL",
		},
		28: {
			0: "COSTUME_BODY",
			1: "COSTUME_HAIR",
		},
		29: {
			0: "DS_SLOT1",
			1: "DS_SLOT2",
			2: "DS_SLOT3",
			3: "DS_SLOT4",
			4: "DS_SLOT5",
			5: "DS_SLOT6",
		},
		31: {
			0: "EXTRACT_DRAGON_SOUL",
			1: "EXTRACT_DRAGON_HEART",
		},
	}

	wearflag = {
		1: "WEAR_BODY",
		2: "WEAR_HEAD",
		4: "WEAR_FOOTS",
		8: "WEAR_WRIST",
		16: "WEAR_WEAPON",
		32: "WEAR_NECK",
		64: "WEAR_EAR",
		128: "WEAR_SHIELD",
		256: "WEAR_UNIQUE",
		512: "WEAR_ARROW",
		1024: "WEAR_HAIR",
		2048: "WEAR_ABILITY",
	}

	limittype = {
		1: "LEVEL",
		2: "STR",
		3: "DEX",
		4: "INT",
		5: "CON",
		6: "PC_BANG",
		7: "REAL_TIME",
		8: "REAL_TIME_FIRST_USE",
		9: "TIMER_BASED_ON_WEAR",
	}

	bonus = {
		1: "APPLY_MAX_HP",
		2: "APPLY_MAX_SP",
		3: "APPLY_CON",
		4: "APPLY_INT",
		5: "APPLY_STR",
		6: "APPLY_DEX",
		7: "APPLY_ATT_SPEED",
		8: "APPLY_MOV_SPEED",
		9: "APPLY_CAST_SPEED",
		10: "APPLY_HP_REGEN",
		11: "APPLY_SP_REGEN",
		12: "APPLY_POISON_PCT",
		13: "APPLY_STUN_PCT",
		14: "APPLY_SLOW_PCT",
		15: "APPLY_CRITICAL_PCT",
		16: "APPLY_PENETRATE_PCT",
		17: "APPLY_ATTBONUS_HUMAN",
		18: "APPLY_ATTBONUS_ANIMAL",
		19: "APPLY_ATTBONUS_ORC",
		20: "APPLY_ATTBONUS_MILGYO",
		21: "APPLY_ATTBONUS_UNDEAD",
		22: "APPLY_ATTBONUS_DEVIL",
		23: "APPLY_STEAL_HP",
		24: "APPLY_STEAL_SP",
		25: "APPLY_MANA_BURN_PCT",
		26: "APPLY_DAMAGE_SP_RECOVER",
		27: "APPLY_BLOCK",
		28: "APPLY_DODGE",
		29: "APPLY_RESIST_SWORD",
		30: "APPLY_RESIST_TWOHAND",
		31: "APPLY_RESIST_DAGGER",
		32: "APPLY_RESIST_BELL",
		33: "APPLY_RESIST_FAN",
		34: "APPLY_RESIST_BOW",
		35: "APPLY_RESIST_FIRE",
		36: "APPLY_RESIST_ELEC",
		37: "APPLY_RESIST_MAGIC",
		38: "APPLY_RESIST_WIND",
		39: "APPLY_REFLECT_MELEE",
		40: "APPLY_REFLECT_CURSE",
		41: "APPLY_POISON_REDUCE",
		42: "APPLY_KILL_SP_RECOVER",
		43: "APPLY_EXP_DOUBLE_BONUS",
		44: "APPLY_GOLD_DOUBLE_BONUS",
		45: "APPLY_ITEM_DROP_BONUS",
		46: "APPLY_POTION_BONUS",
		47: "APPLY_KILL_HP_RECOVER",
		48: "APPLY_IMMUNE_STUN",
		49: "APPLY_IMMUNE_SLOW",
		50: "APPLY_IMMUNE_FALL",
		51: "APPLY_SKILL",
		52: "APPLY_BOW_DISTANCE",
		53: "APPLY_ATT_GRADE_BONUS",
		54: "APPLY_DEF_GRADE_BONUS",
		55: "APPLY_MAGIC_ATT_GRADE",
		56: "APPLY_MAGIC_DEF_GRADE",
		57: "APPLY_CURSE_PCT",
		58: "APPLY_MAX_STAMINA",
		59: "APPLY_ATTBONUS_WARRIOR",
		60: "APPLY_ATTBONUS_ASSASSIN",
		61: "APPLY_ATTBONUS_SURA",
		62: "APPLY_ATTBONUS_SHAMAN",
		63: "APPLY_ATTBONUS_MONSTER",
		64: "APPLY_MALL_ATTBONUS",
		65: "APPLY_MALL_DEFBONUS",
		66: "APPLY_MALL_EXPBONUS",
		67: "APPLY_MALL_ITEMBONUS",
		68: "APPLY_MALL_GOLDBONUS",
		69: "APPLY_MAX_HP_PCT",
		70: "APPLY_MAX_SP_PCT",
		71: "APPLY_SKILL_DAMAGE_BONUS",
		72: "APPLY_NORMAL_HIT_DAMAGE_BONUS",
		73: "APPLY_SKILL_DEFEND_BONUS",
		74: "APPLY_NORMAL_HIT_DEFEND_BONUS",
		75: "APPLY_PC_BANG_EXP_BONUS",
		76: "APPLY_PC_BANG_DROP_BONUS",
		77: "APPLY_EXTRACT_HP_PCT",
		78: "APPLY_RESIST_WARRIOR",
		79: "APPLY_RESIST_ASSASSIN",
		80: "APPLY_RESIST_SURA",
		81: "APPLY_RESIST_SHAMAN",
		82: "APPLY_ENERGY",
		83: "APPLY_DEF_GRADE",
		84: "APPLY_COSTUME_ATTR_BONUS",
		85: "APPLY_MAGIC_ATTBONUS_PER",
		86: "APPLY_MELEE_MAGIC_ATTBONUS_PER",
		87: "APPLY_RESIST_ICE",
		88: "APPLY_RESIST_EARTH",
		89: "APPLY_RESIST_DARK",
		90: "APPLY_ANTI_CRITICAL_PCT",
		91: "APPLY_ANTI_PENETRATE_PCT",
	}

	addon_type = {
		180,
		181,
		182,
		183,
		184,
		185,
		186,
		187,
		188,
		189,
		190,
		191,
		192,
		193,
		194,
		195,
		196,
		197,
		198,
		199,
		290,
		291,
		292,
		293,
		294,
		295,
		296,
		297,
		298,
		299,
		1130,
		1131,
		1132,
		1133,
		1134,
		1135,
		1136,
		1137,
		1138,
		1139,
		1170,
		1171,
		1172,
		1173,
		1174,
		1175,
		1176,
		1177,
		1178,
		1179,
		2150,
		2151,
		2152,
		2153,
		2154,
		2155,
		2156,
		2157,
		2158,
		2159,
		2170,
		2171,
		2172,
		2173,
		2174,
		2175,
		2176,
		2177,
		2178,
		2179,
		3160,
		3161,
		3162,
		3163,
		3164,
		3165,
		3166,
		3167,
		3168,
		3169,
		3210,
		3211,
		3212,
		3213,
		3214,
		3215,
		3216,
		3217,
		3218,
		3219,
		5110,
		5111,
		5112,
		5113,
		5114,
		5115,
		5116,
		5117,
		5118,
		5119,
		5120,
		5121,
		5122,
		5123,
		5124,
		5125,
		5126,
		5127,
		5128,
		5129,
		7160,
		7161,
		7162,
		7163,
		7164,
		7165,
		7166,
		7167,
		7168,
		7169,
		65159,
		350,
		351,
		352,
		353,
		354,
		355,
		356,
		357,
		358,
		359,
		360,
		361,
		362,
		363,
		364,
		365,
		366,
		367,
		368,
		369,
		1300,
		1301,
		1302,
		1303,
		1304,
		1305,
		1306,
		1307,
		1308,
		1309,
		2340,
		2341,
		2342,
		2343,
		2344,
		2345,
		2346,
		2347,
		2348,
		2349,
		3330,
		3331,
		3332,
		3333,
		3334,
		3335,
		3336,
		3337,
		3338,
		3339,
		5290,
		5291,
		5292,
		5293,
		5294,
		5295,
		5296,
		5297,
		5298,
		5299,
	}

	errors = ""

	def get_item_type(type, vnum):
		errors = ""
		global errors
		if type in item_type:
			return item_type[type]
		else:
			errors += "Strange type in item %s\r\n" % vnum
			return item_type[0]

	def get_item_subtype(type, subtype, vnum):
		errors = ""
		global errors
		if type in item_subtype:
			if subtype in item_subtype[type]:
				return item_subtype[type][subtype]
		else:
			errors += "Strange subtype in item %s\r\n" % vnum
			return "NONE"

	def get_antiflag(antiflag, vnum):
		global errors
		str = ""
		if antiflag >= 131072:
			antiflag -= 131072
			if len(str) <= 0:
				str = "ANTI_SAFEBOX"
			else:
				str = "ANTI_SAFEBOX | " + str
		if antiflag >= 65536:
			antiflag -= 65536
			if len(str) <= 0:
				str = "ANTI_MYSHOP"
			else:
				str = "ANTI_MYSHOP | " + str
		if antiflag >= 32768:
			antiflag -= 32768
			if len(str) <= 0:
				str = "ANTI_STACK"
			else:
				str = "ANTI_STACK | " + str
		if antiflag >= 16384:
			antiflag -= 16384
			if len(str) <= 0:
				str = "ANTI_PKDROP"
			else:
				str = "ANTI_PKDROP | " + str
		if antiflag >= 8192:
			antiflag -= 8192
			if len(str) <= 0:
				str = "ANTI_GIVE"
			else:
				str = "ANTI_GIVE | " + str
		if antiflag >= 4096:
			antiflag -= 4096
			if len(str) <= 0:
				str = "ANTI_SAVE"
			else:
				str = "ANTI_SAVE | " + str
		if antiflag >= 2048:
			antiflag -= 2048
			if len(str) <= 0:
				str = "ANTI_EMPIRE_C"
			else:
				str = "ANTI_EMPIRE_C | " + str
		if antiflag >= 1024:
			antiflag -= 1024
			if len(str) <= 0:
				str = "ANTI_EMPIRE_B"
			else:
				str = "ANTI_EMPIRE_B | " + str
		if antiflag >= 512:
			antiflag -= 512
			if len(str) <= 0:
				str = "ANTI_EMPIRE_A"
			else:
				str = "ANTI_EMPIRE_A | " + str
		if antiflag >= 256:
			antiflag -= 256
			if len(str) <= 0:
				str = "ANTI_SELL"
			else:
				str = "ANTI_SELL | " + str
		if antiflag >= 64:
			antiflag -= 64
			if len(str) <= 0:
				str = "ANTI_GET"
			else:
				str = "ANTI_GET | " + str
		if antiflag >= 32:
			antiflag -= 32
			if len(str) <= 0:
				str = "ANTI_MUDANG"
			else:
				str = "ANTI_MUDANG | " + str
		if antiflag >= 16:
			antiflag -= 16
			if len(str) <= 0:
				str = "ANTI_SURA"
			else:
				str = "ANTI_SURA | " + str
		if antiflag >= 8:
			antiflag -= 8
			if len(str) <= 0:
				str = "ANTI_ASSASSIN"
			else:
				str = "ANTI_ASSASSIN | " + str
		if antiflag >= 4:
			antiflag -= 4
			if len(str) <= 0:
				str = "ANTI_MUSA"
			else:
				str = "ANTI_MUSA | " + str
		if antiflag >= 2:
			antiflag -= 2
			if len(str) <= 0:
				str = "ANTI_MALE"
			else:
				str = "ANTI_MALE | " + str
		if antiflag >= 1:
			antiflag -= 1
			if len(str) <= 0:
				str = "ANTI_FEMALE"
			else:
				str = "ANTI_FEMALE | " + str
		if antiflag == 0 and len(str) > 0:
			return "\"" + str + "\""
		else:
			errors += "Strange antiflag in item %s\r\n" % vnum
			return "\"NONE\""
		
	def get_flag(flag, vnum):
		global errors
		str = ""
		if flag >= 32768:
			flag -= 32768
			if len(str) <= 0:
				str = "ITEM_APPLICABLE"
			else:
				str = "ITEM_APPLICABLE | " + str
		if flag >= 16384:
			flag -= 16384
			if len(str) <= 0:
				str = "REFINEABLE"
			else:
				str = "REFINEABLE | " + str
		if flag >= 8192:
			flag -= 8192
			if len(str) <= 0:
				str = "LOG" 
			else:
				str = "LOG | " + str
		if flag >= 4096:
			flag -= 4096
			if len(str) <= 0:
				str = "ITEM_QUEST"
			else:
				str = "ITEM_QUEST | " + str
		if flag >= 2048:
			flag -= 2048
			if len(str) <= 0:
				str = "QUEST_GIVE"
			else:
				str = "QUEST_GIVE | " + str
		if flag >= 1024:
			flag -= 1024
			if len(str) <= 0:
				str = "QUEST_USE_MULTIPLE"
			else:
				str = "QUEST_USE_MULTIPLE | " + str
		if flag >= 512:
			flag -= 512
			if len(str) <= 0:
				str = "QUEST_USE"
			else:
				str = "QUEST_USE | " + str
		if flag >= 256:
			flag -= 256
			if len(str) <= 0:
				str = "CONFIRM_WHEN_USE"
			else:
				str = "CONFIRM_WHEN_USE | " + str
		if flag >= 128:
			flag -= 128
			if len(str) <= 0:
				str = "ITEM_IRREMOVABLE"
			else:
				str = "ITEM_IRREMOVABLE | " + str
		if flag >= 64:
			flag -= 64
			if len(str) <= 0:
				str = "ITEM_MAKECOUNT"
			else:
				str = "ITEM_MAKECOUNT | " + str
		if flag >= 32:
			flag -= 32
			if len(str) <= 0:
				str = "ITEM_UNIQUE"
			else:
				str = "ITEM_UNIQUE | " + str
		if flag >= 16:
			flag -= 16
			if len(str) <= 0:
				str = "ITEM_SLOW_QUERY"
			else:
				str = "ITEM_SLOW_QUERY | " + str
		if flag >= 8:
			flag -= 8
			if len(str) <= 0:
				str = "COUNT_PER_1GOLD"
			else:
				str = "COUNT_PER_1GOLD | " + str
		if flag >= 4:
			flag -= 4
			if len(str) <= 0:
				str = "ITEM_STACKABLE"
			else:
				str = "ITEM_STACKABLE | " + str
		if flag >= 2:
			flag -= 2
			if len(str) <= 0:
				str = "ITEM_SAVE"
			else:
				str = "ITEM_SAVE | " + str
		if flag >= 1:
			flag -= 1
			if len(str) <= 0:
				str = "ITEM_TUNABLE"
			else:
				str = "ITEM_TUNABLE | " + str
		if flag == 0 and len(str) > 0:
			return "\"" + str + "\""
		else:
			errors += "Strange flag in item %s\r\n" % vnum
			return "\"NONE\""

	def get_wearflag(wear, vnum):
		global errors
		if wear in wearflag:
			return "\"" + wearflag[wear] + "\""
		else:
			errors += "Strange wearflag in item %s\r\n" % vnum
			return "\"NONE\""
			
	def get_immuneflag(immune):
			return ""
			
	def get_limittype(limit):
		if limit in limittype:
			return "\"" + limittype[limit] + "\""
		else:
			return "\"LIMIT_NONE\""
			
	def get_apply(apply):
		if apply in bonus:
			return "\"" + bonus[apply] + "\""
		else:
			return "\"APPLY_NONE\""

	def socket(sockett):
		if sockett == 127:
			return 0
		else:
			return sockett


	print "Connecting to database proto..."
	data = "player"
	db = MySQLdb.connect(host_mysql,user_mysql,passwd_mysql,data)
	cur = db.cursor()
	print "Connected."
	cur.execute("select * from item_proto")
	rows = cur.fetchall()
	out_file_itemproto = open("item_proto.txt", "w")
	out_file_itemnames = open("item_names.txt", "w")
	print "Converting item_proto..."
	item_proto_line1 = "VNUM	NAME	TYPE	SUBTYPE	SIZE	ANTIFLAG	FLAG	WEARFLAG	IMMUNEFLAG	GOLD	SHOP_BUY_PRICE	REFINED_VNUM	REFINE_SET	MAGIC_PCT	LIMITTYPE0	LIMITVALUE0	LIMITTYPE1	LIMITVALUE1	APPLYTYPE0	APPLYVALUE0	APPLYTYPE1	APPLYVALUE1	APPLYTYPE2	APPLYVALUE2	VALUE0	VALUE1	VALUE2	VALUE3	VALUE4	VALUE5	SPECULAR	SOCKET_PCT	ADDON_TYPE"
	out_file_itemproto.write(item_proto_line1 + "\r\n")
	item_names_line1 = "VNUM	LOCALE_NAME"
	out_file_itemnames.write(item_names_line1 + "\r\n")
	for row in rows:
		item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[2] + "\"", "\""  + get_item_type(row[4], row[0]) + "\"" , "\""  + get_item_subtype(row[4], row[5], row[0]) + "\"", row[7] , get_antiflag(row[8], row[0]), get_flag(row[9], row[0]), get_wearflag(row[10], row[0]), get_immuneflag(row[11]), row[12], row[13], row[14], row[15], row[17], get_limittype(row[18]), row[19], get_limittype(row[20]), row[21], get_apply(row[22]), row[23], get_apply(row[24]), row[25], get_apply(row[26]), row[27], row[28], row[29], row[30], row[31], row[32], row[33], row[40], row[41], row[42])
		item_names_line = "%s\t%s" % (row[0], row[3])
		out_file_itemproto.write(item_proto_line + "\r\n")
		out_file_itemnames.write(item_names_line + "\r\n")
	out_file_itemproto.close()
	print "Item proto converted!"
	"""if len(errors) != 0:
		print "Errors during conversion:"
		print errors"""

print item_proto()
print mob_proto()

Note: Please watch your rows! It needs to match with your item_proto tables row order structure:

		item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[1] + "\"", "\""  + get_item_type(row[3], row[0]) + "\"" , "\""  + get_item_subtype(row[3], row[4], row[0]) + "\"", row[6] , get_antiflag(row[7], row[0]), get_flag(row[8], row[0]), get_wearflag(row[9], row[0]), get_immuneflag(row[10]), row[11], row[12], row[13], row[14], row[16], get_limittype(row[17]), row[18], get_limittype(row[19]), row[20], get_apply(row[21]), row[22], get_apply(row[23]), row[24], get_apply(row[25]), row[26], row[27], row[28], row[29], row[30], row[31], row[32], row[39], row[40], row[41])

Mine is:

		item_proto_line = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (row[0], "\"" + row[2] + "\"", "\""  + get_item_type(row[4], row[0]) + "\"" , "\""  + get_item_subtype(row[4], row[5], row[0]) + "\"", row[7] , get_antiflag(row[8], row[0]), get_flag(row[9], row[0]), get_wearflag(row[10], row[0]), get_immuneflag(row[11]), row[12], row[13], row[14], row[15], row[17], get_limittype(row[18]), row[19], get_limittype(row[20]), row[21], get_apply(row[22]), row[23], get_apply(row[24]), row[25], get_apply(row[26]), row[27], row[28], row[29], row[30], row[31], row[32], row[33], row[40], row[41], row[42])

Also check:

item_names_line = "%s\t%s" % (row[0], row[2])

Mine is:

item_names_line = "%s\t%s" % (row[0], row[3])

 

Edited by Werwolf94
I forgot to write the folder structure in pkg add -f commands.
  • Good 1
  • Love 1
  • 4 months later...
On 4/28/2014 at 6:56 PM, Deucalion said:

M2 Download Center

 

Hidden Content

  • Give reaction to this post to see the hidden content.
( Internal )

 

Hi.
I wanna to show you how can you convert item_proto to sql and later to txt files.
XML -> SQL
First we need this program:

 

Hidden Content

  • Give reaction to this post to see the hidden content.

 

scan:

 

Hidden Content

  • Give reaction to this post to see the hidden content.

 

Ther is something, but i haven't better program so you download it for your own responsibility

With it, we can convert our xml proto to sql
But first, from our xml file, we need to delete all <!--AddonType="0"--> and <!--AddonType="99"--> easy with notepad++ and ctrl+h :)

and now we run our program and select file to convert.

After moment we'll have a sql file, but if we have a locale_name column in item_proto we need to change also with ctr+h all gb2312name to locale_name, and now we can upload file with "execute sql file" or simpy with query to our database
 
SQL -> TXT
To convert item_proto sql to txt files, you need this script in python

http://pastebin.com/K5EDE4b6

Configuration:

You need MySQLdb on your freebsd

If you haven't it, just install it - it's a mysql library to python

cd /usr/ports/databases/py-MySQLdb/ && make install clean

You need also change the connection properties in script

default it's:

host_mysql = 'localhost'
user_mysql = 'mt2'
passwd_mysql = 'mt2!@#'

And if you want convert also mob_proto in this way, you need onlu change from

#print mob_proto()

to

print mob_proto()

in the end of file.

 

Now script should generate our protos in his directory .

 

These programs are not mine. The python script i found somewhere and just modified it to 40k version

I think that it's all, if you have any better program or any better way or idea you can show it :D

Maybe in the future I will write to that one big script, but now I have no time for this ;/

If there are any problems, I'll try to help :)

 

#Updated python script

 

Regards

Deucalion

 

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.