/*****************************************************
* [ZP]Extended Give Ammo 2.0                         *
* Copyright 2010 [ru]In1ernal Error		     *
* 						     *
******************************************************
*						     *
*                                                    *
******************************************************
*						     *
* Usage:                                             *
*						     *
* zp_ammo_e - open ammo packs menu		     *
* zp_ammo_e_self <amount> - give ammo to yourself    *
*						     *
* Enjoy!					     *
*****************************************************/



#include <amxmisc>
#include <amxmodx>
#include <zombieplague>

#define PLUGIN "[ZP] Addon: Extended Give Ammo"
#define VERSION "2.0"
#define AUTHOR "[ru]In1ernal Error"

new  cur_add_amount = 10;//g_msgSayText,

public plugin_init() {

	//register_cvar("zp_ammo_ex", VERSION, FCVAR_SERVER|FCVAR_SPONLY);

	register_plugin(PLUGIN, VERSION, AUTHOR);
	register_dictionary("zp_addon_ammo_manager.txt");
	register_concmd("zp_ammo_e", "menu_init",ADMIN_LEVEL_A, "");
	register_concmd("zp_ammo_e_self", "give_ammo_e_self",ADMIN_LEVEL_A, " - zp_ammo_e_self <amount>");	
	register_clcmd("say /ammo", "menu_init",ADMIN_LEVEL_A, "");	
	register_clcmd("say_team /ammo", "menu_init",ADMIN_LEVEL_A, "");		

	register_concmd("say /ammome", "give_ammo_e_self",ADMIN_LEVEL_A, " - zp_ammo_e_self <amount>");
	register_concmd("say_team /ammome", "give_ammo_e_self",ADMIN_LEVEL_A, " - zp_ammo_e_self <amount>");	
	
	
	//g_msgSayText = get_user_msgid("SayText");
}



public menu_init(id){
	new MenuName[64]
	format(MenuName, 63, "\r%L", id, "AM")
	
	new menu = menu_create(MenuName, "menu_handler");
	
	new players[32], inum, tempid;

	get_players(players, inum);

	new nomer[10], name[32];
 
	switch(cur_add_amount){
	
		case 10:
		{
			menu_additem(menu, "\w10 ammo", "33", 0);
		}

		case 100:
		{
			menu_additem(menu, "\w100 ammo", "34", 0);
		}

		case 1000:
		{
			menu_additem(menu, "\w1000 ammo", "35", 0);
		}
	
	}

	//menu_additem(menu, "", "36", 0);
	
	for ( new i; i<inum; i++)
	{		
		tempid = players[i];
		get_user_name(tempid, name, 31);
		num_to_str(tempid, nomer, 9);
		menu_additem(menu, name, nomer, ADMIN_LEVEL_A);
	}

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	
	menu_display(id, menu, 0);
}

public menu_handler(id, menu, item){
	if ( item == MENU_EXIT )
	{
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
		
	new data[6], iName[64];
	new access, callback;

	menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback);

	new tempid = str_to_num(data);

	switch(tempid)
	{
		case 33:
		{
			cur_add_amount = 100;
			//client_printcolor(id, "/g[ZP][AMMO] /y%L /t%i /y%L", id, "CHANGED", cur_add_amount, id, "AMMO");
			menu_destroy(menu);
			menu_init(id);

		}
		case 34:
		{
			cur_add_amount = 1000;
			//client_printcolor(id, "/g[ZP][AMMO] /y%L /t%i /y%L", id, "CHANGED", cur_add_amount, id, "AMMO");
			menu_destroy(menu);
			menu_init(id);

		}
		case 35:
		{
			cur_add_amount = 10;
			//client_printcolor(id, "/g[ZP][AMMO] /y%L /t%i /y%L", id, "CHANGED", cur_add_amount, id, "AMMO");
			menu_destroy(menu);
			menu_init(id);
		}
	/*	case 36:
			{
				menu_destroy(menu);
				menu_init(id);

			}*/
		default:
		{
			
			new Nick[32];
			get_user_name(tempid, Nick, 31);		
		
			if(is_user_connected(tempid))
			{
				give_ammo_e(tempid, cur_add_amount);

				
				new AdminNick[32];
				get_user_name(id, AdminNick, 31);			
				
				client_print_color(id,print_team_default, "^4[ZP][AMMO] %s^1%L ^4%i ^1%L!", Nick, id, "WAS_G", cur_add_amount, id, "AMMO")
				
				if (tempid != id)	client_print_color(tempid,print_team_default, "^4[ZP][AMMO] %s ^1%L ^4%i ^1%L!", AdminNick, tempid, "WAS_YOU", cur_add_amount, tempid, "AMMO")			
				menu_destroy(menu);
				menu_init(id);			
			
			} 
			else 
			{
				client_print_color(id,print_team_default, "^4[ZP][AMMO] %s^1%L!", Nick, "NOTONSERVER")

				menu_destroy(menu);
				menu_init(id);
			}
		}
	}
	return PLUGIN_HANDLED;
}


public give_ammo_e (id, ammo){
	
	new user_ammo = zp_get_user_ammo_packs(id) + ammo;
	
	zp_set_user_ammo_packs ( id, max ( 1, user_ammo) );
	
	return PLUGIN_HANDLED;
}

public give_ammo_e_self(id, level, cid){
	if ( !cmd_access ( id, level, cid, 2 ) ) 
	{
		return PLUGIN_HANDLED;
	}

	new amount[5];

	read_argv ( 1, amount, charsmax(amount));

	give_ammo_e( id, str_to_num(amount));

	return PLUGIN_HANDLED;
}

