/*
	PostNuke Wasteland Achievements
	Date: 20.07.2011
	Latest Update: 13.10.2011
	Author: NeoPhoenix
*/
#if defined included_pnwl_achievement
	#endinput
#else
	#define included_pnwl_achievement
#endif

#include <a_samp>
#define achievement:: am_
#include "libraries/lib_CORE"
#include "n_lib/lib_mysql"
#define MAX_ACHIEVEMENTS 		(29)
#define ACHIEVEMENTS_PER_PAGE  	(10)
#define AM_SHOW_DRAW_TIME		(5)

enum (+=1)
{
	am_dialog_SELECT = 1,
	am_dialog_ACHIEVEMENT
}

enum amList
{
	amName[30],	//Name
	amText[144],//Beschreibung
	amPNeeded,	//Punkte zum Abschluss
	amPMessage,	//Nachricht über den Fortschritt
	amReward,	//Premium credits
};

new amData[MAX_ACHIEVEMENTS][amList] = {
/*0*/ {"Bullseye",				"Verteile 50 Kopftreffer",						50,						10,		10},//Done
/*1*/ {"Entwicklungshelfer",	"Finde alle Entwicklerkommentare im Spiel",		MAX_DEVELOPER_PICKUPS,	1,		30},//Done
/*2*/ {"Kneipenschlaeger",    	"Schlage 50 Gegner K.O.",						50,						10,		20},//Done
/*3*/ {"Vielfrass",				"Verschlinge insgesamt 50 Mahlzeiten",			50,						10,		10},//Done
/*4*/ {"Hundemarke",			"Knuepfe deinem Gegner eine Hundemarke ab",		1,						0,		10},//Done
/*5*/ {"Schiesswuetig",			"Erledige insgesamt 100 Gegner mit Schusswaffen",100,					20,		10},//Done
/*6*/ {"Dafuq?",				"Bringe 10 Gegner mit unueblichen Waffen um",	10,						1,		10},//Done
/*7*/ {"Jubilaeum",				"Erlebe die Jubilaeumsfeier von PNWL",			1,						0,		150},
/*8*/ {"Wieder fit",			"Kuriere 10 Krankheiten aus",					10,						1,		15},
/*9*/ {"Nachtaktiv",			"Spiele die Nacht durch",						1,						0,		10},//Done
/*10*/{"x",						"y",											0,						0,		0},
/*11*/{"Weltenbummler",			"Erkunde alle Orte in Terra Robada",			(1|2|4|8|16),			1,		30},
/*12*/{"Student",				"Lese alle Lektueren",							0,						5,		20},
/*13*/{"Ueberlebenskünstler",	"Überlebe 5 Minuten mit einer HP unter 10",		5,						0,		10},//Done
/*14*/{"Warlord",				"Kaufe 30 Waffen beim Waffenhändler",			30,						5,		10},//Done
/*15*/{"Number One",			"Gewinne 10 Runden Poker",						10,						2,		5},
/*16*/{"Auferstanden",			"Entkomme dem Tod!",							1,						0,		5},//Done
/*17*/{"Defensive",				"Erleide insgesamt 10.000 Schadenspunkte",		10000,					1000,	5},//Done
/*18*/{"Offensive",				"Teile insgesamt 10.000 Schadenspunkte aus",	10000,					1000,	8},//Done
/*19*/{"Schlafmuetze",			"Verschlafe einen ganzen Tag",					24,						0,		5},//Done
/*20*/{"The cake is a lie!",	"Luefte das Geheimnis...",						1,						0,		100},
/*21*/{"Haendler",				"Tausche 100 Items",							100,					10,		20},//Done
/*22*/{"Athlet",				"Laufe 100 Kilometer",							100000,					10000,	10},//Done
/*23*/{"Fernfahrer",			"Fahre 100 Kilometer",							100000,					10000,	10},//Done
/*24*/{"Jaeger",				"Erlege 200 Tiere",								200,					20,		15},//Done
/*25*/{"Minenarbeiter",			"Zerschmettere 200 Steine",						200,					20,		15},//Done
/*26*/{"Spuernase",				"Finde 100 Items in Muelltonnen",				100,					10,		10},//Done
/*27*/{"Revolverheld",			"Niete 30 Gegner mit einhändigen Waffen um",	30,						10,		10},//Done
/*28*/{"Storyline",				"Schließe 10 Quests ab",						10,						5,		15}//Done
};

enum amPList
{
	am,
	need,
}
new am_PlayerInfo[MAX_PLAYERS][MAX_ACHIEVEMENTS][amPList];
enum amPcache
{
	am_page,
	am_item[ACHIEVEMENTS_PER_PAGE+3],
}
new am_PlayerCache[MAX_PLAYERS][amPcache];

stock achievement::SyncAchievements()
{
	mysql_query_once("TRUNCATE pnwl_res_achievements");
	for(new i; i<MAX_ACHIEVEMENTS; i++)
	{
		mysql_real_escape_string(amData[i][amText],query);
		format(string,sizeof(string),"INSERT INTO pnwl_res_achievements (id,amName,amText,amPNeeded,amReward) VALUES ('%d','%s','%s','%d','%d')",i,amData[i][amName],query,amData[i][amPNeeded],amData[i][amReward]);
		mysql_query_once(string);
	}
	return;
}

stock achievement::GetAchievementIdByName(am_search_name[])
{
	for(new aid; aid<MAX_ACHIEVEMENTS; aid++)
	{
		if(!strcmp(am_search_name,amData[aid][amName])) return aid;
	}
	return -1;
}

stock achievement::AddPlayerAchievement(playerid,am_id,bool:show=true,bool:show_all=true)
{
	if(am_id < 0 || am_id >= MAX_ACHIEVEMENTS) return 0;
	if(am_PlayerInfo[playerid][am_id][am] >= 1) return 1;
	new timestamp = gettime(_,_,_);
	am_PlayerInfo[playerid][am_id][am] = timestamp>=1?timestamp:1;
	am_PlayerInfo[playerid][am_id][need] = amData[am_id][amPNeeded];
	
	new am_time[4],am_date[3];
	getdate(am_date[0],am_date[1],am_date[2]);
	gettime(am_time[0],am_time[1],_);
	
	format(string,sizeof(string),"SELECT * FROM pnwl_user_achievements WHERE userid='%d' AND am_name='%s'",PlayerInfo[playerid][PLAYER_ID],amData[am_id][amName]);
	mysql_query(string);
	mysql_store_result();
	new rows = mysql_num_rows();
	mysql_free_result();
	if(rows > 0) 	format(string,sizeof(string),"UPDATE pnwl_user_achievements SET fortschritt='%d',done='1',unlocked='%d' WHERE userid='%d' AND am_name='%s'",amData[am_id][amPNeeded],timestamp,PlayerInfo[playerid][PLAYER_ID],amData[am_id][amName]);
	else			format(string,sizeof(string),"INSERT INTO pnwl_user_achievements (userid,am_name,aid,fortschritt,done,unlocked) VALUES ('%d','%s','%d','%d','1','%d')",PlayerInfo[playerid][PLAYER_ID],amData[am_id][amName],am_id,amData[am_id][amPNeeded],timestamp);
	mysql_query_once(string);

	if(show)
	{
	    format(string,sizeof(string),#FORMAT_CHAT_INFO"Du hast das Achievement \"%s\" freigeschaltet.",amData[am_id][amName]);
		SendClientMessage(playerid,GRUEN,string);
		format(string,sizeof(string),"\"%s\"",amData[am_id][amText]);
		SendClientMessage(playerid,GRUEN,string);
		am_ShowInfoDraw(playerid,am_id);

		if(show_all)
		{
			format(string,sizeof(string),"* %s %s (%d) hat das Achievement \"%s\" freigeschaltet.",PlayerInfo[playerid][Vorname],PlayerInfo[playerid][Nachname],playerid,amData[am_id][amName]);
			for(new i; i<__SERVER[HIGHEST_PLAYER_ID]; i++) if(i != playerid) SendClientMessage(i,GRUEN,string);		
		}	
	}
	
	//Belohnung (Premiumpunkte)
	CORE::AddPlayerCredits(PlayerInfo[playerid][PLAYER_ID],amData[am_id][amReward]);
	return 1;
}

stock achievement::SetPlayerAchievementData(playerid,am_id,fortschritt=0,bool:add=true)
{
	if(am_id < 0 || am_id >= MAX_ACHIEVEMENTS) return 0;
	if(add == true)
	{//ADD
		if(am_PlayerInfo[playerid][am_id][am] >= 1) return 1; 
		if((am_PlayerInfo[playerid][am_id][need] + fortschritt) > amData[am_id][amPNeeded]) fortschritt = amData[am_id][amPNeeded];
		else fortschritt = (am_PlayerInfo[playerid][am_id][need] + fortschritt);
	}
	else
	{//SET
		if(fortschritt >= 0 && fortschritt < amData[am_id][amPNeeded]) am_PlayerInfo[playerid][am_id][need] = fortschritt;
		else am_PlayerInfo[playerid][am_id][need] = 0;
	}

	if(fortschritt >= amData[am_id][amPNeeded])
	{
		am_PlayerInfo[playerid][am_id][need] = amData[am_id][amPNeeded];
		achievement::AddPlayerAchievement(playerid,am_id);
		return 1;
	}
	am_PlayerInfo[playerid][am_id][need] = fortschritt;
	if(amData[am_id][amPMessage] >= 1)
	{
		if((fortschritt % amData[am_id][amPMessage]) == 0)
		{
			format(string,sizeof(string),#FORMAT_CHAT_INFO"Fortschritt bei '%s': %d/%d",amData[am_id][amName],fortschritt,amData[am_id][amPNeeded]);
			SendClientMessage(playerid,GRUEN,string);
		}
	}
	
	format(string,sizeof(string),"SELECT * FROM pnwl_user_achievements WHERE userid='%d' AND am_name='%s'",PlayerInfo[playerid][PLAYER_ID],amData[am_id][amName]);
	mysql_query(string);
	mysql_store_result();
	new rows = mysql_num_rows();
	mysql_free_result();
	if(rows > 0) 	format(string,sizeof(string),"UPDATE pnwl_user_achievements SET fortschritt='%d',done='0' WHERE userid='%d' AND am_name='%s'",am_PlayerInfo[playerid][am_id][need],PlayerInfo[playerid][PLAYER_ID],amData[am_id][amName]);
	else 			format(string,sizeof(string),"INSERT INTO pnwl_user_achievements (userid,am_name,aid,fortschritt) VALUES ('%d','%s','%d','%d')",PlayerInfo[playerid][PLAYER_ID],amData[am_id][amName],am_id,am_PlayerInfo[playerid][am_id][need]);
	mysql_query_once(string);
	return 1;
}

stock achievement::ShowPlayerAchievementList(playerid,page=0)
{
    new loop=2,bool:usepage=false;
	if(page != 0) usepage=true;
	if(!usepage) page = am_PlayerCache[playerid][am_page];
	if(MAX_ACHIEVEMENTS < ((page*ACHIEVEMENTS_PER_PAGE)-ACHIEVEMENTS_PER_PAGE) || page <= 0)
	{
		page = 1;
		usepage = false;
	}

	am_PlayerCache[playerid][am_page] = page;
	format(string,sizeof(string),"Vorherige Seite\nNächste Seite");
	for(new am_id=((page*ACHIEVEMENTS_PER_PAGE)-ACHIEVEMENTS_PER_PAGE); am_id<((page*ACHIEVEMENTS_PER_PAGE)); am_id++)
	{
 		if(am_id < 0 || am_id >= MAX_ACHIEVEMENTS)
		{
			format(string,sizeof(string),"%s\n-",string);
			am_PlayerCache[playerid][am_item][loop] = -1;
		}
		else
		{
		    if(am_PlayerInfo[playerid][am_id][am]>=1) format(string,sizeof(string),"%s\n{51EA3A}100%%\t- %s",string,amData[am_id][amName]);
		    else if(am_PlayerInfo[playerid][am_id][need] >= 1)
			{
			    new Float:fortschritt = ((float(am_PlayerInfo[playerid][am_id][need])/float(amData[am_id][amPNeeded]))*100);
				format(string,sizeof(string),"%s\n{%s}%0.1f%%\t- %s",string,achievement::getAchievementColor(fortschritt),fortschritt,amData[am_id][amName]);
			}
		    else format(string,sizeof(string),"%s\n{FF0505}0.0%%\t- %s",string,amData[am_id][amName]);
		    am_PlayerCache[playerid][am_item][loop] = am_id;
		}
 		loop++;
	}
	new page_string[55];
	format(page_string,sizeof page_string,"{F1F7DC}Achievements, Seite %d",page);
	am_ShowPlayerDialog(playerid,am_dialog_SELECT,DIALOG_STYLE_LIST,page_string,string,"Infos","Beenden");
	return 1;
}

stock achievement::ShowPlayerAchievement(playerid,am_id)
{
    if(am_id < 0 || am_id >= MAX_ACHIEVEMENTS) return 0;
    else
    {
        if(am_PlayerInfo[playerid][am_id][am]>=1) format(string,sizeof(string),"{51EA3A}Name: \"%s\"\nFortschritt: FREIGESCHALTET\n\nBeschreibung:\n%s\n\nBelohnung: %d Credits",amData[am_id][amName],amData[am_id][amText],amData[am_id][amReward]);
	    else if(am_PlayerInfo[playerid][am_id][need] >= 1)
		{
		    new Float:fortschritt = ((float(am_PlayerInfo[playerid][am_id][need])/float(amData[am_id][amPNeeded]))*100);
		    format(string,sizeof(string),"{%s}Name: \"%s\"\nFortschritt: %0.1f%%\n\nBeschreibung:\n%s\n\nBelohnung: Unbekannt",achievement::getAchievementColor(fortschritt),amData[am_id][amName],fortschritt,amData[am_id][amText]);
		}
	    else format(string,sizeof(string),"{FF0505}Name: \"%s\"\nFortschritt: 0.0%%\n\nBeschreibung:\n%s\n\nBelohnung: Unbekannt",amData[am_id][amName],amData[am_id][amText]);
		am_ShowPlayerDialog(playerid,am_dialog_ACHIEVEMENT,DIALOG_STYLE_MSGBOX,"{F1F7DC}Achievement",string,"Zurück","Beenden");
    }
	return 1;
}

achievement::OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	#pragma unused inputtext
	if(GetPVarInt(playerid,"am_dialog") == 1)
	{
	    SetPVarInt(playerid,"am_dialog",0);
		DeletePVar(playerid,"am_dialog");
		
		if(dialogid == am_dialog_SELECT)
		{
			if(!response) return 1;
		    if(listitem == 0 || listitem == 1)
		    {
		        if(listitem == 0) achievement::ShowPlayerAchievementList(playerid,--am_PlayerCache[playerid][am_page]);
		        else achievement::ShowPlayerAchievementList(playerid,++am_PlayerCache[playerid][am_page]);
		        return 1;
		    }
		    new am_id = am_PlayerCache[playerid][am_item][listitem];
			if(am_id == -1) achievement::ShowPlayerAchievementList(playerid);
			else
			{
				if(!am_ShowPlayerAchievement(playerid,am_id)) achievement::ShowPlayerAchievementList(playerid);
			}
			return 1;
		}
		if(dialogid == am_dialog_ACHIEVEMENT)
		{
		    if(response) achievement::ShowPlayerAchievementList(playerid);
		    return 1;
		}
		return true;
	}
	return false;
}

stock achievement::ShowPlayerDialog(playerid, dialogid, dialogstyle, header[], info[], but1[], but2[])
{
	SetPVarInt(playerid,"am_dialog",1);
	ShowPlayerDialog(playerid,dialogid,dialogstyle,header,info,but1,but2);
	return 1;
}

stock achievement::getAchievementColor(Float:fortschritt)
{
	new farbe[7];
	if(fortschritt > 95.0) 		farbe = "3DCE00";
	else if(fortschritt > 83.0) farbe = "43E000";
	else if(fortschritt > 75.0) farbe = "9BE000";
	else if(fortschritt > 67.0) farbe = "BDE000";
	else if(fortschritt > 55.0) farbe = "FFE000";
	else if(fortschritt > 50.0) farbe = "FFC005";
	else if(fortschritt > 45.0) farbe = "FF9E0F";
	else if(fortschritt > 40.0) farbe = "FF890F";
	else if(fortschritt > 35.0) farbe = "FF890F";
	else if(fortschritt > 25.0) farbe = "FF4F0F";
	else if(fortschritt > 15.0) farbe = "FF000C";	
	else farbe = "FF000C";
	return farbe;
}

new Text:ErfolgTextDraw[13];
stock achievement::ShowInfoDraw(playerid,am_id)
{
	if(GetPVarInt(playerid,"am_showinfodraw") != 0) am_HideInfoDraw(playerid);	
	if(am_id < 0 || am_id >= MAX_ACHIEVEMENTS) return 0;
	format(string,sizeof(string),"%s",amData[am_id][amName]);
	if(strlen(string) <= 1) return -1;
	SetPVarInt(playerid,"am_showinfodraw",AM_SHOW_DRAW_TIME);
	for(new i; i<sizeof(ErfolgTextDraw); i++) fixed_TextDrawShowForPlayer(playerid,ErfolgTextDraw[i]);

	PlayerErfolgTextDraw[playerid][0] = CreatePlayerTextDraw(playerid,255.000000, 140.000000, "Erfolg freigeschaltet");
	PlayerTextDrawAlignment(playerid,PlayerErfolgTextDraw[playerid][0], 2);
	PlayerTextDrawBackgroundColor(playerid,PlayerErfolgTextDraw[playerid][0], 255);
	PlayerTextDrawFont(playerid,PlayerErfolgTextDraw[playerid][0], 1);
	PlayerTextDrawLetterSize(playerid,PlayerErfolgTextDraw[playerid][0], 0.419999, 1.799999);
	PlayerTextDrawColor(playerid,PlayerErfolgTextDraw[playerid][0], -1);
	PlayerTextDrawSetOutline(playerid,PlayerErfolgTextDraw[playerid][0], 1);
	PlayerTextDrawSetProportional(playerid,PlayerErfolgTextDraw[playerid][0], 1);
	PlayerTextDrawShow(playerid,PlayerErfolgTextDraw[playerid][0]);
	
	PlayerErfolgTextDraw[playerid][1] = CreatePlayerTextDraw(playerid,255.000000, 157.000000, " ");
	PlayerTextDrawAlignment(playerid,PlayerErfolgTextDraw[playerid][1], 2);
	PlayerTextDrawBackgroundColor(playerid,PlayerErfolgTextDraw[playerid][1], 255);
	PlayerTextDrawFont(playerid,PlayerErfolgTextDraw[playerid][1], 1);
	PlayerTextDrawLetterSize(playerid,PlayerErfolgTextDraw[playerid][1], 0.419999, 1.799999);
	PlayerTextDrawColor(playerid,PlayerErfolgTextDraw[playerid][1], -1);
	PlayerTextDrawSetOutline(playerid,PlayerErfolgTextDraw[playerid][1], 1);
	PlayerTextDrawSetProportional(playerid,PlayerErfolgTextDraw[playerid][1], 1);
	PlayerTextDrawShow(playerid,PlayerErfolgTextDraw[playerid][1]);
	return 1;
}

stock achievement::HideInfoDraw(playerid)
{
	if(GetPVarInt(playerid,"am_showinfodraw") == 0) return 0;
	for(new i; i<sizeof(ErfolgTextDraw); i++) fixed_TextDrawHideForPlayer(playerid,ErfolgTextDraw[i]);	
	DeletePVar(playerid,"am_showinfodraw");
	PlayerTextDrawHide(playerid,PlayerErfolgTextDraw[playerid][0]);
	PlayerTextDrawDestroy(playerid,PlayerErfolgTextDraw[playerid][0]);
	PlayerTextDrawHide(playerid,PlayerErfolgTextDraw[playerid][1]);
	PlayerTextDrawDestroy(playerid,PlayerErfolgTextDraw[playerid][1]);
	return 1;
}

achievement::AchievementInit()
{
	achievement::AchievementCaching();
	
	#define COLOR_SHADOWS 	0xCC9900FF
	#define COLOR_INNER 	0x916330FF
	#define COLOR_MAIN_BOX 	0x7B3B10FF
	ErfolgTextDraw[0] = TextDrawCreate(94.000000, 115.000000, "O");//links oben
	TextDrawAlignment(ErfolgTextDraw[0], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[0], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[0], 2);
	TextDrawLetterSize(ErfolgTextDraw[0], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[0], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[0], 1);
	TextDrawSetProportional(ErfolgTextDraw[0], 0);

	ErfolgTextDraw[1] = TextDrawCreate(94.000000, 125.000000, "O");//links unten
	TextDrawAlignment(ErfolgTextDraw[1], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[1], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[1], 2);
	TextDrawLetterSize(ErfolgTextDraw[1], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[1], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[1], 1);
	TextDrawSetProportional(ErfolgTextDraw[1], 0);

	ErfolgTextDraw[2] = TextDrawCreate(364.000000, 125.000000, "O");//rechts unten
	TextDrawAlignment(ErfolgTextDraw[2], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[2], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[2], 2);
	TextDrawLetterSize(ErfolgTextDraw[2], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[2], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[2], 1);
	TextDrawSetProportional(ErfolgTextDraw[2], 0);

	ErfolgTextDraw[3] = TextDrawCreate(364.000000, 115.000000, "O");//links unten
	TextDrawAlignment(ErfolgTextDraw[3], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[3], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[3], 2);
	TextDrawLetterSize(ErfolgTextDraw[3], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[3], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[3], 1);
	TextDrawSetProportional(ErfolgTextDraw[3], 0);

//====================Inner Rings
	ErfolgTextDraw[4] = TextDrawCreate(71.000000, 113.000000, "O");//rechts oben
	TextDrawAlignment(ErfolgTextDraw[4], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[4], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[4], 2);
	TextDrawLetterSize(ErfolgTextDraw[4], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[4], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[4], 1);
	TextDrawSetProportional(ErfolgTextDraw[4], 0);
	TextDrawSetShadow(ErfolgTextDraw[4], 1);

	ErfolgTextDraw[5] = TextDrawCreate(385.000000, 113.000000, "O");//links oben
	TextDrawAlignment(ErfolgTextDraw[5], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[5], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[5], 2);
	TextDrawLetterSize(ErfolgTextDraw[5], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[5], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[5], 1);
	TextDrawSetProportional(ErfolgTextDraw[5], 0);
	TextDrawSetShadow(ErfolgTextDraw[5], 1);

	ErfolgTextDraw[6] = TextDrawCreate(71.000000, 127.000000, "O");//rechts unten
	TextDrawAlignment(ErfolgTextDraw[6], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[6], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[6], 2);
	TextDrawLetterSize(ErfolgTextDraw[6], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[6], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[6], 1);
	TextDrawSetProportional(ErfolgTextDraw[6], 0);
	TextDrawSetShadow(ErfolgTextDraw[6], 1);

	ErfolgTextDraw[7] = TextDrawCreate(385.000000, 127.000000, "O");//links unten
	TextDrawAlignment(ErfolgTextDraw[7], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[7], COLOR_SHADOWS);
	TextDrawFont(ErfolgTextDraw[7], 2);
	TextDrawLetterSize(ErfolgTextDraw[7], 1.139999, 7.399998);
	TextDrawColor(ErfolgTextDraw[7], COLOR_INNER);
	TextDrawSetOutline(ErfolgTextDraw[7], 1);
	TextDrawSetProportional(ErfolgTextDraw[7], 0);
	TextDrawSetShadow(ErfolgTextDraw[7], 1);

//=============== "Backbox"
	ErfolgTextDraw[8] = TextDrawCreate(60.000000, 139.000000, "_____________");
	TextDrawBackgroundColor(ErfolgTextDraw[8], 255);
	TextDrawFont(ErfolgTextDraw[8], 1);
	TextDrawLetterSize(ErfolgTextDraw[8], 1.010000, 4.099998);
	TextDrawColor(ErfolgTextDraw[8], -1);
	TextDrawSetOutline(ErfolgTextDraw[8], 0);
	TextDrawSetProportional(ErfolgTextDraw[8], 1);
	TextDrawSetShadow(ErfolgTextDraw[8], 1);
	TextDrawUseBox(ErfolgTextDraw[8], 1);
	TextDrawBoxColor(ErfolgTextDraw[8], COLOR_INNER);
	TextDrawTextSize(ErfolgTextDraw[8], 394.780000, 10.000000);

	ErfolgTextDraw[9] = TextDrawCreate(60.000000, 139.000000, "_____________");
	TextDrawBackgroundColor(ErfolgTextDraw[9], 255);
	TextDrawFont(ErfolgTextDraw[9], 1);
	TextDrawLetterSize(ErfolgTextDraw[9], 1.010000, 4.099998);
	TextDrawColor(ErfolgTextDraw[9], -1);
	TextDrawSetOutline(ErfolgTextDraw[9], 0);
	TextDrawSetProportional(ErfolgTextDraw[9], 1);
	TextDrawSetShadow(ErfolgTextDraw[9], 1);
	TextDrawUseBox(ErfolgTextDraw[9], 1);
	TextDrawBoxColor(ErfolgTextDraw[9], COLOR_INNER);
	TextDrawTextSize(ErfolgTextDraw[9], 394.780000, 10.000000);

//=============== Mainbox wo text is un so
	ErfolgTextDraw[10] = TextDrawCreate(66.000000, 142.000000, "_____________");
	TextDrawBackgroundColor(ErfolgTextDraw[10], 255);
	TextDrawFont(ErfolgTextDraw[10], 1);
	TextDrawLetterSize(ErfolgTextDraw[10], 0.509999, 3.399999);
	TextDrawColor(ErfolgTextDraw[10], -1);
	TextDrawSetOutline(ErfolgTextDraw[10], 0);
	TextDrawSetProportional(ErfolgTextDraw[10], 1);
	TextDrawSetShadow(ErfolgTextDraw[10], 1);
	TextDrawUseBox(ErfolgTextDraw[10], 1);
	TextDrawBoxColor(ErfolgTextDraw[10], COLOR_MAIN_BOX);
	TextDrawTextSize(ErfolgTextDraw[10], 388.000000, 10.000000);

//=============== Trennstrich
	ErfolgTextDraw[11] = TextDrawCreate(119.000000, 140.000000, "_");
	TextDrawAlignment(ErfolgTextDraw[11], 2);
	TextDrawBackgroundColor(ErfolgTextDraw[11], 255);
	TextDrawFont(ErfolgTextDraw[11], 1);
	TextDrawLetterSize(ErfolgTextDraw[11], 0.490000, 4.000000);
	TextDrawColor(ErfolgTextDraw[11], -1);
	TextDrawSetOutline(ErfolgTextDraw[11], 0);
	TextDrawSetProportional(ErfolgTextDraw[11], 1);
	TextDrawSetShadow(ErfolgTextDraw[11], 1);
	TextDrawUseBox(ErfolgTextDraw[11], 1);
	TextDrawBoxColor(ErfolgTextDraw[11], COLOR_INNER);
	TextDrawTextSize(ErfolgTextDraw[11], -3.000000, -3.000000);

//=============== Stern
	ErfolgTextDraw[12] = TextDrawCreate(71.000000, 139.000000, "~y~]");
	TextDrawBackgroundColor(ErfolgTextDraw[12], 255);
	TextDrawFont(ErfolgTextDraw[12], 0);
	TextDrawLetterSize(ErfolgTextDraw[12], 1.180000, 3.900000);
	TextDrawColor(ErfolgTextDraw[12], -1);
	TextDrawSetOutline(ErfolgTextDraw[12], 2);
	TextDrawSetProportional(ErfolgTextDraw[12], 1);
	return 1;
}

achievement::LoadPlayerAchievements(playerid)
{
	for(new b; b<MAX_ACHIEVEMENTS; b++) for(new i; amPList:i<amPList; i++) am_PlayerInfo[playerid][b][amPList:i] = 0;
	format(query,sizeof(query),"SELECT * FROM pnwl_user_achievements WHERE userid='%d'",PlayerInfo[playerid][PLAYER_ID]);
	mysql_query(query);
	mysql_store_result();
	new erfolg_cache[3];
	if(mysql_num_rows() >= 1)
	{
		while(mysql_retrieve_row())
		{
			mysql_fetch_field_row(string,"am_name");
			erfolg_cache[0] = achievement::GetAchievementIdByName(string);
			if(erfolg_cache[0] != -1)
			{
				mysql_fetch_field_row(string,"fortschritt");
				erfolg_cache[1] = strval(string);
				mysql_fetch_field_row(string,"done");
				erfolg_cache[2] = strval(string);
				am_PlayerInfo[playerid][erfolg_cache[0]][am] 	= erfolg_cache[2];
				am_PlayerInfo[playerid][erfolg_cache[0]][need] 	= erfolg_cache[1];
			}
		}
	}
	mysql_free_result();
	return 1;
}

enum am_cache_enum
{
	amBullseye,
	amEntwicklungshelfer,
	amKneipenschlaeger,
	amVielfrass,
	amHundemarke,
	amSchiesswuetig,
	amDafuq,
	amJubilaeum,
	amWiederFit,
	amNachtaktiv,
	amX,
	amWeltenbummler,
	amStudent,
	amUeberlebenskuenstler,
	amWarlord,
	amNumberOne,
	amAuferstanden,
	amDefensive,
	amOffensive,
	amSchlafmuetze,
	amTheCakeIsALie,
	amHaendler,
	amAthlet,
	amFernfahrer,
	amJaeger,
	amMinenarbeiter,
	amSpuernase,
	amRevolverheld,
	amStoryline,
}
new __amCache[am_cache_enum];

achievement::AchievementCaching()
{
	for(new i; am_cache_enum:i<am_cache_enum; i++) __amCache[am_cache_enum:i] = -1;
	__amCache[amBullseye] 				= achievement::GetAchievementIdByName("Bullseye");
	__amCache[amEntwicklungshelfer] 	= achievement::GetAchievementIdByName("Entwicklungshelfer");
	__amCache[amKneipenschlaeger] 		= achievement::GetAchievementIdByName("Kneipenschlaeger");
	__amCache[amVielfrass] 				= achievement::GetAchievementIdByName("Vielfrass");
	__amCache[amHundemarke] 			= achievement::GetAchievementIdByName("Hundemarke");
	__amCache[amSchiesswuetig]	 		= achievement::GetAchievementIdByName("Schiesswuetig");
	__amCache[amDafuq] 					= achievement::GetAchievementIdByName("Dafuq?");
	__amCache[amJubilaeum] 				= achievement::GetAchievementIdByName("Jubilaeum");
	__amCache[amWiederFit] 				= achievement::GetAchievementIdByName("Wieder fit");
	__amCache[amNachtaktiv] 			= achievement::GetAchievementIdByName("Nachtaktiv");
	__amCache[amWeltenbummler] 			= achievement::GetAchievementIdByName("Weltenbummler");
	__amCache[amStudent] 				= achievement::GetAchievementIdByName("Student");
	__amCache[amUeberlebenskuenstler] 	= achievement::GetAchievementIdByName("Ueberlebenskuenstler");
	__amCache[amWarlord] 				= achievement::GetAchievementIdByName("Warlord");
	__amCache[amNumberOne] 				= achievement::GetAchievementIdByName("NumberOne");
	__amCache[amAuferstanden] 			= achievement::GetAchievementIdByName("Auferstanden");
	__amCache[amDefensive] 				= achievement::GetAchievementIdByName("Defensive");
	__amCache[amOffensive] 				= achievement::GetAchievementIdByName("Offensive");
	__amCache[amSchlafmuetze]			= achievement::GetAchievementIdByName("Schlafmuetze");
	__amCache[amTheCakeIsALie] 			= achievement::GetAchievementIdByName("The cake is a lie!");
	__amCache[amHaendler] 				= achievement::GetAchievementIdByName("Haendler");
	__amCache[amAthlet] 				= achievement::GetAchievementIdByName("Athlet");
	__amCache[amFernfahrer] 			= achievement::GetAchievementIdByName("Fernfahrer");
	__amCache[amJaeger] 				= achievement::GetAchievementIdByName("Jaeger");
	__amCache[amMinenarbeiter] 			= achievement::GetAchievementIdByName("Minenarbeiter");
	__amCache[amSpuernase] 				= achievement::GetAchievementIdByName("Spuernase");
	__amCache[amRevolverheld] 			= achievement::GetAchievementIdByName("Revolverheld");
	__amCache[amStoryline]	 			= achievement::GetAchievementIdByName("Storyline");
	return 1;
}