/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <hamsandwich>
#include <codmod>
#include <ColorChat>


#define PLUGIN "COD Elite | VIP"
#define VERSION "1.0"
#define AUTHOR "Play"


#define MENU_KEYS MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_0
#define MAX_WIELKOSC_OPISU 512
#define flaga ADMIN_LEVEL_H

forward amxbans_admin_connect(id);

new bool:gVip[33], g_Hudmsg

native cod_set_user_hud(id)
native cod_get_user_hud(id)

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("DeathMsg", "DeathMsg", "a");
	register_message(get_user_msgid("ScoreAttrib"), "VipStatus");
	register_message(get_user_msgid("SayText"),"handleSayText");	
	register_menucmd(register_menuid("ShowMenu"), MENU_KEYS, "Show_Handler");
	register_clcmd("say /vip", "OpenMenu");
	set_task(90.0, "ShowInfo",.flags = "b");
	
	g_Hudmsg = CreateHudSyncObj();
	
}
public client_authorized(id)
{
	if(get_user_flags(id) & flaga)
	{
		gVip[id] = true;
		new gName[64];
		get_user_name(id, gName,charsmax(gName));	
		set_hudmessage(255, 0, 0, 0.25, 0.2, 0, 6.0, 6.0);
		ShowSyncHudMsg(0, g_Hudmsg, "Vip %s wbija na serwer !",gName);
	}
}
public client_disconnect(id)
{
	gVip[id] = false;
}
public DeathMsg()
{
	new killer = read_data(1);
	new victim = read_data(2);
	
	if(is_user_alive(killer) && gVip[killer] && get_user_team(killer) != get_user_team(victim))
	{
		DeathMsgVip(killer,victim,read_data(3));
	}
}
public DeathMsgVip(kid,vid,hs)
{
	cod_set_user_xp(kid, cod_get_user_xp(kid)+(hs?800:500));
}
public OpenMenu(id)
{
	if(cod_set_user_hud(id))
		return PLUGIN_CONTINUE;
		
	show_menu(id, MENU_KEYS, "\yCo Otrzymuje VIP ?^n^n\r+\w Przywitanie VIP'a^n\r+\w Dodatkowy Exp za zabicie^n\r+\w Prefix przed nickiem^n\r+\w Dodatkowe Ordery za zabicie^n\r+\w Rezerwacja Slota^n^n\wCena: \r11.07 zl^n^n\r1.\w Pokaz vipow online^n\r2.\w Jak kupic VIP'a ? - Poradnik^n^n^n\r0.\w Wyjdz", -1, "ShowMenu");
	return PLUGIN_HANDLED;
	
}
public Show_Handler(id, menu, key) 
{
	if(key == MENU_EXIT)
	{
		cod_get_user_hud(id)
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}	
	switch(key) 
	{
		case 0: OnlineVIP(id)		
		case 1: ShowPoradnik(id)
	}

	return PLUGIN_HANDLED;
}

public OnlineVIP(id)
{
	new players[32], pnum, tempid;
	new szName[32], szTempid[10];
	new szText[512];
	formatex( szText, charsmax( szText ), "Lista VIPOW ONLINE")
	new menu = menu_create( szText, "OnlineVIP_Handler" )
	
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE
		
	if(cod_set_user_hud(id))
		return PLUGIN_CONTINUE;	
			
	get_players(players, pnum, "a");
	
	for( new i; i<pnum; i++ )
	{
		tempid = players[i];
		
		if (!(get_user_flags(tempid) & ADMIN_LEVEL_H))
			continue;
		
		get_user_name(tempid, szName, 31);
		num_to_str(tempid, szTempid, 9);
		menu_additem(menu, szName, szTempid, 0);
	}
	
	menu_display(id, menu);
	return PLUGIN_HANDLED;
}
public OnlineVIP_Handler(id, menu, item)
{
	if( item == MENU_EXIT )
	{
		cod_get_user_hud(id)
		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);
	// i tutaj mozesz molestowac vipa wybranego z listy, jego index kryje sie w tempid
	
	menu_destroy(menu);
	OnlineVIP(id)
	return PLUGIN_HANDLED;
} 
public ShowPoradnik(id)
{		
	if(cod_set_user_hud(id))
		return PLUGIN_CONTINUE;
		
	new opis[1023]
	format(opis, charsmax(opis), "\r1.\w Wejdz na\y www.CSGramy.eu/sklep^n\r2.\w Zaloguj sie lub zaloz konto^n\r3.\w Wybierz Premium w zakladce (Uslugi)^n\r4.\w Wybierz Usluge^n\r5.\w Milej Gry :)");
	
	new menu = menu_create(opis, "OpenMenu")
	
	menu_additem(menu, "Wroc")
	menu_display(id, menu)
	 
	return PLUGIN_CONTINUE;
}
public ShowInfo()
{
	ColorChat(0, NORMAL, "[VIP]^x04 Chcesz dowiedziec sie co posiada VIP i jak go Kupic ? Wystarczy wpisac na chacie ^x03/Vip");
}
public handleSayText(msgId,msgDest,msgEnt)
{
	new id = get_msg_arg_int(1);
	
	if(is_user_connected(id) && gVip[id])
	{
		new szTmp[256],szTmp2[256];
		get_msg_arg_string(2,szTmp, charsmax(szTmp))
		
		new szPrefix[64] = "^x03[VIP]";
		
		if(!equal(szTmp,"#Cstrike_Chat_All"))
		{
			add(szTmp2,charsmax(szTmp2),szPrefix);
			add(szTmp2,charsmax(szTmp2)," ");
			add(szTmp2,charsmax(szTmp2),szTmp);
		}
		else
		{
			add(szTmp2,charsmax(szTmp2),szPrefix);
			add(szTmp2,charsmax(szTmp2),"^x03 %s1^x01 :  %s2");
		}
		set_msg_arg_string(2,szTmp2);
	}
	return PLUGIN_CONTINUE;
}
public VipStatus()
{
	new id = get_msg_arg_int(1);
	
	if(is_user_alive(id) && gVip[id])
	{
		set_msg_arg_int(2, ARG_BYTE, get_msg_arg_int(2)|4);
	}
}
public amxbans_admin_connect(id)
{
	client_authorized(id);
}
