#include <amxmodx>
#include <fakemeta>

#define OFFSET_MONEY 115
#define OFFSET_LINUX 5

#define MAP ADMIN_MAP
#define SLAY ADMIN_SLAY
#define CHAT ADMIN_CHAT
#define BAN ADMIN_BAN
#define KICK ADMIN_KICK
#define VOTE ADMIN_VOTE

new PLUGIN [] = "Buy Access"
new VERSION [] = "1.1"
new AUTHOR [] = "M1R0n,M'"

new bool:g_Bought[33];

new MenuBuy;

new g_Status;

new g_MapCost;
new g_BanCost;
new g_ChatCost;
new g_KickCost;
new g_SlayCost;
new g_VoteCost;

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR);

	register_clcmd("say /buyp",	"show_buymenu");
	register_clcmd("say buyp",	"show_buymenu");
	register_clcmd("say_team /buyp","show_buymenu");
	register_clcmd("say_team buyp",	"show_buymenu");

	MenuBuy = register_menuid("Access Shop");
	register_menucmd(MenuBuy, 1023, "pshop");

	register_dictionary("buyaccess.txt");

	g_Status = register_cvar( "amx_buy_access", "1" );

        g_MapCost = register_cvar( "amx_buy_map", "6000" );
	g_BanCost = register_cvar( "amx_buy_ban", "10000" );
	g_ChatCost = register_cvar( "amx_buy_chat", "5000" );
	g_KickCost = register_cvar( "amx_buy_kick", "9000" );
	g_SlayCost = register_cvar( "amx_buy_slay", "8000" );
	g_VoteCost = register_cvar( "amx_buy_vote", "7000" );

	
}

public show_buymenu(id) 
{
	if(get_pcvar_num(g_Status) == 1) 
	{
		new iBuffer[512], iLen;

		iLen = formatex(iBuffer, 511, "\w%L^n", id, "MENU_TITLE");
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r1\y. \w%L \y- \r%d$^n", id, "MENU_MAP", get_pcvar_num(g_MapCost));
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r2\y. \w%L \y- \r%d$^n", id, "MENU_BAN", get_pcvar_num(g_BanCost));
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r3\y. \w%L \y- \r%d$^n", id, "MENU_CHAT", get_pcvar_num(g_ChatCost));
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r4\y. \w%L \y- \r%d$^n", id, "MENU_KICK", get_pcvar_num(g_KickCost));
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r5\y. \w%L \y- \r%d$^n", id, "MENU_SLAY", get_pcvar_num(g_SlayCost));
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r6\y. \w%L \y- \r%d$^n", id, "MENU_VOTE", get_pcvar_num(g_VoteCost));
		iLen += formatex(iBuffer[iLen], 511-iLen, "\r0\y. \w%L", id, "MENU_EXIT");

		new iKeys = ( 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<< 8 | 1<<9 );
		show_menu(id, iKeys, iBuffer, -1, "Access Shop"); 
	} 
	else
		client_print(id, print_chat, "%L", id, "BUYOFF");
	return PLUGIN_HANDLED;
}

public pshop(id,key) 
{
	switch(key) 
	{
		case 0: 
		{

			if (g_Bought[id])
                	        return;

			new money = fm_get_user_money(id);
			new costa = get_pcvar_num(g_MapCost);
	
			if( money >= costa ) 
			{
				set_user_flags(id, get_user_flags(id) | MAP);
				fm_set_user_money(id, money - costa );
				client_print(id, print_chat, "%L", id, "BUY_MAP");
 				g_Bought[id] = true
			} 
			else 
			{
				client_print(id, print_chat, "%L", id, "NOMONEY");
			}
		}
		case 1:
		{



			new money = fm_get_user_money(id);
			new costa = get_pcvar_num(g_BanCost);
	
			if( money >= costa ) 
			{
				set_user_flags(id, get_user_flags(id) | BAN);
				fm_set_user_money(id, money - costa );
				client_print(id, print_chat, "%L", id, "BUY_BAN");
				g_Bought[id] = true
			} 
			else 
			{
				client_print(id, print_chat, "%L", id, "NOMONEY");
			}
		}
		case 2:
		{


			new money = fm_get_user_money(id);
			new costa = get_pcvar_num(g_ChatCost);
	
			if( money >= costa ) 
			{
				set_user_flags(id, get_user_flags(id) | CHAT);
				fm_set_user_money(id, money - costa );
				client_print(id, print_chat, "%L", id, "BUY_CHAT");
				g_Bought[id] = true
			} 
			else 
			{
				client_print(id, print_chat, "%L", id, "NOMONEY");
			}
		}
		case 3:
		{


			new money = fm_get_user_money(id);
			new costa = get_pcvar_num(g_KickCost);
	
			if( money >= costa ) 
			{
				set_user_flags(id, get_user_flags(id) | KICK);
				fm_set_user_money(id, money - costa );
				client_print(id, print_chat, "%L", id, "BUY_KICK");
				g_Bought[id] = true
			} 
			else 
			{
				client_print(id, print_chat, "%L", id, "NOMONEY");
			}
		}
		case 4:
		{


			new money = fm_get_user_money(id);
			new costa = get_pcvar_num(g_SlayCost);
	
			if( money >= costa ) 
			{
				set_user_flags(id, get_user_flags(id) | SLAY);
				fm_set_user_money(id, money - costa );
				client_print(id, print_chat, "%L", id, "BUY_SLAY");
				g_Bought[id] = true
			} 
			else 
			{
				client_print(id, print_chat, "%L", id, "NOMONEY");
			}
		}
		case 5:
		{


			new money = fm_get_user_money(id);
			new costa = get_pcvar_num(g_VoteCost);
	
			if( money >= costa ) 
			{
				set_user_flags(id, get_user_flags(id) | VOTE);
				fm_set_user_money(id, money - costa );
				client_print(id, print_chat, "%L", id, "BUY_VOTE");
				g_Bought[id] = true
			} 
			else 
			{
				client_print(id, print_chat, "%L", id, "NOMONEY");
			}
		}
	}
}

fm_set_user_money(iPlrId, iMoney, iFlash=1)
{
    set_pdata_int(iPlrId, OFFSET_MONEY, iMoney, OFFSET_LINUX);

    static s_iMsgId_Money;
    if( !s_iMsgId_Money )
    s_iMsgId_Money = get_user_msgid("Money");

    message_begin(MSG_ONE, s_iMsgId_Money, {0,0,0}, iPlrId)
    write_long(iMoney);
    write_byte(iFlash);
    message_end();
}

stock fm_get_user_money(index)
{
    return get_pdata_int(index, OFFSET_MONEY, OFFSET_LINUX);
}  
