#include <amxmodx>
#include <amxmisc>

#define MAX 64

new const PLUGIN[] = "Simple SQL Table Generator"
new const VERSION[] = "1.0"
new const AUTHOR[] = "DeRoiD"
new const NAME[] = "sql_example"
new const ID[] = "key"

new File[MAX]

new const Table[][] =  
{
	"",
	"s Nev",
	"s Felhasznalonev",
	"n Oles",
	"n Penz"
}

new const MakeData[][] =  
{
	"",
	"CREATE TABLE IF NOT EXISTS `%s` (^n",
	"  `%s` int(32) NOT NULL AUTO_INCREMENT,^n",
	"  `%s` varchar(32) NOT NULL,^n",
	"  `%s` int(32) NOT NULL,^n",
	"    PRIMARY KEY (`%s`)^n",
	") ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;"
}

public plugin_cfg()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	static Directory[MAX]
	get_localinfo("amxx_configsdir", Directory, MAX-1)
	formatex(File, MAX-1, "%s/sql_table.txt", Directory)
	
	MakeFile()
}

public MakeFile()
{
	if(file_exists(File))
	{
		delete_file(File)
	}
	
	static Text[1014], Len[256]
	
	formatex(Len, 255, MakeData[1], NAME)
	add(Text, 1013, Len)
	
	formatex(Len, 255, MakeData[2], ID)
	add(Text, 1013, Len)
	
	for(new i = 1; i < sizeof(Table); i++)
	{
		new Info[32], x, New[MAX]
		parse(Table[i], Info, 31)
		
		if(equal(Info, "s"))
		{
			formatex(New, MAX-1, Table[i])
			replace_all(New, MAX-1, "s ", "")
			x = 3
		}
		else if(equal(Info, "n"))
		{
			formatex(New, MAX-1, Table[i])
			replace_all(New, MAX-1, "n ", "")
			x = 4
		}
		
		formatex(Len, 255, MakeData[x], New)
		add(Text, 1013, Len)
	}
	
	formatex(Len, 255, MakeData[5], ID)
	add(Text, 1013, Len)
	
	formatex(Len, 255, MakeData[6])
	add(Text, 1013, Len)
	
	write_file(File, Text)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
*/
