/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <hamsandwich>
#include <zombieplague>

native zp_cs_get_user_money(id)
native zp_cs_set_user_money(id,value)

#define PLUGIN "[ZP]Addon: HP&DMG System"
#define VERSION "0.7"
#define AUTHOR "heka"

#define MAX_HEALTH_LEVEL 10
#define MAX_DAMAGE_LEVEL 10

#define HEALTH_LEVEL_COST 3000
#define DAMAGE_LEVEL_COST 3000

new
	g_Levels_Menu,
	buffer[512],
	g_Health_Level[33],
	g_Damage_Level[33]


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR);

	RegisterHam(Ham_TakeDamage, "player", "CPlayer__TakeDamage")
	
	register_clcmd("say /levels_menu","Level_Menu");
}

public client_putinserver(iPlayer){
	g_Health_Level[iPlayer] = 0
}

public Level_Menu(iPlayer){
	if(g_Health_Level[iPlayer] >= 10 && g_Damage_Level[iPlayer] >= 10){
		formatex(buffer, charsmax(buffer), "Health Level Max^nDamage Level Max");
	}else
	if(g_Health_Level[iPlayer] >= 10 && g_Damage_Level[iPlayer] < 10){
		formatex(buffer, charsmax(buffer), "Health Level Max^nDamage Level %d", g_Damage_Level[iPlayer]);
	}else
	if(g_Health_Level[iPlayer] < 10 && g_Damage_Level[iPlayer] >= 10){
		formatex(buffer, charsmax(buffer), "Health Level %d^nDamage Level Max", g_Health_Level[iPlayer]);
	}else{
		formatex(buffer, charsmax(buffer), "Health Level %d^nDamage Level %d", g_Health_Level[iPlayer], g_Damage_Level[iPlayer]);
	}

	g_Levels_Menu = menu_create(buffer, "Level_Menu_Handler");

	if(!is_user_alive(iPlayer)){
		menu_additem(g_Levels_Menu, "\dUpgrade HP Level\r [Only for Alive Players]", "1");
	}
	else if(g_Health_Level[iPlayer] >= MAX_HEALTH_LEVEL){
		menu_additem(g_Levels_Menu, "\dUpgrade HP Level\r [Max Health Level]", "1");
	}
	else if(zp_cs_get_user_money(iPlayer) < HEALTH_LEVEL_COST){
		menu_additem(g_Levels_Menu, "\dUpgrade Health Level\r [Not enough money]", "2");
	}else{
		menu_additem(g_Levels_Menu, "Upgrade HP Level \r[3000$]", "1");
	}
	if(!is_user_alive(iPlayer)){
		menu_additem(g_Levels_Menu, "\dUpgrade Damage Level\r [Only for Alive Players]", "2");
	}
	else if(g_Damage_Level[iPlayer] >= MAX_DAMAGE_LEVEL){
		menu_additem(g_Levels_Menu, "\dUpgrade Damage Level\r [Max Damage Level]", "2");
	}
	else if(zp_cs_get_user_money(iPlayer) < DAMAGE_LEVEL_COST){
		menu_additem(g_Levels_Menu, "\dUpgrade Damage Level\r [Not enough money]", "2");
	}else{
		menu_additem(g_Levels_Menu, "Upgrade Damage Level \r[3000$]", "2");
	}	
	
	menu_setprop(g_Levels_Menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(iPlayer, g_Levels_Menu, 0);
}

public Level_Menu_Handler(iPlayer, iMenu, iItem){
	if(iItem == MENU_EXIT) menu_destroy(iMenu);

	new data[6], iName[64], access, callback, iKey

	menu_item_getinfo(iMenu, iItem, access, data, 5, iName, 63, callback)

	iKey = str_to_num(data)

	switch(iKey){
		case 1:{
			if(g_Health_Level[iPlayer] >= MAX_HEALTH_LEVEL){
				client_print(iPlayer, print_center, "Max Health Level")

				return PLUGIN_HANDLED;
			}else if(!is_user_alive(iPlayer)){
				client_print(iPlayer, print_center, "Only for Alive Players")

				return PLUGIN_HANDLED;
			}else if(zp_cs_get_user_money(iPlayer) < HEALTH_LEVEL_COST){
				client_print(iPlayer, print_center, "Not enough money")

				return PLUGIN_HANDLED;
			}else{
				if (!zp_get_user_zombie(iPlayer) && !zp_get_user_survivor(iPlayer)) set_user_health(iPlayer, get_user_health(iPlayer) + 20)

				g_Health_Level[iPlayer]++
				client_print(iPlayer, print_center, "Health Level Upgrade to %d", g_Health_Level[iPlayer])

				zp_cs_set_user_money(iPlayer, zp_cs_get_user_money(iPlayer) - HEALTH_LEVEL_COST)
			}
		}
		case 2:{
			if(g_Damage_Level[iPlayer] >= MAX_HEALTH_LEVEL){
				client_print(iPlayer, print_center, "Max Damage Level")

				return PLUGIN_HANDLED;
			}else if(!is_user_alive(iPlayer)){
				client_print(iPlayer, print_center, "Only for Alive Players")

				return PLUGIN_HANDLED;
			}else if(zp_cs_get_user_money(iPlayer) < DAMAGE_LEVEL_COST){
				client_print(iPlayer, print_center, "Not enough money")

				return PLUGIN_HANDLED;
			}else{
				g_Damage_Level[iPlayer]++
				client_print(iPlayer, print_center, "Damage Level Upgrade to %d", g_Damage_Level[iPlayer])

				zp_cs_set_user_money(iPlayer, zp_cs_get_user_money(iPlayer) - DAMAGE_LEVEL_COST)
			}
		}
	}
	return PLUGIN_HANDLED;
}

public CPlayer__TakeDamage(iPlayer, iInflector, iAttacker, Float:iDamage, damagebits)
{
	if (iPlayer == iAttacker) return;
	if (!is_user_connected(iAttacker)) return;
	if (zp_get_user_zombie(iAttacker)) return;
	
	if (!zp_get_user_survivor(iAttacker)) SetHamParamFloat(4, iDamage + g_Damage_Level[iAttacker] * 20.0);
}

public zp_user_humanized_post(iPlayer){
	if (zp_get_user_survivor(iPlayer)) return;

	set_user_health(iPlayer, get_user_health(iPlayer) + g_Health_Level[iPlayer] * 20)
}