/*
HP-PLUGIN 4.8 by Sir D.
 
Feature:
- Healthpoints und Armoranzeige Deines Gegners, nachdem er Dich gefraggt hat.
- Welche Waffe er benutzt hat.
- Wieviel Schaden Du ihm zugefügt hast.
- verschiedene Statistik-Anzeigen
 
NEU:
- HP- / und Statistik-Anzeigen werden nun ausschließlich per Menü angezeigt. Deswegen ist die Aktivierung von
  'amv_enable_beta "menu1"' in der adminmod.cfg zwingend erfordelich!
- Durch das Plugin 'sdal_allowsounds' kann der Client per Chateingabe '/stop' bzw. '/play' entscheiden, ob er
  die Anzeigen sehen möchte. Generell werden sie ihm immer angezeigt, wenn er nicht einmal '/stop' eingegeben hat.
  Nähere Angaben dazu im Plugin sdal_allowsounds. 
 
Benötigt:
- installiertes LogD mit mp_logdetail 3 (logd_block 58 um die Injure-Logs abzublocken!)
- amv_enable_menu "menu1" in der adminmod.cfg
- plugin_sdal_allowsounds (optional). Wenn nicht installiert, kann der Client nicht '/stop' eingeben, um diese Anzeigen
  für sich zu deaktivieren.
 
Befehle:
- hp_plugin 	0/1	:schaltet das Plugin aus/an
- hp_dead 	0/1	:schaltet die Anzeige direkt nach dem Tod an/aus
- hp_armor 	0/1	:schaltet die Anzeige der Armor an/aus
- hp_weapon 	0/1	:schaltet die Anzeige der Waffe an/aus
- hp_udid 	0/1	:schaltet die Anzeige der Schadenspunkte an/aus
 
vault.ini:
- HP_PLUGIN 0/1
- HP_DEAD 0/1
- HP_ARMOR 0/1
- HP_WEAPON 0/1
- HP_UDID 0/1
 
Änderungen zu Vorgängern:
--------------------------
4.8:	- Bugfix: Korrektes Löschen der Runden-Damage der Spieler
	- Bugfix: Ein neuer Spieler übernahm die Stats-Werte eines disconnecteten Spieler.
	- Änderung der Damage-Bewertung: 
	  Die verursachte Damage wird nun anhand der vorhandenen Spieler-HP berechnet
	  und nicht mehr an der Damage, die die Waffe insgesamt verursacht hat.
	  Beispiel: Wenn der gegnerische Spieler nur noch 17 HP hat, werden auch nur bei einem
	  Headshot diese 17 HP als Damage gutgeschrieben und nicht mehr der Wert,
	  der durch den Headshot mit dieser Waffe insgesamt hervorgerufen wurde.
4.7:	- Statistik: Bester Spieler der Runde und Map, PvP-Statistik.
4.6:	- Mit 'hp' kann man auch am Ende Runde das Statistik-Menü aufrufen.
	- Code-Veränderung der Waffen-Statistik
	- Headshot-Statistik
4.5: 	- Alles wird per Menü angezeigt. Darum kein Befehl für 'display' mehr nötig.
	- Mit 'myhits' ruft man seine eigene Schadens-Statistik auf.
	- Mit 'hits' ruft man die allg. Schadens-Statistik auf.
	- Mit 'weapon' ruft man die Waffen-Statistik auf.
	- Befehlsänderungen gegenüber den alten Versionen!
	- Änderung in neue Waffennamen und die neuen Waffen für CS 1.6 hinzugefügt.
	- Auf die Anzeige, wieviel Armor man dem Gegner abgezogen hat, wird verzichtet.
 
4.4: 	- Rechenfehler ausgemerzt. Danke an [FN] Rinde!
	- Wenn das Adminmod-Menü aktiviert ist, besteht die Möglichkeit mit der Chateingabe /hits den Spieler anzuzeigen,
  	  der den meisten Schaden an Spielern erzeugt hat.
	- Wenn das Adminmod-Menü aktiviert ist, besteht die Möglichkeit mit der Chateingabe /hitme alle Spieler anzuzeigen,
	  denen Du Schaden zugefügt hast. 
 
4.2/4.3:- Bugfixes
 
4.1: 	- Fix Waffennamen und Zeilenumbruch
	- neue Waffenerkennung
	- neue Vault.ini Werte
	- verbesserter Code
 
Vorraussetzung:
----------------------
Korrekt installiertes Logd, mp_logdetail 3 und vorhandene Logs. (log on)
Damit die Logs nicht zu groß werden, ist es ratsam, logd_block 58 ebenfalls
in die (listen)server.cfg einzutragen.
Zusätzlich wird amv_enable_beta "menu1" in der adminmod.cfg benötigt!!!!
 
Bei Problemen im www.adminmod.de Forum melden.
 
*/
 
#include <core> 
#include <console> 
#include <string> 
#include <admin> 
#include <adminlib>
 
new g_Version[] = "21.11.03_v4.8";
 
new Key[]="am_sound";
 
#define ACCESS_CONSOLE 131072
 
#define MAX_WEAPONS	26
/* Alte Waffennamen
new g_WeaponName[MAX_WEAPONS][MAX_NAME_LENGTH]	=	{{"usp"},{"glock18"},{"deagle"},{"mp5navy"},{"m4a1"},{"ak47"},{"awp"},{"aug"},{"sg552"},
							{"scout"},{"m249"},{"p90"},{"p228"},{"tmp"},{"mac10"},{"ump40"},{"fiveseven"},
							{"elite"},{"m3"},{"xm1014"},{"sg550"},{"g3sg1"},{"grenade"},{"knife"}};
 
new g_WeaponText[MAX_WEAPONS][MAX_TEXT_LENGTH]	=	{{"der H&K USP"},{"der Glock 18"},{"der Desert Eagle"},
							{"der MP5 Navy"},{"der M4A1"},{"der AK-47"},
							{"der AWP"},{"der Steyr Aug"},{"der Sig SG-552"},{"der Steyr Scout"},{"der FN M249 Para"},
							{"der FN P90"},{"der SIG P228"},{"der Steyr TMP"},{"der Ingram MAC-10"},
							{"der H&K UMP45"},{"der FN Five-Seven"},{"den Elite Dual Berettas"},
							{"der M3 Super90"},{"der XM1014"},{"der Sig SG-550 Sniper"},{"der H&K G3/SG-1"},
							{"der HE Granate"},{"dem Messer"}};
*/
 
new g_WeaponName[MAX_WEAPONS][]= {
    "glock18",
    "usp",
    "p228",
    "deagle",
    "elites",
    "fn57",
    "m3",
    "xm1014",
    "mac10",
    "mp5",
    "ump45",
    "p90",
    "tmp",
    "galil",
    "ak47",
    "scout",
    "sg552",
    "awp",
    "g3sg1",
    "famas",
    "aug",
    "m4a1",
    "sg550",
    "m249",
    "hegren",
    "knife"
};
 
new g_WeaponText[MAX_WEAPONS][]= {
    "der 9x19mm Sidearm",
    "der K&M .45 Tactical",
    "der 228 Compact",
    "der Night Hawk .50C",
    "den .40 Dual Elites",
    "der ES Five-Seven",
    "der Leone 12 Gauge Super",
    "der Leone YG1265 Auto Shotgun",
    "der Ingram MAC-10",
    "der K&M Sub-Machine Gun",
    "der K&M UMP45",
    "der ES C90",
    "der Schmidt Machine Pistol",
    "der IDF Defender",
    "der CV-47",
    "der Schmidt Scout",
    "der Krieg 552 Commando",
    "der Magnum Sniper Rifle",
    "der D3/AU-1 Semi-Auto Sniper Rifle",
    "der Clarion 5.56",
    "der Bullpup",
    "der Maverick M4A1 Carabine",
    "der Krieg 550 Commando",
    "der ES M249 Para",
    "der HE Grenade",
    "dem Messer"
};
 
/*Ausgetestete Damage-Werte der Waffen. Ausgehend vom maximaler Bodydamage. 
Jeder höhere Damage-Wert muss also ein Headshot sein. Werte sind aufgerundet, um wirklich sicher zu sein, 
dass es sich um einen Headshot handelt. Naja, sind eben Annäherungswerte.*/
/*Pistolen*/
#define DEAGLE		80
#define GLOCK		40
#define USP		40
#define ELITE		40
#define FIVESEVEN	40
#define P228		40
/*Shotguns, unmöglich mit Annäherung genau den Headshot zu definieren.*/
#define M3		200
#define XM1014		200
/*SMG*/
#define MP5		36
#define P90		40
#define TMP		36
#define MAC		40
#define UMP40		45
/*Rifles*/
#define GALLIL		45
#define DEFENDER	45
#define AUG		50
#define SG552		50
#define AWP		155
#define M4A1		50
#define AK47		50
#define SCOUT		95
#define SG550		70
#define G3SG1		70
/*MG*/
#define M249		50
#define HEGREN		100
#define KNIFE		100
 
 
new g_WeaponDamage[MAX_WEAPONS][MAX_NUMBER_LENGTH]= 	{{GLOCK},{USP},{P228},{DEAGLE},{ELITE},{FIVESEVEN},
							{M3},{XM1014},{MAC},{MP5},{UMP40},{P90},{TMP},{GALLIL},
							{AK47},{SCOUT},{SG552},{AWP},{G3SG1},{DEFENDER},{AUG},{M4A1},
							{SG550},{M249},{HEGREN},{KNIFE}};
 
new g_PlayerEnemy[MAX_PLAYERS][MAX_NAME_LENGTH];
new g_PlayerEnemyID[MAX_PLAYERS];
new g_PlayerEnemyHP[MAX_PLAYERS];
new g_PlayerEnemyArmor[MAX_PLAYERS];
new g_PlayerEnemyWeapon[MAX_PLAYERS];
new g_PlayerEnemyInjure[MAX_PLAYERS][MAX_PLAYERS];
new g_PlayerEnemyInjureTotal[MAX_PLAYERS][MAX_PLAYERS];
new g_PlayerHS[MAX_PLAYERS];
new g_PlayerHSMaxID;
new g_KillsByWeapon[MAX_WEAPONS];
new g_KillsMaxWeaponID;
new g_TotalKills;
new g_BestPlayerRound[MAX_PLAYERS];
new g_BestPlayerRoundID;
new g_BestPlayerMap[MAX_PLAYERS];
new g_BestPlayerMapID;
new g_PvPKill[MAX_PLAYERS][MAX_PLAYERS];
 
new g_round_end;
 
new g_plugin=1;
new g_display_after_dead=1;
new g_display_armor=1;
new g_display_weapon=1;
new g_display_udid=1;
 
new g_UserMenu[MAX_PLAYERS];
new g_UserSelectMenu[MAX_PLAYERS];
new g_UserMenuTime[MAX_PLAYERS];
 
forward allowsound(User[]);
forward display_victim(User[],UserID);
forward reset_array(UserID);
forward most_damage(User[],UserID);
forward more_statistic(User[],UserID);
forward most_used_weapon(User[],UserID);
 
 
public plugin_init(){
	new Menu[MAX_NAME_LENGTH];
	getstrvar("amv_enable_beta",Menu,MAX_NAME_LENGTH);
	if(strstrx(Menu,"menu1")==-1){
		plugin_registerinfo("HP Plugin","Disabled!^nMissing 'amv_enable_beta menu1' in adminmod.cfg",g_Version);
	}else{
		plugin_registerinfo("HP Plugin","Announces hp, armor and weapon of your enemy and the damage you did to him",g_Version);
		plugin_registercmd("hp","hp_setting",ACCESS_MAP,"hp: show plugin settings");
		plugin_registercmd("hp_plugin","hp_setting",ACCESS_MAP,"hp_plugin '0/1': Turns plugin off/on");
		plugin_registercmd("hp_dead","hp_setting",ACCESS_MAP,"hp_dead '0/1': Turns hp display after dead off/on");
		plugin_registercmd("hp_armor","hp_setting",ACCESS_MAP,"hp_armor '0/1': Turns armor display off/on");
		plugin_registercmd("hp_weapon","hp_setting",ACCESS_MAP,"hp_weapon '0/1': Turns weapon display off/on");
		plugin_registercmd("hp_udid","hp_setting",ACCESS_MAP,"hp_udid '0/1': Turns damage display off/on (Damage u did to your enemy)");
		plugin_registercmd("hp_kill","hp_kill",ACCESS_CONSOLE);
		plugin_registercmd("hp_injure","hp_injure",ACCESS_CONSOLE);
		plugin_registercmd("hp_reset","hp_reset",ACCESS_CONSOLE);
		plugin_registercmd("say","HandleSay",ACCESS_ALL,"say hp/hp?/?hp: hp of your enemy who kills u");
		plugin_registercmd("menuselect","HandleMenu",ACCESS_ALL);
		plugin_registercmd("radio1","SetMenuData",ACCESS_ALL);
		plugin_registercmd("radio2","SetMenuData",ACCESS_ALL);
		plugin_registercmd("radio3","SetMenuData",ACCESS_ALL);
		plugin_registercmd("buyequip","SetMenuData",ACCESS_ALL);
		plugin_registercmd("buy","SetMenuData",ACCESS_ALL);
		plugin_registercmd("chooseteam","SetMenuData",ACCESS_ALL);
		plugin_registercmd("showbriefing","SetMenuData",ACCESS_ALL);
 
		exec( "logd_reg 57 admin_command hp_kill" );
		exec( "logd_reg 58 admin_command hp_injure" ); 
		exec( "logd_reg 62 admin_command hp_reset" );  
 
		get_vaultnumdata("HP_PLUGIN",g_plugin);
		if(g_plugin==0){
			selfmessage("[HP] Plugin is disabled!");
		}			
		get_vaultnumdata("HP_DEAD",g_display_after_dead);
		if(g_display_after_dead==0){
			selfmessage("[HP] Display hp after dead is disabled!");
		}
		get_vaultnumdata("HP_ARMOR",g_display_armor);
		if(g_display_armor==0){
			selfmessage("[HP] Display armor is disabled!");
		}
		get_vaultnumdata("HP_WEAPON", g_display_weapon);
		if(g_display_weapon==0){
			selfmessage("[HP] Display weapon is disabled!");
		}
		get_vaultnumdata("HP_UDID",g_display_udid);
		if(g_display_udid==0){
			selfmessage("[HP] Display damage you did to your enemy is disabled!");
		}
	}	
	return PLUGIN_CONTINUE;
}
 
public hp_setting(HLCommand,HLData,HLUserName,UserIndex){
	new Data[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new Command[MAX_COMMAND_LENGTH];
	new i;
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
 
	if(strlen(Data)!=0){
		i=strtonum(Data);
		if(i>1 || i<0){
			i=1;
		}	
		strcpy(Command,Command[7],MAX_COMMAND_LENGTH);
		if(strcmp(Command,"plugin")==0){
			set_vaultnumdata("HP_PLUGIN",i);
			g_plugin=i;
		}else if(strcmp(Command,"dead")==0){
			set_vaultnumdata("HP_DEAD",i);
			g_display_after_dead=i;
		}else if(strcmp(Command,"armor")==0){
			set_vaultnumdata("HP_ARMOR",i);
			g_display_armor=i;
		}else if(strcmp(Command,"weapon")==0){
			set_vaultnumdata("HP_WEAPON",i);
			g_display_weapon=i;
		}else if(strcmp(Command,"udid")==0){
			set_vaultnumdata("HP_UDID",i);
			g_display_udid=i;
		}
	}
	selfmessage("");
	snprintf(Text,MAX_TEXT_LENGTH,"HP-PLUGIN (v.%s):",g_Version);
	selfmessage(Text);
	selfmessage("-----------------------------");
	snprintf(Text,MAX_TEXT_LENGTH,"* Plugin is set to %i",g_plugin);
	selfmessage(Text);
	snprintf(Text,MAX_TEXT_LENGTH,"* Display hp after dead is set to %i",g_display_after_dead);
	selfmessage(Text);
	snprintf(Text,MAX_TEXT_LENGTH,"* Display armor is set to %i",g_display_armor);
	selfmessage(Text);
	snprintf(Text,MAX_TEXT_LENGTH,"* Display weapon is set to %i",g_display_weapon);
	selfmessage(Text);
	snprintf(Text,MAX_TEXT_LENGTH,"* Display damage you did to your enemy is set to %i",g_display_udid);
	selfmessage(Text);
	selfmessage("");
	return PLUGIN_HANDLED;
}
 
allowsound(User[]){
	new Info[MAX_NUMBER_LENGTH];
	new iInfo;
	new Authid[MAX_AUTHID_LENGTH];
	get_userAuthID(User,Authid,MAX_AUTHID_LENGTH);
	if(strcmp(Authid,"BOT")!=0){
		get_userinfo(User,Key,Info,MAX_NUMBER_LENGTH);
		iInfo=strtonum(Info);
		if(strlen(Info)==0 || iInfo > 0){/*damit wird automatisch immer der Sound auf 1 gesetzt,wenn kein setinfo vorhanden, bis 'stop' eingegeben wird*/
			return 1;
		}
	}
	return 0;
}
 
public hp_kill(HLCommand,HLData,HLUserName,UserIndex){
	new Data[MAX_DATA_LENGTH];
	new Victim[MAX_NAME_LENGTH];
	new Weapon[MAX_NAME_LENGTH];
	new Attacker[MAX_NAME_LENGTH];
	new strAID[3];
	new strVID[3];
	new iAHealth;
	new iAArmor;
	new iAID;
	new iVID;
	new iATeam;
	new iVTeam;
	new i;
 
	convert_string(HLData,Data,MAX_DATA_LENGTH);
 
	strsplit(Data," ",strAID,3,strVID,3,Weapon,MAX_NAME_LENGTH);
 
	iAID=strtonum(strAID);
	iVID=strtonum(strVID);
 
	playerinfo(iAID,Attacker,MAX_NAME_LENGTH,_,_,iATeam);
	playerinfo(iVID,Victim,MAX_NAME_LENGTH,_,_,iVTeam);
 
	get_userHealth(Attacker, iAHealth);
	get_userArmor(Attacker, iAArmor);
 
	strcpy(g_PlayerEnemy[iVID][0],Attacker,MAX_NAME_LENGTH);
	g_PlayerEnemyHP[iVID]=iAHealth;
	g_PlayerEnemyArmor[iVID]=iAArmor;
	g_PlayerEnemyID[iVID]=iAID;
	g_TotalKills++;
	g_PvPKill[iAID][iVID] +=1;
	if(iATeam!=iVTeam){
		g_BestPlayerRound[iAID] +=1;
	}else{
		g_BestPlayerRound[iAID] -=1;
	}
	if(g_BestPlayerRound[g_BestPlayerRoundID]<g_BestPlayerRound[iAID]){
		g_BestPlayerRoundID=iAID;
	}
	for(i=0;i<MAX_WEAPONS;i++){
		if(strcmp(Weapon,g_WeaponName[i])==0){
			g_PlayerEnemyWeapon[iVID]=i;
			g_KillsByWeapon[i] += 1;
			if(g_KillsByWeapon[g_KillsMaxWeaponID]<g_KillsByWeapon[i]){
				g_KillsMaxWeaponID=i;
			}
			break;
		}
	}
 
	if(g_display_after_dead && allowsound(Victim)){
		display_victim(Victim,iVID);
	}
	return PLUGIN_CONTINUE;
}
 
public hp_injure(HLCommand,HLData,HLUserName,UserIndex){
	new Data[MAX_DATA_LENGTH];
	new Dummy[MAX_DATA_LENGTH];
	new strAID[3];
	new strVID[3];
	new sWeapon[MAX_NAME_LENGTH];
	new sHealth[4];
	new sDamage[4];
	new iVID;
	new iAID;
	new iDamage;
	new iHealth;
	new i;
 
	convert_string(HLData,Data,MAX_DATA_LENGTH);
 
	strsep(Data," ",strAID,3,strVID,3,sWeapon,MAX_NAME_LENGTH,Dummy,MAX_DATA_LENGTH);
	strsplit(Dummy,"#",sDamage,4,sDamage,4,sHealth,4,sHealth,4);
 
	iAID=strtonum(strAID);
	iVID=strtonum(strVID);
	iDamage=strtonum(sDamage);
	iHealth=strtonum(sHealth);
 
	if(iHealth<0){
		iDamage=iDamage+iHealth;
	}
	g_PlayerEnemyInjure[iAID][iVID]+=iDamage;
	g_PlayerEnemyInjure[iAID][0]+=iDamage;
	g_PlayerEnemyInjureTotal[iAID][0]+=iDamage;
 
	for(i=0;i<MAX_WEAPONS;i++){
		if(strcmp(sWeapon,g_WeaponName[i])==0 && iDamage >= g_WeaponDamage[i][0]){
			g_PlayerHS[iAID]+=1;
			if(g_PlayerHS[iAID]>g_PlayerHS[g_PlayerHSMaxID]){
				g_PlayerHSMaxID=iAID;
			}
		}
	}
	return PLUGIN_CONTINUE;
}
 
public hp_reset(HLCommand,HLData,HLUserName,UserIndex){
	new Data[MAX_NAME_LENGTH];
	new i;
	new j;
	new maxplayers=maxplayercount();
   	convert_string(HLData,Data,MAX_NAME_LENGTH); 
    	if(Data[0]=='G' || Data[8]=='R'){
		g_TotalKills=0;
		g_KillsMaxWeaponID=0;
		g_PlayerHSMaxID=0;
		g_BestPlayerMapID=0;
    		for(i=0;i<=maxplayers;i++){
    			g_PlayerEnemyInjureTotal[i][0]=0;
    			g_PlayerHS[i]=0;
    			g_BestPlayerMap[i]=0;
    			for(j=0;j<=maxplayers;j++){
    				g_PvPKill[i][j]=0;
    			}
    		}
    		for(i=0;i<=MAX_WEAPONS;i++){
    			g_KillsByWeapon[i]=0;
    		}			
    	}else if(Data[6]=='S'){
    		g_round_end=0;
    		g_BestPlayerRoundID=0;
		for(i=0;i<=maxplayers;i++){
			strinit(g_PlayerEnemy[i]);
			strinit(g_PlayerEnemyInjure[i]);
			g_PlayerEnemyID[i]=0;
			g_PlayerEnemyHP[i]=0;
			g_PlayerEnemyArmor[i]=0;
			g_PlayerEnemyWeapon[i]=0;
			g_UserMenu[i]=0;
			g_UserSelectMenu[i]=0;
			g_UserMenuTime[i]=0;
			g_BestPlayerRound[i]=0;
			for(j=0;j<=maxplayers;j++){
				strinit(g_PlayerEnemy[i][j]);
				strinit(g_PlayerEnemyInjure[i][j]);
			}
		}
	}else if(Data[6]=='E'){
		g_round_end=1;
	}
	return PLUGIN_CONTINUE;
}	
 
public HandleSay(HLCommand,HLData,HLUserName,UserIndex){
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new IsDead;
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (strcasestrx(Data, "hp")!=-1 || strcasestrx(Data, "myhits")!=-1 || strcasestrx(Data, "hits")!=-1 || strcasestrx(Data, "weapon")!=-1){
		if(g_plugin){
			if(playerinfo(UserIndex,User,MAX_NAME_LENGTH,_,_,_,IsDead)){
				if (strcasestrx(Data, "hp")!=-1){
					if(g_PlayerEnemyID[UserIndex]!=0 && IsDead == 1){
						display_victim(User,UserIndex);
					}else{
						display_statistik(User,UserIndex);
					}
				}else if (strcasestrx(Data, "myhits")!=-1){
					own_statistic(User,UserIndex);
				}else if (strcasestrx(Data, "hits")!=-1){
					most_damage(User,UserIndex);
				}else if (strcasestrx(Data, "weapon")!=-1){
					most_used_weapon(User,UserIndex);
				}
			}
		}
	}
	return PLUGIN_CONTINUE;
}
 
display_victim(User[],UserID){
	new Text[512];
	new Armor[MAX_TEXT_LENGTH];
	new Weapon[MAX_TEXT_LENGTH];
	new UDid[MAX_TEXT_LENGTH];
	if(g_display_armor){
		snprintf(Armor,MAX_TEXT_LENGTH,"und %i Armor.",g_PlayerEnemyArmor[UserID]);
	}
	if(g_display_weapon){
		snprintf(Weapon,MAX_TEXT_LENGTH,"^n^nEr traf Dich mit %s!",g_WeaponText[g_PlayerEnemyWeapon[UserID]]);
	}
	if(g_display_udid){
		snprintf(UDid,MAX_TEXT_LENGTH,"^n^nDu hast ihm %i Schaden zugefuegt!",g_PlayerEnemyInjure[UserID][g_PlayerEnemyID[UserID]]);
	}
	snprintf(Text,MAX_TEXT_LENGTH,"\r%s^n^n\what noch %i HP %s%s%s^n^n^n\y1. Weiter -- 0. Cancel",g_PlayerEnemy[UserID],g_PlayerEnemyHP[UserID],Armor,Weapon,UDid);
	g_UserMenu[UserID]=1;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
display_statistik(User[],UserID){
	new Text[512];
	new IsDead;
	new a;
	snprintf(Text,512,"\yHP-STATISTIK:^n");
	playerinfo(UserID,User,MAX_NAME_LENGTH,_,_,_,IsDead);
	if(IsDead || g_round_end){
		snprintf(Text,512,"%s^n\w1. Eigene Damage",Text);
		a=1;
	}
	snprintf(Text,512,"%s^n\w2. allg. Damage^n3. Waffen^n4. Headshots^n5. Rundenpunkte^n6. Mappunkte^n7. PvP-Statistik",Text);
	a=a+126;
	if(g_PlayerEnemyID[UserID]!=0 && IsDead){
		strcat(Text,"^n9. HP Deines Gegners",MAX_TEXT_LENGTH);
		a=a+256;
	}
	strcat(Text,"^n^n\y0. Cancel",MAX_TEXT_LENGTH);
	a=a+512;
	g_UserMenu[UserID]=2;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,a,10);
}
 
own_statistic(User[],UserID){
	new Text[512];
	new Enemy[MAX_NAME_LENGTH];
	new i;
	new j;
	new x;
	new maxplayers=maxplayercount();
	new maxdam;
 
	for(i=1;i<=maxplayers;i++){
		if(g_PlayerEnemyInjure[UserID][i]!=0){
			if(g_PlayerEnemyInjure[UserID][i]>maxdam){
				maxdam=g_PlayerEnemyInjure[UserID][i];
			}
		}
	}
 
	snprintf(Text,MAX_TEXT_LENGTH,"\ySchadens-Statistik von %s:^n",User);
	for(i=maxdam;i>0;i--){
		if(x==5){
			break;
		}
		for(j=1;j<=maxplayers;j++){
			if(x==5){
				break;
			}
			if(g_PlayerEnemyInjure[UserID][j]!=0){
				if(g_PlayerEnemyInjure[UserID][j]==i){
					if(playerinfo(j,Enemy,MAX_NAME_LENGTH)){
						x++;
						snprintf(Text,MAX_TEXT_LENGTH,"%s^n\w%i -- %s",Text,g_PlayerEnemyInjure[UserID][j],Enemy);
					}
				}
			}
		}	
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=3;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
most_damage(User[],UserID){
	new Text[512];
	new maxplayers=maxplayercount();
	new Name[MAX_NAME_LENGTH];
	new Name2[MAX_NAME_LENGTH];
	new i;
	new round_dam_playeruid;
	new round_damage;
	new map_dam_playeruid;
	new map_damage;
	snprintf(Text,512,"\yDie hoechste Damage verursachte:");
	for(i=1;i<=maxplayers;i++){
		if(g_PlayerEnemyInjure[i][0]!=0){
			if(g_PlayerEnemyInjure[i][0]>round_damage){
				round_damage=g_PlayerEnemyInjure[i][0];
				round_dam_playeruid=i;
			}
		}
	}
 
	for(i=1;i<=maxplayers;i++){
		if(g_PlayerEnemyInjureTotal[i][0]!=0){
			if(g_PlayerEnemyInjureTotal[i][0]>map_damage){
				map_damage=g_PlayerEnemyInjureTotal[i][0];
				map_dam_playeruid=i;
			}
		}
	}
 
	if(round_dam_playeruid!=0){
		playerinfo(round_dam_playeruid,Name,MAX_NAME_LENGTH);
		snprintf(Text,512,"%s^n^nIn dieser Runde:^n^n\w%s mit %i HP",Text,Name,round_damage);
	}
	if(map_dam_playeruid!=0){
		playerinfo(map_dam_playeruid,Name2,MAX_NAME_LENGTH);
		snprintf(Text,512,"%s^n^n\yInnerhalb der Mapzeit:^n^n\w%s mit %i HP",Text,Name2,map_damage);
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=4;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
most_used_weapon(User[],UserID){
	new Text[512];
	new i;
	new j;
	new x;
	snprintf(Text,MAX_TEXT_LENGTH,"\yMeist benutzte Waffen:^n");
	for(i=g_KillsByWeapon[g_KillsMaxWeaponID];i>0;i--){
		if(x==5){
			break;
		}
		for(j=0;j<MAX_WEAPONS;j++){
			if(x==5){
				break;
			}
			if(g_KillsByWeapon[j]!=0){
				if(g_KillsByWeapon[j]==i){
					x++;
					snprintf(Text,MAX_TEXT_LENGTH,"%s^n\w%i -- %s",Text,g_KillsByWeapon[j],g_WeaponText[j][3]);
				}
			}
		}	
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=5;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
most_headshots(User[],UserID){
	new Text[512];
	new maxplayers=maxplayercount();
	new Player[MAX_NAME_LENGTH];
	new i;
	new j;
	new x;
	snprintf(Text,MAX_TEXT_LENGTH,"\ySpieler mit den meisten Headshots:^n");
	for(i=g_PlayerHS[g_PlayerHSMaxID];i>0;i--){
		if(x==5){
			break;
		}
		for(j=1;j<=maxplayers;j++){
			if(x==5){
				break;
			}
			if(g_PlayerHS[j]!=0){
				if(g_PlayerHS[j]==i){
					x++;
					playerinfo(j,Player,MAX_NAME_LENGTH);
					snprintf(Text,MAX_TEXT_LENGTH,"%s^n\w%i -- %s",Text,g_PlayerHS[j],Player);
				}
			}
		}	
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=4;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
best_playerround(User[],UserID){
	new Text[512];
	new maxplayers=maxplayercount();
	new Player[MAX_NAME_LENGTH];
	new i;
	new j;
	new x;
	snprintf(Text,MAX_TEXT_LENGTH,"\yDie besten Spieler der Runde:^n");
	for(i=g_BestPlayerRound[g_BestPlayerRoundID];i>0;i--){
		if(x==5){
			break;
		}
		for(j=1;j<=maxplayers;j++){
			if(x==5){
				break;
			}
			if(g_BestPlayerRound[j]!=0){
				if(g_BestPlayerRound[j]==i){
					x++;
					playerinfo(j,Player,MAX_NAME_LENGTH);
					snprintf(Text,MAX_TEXT_LENGTH,"%s^n\w%i -- %s",Text,g_BestPlayerRound[j],Player);
				}
			}
		}	
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=5;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
best_playermap(User[],UserID){
	new Text[512];
	new maxplayers=maxplayercount();
	new Player[MAX_NAME_LENGTH];
	new PlayerPoints[MAX_PLAYERS];
	new mostfrags;
	new i;
	new j;
	new x;
	snprintf(Text,MAX_TEXT_LENGTH,"\yDie besten Spieler der Map:^n");
	for(j=1;j<=maxplayers;j++){
		if(playerinfo(j,Player,MAX_NAME_LENGTH)){
			get_userFrags(Player,PlayerPoints[j]);
			if(PlayerPoints[j]>mostfrags){
				mostfrags=PlayerPoints[j];
			}
		}
	}
 
	for(i=mostfrags;i>0;i--){
		if(x==5){
			break;
		}
		for(j=1;j<=maxplayers;j++){
			if(x==5){
				break;
			}
			if(PlayerPoints[j]!=0){
				if(PlayerPoints[j]==i){
					x++;
					if(playerinfo(j,Player,MAX_NAME_LENGTH)){
						snprintf(Text,MAX_TEXT_LENGTH,"%s^n\w%i -- %s",Text,PlayerPoints[j],Player);
					}
				}
			}
		}	
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=6;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
pvp_statistic(User[],UserID){
	new Text[512];
	new maxplayers=maxplayercount();
	new Player[MAX_NAME_LENGTH];
	new j;
	snprintf(Text,MAX_TEXT_LENGTH,"\y%s gegen:^n",User);
	for(j=1;j<=maxplayers;j++){
		if(g_PvPKill[UserID][j]!=0 || g_PvPKill[j][UserID]!=0){
			if(playerinfo(j,Player,MAX_NAME_LENGTH)){
				snprintf(Text,MAX_TEXT_LENGTH,"%s^n\w%i:%i -- %s",Text,g_PvPKill[UserID][j],g_PvPKill[j][UserID],Player);
			}
		}
	}
	strcat(Text,"^n^n\y1. Zurueck",MAX_TEXT_LENGTH);
	g_UserMenu[UserID]=7;
	g_UserMenuTime[UserID]=systemtime();
	menu(User,Text,1023,10);
}
 
public HandleMenu(HLCommand,HLData,HLUserName,UserIndex){
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if(g_UserMenu[UserIndex]!=0){
		if((systemtime()-g_UserMenuTime[UserIndex])<=10){
			g_UserSelectMenu[UserIndex]=strtonum(Data);
			if(g_UserMenu[UserIndex]==1){
				if(g_UserSelectMenu[UserIndex]==1){
					display_statistik(User,UserIndex);
					return PLUGIN_HANDLED;
				}else{
					reset_array(UserIndex);
					return PLUGIN_CONTINUE;
				}
			}else if(g_UserMenu[UserIndex]==2){
				if(g_UserSelectMenu[UserIndex]==1){
					own_statistic(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if (g_UserSelectMenu[UserIndex]==2){
					most_damage(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if (g_UserSelectMenu[UserIndex]==3){
					most_used_weapon(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if (g_UserSelectMenu[UserIndex]==4){
					most_headshots(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if (g_UserSelectMenu[UserIndex]==5){
					best_playerround(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if (g_UserSelectMenu[UserIndex]==6){
					best_playermap(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if (g_UserSelectMenu[UserIndex]==7){
					pvp_statistic(User,UserIndex);
					return PLUGIN_HANDLED;
				}else if(g_UserSelectMenu[UserIndex]==9 && g_PlayerEnemyID[UserIndex]!=0){
					display_victim(User,UserIndex);
					return PLUGIN_HANDLED;
				}else{
					reset_array(UserIndex);
					return PLUGIN_CONTINUE;
				}
			}else{
				if(g_UserSelectMenu[UserIndex]==1){
					display_statistik(User,UserIndex);
					return PLUGIN_HANDLED;
				}else{
					reset_array(UserIndex);
					return PLUGIN_CONTINUE;
				}
			}
		}else{
			reset_array(UserIndex);
			return PLUGIN_CONTINUE;
		}
	}
	return PLUGIN_CONTINUE;
}
 
public SetMenuData(HLCommand,HLData,HLUserName,UserIndex){
	if(g_UserMenu[UserIndex]==1){
		reset_array(UserIndex);
	}
	return PLUGIN_CONTINUE;
}
 
reset_array(UserID){
	g_UserMenu[UserID]=0;
	g_UserSelectMenu[UserID]=0;
	g_UserMenuTime[UserID]=0;
}
 
public plugin_connect(HLUserName,HLIP, UserIndex){
	new i;
	new maxplayers=maxplayercount();
	reset_array(UserIndex);
	for(i=1;i<=maxplayers;i++){
		g_PlayerEnemyInjureTotal[UserIndex][i]=0;
		g_PvPKill[UserIndex][i]=0;
	}
	g_PlayerEnemyInjureTotal[UserIndex][0]=0;
	g_PlayerHS[UserIndex]=0;
	return PLUGIN_CONTINUE;
}
 
public plugin_disconnect(HLUserName,UserIndex){
	new i;
	new maxplayers=maxplayercount();
	new most;
	reset_array(UserIndex);
 
	for(i=1;i<=maxplayers;i++){
		g_PlayerEnemyInjureTotal[UserIndex][i]=0;
		g_PvPKill[UserIndex][i]=0;
 
	}
	if(g_PlayerHSMaxID==UserIndex){
		for(i=1;i<=maxplayers && g_PlayerHSMaxID!=i;i++){
			if(g_PlayerHS[i]!=0){
				if(g_PlayerHS[i]>most){
					most=g_PlayerHS[i];
					g_PlayerHSMaxID=i;
				}
			}
		}
	}
	most=0;
	if(g_BestPlayerRoundID==UserIndex){
		for(i=1;i<=maxplayers && g_BestPlayerRoundID!=i;i++){
			if(g_BestPlayerRound[i]!=0){
				if(g_BestPlayerRound[i]>most){
					most=g_BestPlayerRound[i];
					g_BestPlayerRoundID=i;
				}
			}
		}
	}
	most=0;
	if(g_BestPlayerMapID==UserIndex){
		for(i=1;i<=maxplayers && g_BestPlayerMapID!=i;i++){
			if(g_BestPlayerMap[i]!=0){
				if(g_BestPlayerMap[i]>most){
					most=g_BestPlayerMap[i];
					g_BestPlayerMapID=i;
				}
			}
		}
	}
	/*Zur Sicherheit nochmal wie im connect*/
	for(i=1;i<=maxplayers;i++){
		g_PlayerEnemyInjureTotal[UserIndex][i]=0;
		g_PvPKill[UserIndex][i]=0;
	}
	g_PlayerEnemyInjureTotal[UserIndex][0]=0;
	g_PlayerHS[UserIndex]=0;
	return PLUGIN_CONTINUE;
}
 
/*
quicksort (Array[],lo,hi){
	new i=lo;
	new j=hi;
	new x=Array[(lo+hi)/2];
 
	//  Aufteilung
	while (i<=j)
	{    
	    while (Array[i]<x){
	    	i++; 
	    }
	    while (Array[j]>x){
	    	j--;
	    }
	    if (i<=j){
	        new t=Array[i];
        	Array[i]=Array[j];
        	Array[j]=t;
	        i++; 
	        j--;
	    }
	}
 
	// Rekursion
	if (lo<j){
		quicksort(Array,lo, j);
	}
	if (i<hi){
		quicksort(Array,i, hi);
	}
}*/