#include <amxmodx>
#include <zombieplague>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
#include <PrintChatColor>

#define PLUGIN "Menu Giver Money"
#define VERSION "1.3"
#define AUTHOR "heka"

#define VIP_FLAG ADMIN_LEVEL_H
#define ADMIN_FLAG ADMIN_BAN

new g_giver_block[33], g_giver_block2[33], g_round

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

	register_event("HLTV", "ev_roundstart", "a", "1=0", "2=0")
	
	register_clcmd("say /menu_giver", "menu_giver")

	g_round = -1
}

public ev_roundstart()
{
	new i

	for(i=0;i<=32;i++)
	{
		if(g_giver_block[i]) 
		{
			g_giver_block[i]--
		}
	}

	for(i=0;i<=32;i++)
	{
		if(g_giver_block2[i]) 
		{
			g_giver_block2[i]--
		}
	}

	g_round++
}

public menu_giver(id)
{
	if(!(get_user_flags(id) & VIP_FLAG))
	{
		return;
	}

	if(!is_user_alive(id))
	{
		return;
	}

	new giver = menu_create("\rVipMenu:", "giver_handled")

	if(is_user_alive(id) && g_giver_block[id])
		menu_additem(giver, "\dВзять 20 Ammo (VIP)", "1", 0)
	else
		menu_additem(giver, "\wВзять 20 \rAmmo \y(\rVIP\y)", "1", 0)

	if(is_user_alive(id) && g_giver_block2[id])
		menu_additem(giver, "\dВзять 40 Ammo (ADMIN)", "2", 0)
	else
		menu_additem(giver, "\wВзять 40 \rAmmo \y(\rADMIN\y)", "2", 0)

	menu_setprop(giver, MPROP_EXIT, MEXIT_ALL)

	menu_display(id, giver, 0)
}

public giver_handled(id, giver, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(giver)
		
		return PLUGIN_HANDLED
	}

	new s_Data[6], s_Name[64], i_Access, i_Callback

	menu_item_getinfo(giver, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(s_Name), i_Callback)

	new i_Key = str_to_num(s_Data)

	switch(i_Key)
	{
		case 1:
		{
			if(!(get_user_flags(id) & VIP_FLAG))
			{
				PrintChatColor(id,print_chat, "!g[ZP]!yУ тебя нет прав на это!!!")
				return PLUGIN_HANDLED
			}
			if(g_giver_block[id])
			{
				PrintChatColor(id,print_chat, "!g[ZP]!yБрать !tAmmo !yможно только раз в !g%d !yраунда", g_giver_block[id])
				return PLUGIN_HANDLED
			}

			g_giver_block[id] = 3

			PrintChatColor(id,print_chat, "!g[ZP]!yТы взял себе !g20 !tAmmo")
			zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + 20)
			menu_destroy(giver)
			return PLUGIN_HANDLED
		}
		case 2:
		{
			if(!(get_user_flags(id) & ADMIN_FLAG))
			{
				PrintChatColor(id,print_chat, "!g[ZP]!yУ тебя нет прав на это!!!")
				return PLUGIN_HANDLED
			}
			if(g_giver_block2[id])
			{
				PrintChatColor(id,print_chat, "!g[ZP]!yБрать !tAmmo !yможно только раз в !g%d !yраунда", g_giver_block2[id])
				return PLUGIN_HANDLED
			}
			
			g_giver_block2[id] = 4

			PrintChatColor(id,print_chat, "!g[ZP]!yТы взял себе !g40 !tAmmo")
			zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + 40)
			menu_destroy(giver)
			return PLUGIN_HANDLED
		}
	}
	menu_destroy(giver)
	return PLUGIN_HANDLED
}