#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <fun>

#pragma semicolon 1;

#define PLUGIN_NAME				"Block Maker"
#define PLUGIN_VERSION				"4.02"
#define PLUGIN_AUTHOR				"Pastout"
#define PLUGIN_PREFIX				"BM"

#define get_bit(%1,%2) 		( %1 &   1 << ( %2 & 31 ) )
#define set_bit(%1,%2)	 	( %1 |=  ( 1 << ( %2 & 31 ) ) )
#define clear_bit(%1,%2)	( %1 &= ~( 1 << ( %2 & 31 ) ) )

#define TASK_TIMER 7000
#define MAX_PLAYERS 32

new const g_blank[] =				"";

new const g_block_classname[] =			"BCM_Block";
new const g_start_classname[] =			"BCM_TeleportStart";
new const g_destination_classname[] =		"BCM_TeleportDestination";

new const g_model_platform[] =			"models/BCMmodels/platform.mdl";
new const g_model_bhop[] =			"models/BCMmodels/bhop.mdl";
new const g_model_damage[] =			"models/BCMmodels/damage.mdl";
new const g_model_healer[] =			"models/BCMmodels/healer.mdl";
new const g_model_no_fall_damage[] =		"models/BCMmodels/nofalldamage.mdl";
new const g_model_ice[] =			"models/BCMmodels/ice.mdl";
new const g_model_trampoline[] =			"models/BCMmodels/trampoline.mdl";
new const g_model_speed_boost[] =		"models/BCMmodels/speedboost.mdl";
new const g_model_death[] =			"models/BCMmodels/death.mdl";
new const g_model_low_gravity[] =		"models/BCMmodels/lowgravity.mdl";
new const g_model_slap[] =			"models/BCMmodels/slap.mdl";
new const g_model_honey[] =			"models/BCMmodels/honey.mdl";
new const g_model_ct_barrier[] =			"models/BCMmodels/barrier_ct.mdl";
new const g_model_t_barrier[] =			"models/BCMmodels/barrier_t.mdl";
new const g_model_glass[] =			"models/BCMmodels/platform.mdl";
new const g_model_no_slow_down_bhop[] =		"models/BCMmodels/nsdbhop.mdl";
new const g_model_delayed_bhop[] =		"models/BCMmodels/delayed_bhop.mdl";
new const g_model_invincibility[] =		"models/BCMmodels/invincibility.mdl";
new const g_model_stealth[] =			"models/BCMmodels/stealth.mdl";
new const g_model_boots_of_speed[] =		"models/BCMmodels/bootsofspeed.mdl";
new const g_model_weapon_block[] =		"models/BCMmodels/weapon.mdl";
new const g_model_nade_block[] =			"models/BCMmodels/nade.mdl";
new const g_model_duck_block[] =			"models/BCMmodels/duck.mdl";
new const g_model_xp_block[] =			"models/BCMmodels/throw.mdl";
new const g_model_blind_trap[] =			"models/BCMmodels/blind.mdl";
new const g_model_superman[] =			"models/BCMmodels/superman.mdl";
new const g_model_money[] =			"models/BCMmodels/money.mdl";
new const g_model_teleport[] =			"models/BCMmodels/teleport.mdl";
new const g_model_destination[] =		"models/BCMmodels/destination.mdl";
new const g_model_magiccarpet[] =		"models/BCMmodels/magic_carpet.mdl";

new const g_sprite_teleport_start[] =		"sprites/bcm_teleport_start.spr";
new const g_sprite_teleport_destination[] =	"sprites/bcm_teleport_end.spr";
new const g_teleport_start_frames = 20;
new const g_teleport_end_frames = 5;

enum ( <<= 1 )
{
	B1 = 1,
	B2,
	B3,
	B4,
	B5,
	B6,
	B7,
	B8,
	B9,
	B0
};

enum
{
	K1,
	K2,
	K3,
	K4,
	K5,
	K6,
	K7,
	K8,
	K9,
	K0
};

enum
{
	CHOICE_DELETE,
	CHOICE_LOAD,
	CHOICE_DEL_CONFIG,
	CHOICE_LOAD_CONFIG
};

enum
{
	CONFIG_NAME,
	CONFIG_RENAME
};

enum
{
	X,
	Y,
	Z
};

enum ( += 1000 )
{
	TASK_SPRITE = 1000,
	TASK_SOLID,
	TASK_SOLIDNOT,
	TASK_ICE,
	TASK_HONEY,
	TASK_NOSLOWDOWN,
	TASK_INVINCIBLE,
	TASK_STEALTH,
	TASK_BOOTSOFSPEED,
	TASK_SUPERMAN,
	TASK_MOVEBACK
};

enum { AUTOMATIC_NONE, AUTOMATIC_ROUND, AUTOMATIC_RANDOM, AUTOMATIC_VOTE };

const BLOCK_DELETE_CHUNK = 50;
const Float:LOADING_DELAY = 2.5;

new g_file[256];
new g_new_file[256];
new g_config_file[256];

new g_keys_main_menu;
new g_keys_block_menu;
new g_keys_block_selection_menu;
new g_keys_properties_menu;
new g_keys_teleport_menu;
new g_keys_config_menu;
new g_keys_config_selection_menu;
new g_keys_config_vote_menu;
new g_keys_options_menu;
new g_keys_choice_menu;

new g_main_menu[256];
new g_block_menu[256];
new g_teleport_menu[256];
new g_config_menu[256];
new g_options_menu[256];
new g_choice_menu[256];

const MAX_CONFIGS = 32;
new g_config_names[MAX_CONFIGS][32];
new g_config_index[MAX_CONFIGS];
new g_config_count = 0;
new g_current_config = 0;
new g_voted_config = -1;
new g_config_vote[32];
new g_config_vote_menu[32];
new g_rock_the_config[32];
new bool:g_in_config_vote = false;
new bool:g_vote_config_locked = false;

new g_connected;
new g_alive;
new g_admin;
new g_snapping;
new g_viewing_properties_menu;
new g_no_fall_damage;
new g_ice;
new g_low_gravity;
new g_no_slow_down;
new g_has_hud_text;
new g_block_status;
new g_awp_used;
new g_deagle_used;
new g_usp_used;
new g_tmp_used;
new g_aug_used;
new g_m3_used;
new g_mac10_used;
new g_ak47_used;
new g_c4_used;
new g_hegrenade_used;
new g_smokegrenade_used;
new g_flashgrenade_used;
new g_money_used;
new g_reseted;
new g_noclip;
new g_godmode;
new g_auto_block_properties;
new g_iHasVoted;
new g_iHasVotedAlready;
new g_bootsofspeed;
new g_max_players;
new g_block_count;
new g_iMsgId_SayText;
new gmsgScreenFade;
new g_load_start_line;
new stuck;

new g_rounds = 0;
new g_iTimer = 20;

new Dir[64];
new Map[32];

new g_selected_block_size[33];
new g_choice_option[33];
new g_block_selection_page[33];
new g_teleport_start[33];
new g_teleport_block_start[33];
new g_grabbed[33];
new g_szViewModel[33][32];
new g_grouped_blocks[33][256];
new g_group_count[33];
new g_property_info[33][2];
new g_slap[33][5];
new g_honey[33];
new g_boots_of_speed[33];
new g_menu_before_options[33];
new g_config_menu_page[33];
new g_value_types[33];

new Float:g_snapping_gap[33];
new Float:g_grab_offset[33][3];
new Float:g_grab_length[33];
new Float:g_next_damage_time[33];
new Float:g_next_heal_time[33];
new Float:g_invincibility_time_out[33];
new Float:g_invincibility_next_use[33];
new Float:g_stealth_time_out[33];
new Float:g_stealth_next_use[33];
new Float:g_boots_of_speed_time_out[33];
new Float:g_boots_of_speed_next_use[33];
new Float:g_superman_time_out[33];
new Float:g_superman_next_use[33];
new Float:g_blind_next_use[33];
new Float:g_set_velocity[33][3];

enum
{
	PLATFORM,
	BHOP,
	DAMAGE,
	HEALER,
	NO_FALL_DAMAGE,
	ICE,
	TRAMPOLINE,
	SPEED_BOOST,
	DEATH,
	LOW_GRAVITY,
	SLAP,
	HONEY,
	CT_BARRIER,
	T_BARRIER,
	GLASS,
	NO_SLOW_DOWN_BHOP,
	DELAYED_BHOP,
	INVINCIBILITY,
	STEALTH,
	BOOTS_OF_SPEED,
	WEAPON_BLOCK,
	NADE_BLOCK,
	DUCK_BLOCK,
	XP_BLOCK,
	BLIND_TRAP,
	SUPERMAN,
	MONEY,
	BOUNCE_DEATH,
	TELEPORT,
	DESTINATION,
	MAGIC_CARPET,
	
	TOTAL_BLOCKS
};

enum
{
	TELEPORT_START,
	TELEPORT_DESTINATION
};

enum
{
	NORMAL,
	SMALL,
	LARGE,
	POLE
};

enum
{
	NORMAL,
	GLOWSHELL,
	TRANSCOLOR,
	TRANSALPHA,
	TRANSWHITE
};

const TOTAL_BLOCKS = 31;
new MAX_BLOCKS;
new g_selected_block_type[TOTAL_BLOCKS];
new g_render[TOTAL_BLOCKS];
new g_red[TOTAL_BLOCKS];
new g_green[TOTAL_BLOCKS];
new g_blue[TOTAL_BLOCKS];
new g_alpha[TOTAL_BLOCKS];

new g_pCvar_ShowMessage;
new g_pCvar_Enable;
new g_pCvar_LoadingRounds;
//new g_pCvar_TimeUnlockRtt;
new g_pCvar_AutoLoading;

new const g_block_names[TOTAL_BLOCKS][] =
{
	"Platform",
	"Bhop",
	"Damage",
	"Healer",
	"No Fall Damage",
	"Ice",
	"Trampoline",
	"Speed Boost",
	"Death",
	"Low Gravity",
	"Slap",
	"Honey",
	"CT Barrier",
	"T Barrier",
	"Glass",
	"No Slow Bhop",
	"Delayed Bhop",
	"Invincibility",
	"Stealth",
	"Boots Of Speed",
	"Weapon",
	"Grenade",
	"Duck",
	"Anti-Throw",
	"Blind Trap",
	"Superman",
	"Money",
	"Bouncing Death",
	"Teleport Block",
	"Destination",
	"Magic Carpet"
};

new const g_property1_name[TOTAL_BLOCKS][] =
{
	"",
	"No Fall Damage",
	"Damage Per Interval",
	"Health Per Interval",
	"",
	"Friction",
	"Upward Speed",
	"Forward Speed",
	"",
	"Gravity",
	"Hardness",
	"Speed In Honey",
	"Admin Access",
	"Admin Access",
	"",
	"No Fall Damage",
	"Delay Before Dissapear",
	"Invincibility Time",
	"Stealth Time",
	"Boots Of Speed Time",
	"Weapons",
	"Nades",
	"",
	"Height Amount",
	"Bind Red",
	"Superman Power",
	"Money Amount",
	"Bouncing Height",
	"Teleport Name",
	"Destination Name",
	"Magic Carpet"
};

new const g_property1_default_value[TOTAL_BLOCKS][] =
{
	"",
	"0",
	"5",
	"1",
	"",
	"0.15",
	"500",
	"1000",
	"",
	"200",
	"2",
	"75",
	"1",
	"1",
	"",
	"0",
	"1",
	"10",
	"10",
	"10",
	"1",
	"1",
	"",
	"500",
	"255",
	"10",
	"1337",
	"400",
	"Name",
	"Name",
	"4"
};

new const g_property2_name[TOTAL_BLOCKS][] =
{
	"",
	"",
	"Interval Between Damage",
	"Interval Between Heals",
	"",
	"",
	"",
	"Upward Speed",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"Delay After Usage",
	"Delay After Usage",
	"Delay After Usage",
	"Bullets",
	"",
	"",
	"Speed",
	"Blind Green",
	"Delay After Usage",
	"",
	"",
	"",
	"",
	"Delay Before Respawn"
};
 
new const g_property2_default_value[TOTAL_BLOCKS][] =
{
	"",
	"",
	"0.5",
	"0.5",
	"",
	"",
	"",
	"200",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"60",
	"60",
	"60",
	"1",
	"",
	"",
	"300",
	"255",
	"60",
	"",
	"",
	"",
	"",
	"5"
};

new const g_property3_name[TOTAL_BLOCKS][] =
{
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"",
	"Transparency",
	"Transparency",
	"",
	"",
	"Speed",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Blind Blue",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency",
	"Transparency"
};

new const g_property3_default_value[TOTAL_BLOCKS][] =
{
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"",
	"255",
	"255",
	"",
	"",
	"400",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255",
	"255"
};

new const g_property4_name[TOTAL_BLOCKS][] =
{
	"",
	"On Top Only",
	"On Top Only",
	"Heal Type",
	"",
	"",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"Alpha Amount",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only",
	"On Top Only"
};

new const g_property4_default_value[TOTAL_BLOCKS][] =
{
	"",
	"1",
	"1",
	"1",
	"",
	"",
	"0",
	"0",
	"1",
	"0",
	"1",
	"1",
	"0",
	"0",
	"",
	"0",
	"0",
	"1",
	"1",
	"1",
	"1",
	"1",
	"1",
	"1",
	"255",////
	"1",
	"1",
	"0",
	"1",
	"1",
	"0"
};

new const g_block_save_ids[TOTAL_BLOCKS] =
{
	'A',
	'B',
	'C',
	'D',
	'E',
	'F',
	'G',
	'H',
	'I',
	'J',
	'K',
	'L',
	'M',
	'N',
	'O',
	'P',
	'Q',
	'R',
	'S',
	'T',
	'U',
	'V',
	'3',
	'X',
	'Y',
	'Z',
	'8',
	'4',
	'5',
	'6',
	'7'
};

new g_block_models[TOTAL_BLOCKS][256];
new g_block_selection_pages_max;

public plugin_precache()
{
	g_block_models[PLATFORM] =		g_model_platform;
	g_block_models[BHOP] =			g_model_bhop;
	g_block_models[DAMAGE] =		g_model_damage;
	g_block_models[HEALER] =		g_model_healer;
	g_block_models[NO_FALL_DAMAGE] =	g_model_no_fall_damage;
	g_block_models[ICE] =			g_model_ice;
	g_block_models[TRAMPOLINE] =		g_model_trampoline;
	g_block_models[SPEED_BOOST] =		g_model_speed_boost;
	g_block_models[DEATH] =			g_model_death;
	g_block_models[LOW_GRAVITY] =		g_model_low_gravity;
	g_block_models[SLAP] =			g_model_slap;
	g_block_models[HONEY] =			g_model_honey;
	g_block_models[CT_BARRIER] =		g_model_ct_barrier;
	g_block_models[T_BARRIER] =		g_model_t_barrier;
	g_block_models[GLASS] =			g_model_glass;
	g_block_models[NO_SLOW_DOWN_BHOP] =	g_model_no_slow_down_bhop;
	g_block_models[DELAYED_BHOP] =		g_model_delayed_bhop;
	g_block_models[INVINCIBILITY] =		g_model_invincibility;
	g_block_models[STEALTH] =		g_model_stealth;
	g_block_models[BOOTS_OF_SPEED] =	g_model_boots_of_speed;
	g_block_models[WEAPON_BLOCK] =		g_model_weapon_block;
	g_block_models[NADE_BLOCK] =		g_model_nade_block;
	g_block_models[DUCK_BLOCK] =		g_model_duck_block;
	g_block_models[XP_BLOCK] =		g_model_xp_block;
	g_block_models[BLIND_TRAP] =		g_model_blind_trap;
	g_block_models[SUPERMAN] =		g_model_superman;
	g_block_models[MONEY] =			g_model_money;
	g_block_models[BOUNCE_DEATH] =		g_model_death;
	g_block_models[TELEPORT] =		g_model_teleport;
	g_block_models[DESTINATION] =		g_model_destination;
	g_block_models[MAGIC_CARPET] =		g_model_magiccarpet;
	
	SetupBlockRendering(GLASS, TRANSWHITE, 255, 255, 255, 100);
	SetupBlockRendering(INVINCIBILITY, GLOWSHELL, 255, 255, 255, 16);
	SetupBlockRendering(STEALTH, TRANSWHITE, 255, 255, 255, 100);
	SetupBlockRendering(TELEPORT, TRANSCOLOR, 0, 55, 0, 150);
	SetupBlockRendering(DESTINATION, TRANSCOLOR, 0, 0, 55, 150);
	
	new block_model_small[256];
	new block_model_large[256];
	new block_model_pole[256];

	for ( new i = 0; i < TOTAL_BLOCKS; ++i )
	{
		SetBlockModelNameSmall(block_model_small, g_block_models[i], 256);
		SetBlockModelNameLarge(block_model_large, g_block_models[i], 256);
		SetBlockModelNamePole(block_model_pole, g_block_models[i], 256);
		
		precache_model(g_block_models[i]);
		precache_model(block_model_small);
		precache_model(block_model_large);
		precache_model(block_model_pole);
	}
	
	precache_model(g_sprite_teleport_start);
	precache_model(g_sprite_teleport_destination);
}

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);

	register_clcmd("say bm",			"CmdMainMenu", ADMIN_MENU);
	register_clcmd("say /bm",			"CmdMainMenu", ADMIN_MENU);
	register_clcmd("say rtt",			"CmdRockTheConfig");
	register_clcmd("say /rtt",			"CmdRockTheConfig");
	register_clcmd("say rtc",			"CmdRockTheConfig");
	register_clcmd("say /rtc",			"CmdRockTheConfig");
	register_clcmd("say rockthetemplate",		"CmdRockTheTemplate", ADMIN_MENU);
	register_clcmd("say /rockthetemplate",		"CmdRockTheTemplate", ADMIN_MENU);
	register_clcmd("say config",			"CmdConfig");
	register_clcmd("say /config",			"CmdConfig");
	
	register_clcmd("BCM_SetProperty",		"SetPropertyBlock",	-1);
	
	register_clcmd("+BMGrab",		"CmdGrab",		-1, g_blank);
	register_clcmd("-BMGrab",		"CmdRelease",		-1, g_blank);
	
	register_clcmd("Enter_Value", 		"CmdEnterValue");
	register_clcmd("BCM_Configs", 		"CmdConfigs", 		-1);
	
	g_pCvar_ShowMessage = register_cvar("BCM_Show_Messages", "1");
	g_pCvar_Enable = register_cvar("BCM_Enable", "1");
	g_pCvar_LoadingRounds = register_cvar("BCM_loadingrounds", "0");
	//g_pCvar_TimeUnlockRtt = register_cvar("BCM_timelockrtt", "180.0");
	g_pCvar_AutoLoading = register_cvar("BCM_automaticloading", "0");
	
	CreateMenus();
	
	register_menucmd(register_menuid("BcmMainMenu"),		g_keys_main_menu,		"HandleMainMenu");
	register_menucmd(register_menuid("BcmBlockMenu"),		g_keys_block_menu,		"HandleBlockMenu");
	register_menucmd(register_menuid("BcmBlockSelectionMenu"),	g_keys_block_selection_menu,	"HandleBlockSelectionMenu");
	register_menucmd(register_menuid("BcmPropertiesMenu"),		g_keys_properties_menu,		"HandlePropertiesMenu");
	register_menucmd(register_menuid("BcmTeleportMenu"),		g_keys_teleport_menu,		"HandleTeleportMenu");
	register_menucmd(register_menuid("BcmConfigMenu"), 		g_keys_config_menu, 		"HandleConfigMenu");
	register_menucmd(register_menuid("BcmConfigSelectionMenu"), 	g_keys_config_selection_menu, 	"HandleConfigSelectionMenu");
	register_menucmd(register_menuid("BcmConfigVoteMenu"), 		g_keys_config_vote_menu, 	"HandleConfigVoteMenu");
	register_menucmd(register_menuid("BcmOptionsMenu"),		g_keys_options_menu,		"HandleOptionsMenu");
	register_menucmd(register_menuid("BcmChoiceMenu"),		g_keys_choice_menu,		"HandleChoiceMenu");
	
	RegisterHam(Ham_Spawn,		"player",	"FwdPlayerSpawn",	1);
	RegisterHam(Ham_Killed,		"player",	"FwdPlayerKilled",	1);
	
	register_forward(FM_CmdStart,			"FwdCmdStart");
	register_message(get_user_msgid("StatusValue"),	"MsgStatusValue");

	register_event( "CurWeapon", 	"EventCurWeaponModelView", 	"be", 	"1!0" );
	register_event( "CurWeapon",	"EventCurWeapon",		"be" );
	//register_event("HLTV", "EventNewRound", "a", "1=0", "2=0");
	register_logevent( "EventNewRound" , 2 , "1=Round_End" );

	gmsgScreenFade = get_user_msgid("ScreenFade");
	g_iMsgId_SayText = get_user_msgid( "SayText" );
	g_max_players =	get_maxplayers();
	

	for(new x = 0; x < g_max_players; x++)
		g_rock_the_config[x] = 0;
	
	//make save folder in basedir (new saving/loading method)
	get_basedir(Dir, 64);
	add(Dir, 64, "/blockmaker");
	
	//make config folder if it doesn't already exist
	if (!dir_exists(Dir))
		mkdir(Dir);
	
	get_mapname(Map, 32);
	
	if(equali(Map, "awp_map") || equali(Map, "cs_assualt"))
		MAX_BLOCKS = 180;
	else
		MAX_BLOCKS = 325;
	
	formatex(g_config_file, 96, "%s/%s.bm.config", Dir, Map);

}

public plugin_cfg()
{
	LoadBlockConfigurations();
	newLoad(0);
}

LoadBlockConfigurations() {
	g_config_count = 1;
	g_config_index[0] = 0;
	copy(g_config_names[0], 32, "Default");
	if (file_exists(g_config_file)) {
		new fp = fopen(g_config_file, "rt");
		new index[16];
		new name[32];
		new data[128];
		while (!feof(fp) && (g_config_count < MAX_CONFIGS)) {
			fgets(fp, data, 128);
			if(2 == parse(data, index, 16, name, 32)) {
				copy(g_config_names[g_config_count], 32, name);
				g_config_index[g_config_count] = str_to_num(index);
				g_config_count ++;
			}
			
		}
		fclose(fp);
	}
	new TOTAL_CONFIGS;
	TOTAL_CONFIGS = random_num(0, g_config_count-1);
	GetConfigFileName(TOTAL_CONFIGS, g_new_file);
	g_current_config = TOTAL_CONFIGS;
}

SaveBlockConfigurations() {
	new fp = fopen(g_config_file, "wt");
	new data[128];
	for(new i = 1; i < g_config_count; i++) {
		formatex(data, 128, "%d ^"%s^"^n", g_config_index[i], g_config_names[i]);
		fputs(fp, data);
	}
	fclose(fp);
}

public CmdConfigs(id)
	for(new i = 0; i < g_config_count; i++)
		BCM_Print(id, "^1 %d^3/^1%s.", g_config_index[i], g_config_names[i]);

public client_putinserver(id)
{
	if(bool:!is_user_hltv(id))
		set_bit(g_connected, id);
	
	clear_bit(g_alive, id);
	
	if(is_user_admin(id))
		set_bit(g_admin, id);
	
	clear_bit(g_viewing_properties_menu, id);
	
	set_bit(g_snapping, id);

	g_snapping_gap[id] =			0.0;

	g_group_count[id] =			0;
	
	clear_bit(g_noclip, id);
	clear_bit(g_godmode, id);
	clear_bit(g_reseted, id);
	clear_bit(g_iHasVotedAlready, id);
	
	ResetPlayer(id);
}

public client_disconnect(id)
{
	
	clear_bit(g_connected, id);
	clear_bit(g_alive, id);
	clear_bit(g_admin, id);
	
	ClearGroup(id);
	
	if ( g_grabbed[id] )
	{
		if ( is_valid_ent(g_grabbed[id]) )
		{
			entity_set_int(g_grabbed[id], EV_INT_iuser2, 0);
		}
		
		g_grabbed[id] =	0;
	}
}

CreateMenus()
{
	g_block_selection_pages_max = floatround((float(TOTAL_BLOCKS) / 8.0), floatround_ceil);
	
	new size = charsmax(g_main_menu);
	add(g_main_menu, size, "\rCurrent Config:\d %s^n\yBlockmaker \wBlock Count: \y(\r%d\w/\r%d\y)^n^n");
	add(g_main_menu, size, "\r1. \wBlock Menu^n");
	add(g_main_menu, size, "\r2. \wTeleport Menu^n");
	add(g_main_menu, size, "\r3. \wConfig Menu^n^n");
	add(g_main_menu, size, "\r6. %sNoclip: %s^n");
	add(g_main_menu, size, "\r7. %sGodmode: %s^n^n");
	add(g_main_menu, size, "\r8. \wHelp Menu^n");
	add(g_main_menu, size, "\r9. \wOptions Menu^n^n");
	add(g_main_menu, size, "\r0. \wClose");
	g_keys_main_menu =		B1 | B2 | B3 | B6 | B7 | B9 | B0;
	
	size = charsmax(g_block_menu);
	add(g_block_menu, size, "\rBlock \yMenu \wBlock Count: \y(\r%d\w/\r%d\y)^n^n");
	add(g_block_menu, size, "\r1. \wBlock Type: \y%s^n");
	add(g_block_menu, size, "\r2. %sCreate Block^n");
	add(g_block_menu, size, "\r3. %sConvert Block^n");
	add(g_block_menu, size, "\r4. %sDelete Block^n");
	add(g_block_menu, size, "\r5. %sRotate Block^n^n");
	add(g_block_menu, size, "\r6. \wAdjust Size: \y%s^n");
	add(g_block_menu, size, "\r7. %sSet Properties^n^n");
	add(g_block_menu, size, "\r9. \wOptions Menu^n^n");
	add(g_block_menu, size, "\r0. \wBack");
	g_keys_block_menu =		B1 | B2 | B3 | B4 | B5 | B6 | B7 | B9 | B0;
	g_keys_block_selection_menu =	B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 | B0;
	g_keys_properties_menu =	B1 | B2 | B3 | B4 | B0;
	
	size = charsmax(g_teleport_menu);
	add(g_teleport_menu, size, "\yTeleport Menu^n^n");
	add(g_teleport_menu, size, "\r1. %sCreate Start^n");
	add(g_teleport_menu, size, "\r2. %sCreate Destination^n");
	add(g_teleport_menu, size, "\r3. %sSwap Start/Destination^n");
	add(g_teleport_menu, size, "\r4. %sDelete Teleport^n^n");
	add(g_teleport_menu, size, "\r6. %sNoclip: %s^n");
	add(g_teleport_menu, size, "\r7. %sGodmode: %s^n^n");
	add(g_teleport_menu, size, "\r9. \wOptions Menu^n^n");
	add(g_teleport_menu, size, "\r0. \wBack");
	g_keys_teleport_menu =		B1 | B2 | B3 | B4 | B6 | B7 | B9 | B0;
	
	size = charsmax(g_config_menu);
	add(g_config_menu, size, "\yConfiguration Menu \w(\rbe sure to save first!\w)^n^n");
	add(g_config_menu, size, "\r1. %sLoad Config^n");
	add(g_config_menu, size, "\r2. %sCreate and Load new Config^n");
	add(g_config_menu, size, "\r3. %sDelete current Config (\y%s\w)^n");
	add(g_config_menu, size, "\r4. %sRename current Config (\y%s\w)^n^n");
	add(g_config_menu, size, "\r0. \wBack");
	g_keys_config_menu = 		B1 | B2 | B3 | B4 | B0;
	g_keys_config_selection_menu = 	B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 | B0;
	g_keys_config_vote_menu = 	B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 | B0;
	
	size = charsmax(g_options_menu);
	add(g_options_menu, size, "\yOptions Menu^n^n");
	add(g_options_menu, size, "\r1. %sSnapping: %s^n");
	add(g_options_menu, size, "\r2. %sSnapping Gap: \y%.1f^n^n");
	add(g_options_menu, size, "\r3. %sAdd to Group^n");
	add(g_options_menu, size, "\r4. %sClear Group^n^n");
	add(g_options_menu, size, "\r5. %sDelete All^n");
	add(g_options_menu, size, "\r6. %sAuto display info: %s^n^n");
	add(g_options_menu, size, "\r7. %sSave to file^n");
	add(g_options_menu, size, "\r8. %sLoad from file^n^n");
	add(g_options_menu, size, "\r0. \wBack");
	g_keys_options_menu =		B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B0;
	
	size = charsmax(g_choice_menu);
	add(g_choice_menu, size, "\y%s^n^n");
	add(g_choice_menu, size, "\r1. \wYes^n");
	add(g_choice_menu, size, "\r2. \wNo^n^n^n");
	add(g_choice_menu, size, "\r3. \wJust \yBlocks^n");
	add(g_choice_menu, size, "\r4. \wJust \yTeleports^n");
	add(g_choice_menu, size, "\r0. \wBack");
	g_keys_choice_menu =		B1 | B2 | B3 | B4 | B0;

}

new g_iRounds;

public EventNewRound(id) {
	if( g_iRounds >= 6 ) {
		BCM_Print( 0, "^4[AMXX]^1 This server is using^3 Blockmaker^4 v%s^1, by^3 Pastout!", PLUGIN_VERSION );
		g_iRounds = 0;
	}
	
	g_iRounds++;
	
	if(g_in_config_vote) {
		return PLUGIN_HANDLED;
	}
	new type = get_pcvar_num(g_pCvar_AutoLoading);
	new bool:loadAnyways = false;
	if(g_voted_config >= 0) {
		loadAnyways = true;
		type = AUTOMATIC_VOTE;
	}
	if(!loadAnyways && type == AUTOMATIC_NONE) {
		return PLUGIN_HANDLED;
	}
	
	if(g_current_config == g_voted_config)
	{
		loadAnyways = false;
		g_voted_config = -1;
		BCM_Print(0, "^1Due to the same^3 config^1 no^4 loading^1 necessary.");
		
		return PLUGIN_HANDLED;
	}
	
	g_rounds++;
	new roundLimit = get_pcvar_num(g_pCvar_LoadingRounds);
	if(!loadAnyways && roundLimit == 0) {
		return PLUGIN_HANDLED;
	}
	if(!loadAnyways && ((g_rounds + 1) % roundLimit == 0)) {
		VoteConfigs();
	}
	if(!loadAnyways && (g_rounds % roundLimit != 0)) {
		return PLUGIN_HANDLED;
	}
	g_rounds = 0;
	for(new x = 0; x < g_max_players; x++) {
		g_rock_the_config[x] = 0;
	}
	
	if(type == AUTOMATIC_RANDOM) {
		g_current_config = random_num(0, g_config_count - 1);
	} else if(type == AUTOMATIC_ROUND) {
		g_current_config++;
		g_current_config = g_current_config % g_config_count;
	} else if(type == AUTOMATIC_VOTE) {
		g_current_config = g_voted_config;
		g_voted_config = -1;
	}
	
	GetConfigFileName(g_current_config, g_new_file);
	BCM_Print(0, "^1Config^3 loaded^1 is: ^4[^3%s^4]^1.", g_config_names[g_current_config]);
	DeleteAll(0, false);
	g_load_start_line = 0;
	set_task(LOADING_DELAY, "TaskLoad", 0);
	return PLUGIN_HANDLED;
	
}


public ShowVoteMenu() {
	for(new x = 0; x < g_max_players; x++) {
		if(is_user_connected(x)) {
			ShowConfigVoteMenu(x);
		}
	}
}
public VoteConfigs() {
	
	for(new x = 0; x < g_max_players; x++) {
		g_config_vote[x] = -1;
		g_config_vote_menu[x] = 0;
		g_rock_the_config[x] = 0;
	}
	g_in_config_vote = true;
	
	BCM_Print(0, "^1Voting for a^3 Config^1 will start in^4 10^1 Seconds");
	set_task(10.0, "ShowVoteMenu");
	set_task(30.0, "VoteDone");
}	

public VoteDone() {
	new voteCount[MAX_CONFIGS];
	for(new x = 0; x < g_max_players; x++) {
		if(g_config_vote[x] > -1) {
			voteCount[g_config_vote[x]]++;
		}
	}
	
	new numMax = 0;
	new amount = 0;
	for(new x = 0; x < MAX_CONFIGS; x++) {
		if(voteCount[x] > numMax) {
			numMax = voteCount[x];
			amount = 1;
		} else if(voteCount[x] == numMax) {
			amount++;
		}
	}
	new maxCount;// = random_num(1, amount) - 1;
	for(new x = 0; x < MAX_CONFIGS; x++) {
		if(voteCount[x] == numMax) {
			if(maxCount == 0) {
				g_voted_config = x;
			}
			maxCount--;
		}
	}
	
	BCM_Print(0, "^1Config Voting^3 Finished^1, Result is:^4 [^3%s^4]^1.", g_config_names[g_voted_config]);
	g_in_config_vote = false;
}

public CmdRockTheTemplate(id) {
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	if(!g_vote_config_locked)
	{
		new szName[32];
		get_user_name(id, szName, 31);
		BCM_Print(id, "Admin:^3 %s^1 has started a^4 vote^1.", szName);
	}
	
	g_vote_config_locked = true;
	//set_task(get_pcvar_float(g_pCvar_TimeUnlockRtt), "UnlockVoteConfig");
	set_task(180.0, "UnlockVoteConfig");
	VoteConfigs();
	
	new Players[32];
	new playerCount, i;
	get_players(Players, playerCount);
	for (i=0; i<playerCount; i++) 
		clear_bit(g_iHasVoted, Players[ i ]);
	
	return PLUGIN_HANDLED;
}

public CmdRockTheConfig(id) {
	
	if(g_vote_config_locked) {
		BCM_Print(id, "You Must Wait To Rock The Config Again!");
		return PLUGIN_HANDLED;
	}
	
	if(g_in_config_vote) {
		BCM_Print(0, "Template Voting in Progress.");
		return PLUGIN_HANDLED;
	}
	g_rock_the_config[id] = 1;
	new count = 0;
	new connected = 0;
	for(new x = 0; x < g_max_players; x++) {
		if(is_user_connected(x)) {
			connected++;
			if(g_rock_the_config[x] != 0) {
				count ++;
			}
		}
	}
	if( floatround(float(connected) * 0.8) - count < 1 )
	{
		BCM_Print(0, "^1Enough people have^3 Rock The Config");
	}
	else if(get_bit(g_iHasVoted, id))
	{
		BCM_Print(id, "^1You have already^3 rock the template^1!");
	}
	else
	{
		BCM_Print(id, "^1Need [^3%d^1] More to^3 Rock The Config", floatround(float(connected) * 0.8) - count);
		set_bit(g_iHasVoted, id);

		new Players[32];
		new playerCount, i, iPlayer;
		new szName[32];
		get_user_name(id, szName, 31);
		get_players(Players, playerCount);
		for (i=0; i<playerCount; i++) 
		{
			iPlayer = Players[ i ];
			if(iPlayer != id)
			{
				BCM_Print(iPlayer, "^3%s^1 has^3 Rock The Config^1 out of [^4 %d^1/^4%d^1 ]", szName, count, floatround(float(connected) * 0.8));
			}
		}
	}
	
	if(floatround(float(connected) * 0.8) <= count) {
		g_vote_config_locked = true;
		//set_task(get_pcvar_float(g_pCvar_TimeUnlockRtt), "UnlockVoteConfig");
		set_task(180.0, "UnlockVoteConfig");
		VoteConfigs();
		
		new Players[32];
		new playerCount, i;
		get_players(Players, playerCount);
		for (i=0; i<playerCount; i++) 
			clear_bit(g_iHasVoted, Players[ i ]);
	}
	return PLUGIN_HANDLED;	
}

public UnlockVoteConfig() {
	g_vote_config_locked = false;
}

public CmdConfig(id) {
	GetConfigFileName(g_current_config, g_new_file);
	BCM_Print(id, "^1The Current Config is^4 [^x03%s^x04]^1.", g_config_names[g_current_config]);
}

SetupBlockRendering(block_type, render_type, red, green, blue, alpha)
{
	g_render[block_type] =		render_type;
	g_red[block_type] =		red;
	g_green[block_type] =		green;
	g_blue[block_type] =		blue;
	g_alpha[block_type] =		alpha;
}

SetBlockModelNameLarge(block_model_target[256], block_model_source[256], size)
{
	block_model_target = block_model_source;
	replace(block_model_target, size, ".mdl", "_large.mdl");
}

SetBlockModelNameSmall(block_model_target[256], block_model_source[256], size)
{
	block_model_target = block_model_source;
	replace(block_model_target, size, ".mdl", "_small.mdl");
}

SetBlockModelNamePole(block_model_target[256], block_model_source[256], size)
{
	block_model_target = block_model_source;
	replace(block_model_target, size, ".mdl", "_pole.mdl");
}

public FwdPlayerSpawn(id)
{
	if ( !is_user_alive(id) ) return HAM_IGNORED;
	
	set_bit(g_alive, id);
	
	if ( get_bit(g_noclip, id) )		set_user_noclip(id, 1);
	if ( get_bit(g_godmode, id) )		set_user_godmode(id, 1);
	
	if ( !get_bit(g_reseted, id) )
	{
		ResetPlayer(id);
	}
	
	clear_bit(g_reseted, id);
	
	return HAM_IGNORED;
}

public FwdPlayerKilled(id)
{
	if(is_user_alive(id))
		set_bit(g_alive, id);
	else
		clear_bit(g_alive, id);
	
	ResetPlayer(id);

}

public FwdCmdStart(id, handle)
{
	if ( !get_bit(g_connected, id) ) return FMRES_IGNORED;
	
	static buttons, oldbuttons;
	buttons =	get_uc(handle, UC_Buttons);
	oldbuttons =	entity_get_int(id, EV_INT_oldbuttons);
	
	if ( get_bit(g_alive, id)
	&& buttons & IN_USE
	&& !( oldbuttons & IN_USE )
	&& !get_bit(g_has_hud_text, id) )
	{
		static iEntity, body;
		get_user_aiming(id, iEntity, body, 1000);
		
		if ( IsBlock(iEntity) )
		{
			static block_type, szCreator[32], szLastMover[32];
			block_type = entity_get_int(iEntity, EV_INT_body);
		
			pev(iEntity, pev_targetname, szCreator, 31);
			replace_all(szCreator, 31, "_", " ");
			pev(iEntity, pev_target, szLastMover, 31);
			replace_all(szLastMover, 31, "_", " ");
			
			set_hudmessage(255, 255, 255, 0.04, 0.18, 0, 6.0, 12.0);
			show_hudmessage(id, "Template: %s^nBlock Count: %d", g_config_names[g_current_config], g_block_count);
			
			static property[5];
			
			static message[512], len;
			len = format(message, charsmax(message), "Type: %s^n Creator: %s^n Last Mover: %s", g_block_names[block_type], szCreator, szLastMover);
			
			if ( g_property1_name[block_type][0] && get_bit(g_admin, id) )
			{
				GetProperty(iEntity, 1, property);
				switch ( block_type )
				{
					case BHOP, NO_SLOW_DOWN_BHOP:
					{
						if( property[0] == '1' )
						{
							len += format(message[len], charsmax(message) - len, "^n%s", g_property1_name[block_type]);
						}
					}
					case MAGIC_CARPET:
					{
						len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property[0] == '4' ? "Off" : property[0] == '3' ? "All" : property[0] == '2' ? "Counter-Terrorists" : "Terrorists");
					}
					case SLAP:
					{
						len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property[0] == '3' ? "High" : property[0] == '2' ? "Medium" : "Low");
					}
					case CT_BARRIER, T_BARRIER:
					{
						len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property[0] == '3' ? "All Admins Only" : property[0] == '2' ? "Team Admins Only" : "Normal");
					}
					case WEAPON_BLOCK:
					{
						len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property[0] == '9' ? "Famas" : property[0] == '8' ? "AK47" : property[0] == '7' ? "Mac 10" : property[0] == '6' ? "Shotgun" : property[0] == '5' ? "Aug" : property[0] == '4' ? "Tmp" : property[0] == '3' ? "Usp" : property[0] == '2' ? "Deagle" : "Awp");
					}
					case NADE_BLOCK:
					{
						len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property[0] == '3' ? "Flash Grenade" : property[0] == '2' ? "Frost Grenade" : "HE Grenade");
					}
					case PLATFORM, DAMAGE, HEALER, NO_FALL_DAMAGE, ICE, TRAMPOLINE, SPEED_BOOST, DEATH, LOW_GRAVITY, HONEY, DELAYED_BHOP, INVINCIBILITY, STEALTH,\
					BOOTS_OF_SPEED, DUCK_BLOCK, XP_BLOCK, BLIND_TRAP, SUPERMAN, MONEY, BOUNCE_DEATH, TELEPORT, DESTINATION:
					{
						len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property);
					}
				}
			}
			if ( g_property2_name[block_type][0] && get_bit(g_admin, id) )
			{
				GetProperty(iEntity, 2, property);
				
				len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property2_name[block_type], property);
			}
			if ( g_property3_name[block_type][0]
			&& ( block_type == BOOTS_OF_SPEED
			|| block_type == BLIND_TRAP
				|| property[0] != '0'
				&& property[0] != '2'
				&& property[1] != '5'
				&& property[2] != '5' ) )
			{
				GetProperty(iEntity, 3, property);
				
				len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property3_name[block_type], property);
			}
			if ( g_property4_name[block_type][0] && get_bit(g_admin, id) )
			{
				GetProperty(iEntity, 4, property);
				if( block_type == BLIND_TRAP )
				{
					len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property4_name[block_type], property);
				}
				if( block_type == HEALER )
				{
					len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property1_name[block_type], property[0] == '3' ? "Health/Armor" : property[0] == '2' ? "Armor" : "Health");
				}
				else
				{
					len += format(message[len], charsmax(message) - len, "^n%s: %s", g_property4_name[block_type], property[0] == '1' ? "Yes" : "No");
				}
			}
			
			set_hudmessage(255, 51, 0, -1.0, 0.84, 0, 0.75, 0.75, 0.75, 0.75, 2);
			show_hudmessage(id, message);
		}
	}
	
	if ( !g_grabbed[id] ) return FMRES_IGNORED;
	
	if ( buttons & IN_JUMP
	&& !( oldbuttons & IN_JUMP ) ) if ( g_grab_length[id] > 72.0 ) g_grab_length[id] -= 16.0;
	
	if ( buttons & IN_DUCK
	&& !( oldbuttons & IN_DUCK ) ) g_grab_length[id] += 16.0;
	
	if ( buttons & IN_ATTACK
	&& !( oldbuttons & IN_ATTACK ) ) CmdAttack(id);
	
	if ( buttons & IN_ATTACK2
	&& !( oldbuttons & IN_ATTACK2 ) ) CmdAttack2(id);
	
	if ( !is_valid_ent(g_grabbed[id]) )
	{
		CmdRelease(id);
		return FMRES_IGNORED;
	}
	
	if ( !IsBlockInGroup(id, g_grabbed[id]) && g_group_count[id] > 1 )
	{
		MoveGrabbedEntity(id);
		return FMRES_IGNORED;
	}
	
	static block;
	static Float:move_to[3];
	static Float:offset[3];
	static Float:origin[3];
	
	MoveGrabbedEntity(id, move_to);
	
	for ( new i = 0; i <= g_group_count[id]; ++i )
	{
		block = g_grouped_blocks[id][i];
		
		if ( !IsBlockInGroup(id, block) ) continue;
		
		entity_get_vector(block, EV_VEC_vuser1, offset);
		
		origin[0] = move_to[0] - offset[0];
		origin[1] = move_to[1] - offset[1];
		origin[2] = move_to[2] - offset[2];
		
		MoveEntity(id, block, origin, false);
	}
	
	return FMRES_IGNORED;
}

public EventCurWeapon(id)
{
	static block, property[5];
	new Float:gametime = get_gametime();
	new Float:time_out = g_boots_of_speed_time_out[id] - gametime;
	
	if (time_out >= 0.0)
	{
		GetProperty(block, 3, property);
		entity_set_float(id, EV_FL_maxspeed, str_to_float(property));
	}

	else if ( get_bit(g_ice, id) )
	{
		entity_set_float(id, EV_FL_maxspeed, 400.0);
	}
	else if ( g_honey[id] )
	{
		block = g_honey[id];
		GetProperty(block, 1, property);
		
		entity_set_float(id, EV_FL_maxspeed, str_to_float(property));
	}

	//ResetMaxspeed(id);
}

public pfn_touch(iEntity, id)
{
	if ( !( 1 <= id <= g_max_players )
	|| !get_bit(g_alive, id)
	|| !IsBlock(iEntity) ) return PLUGIN_CONTINUE;
	
	new block_type =	entity_get_int(iEntity, EV_INT_body);
	if ( block_type == GLASS ) return PLUGIN_CONTINUE;
	
	new flags =		entity_get_int(id, EV_INT_flags);
	new groundentity =	entity_get_edict(id, EV_ENT_groundentity);
	
	static property[5];
	GetProperty(iEntity, 4, property);
	
	if ( property[0] == '0'
	|| ( ( !property[0]
		|| property[0] == '1'
		|| property[0] == '/'
		|| block_type == BLIND_TRAP || block_type == HEALER )
	&& flags & FL_ONGROUND
	&& groundentity == iEntity ) )
	{
		switch ( block_type )
		{
			case BHOP, NO_SLOW_DOWN_BHOP:		ActionBhop(iEntity);
			case DAMAGE:				ActionDamage(id, iEntity);
			case HEALER:				ActionHeal(id, iEntity);
			case TRAMPOLINE:			ActionTrampoline(id, iEntity);
			case SPEED_BOOST:			ActionSpeedBoost(id, iEntity);
			case DEATH:				ActionDeath(id);
			case SLAP:
			{
				GetProperty(iEntity, 1, property);
				g_slap[id] = property;
			}
			case LOW_GRAVITY:			ActionLowGravity(id, iEntity);
			case HONEY:				ActionHoney(id, iEntity);
			case CT_BARRIER:			ActionCTBarrier(id, iEntity);
			case T_BARRIER:				ActionTBarrier(id, iEntity);
			case DELAYED_BHOP:			ActionDelayedBhop(iEntity);
			case STEALTH:				ActionStealth(id, iEntity);
			case INVINCIBILITY:			ActionInvincibility(id, iEntity);
			case BOOTS_OF_SPEED:			ActionBootsOfSpeed(id, iEntity);
			case WEAPON_BLOCK:			ActionWeaponBlock(id, iEntity);
			case NADE_BLOCK:			ActionNadeBlock(id, iEntity);
			case DUCK_BLOCK:			ActionDuckBlock(id);
			case XP_BLOCK:				ActionXPBlock(id);
			case SUPERMAN:				ActionSuperman(id, iEntity);
			case BLIND_TRAP:			ActionBlindTrap(id, iEntity);
			case MONEY:				ActionMoney(id, iEntity);
			case BOUNCE_DEATH:               		ActionDeathBounce(id);
			case TELEPORT:				ActionTeleportBlock(id, iEntity);
			case MAGIC_CARPET:			ActionMagicCarpet(id, iEntity);
		}
	}
	
	if ( flags & FL_ONGROUND
	&& groundentity == iEntity )
	{
		switch ( block_type )
		{
			case BHOP:
			{
				GetProperty(iEntity, 1, property);
				if ( property[0] == '1' )
				{
					set_bit(g_no_fall_damage, id);
				}
			}
			case NO_FALL_DAMAGE:			set_bit(g_no_fall_damage, id);
			case ICE:				ActionIce(id, iEntity);
			case NO_SLOW_DOWN_BHOP:
			{
				ActionNoSlowDown(id);
				
				GetProperty(iEntity, 1, property);
				if ( property[0] == '1' )
				{
					set_bit(g_no_fall_damage, id);
				}
			}
		}
	}
	
	return PLUGIN_CONTINUE;
}

public client_PreThink(id)
{
	if ( !get_bit(g_alive, id) ) return PLUGIN_CONTINUE;

	new Float:gametime =			get_gametime();
	new Float:timeleft_invincibility =	g_invincibility_time_out[id] - gametime;
	new Float:timeleft_stealth =		g_stealth_time_out[id] - gametime;
	new Float:timeleft_boots_of_speed =	g_boots_of_speed_time_out[id] - gametime;
	new Float:timeleft_superman =		g_superman_time_out[id] - gametime;
	
	if ( timeleft_invincibility >= 0.0
	|| timeleft_stealth >= 0.0
	|| timeleft_boots_of_speed >= 0.0
	|| timeleft_superman >= 0.0 )
		
	{
		new text[48], text_to_show[256];
		
		format(text, charsmax(text), "%s %s", PLUGIN_PREFIX, PLUGIN_VERSION);
		add(text_to_show, charsmax(text_to_show), text);
	
		if ( timeleft_invincibility >= 0.0 )
		{
			format(text, charsmax(text), "^nInvincible %.1f", timeleft_invincibility);
			add(text_to_show, charsmax(text_to_show), text);
		}
		
		if ( timeleft_stealth >= 0.0 )
		{
			format(text, charsmax(text), "^nStealth %.1f", timeleft_stealth);
			add(text_to_show, charsmax(text_to_show), text);
		}
		
		if ( timeleft_boots_of_speed >= 0.0 )
		{
			format(text, charsmax(text), "^nBoots Of Speed %.1f", timeleft_boots_of_speed);
			add(text_to_show, charsmax(text_to_show), text);
		}
		if ( timeleft_superman >= 0.0 )
		{
			format(text, charsmax(text), "^nTimed Gravity: %.1f^n", timeleft_superman);
			add(text_to_show, charsmax(text_to_show), text);
		}
		
		set_hudmessage(255, 51, 0, -1.0, 0.84, 0, 0.75, 0.75, 0.75, 0.75, 2);
		show_hudmessage(id, text_to_show);
		
		set_bit(g_has_hud_text, id);
	}
	else
	{
		clear_bit(g_has_hud_text, id);
	}
	
	if ( get_bit(g_ice, id) || get_bit(g_no_slow_down, id) )
	{
		entity_set_float(id, EV_FL_fuser2, 0.0);
	}
	
	if ( g_set_velocity[id][0] != 0.0
	|| g_set_velocity[id][1] != 0.0
	|| g_set_velocity[id][2] != 0.0 )
	{
		entity_set_vector(id, EV_VEC_velocity, g_set_velocity[id]);
		
		g_set_velocity[id][0] = 0.0;
		g_set_velocity[id][1] = 0.0;
		g_set_velocity[id][2] = 0.0;
	}
	
	if ( get_bit(g_low_gravity, id) )
	{
		if ( entity_get_int(id, EV_INT_flags) & FL_ONGROUND )
		{
			entity_set_float(id, EV_FL_gravity, 1.0);
			clear_bit(g_low_gravity, id);
		}
	}
	
	if ( g_slap[id][0] )
	{
		new slap_times = str_to_num(g_slap[id]) * 2;
		while ( slap_times )
		{
			user_slap(id, 0);
			slap_times--;
		}
		
		g_slap[id][0] = 0;
	}		
	
	return PLUGIN_CONTINUE;
}

public server_frame()
{
	static iEntity;
	static entinsphere;
	static Float:origin[3];
	
	while ( ( iEntity = find_ent_by_class(iEntity, g_start_classname) ) )
	{
		entity_get_vector(iEntity, EV_VEC_origin, origin);
		
		entinsphere = -1;
		while ( ( entinsphere = find_ent_in_sphere(entinsphere, origin, 40.0) ) )
		{
			static classname[32];
			entity_get_string(entinsphere, EV_SZ_classname, classname, charsmax(classname));
			
			if ( 1 <= entinsphere <= g_max_players && get_bit(g_alive, entinsphere) )
			{
				ActionTeleport(entinsphere, iEntity);
			}
			else if ( equal(classname, "grenade") )
			{
				entity_set_int(iEntity, EV_INT_solid, SOLID_NOT);
				ActionTeleport(entinsphere, iEntity);
				entity_set_float(iEntity, EV_FL_ltime, get_gametime() + 2.0);
			}
			else if ( get_gametime() >= entity_get_float(iEntity, EV_FL_ltime) )
			{
				entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
			}
		}
	}
	
	static bool:ent_near;
	
	ent_near = false;
	while ( ( iEntity = find_ent_by_class(iEntity, g_destination_classname) ) )
	{
		entity_get_vector(iEntity, EV_VEC_origin, origin);
		
		entinsphere = -1;
		while ( ( entinsphere = find_ent_in_sphere(entinsphere, origin, 64.0) ) )
		{
			static classname[32];
			entity_get_string(entinsphere, EV_SZ_classname, classname, charsmax(classname));
			
			if ( 1 <= entinsphere <= g_max_players && get_bit(g_alive, entinsphere)
			|| equal(classname, "grenade") )
			{
				ent_near = true;
				break;
			}
		}
		
		if ( ent_near )
		{
			if ( !entity_get_int(iEntity, EV_INT_iuser2) )
			{
				entity_set_int(iEntity, EV_INT_solid, SOLID_NOT);
			}
		}
		else
		{
			entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
		}
	}
}

public client_PostThink(id)
{
	if ( !get_bit(g_alive, id) ) return PLUGIN_CONTINUE;
	
	if ( get_bit(g_no_fall_damage, id) )
	{
		entity_set_int(id,  EV_INT_watertype, -3);
		clear_bit(g_no_fall_damage, id);
	}
	
	return PLUGIN_CONTINUE;
}

ActionBhop(iEntity)
{
	if ( task_exists(TASK_SOLIDNOT + iEntity)
	|| task_exists(TASK_SOLID + iEntity) ) return PLUGIN_HANDLED;
	
	set_task(0.1, "TaskSolidNot", TASK_SOLIDNOT + iEntity);
	
	return PLUGIN_HANDLED;
}

ActionDeath(id)	
{
	if (!get_user_godmode(id))
	{
		new szPlayerName[32];
		get_user_name(id, szPlayerName, 31);
		BCM_Print(0, "^3%s^1 has died on a ^3Deathblock^1.", szPlayerName);
		fakedamage(id, "the block of death", 10000.0, DMG_GENERIC);
		
	}
}

ActionDamage(id, iEntity)
{
	new Float:gametime = get_gametime();
	if ( !( gametime >= g_next_damage_time[id] )
	|| get_user_health(id) <= 0 ) return PLUGIN_HANDLED;
	
	static property[5];
	
	GetProperty(iEntity, 1, property);
	fakedamage(id, "Damage block", str_to_float(property), DMG_CRUSH);
	
	static Float:interval;
	GetProperty(iEntity, 2, property);
	interval = str_to_float(property);
	g_next_damage_time[id] = gametime + interval;
	
	return PLUGIN_HANDLED;
}

ActionHeal(id, iEntity)
{
	new Float:gametime = get_gametime();
	
	static property[5];
	GetProperty(iEntity, 4, property);
	switch ( property[0] )
	{
		case '1':
		{
			if ( !( gametime >= g_next_heal_time[id] ) ) return PLUGIN_HANDLED;
	
			new hp = get_user_health(id);
		  
			if( hp >= 100 ) {
				g_next_heal_time[id] = gametime;         
				return PLUGIN_HANDLED;
			}
			
			GetProperty(iEntity, 1, property);
			new Float:new_health = get_user_health(id) + str_to_float(property);
			
			if ( new_health < 100 )	entity_set_float(id, EV_FL_health, new_health);
			else			entity_set_float(id, EV_FL_health, 100.0);
			
			static Float:interval;
			GetProperty(iEntity, 2, property);
			interval = str_to_float(property);
			g_next_heal_time[id] = gametime + interval;
			
			return PLUGIN_HANDLED;
		}
		case '2':
		{
			if ( !( gametime >= g_next_heal_time[id] ) ) return PLUGIN_HANDLED;
	
			new armor = get_user_armor(id);
		  
			if( armor >= 100 ) {
				g_next_heal_time[id] = gametime;         
				return PLUGIN_HANDLED;
			}
			
			GetProperty(iEntity, 1, property);
			new Float:new_armor = get_user_armor(id) + str_to_float(property);
			
			if ( new_armor < 100 )	entity_set_float(id, EV_FL_armorvalue, new_armor);
			else			entity_set_float(id, EV_FL_armorvalue, 100.0);
			
			static Float:interval;
			GetProperty(iEntity, 2, property);
			interval = str_to_float(property);
			g_next_heal_time[id] = gametime + interval;
			
			return PLUGIN_HANDLED;
		}
		case '3':
		{
			if ( !( gametime >= g_next_heal_time[id] ) ) return PLUGIN_HANDLED;
	
			new hp = get_user_health(id);
			if( hp <= 100 ) {
				g_next_heal_time[id] = gametime;   
				GetProperty(iEntity, 1, property);
				new Float:new_health = get_user_health(id) + str_to_float(property);
				
				if ( new_health < 100 )	entity_set_float(id, EV_FL_health, new_health);
				else			entity_set_float(id, EV_FL_health, 100.0);
			}
			
			new armor = get_user_armor(id);
			if( armor <= 100 ) {
				g_next_heal_time[id] = gametime;   
				GetProperty(iEntity, 1, property);
				new Float:new_armor = get_user_armor(id) + str_to_float(property);
				
				if ( new_armor < 100 )	entity_set_float(id, EV_FL_armorvalue, new_armor);
				else			entity_set_float(id, EV_FL_armorvalue, 100.0);
			}
			static Float:interval;
			GetProperty(iEntity, 2, property);
			interval = str_to_float(property);
			g_next_heal_time[id] = gametime + interval;
		}
		
	}
	return PLUGIN_HANDLED;
}

ActionIce(id, iEntity)
{
	if ( !get_bit(g_ice, id) )
	{
		static property[5];
		GetProperty(iEntity, 1, property);
		new Float:new_friction = str_to_float(property);
		if(new_friction >= 0.0)  
		{
			entity_set_float(id, EV_FL_friction, new_friction);
		
		} else {
			
			entity_set_float(id, EV_FL_friction, 0.15);
		}
		entity_set_float(id, EV_FL_maxspeed, 600.0);
		
		set_bit(g_ice, id);
	}
	
	new task_id = TASK_ICE + id;
	if ( task_exists(task_id) ) 
	{
		remove_task(task_id);
	}
	
	set_task(0.1, "TaskNotOnIce", task_id);
}

ActionTrampoline(id, iEntity)
{
	static property1[5];
	GetProperty(iEntity, 1, property1);
	
	entity_get_vector(id, EV_VEC_velocity, g_set_velocity[id]);
	
	g_set_velocity[id][2] = str_to_float(property1);
	
	entity_set_int(id, EV_INT_gaitsequence, 6);
	
	set_bit(g_no_fall_damage, id);
}

ActionSpeedBoost(id, iEntity)
{
	static property[5];
	
	GetProperty(iEntity, 1, property);
	velocity_by_aim(id, str_to_num(property), g_set_velocity[id]);
	
	GetProperty(iEntity, 2, property);
	g_set_velocity[id][2] = str_to_float(property);
	
	entity_set_int(id, EV_INT_gaitsequence, 6);

}

ActionLowGravity(id, iEntity)
{
	if ( get_bit(g_low_gravity, id) ) return PLUGIN_HANDLED;
	
	static property1[5];
	GetProperty(iEntity, 1, property1);
	
	entity_set_float(id, EV_FL_gravity, str_to_float(property1) / 800);
	
	set_bit(g_low_gravity, id);
	
	return PLUGIN_HANDLED;
}

ActionHoney(id, iEntity)
{
	if ( g_honey[id] != iEntity )
	{
		static property1[5];
		GetProperty(iEntity, 1, property1);
		
		new Float:speed = str_to_float(property1);
		entity_set_float(id, EV_FL_maxspeed, speed == 0 ? -1.0 : speed);
		
		g_honey[id] = iEntity;
	}
	
	new task_id = TASK_HONEY + id;
	if ( task_exists(task_id) )
	{
		remove_task(task_id);
	}
	else
	{
		static Float:velocity[3];
		entity_get_vector(id, EV_VEC_velocity, velocity);
		
		velocity[0] /= 2.0;
		velocity[1] /= 2.0;
		
		entity_set_vector(id, EV_VEC_velocity, velocity);
	}
	
	set_task(0.1, "TaskNotInHoney", task_id);
}

ActionCTBarrier(id, iEntity)
{
	static property[5];
	GetProperty(iEntity, 1, property);
	new CsTeams:playerTeam = cs_get_user_team(id);
	switch ( property[0] )
	{
		case '1'://Normal
		{
			if(playerTeam == CS_TEAM_CT)
			{
				return;
			}
			if(playerTeam == CS_TEAM_T)
			{
				TaskSolidNot(TASK_SOLIDNOT + iEntity);
			}
		}
		case '2': // Team admins only
		{
			if(playerTeam == CS_TEAM_CT )
			{
				return;
			}
			if(playerTeam == CS_TEAM_T && get_bit(g_admin, id) )
			{
				TaskSolidNot(TASK_SOLIDNOT + iEntity);
			}
		}
		case '3':
		{
			if(playerTeam == CS_TEAM_CT || playerTeam == CS_TEAM_T && get_bit(g_admin, id) )
			{
				TaskSolidNot(TASK_SOLIDNOT + iEntity);
			}
		}
	}
}

ActionTBarrier(id, iEntity)
{
	static property[5];
	GetProperty(iEntity, 1, property);
	new CsTeams:playerTeam = cs_get_user_team(id);
	switch ( property[0] )
	{
		case '1'://Normal
		{
			if(playerTeam == CS_TEAM_T)
			{
				return;
			}
			if(playerTeam == CS_TEAM_CT)
			{
				TaskSolidNot(TASK_SOLIDNOT + iEntity);
			}
		}
		case '2': // Team admins only
		{
			if(playerTeam == CS_TEAM_T)
			{
				return;
			}
			if(playerTeam == CS_TEAM_CT && get_bit(g_admin, id) )
			{
				TaskSolidNot(TASK_SOLIDNOT + iEntity);
			}
		}
		case '3': 
		{
			if(playerTeam == CS_TEAM_T || playerTeam == CS_TEAM_CT && get_bit(g_admin, id) )
			{
				TaskSolidNot(TASK_SOLIDNOT + iEntity);
			}
		}
	}	
}					

ActionNoSlowDown(id)
{
	set_bit(g_no_slow_down, id);
	
	new task_id = TASK_NOSLOWDOWN + id;
	if ( task_exists(task_id) ) remove_task(task_id);
	
	set_task(0.1, "TaskSlowDown", task_id);
}

ActionDelayedBhop(iEntity)
{
	if ( task_exists(TASK_SOLIDNOT + iEntity)
	|| task_exists(TASK_SOLID + iEntity) ) return PLUGIN_HANDLED;
	
	static property1[5];
	GetProperty(iEntity, 1, property1);
	
	set_task(str_to_float(property1), "TaskSolidNot", TASK_SOLIDNOT + iEntity);
	return PLUGIN_HANDLED;
}

ActionInvincibility(id, iEntity)
{
	new Float:gametime = get_gametime();
	if ( gametime >= g_invincibility_next_use[id] )
	{
		static property[5];
		
		entity_set_float(id, EV_FL_takedamage, DAMAGE_NO);
		
		if ( gametime >= g_stealth_time_out[id] )
		{
			set_user_rendering(id, kRenderFxGlowShell, 0, 51, 0, kRenderNormal, 16);
		}
		
		//emit_sound(id, CHAN_STATIC, g_sound_invincibility, 1.0, ATTN_NORM, 0, PITCH_NORM);
		
		static Float:time_out;
		GetProperty(iEntity, 1, property);
		time_out = str_to_float(property);
		set_task(time_out, "TaskRemoveInvincibility", TASK_INVINCIBLE + id, "", 0, "a", 1);
		
		static Float:delay;
		GetProperty(iEntity, 2, property);
		delay = str_to_float(property);
		
		g_invincibility_time_out[id] = gametime + time_out;
		g_invincibility_next_use[id] = gametime + time_out + delay;
	}
	else if ( !get_bit(g_has_hud_text, id) )
	{
		set_hudmessage(255, 51, 0, -1.0, 0.84, 0, 0.75, 0.75, 0.75, 0.75, 2);
		show_hudmessage(id, "%s %s^nInvincibility^nNext Use %.1f", PLUGIN_PREFIX, PLUGIN_VERSION, g_invincibility_next_use[id] - gametime);
	}
}

ActionStealth(id, iEntity)
{
	new Float:gametime = get_gametime();
	if ( gametime >= g_stealth_next_use[id] )
	{
		static property[5];
		
		set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransColor, 0);
		
		set_bit(g_block_status, id);
		
		//emit_sound(id, CHAN_STATIC, g_sound_stealth, 1.0, ATTN_NORM, 0, PITCH_NORM);
		
		static Float:time_out;
		GetProperty(iEntity, 1, property);
		time_out = str_to_float(property);
		set_task(time_out, "TaskRemoveStealth", TASK_STEALTH + id, "", 0, "a", 1);
		
		static Float:delay;
		GetProperty(iEntity, 2, property);
		delay = str_to_float(property);
		
		g_stealth_time_out[id] = gametime + time_out;
		g_stealth_next_use[id] = gametime + time_out + delay;
	}
	else if ( !get_bit(g_has_hud_text, id) )
	{
		set_hudmessage(255, 51, 0, -1.0, 0.84, 0, 0.75, 0.75, 0.75, 0.75, 2);
		show_hudmessage(id, "%s %s^nStealth^nNext Use %.1f", PLUGIN_PREFIX, PLUGIN_VERSION, g_stealth_next_use[id] - gametime);
	}
}

ActionBootsOfSpeed(id, iEntity)
{
	new Float:gametime = get_gametime();
	if ( !g_boots_of_speed[id] )
	{
		set_bit(g_bootsofspeed, id);
		static property[5];
		
		GetProperty(iEntity, 3, property);
		entity_set_float(id, EV_FL_maxspeed, str_to_float(property));
		
		g_boots_of_speed[id] = iEntity;
		
		//emit_sound(id, CHAN_STATIC, g_sound_boots_of_speed, 1.0, ATTN_NORM, 0, PITCH_NORM);
		
		static Float:time_out;
		GetProperty(iEntity, 1, property);
		time_out = str_to_float(property);
		set_task(time_out, "TaskRemoveBootsOfSpeed", TASK_BOOTSOFSPEED + id, "", 0, "a", 1);
		
		static Float:delay;
		GetProperty(iEntity, 2, property);
		delay = str_to_float(property);
		
		g_boots_of_speed_time_out[id] = gametime + time_out;
		g_boots_of_speed_next_use[id] = gametime + time_out + delay;
	}
	else if ( !get_bit(g_has_hud_text, id) )
	{
		set_hudmessage(255, 51, 0, -1.0, 0.84, 0, 0.75, 0.75, 0.75, 0.75, 2);
		show_hudmessage(id, "%s %s^nBoots Of Speed^nNext Use %.1f", PLUGIN_PREFIX, PLUGIN_VERSION, g_boots_of_speed_next_use[id] - gametime);
	}

}

ActionNadeBlock(id, iEntity)
{
	new CsTeams:playerTeam = cs_get_user_team(id);
	if(is_user_alive(id) && playerTeam == CS_TEAM_T)
	{
		static property[5];
		GetProperty(iEntity, 1, property);
		switch ( property[0] )
		{
			case '1':
			{
				if(!get_bit(g_hegrenade_used, id))
				{
					if ( cs_get_user_bpammo(id, CSW_HEGRENADE) > 0 )
					{
						return PLUGIN_HANDLED;
					}
					give_item(id, "weapon_hegrenade");
					set_bit(g_hegrenade_used, id);
				}
			}
			case '2':
			{
				if(!get_bit(g_smokegrenade_used, id))
				{
					if ( cs_get_user_bpammo(id, CSW_SMOKEGRENADE) > 0 )
					{
						return PLUGIN_HANDLED;
					}
					give_item(id, "weapon_smokegrenade");
					set_bit(g_smokegrenade_used, id);
				}
			}
			case '3':
			{
				if(!get_bit(g_flashgrenade_used, id))
				{
					if ( cs_get_user_bpammo(id, CSW_FLASHBANG) > 0 )
					{
						return PLUGIN_HANDLED;
					}
					give_item(id, "weapon_flashbang");
					set_bit(g_flashgrenade_used, id);
				}
			}
		}
	}
	return PLUGIN_HANDLED;
}


ActionWeaponBlock(id, iEntity)
{
	new CsTeams:playerTeam = cs_get_user_team(id);
	if(is_user_alive(id) && playerTeam == CS_TEAM_T)
	{
		static property[5];
		GetProperty(iEntity, 1, property);
		new szPlayerName[32];
		get_user_name(id, szPlayerName, 32);
		switch ( property[0] )
		{
			case '1':
			{
				if(!get_bit(g_awp_used, id) )
				{
					if( !user_has_weapon(id, CSW_AWP) )
					{
						give_item(id, "weapon_awp");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_awp", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_AWP, 0);
					set_bit(g_awp_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an AWP with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '2':
			{
				if(!get_bit(g_deagle_used, id))
				{
					if( !user_has_weapon(id, CSW_DEAGLE) )
					{
						give_item(id, "weapon_deagle");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_deagle", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_DEAGLE, 0);
					set_bit(g_deagle_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an Deagle with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '3':
			{
				if(!get_bit(g_usp_used, id))
				{
					if( !user_has_weapon(id, CSW_USP) )
					{
						give_item(id, "weapon_usp");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_usp", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_USP, 0);
					set_bit(g_usp_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an USP with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '4':
			{
				if(!get_bit(g_tmp_used, id))
				{
					if( !user_has_weapon(id, CSW_TMP) )
					{
						give_item(id, "weapon_tmp");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_tmp", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_TMP, 0);
					set_bit(g_tmp_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an TMP with %d bullets%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '5':
			{
				if(!get_bit(g_aug_used, id))
				{
					if( !user_has_weapon(id, CSW_AUG) )
					{
						give_item(id, "weapon_aug");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_aug", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_AUG, 0);
					set_bit(g_aug_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an Aug with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '6':
			{
				if(!get_bit(g_m3_used, id))
				{
					if( !user_has_weapon(id, CSW_M3) )
					{
						give_item(id, "weapon_m3");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_m3", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_M3, 0);
					set_bit(g_m3_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an Shotgun with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '7':
			{
				if(!get_bit(g_mac10_used, id))
				{
					if( !user_has_weapon(id, CSW_MAC10) )
					{
						give_item(id, "weapon_mac10");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_mac10", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_MAC10, 0);
					set_bit(g_mac10_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an Mac10 with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '8':
			{
				if(!get_bit(g_ak47_used, id))
				{
					if( !user_has_weapon(id, CSW_AK47) )
					{
						give_item(id, "weapon_ak47");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_ak47", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_AK47, 0);
					set_bit(g_ak47_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an AK47 with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
			case '9':
			{
				if(!get_bit(g_c4_used, id))
				{
					if( !user_has_weapon(id, CSW_FAMAS) )
					{
						give_item(id, "weapon_famas");
					}
					new weapon_id = find_ent_by_owner(-1, "weapon_famas", id);
					if(weapon_id)
					{
						GetProperty(iEntity, 2, property);
						cs_set_weapon_ammo(weapon_id, str_to_num(property));
					}
					cs_set_user_bpammo(id, CSW_FAMAS, 0);
					set_bit(g_c4_used, id);
					
					set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 10.0, 1.0, 1.0);
					show_hudmessage(0, "%s has an Famas with %d bullet%s!!! BEWARE CTS !!!", szPlayerName, str_to_num(property), str_to_num(property) == 1 ? "" : "s" );
				}
			}
		}
	}
	else if ( !get_bit(g_has_hud_text, id) )
	{
		set_hudmessage(255, 51, 0, -1.0, 0.35, 0, 6.0, 2.0, 1.0, 1.0);
		show_hudmessage(id, "Gun next use: Next Round");
	}	
}

ActionDuckBlock(id)
{
	set_pev(id, pev_bInDuck, 1);
}

ActionXPBlock(id)
{
	set_bit(g_no_fall_damage, id);
	new Float:origin[3], Float:oFar[3], Float:oRetNormal[3];
	pev(id, pev_velocity, g_set_velocity[id]);
	pev(id, pev_origin, origin);
	oFar[0] = origin[0] + (g_set_velocity[id][0] * 8192.0);
	oFar[1] = origin[1] + (g_set_velocity[id][1] * 8192.0);
	oFar[2] = origin[2] + (g_set_velocity[id][2] * 8192.0);
	fm_trace_normal(id, origin, oFar, oRetNormal);
	g_set_velocity[id][0] = -2.0 * (g_set_velocity[id][0]*oRetNormal[0])*oRetNormal[0] + g_set_velocity[id][0];
	g_set_velocity[id][1] = -2.0 * (g_set_velocity[id][1]*oRetNormal[1])*oRetNormal[1] + g_set_velocity[id][1];
	g_set_velocity[id][2] = -2.0 * (g_set_velocity[id][2]*oRetNormal[2])*oRetNormal[2] + g_set_velocity[id][2];
}

ActionBlindTrap(id, iEntity)
{
	static color_red[5], color_green[5], color_blue[5], color_alpha[5];
	
	new Float:gametime = get_gametime();
	if ( gametime >= g_blind_next_use[id] )
	{	
		static Float:delay;
		delay = 3.0;
		g_blind_next_use[id] = gametime + delay;
		
		GetProperty(iEntity, 1, color_red);
		GetProperty(iEntity, 2, color_green);
		GetProperty(iEntity, 3, color_blue);
		GetProperty(iEntity, 4, color_alpha);

		message_begin(MSG_ONE, gmsgScreenFade, {0,0,0}, id);
		write_short(4096*3);    // Duration
		write_short(4096*3);    // Hold time
		write_short(4096);    // Fade type
		write_byte(str_to_num(color_red));
		write_byte(str_to_num(color_green));
		write_byte(str_to_num(color_blue));
		write_byte(str_to_num(color_alpha));    // Alpha
		message_end();
	}
}

ActionSuperman(id, iEntity)
{
	new Float:gametime = get_gametime();
	if ( gametime >= g_superman_next_use[id] )
	{	
		static property[5];

		set_user_gravity(id, 0.50);
		
		set_bit(g_block_status, id);

		static Float:time_out;
		GetProperty(iEntity, 1, property);
		time_out = str_to_float(property);
		set_task(time_out, "TaskRemoveSuperman", TASK_SUPERMAN + id, g_blank, 0, "a", 1);
	
		static Float:delay;
		GetProperty(iEntity, 2, property);
		delay = str_to_float(property);
		
		g_superman_time_out[id] = gametime + time_out;
		g_superman_next_use[id] = gametime + time_out + delay;
		//emit_sound(id, CHAN_STATIC, g_sound_supermario, 0.3, ATTN_NORM, 0, PITCH_NORM);
	}
	else if ( !get_bit(g_has_hud_text, id) )
	{
		set_hudmessage(255, 51, 0, -1.0, 0.84, 0, 0.75, 0.75, 0.75, 0.75, 2);
		show_hudmessage(id, "%s %s^nSuperman^nNext Use %.1f", PLUGIN_PREFIX, PLUGIN_VERSION, g_superman_next_use[id] - gametime);
	}
}

ActionMoney(id, iEntity)
{
	if (is_user_alive(id) && !get_bit(g_money_used, id))
	{
		static property[5];
		GetProperty(iEntity, 1, property);
		cs_set_user_money(id, cs_get_user_money (id) + str_to_num(property));
		set_bit(g_money_used, id);
		BCM_Print(id, "^1You just got ^3$^4%i^1!", str_to_num(property));// ^4=Green ^3=Silver ^1=Normal
		//emit_sound(id, CHAN_STATIC, g_sound_money, 1.0, ATTN_NORM, 0, PITCH_NORM);
	}
	else if ( !get_bit(g_has_hud_text, id) )
	{
		set_hudmessage(255, 51, 0, 0.01, 0.18, 0, 0.0, 1.0, 0.25, 0.25, 2);
		show_hudmessage(id, "Money Usage: One per round!");
	}
}

ActionDeathBounce(id)
{
	if (!get_user_godmode(id))
	{
		new szPlayerName[32];
		get_user_name(id, szPlayerName, 31);
		BCM_Print(0, "^3%s^1 has died on a ^3Deathblock^1.", szPlayerName);
		//emit_sound(id, CHAN_STATIC, g_sound_death_bounce, 0.1, ATTN_NORM, 0, PITCH_NORM);
		fakedamage(id, "the block of death", 10000.0, DMG_GENERIC);
		
	}
}

public bounce_death(iEntity)
{
	if ( IsBlock(iEntity) )
	{
		new block_type = entity_get_int(iEntity, EV_INT_body);
		if(pev_valid(iEntity) && block_type == BOUNCE_DEATH)
		{
			
			static property[5];
			GetProperty(iEntity, 1, property);
			if(pev(iEntity, pev_flags)&FL_ONGROUND)
			{
				new Float:velocity[3];
				velocity[2] = str_to_float(property);
				set_pev(iEntity, pev_velocity, velocity);
			}
			set_task(0.1, "bounce_death", iEntity);
		}
	}
}

ActionTeleport(id, iEntity)
{
	new tele = entity_get_int(iEntity, EV_INT_iuser1);
	if ( !tele ) return PLUGIN_HANDLED;
	
	static Float:tele_origin[3];
	entity_get_vector(tele, EV_VEC_origin, tele_origin);
	
	new player = -1;
	do
	{
		player = find_ent_in_sphere(player, tele_origin, 16.0);
		
		if ( !is_user_alive(player)
		|| player == id
		|| cs_get_user_team(id) == cs_get_user_team(player) ) continue;
		
		user_kill(player, 1);
	}
	while ( player );
	
	entity_set_vector(id, EV_VEC_origin, tele_origin);

	static Float:velocity[3];
	entity_get_vector(id, EV_VEC_velocity, velocity);
	velocity[2] = floatabs(velocity[2]);
	entity_set_vector(id, EV_VEC_velocity, velocity);
	//emit_sound(id, CHAN_STATIC, g_sound_teleport, 1.0, ATTN_NORM, 0, PITCH_NORM);
	
	return PLUGIN_HANDLED;
}

ActionTeleportBlock(id, iEntity)
{	
	set_bit(g_no_fall_damage, id);	
	g_teleport_block_start[id] = iEntity;
	new tele = entity_get_int(iEntity, EV_INT_iuser4);
	if ( !tele ) return PLUGIN_HANDLED;
	
	static Float:tele_origin[3];
	entity_get_vector(tele, EV_VEC_origin, tele_origin);
	tele_origin[2] += 48.0;
	new player = -1;
	do
	{
		player = find_ent_in_sphere(player, tele_origin, 16.0);
		
		if ( !is_user_alive(player)
		|| player == id
		|| cs_get_user_team(id) == cs_get_user_team(player) ) continue;
		
		user_kill(player, 1);
	}
	while ( player );
	
	entity_set_vector(id, EV_VEC_origin, tele_origin);

	//emit_sound(id, CHAN_STATIC, g_sound_teleport, 1.0, ATTN_NORM, 0, PITCH_NORM);

	return PLUGIN_HANDLED;
}

ActionMagicCarpet(id, iEntity)
{
	static property[5];
	new Float:vVelocity[3]; 
	
	GetProperty(iEntity, 1, property);
	switch ( property[0] )
	{
		case '1':
		{
			if( get_user_team(id) == 1 ) {
				pev( id, pev_velocity, vVelocity ); 
				vVelocity[2] = 0.0; 
				set_pev( iEntity, pev_velocity, vVelocity ); 
				entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_FLY);
				GetProperty(iEntity, 2, property);
				new task_id = TASK_MOVEBACK + iEntity;
				if ( !task_exists(task_id) )
					set_task(str_to_float(property), "TaskMoveBack", TASK_MOVEBACK + iEntity);
			}
		}
		case '2':
		{
			if( get_user_team(id) == 2 ) {
				pev( id, pev_velocity, vVelocity ); 
				vVelocity[2] = 0.0; 
				set_pev( iEntity, pev_velocity, vVelocity ); 
				entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_FLY);
				GetProperty(iEntity, 2, property);
				new task_id = TASK_MOVEBACK + iEntity;
				if ( !task_exists(task_id) )
					set_task(str_to_float(property), "TaskMoveBack", TASK_MOVEBACK + iEntity);
			}
		}
		case '3':
		{
			pev( id, pev_velocity, vVelocity ); 
			vVelocity[2] = 0.0; 
			set_pev( iEntity, pev_velocity, vVelocity ); 
			entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_FLY);
			GetProperty(iEntity, 2, property);
			new task_id = TASK_MOVEBACK + iEntity;
			if ( !task_exists(task_id) )
				set_task(str_to_float(property), "TaskMoveBack", TASK_MOVEBACK + iEntity);
		}
		case '4':
		{
			// platfrom
			//entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
		}
	}
	
}

public TaskSolidNot(iEntity)
{
	iEntity -= TASK_SOLIDNOT;
	
	if ( !is_valid_ent(iEntity)
	|| entity_get_int(iEntity, EV_INT_iuser2) ) return PLUGIN_HANDLED;
	
	entity_set_int(iEntity, EV_INT_solid, SOLID_NOT);
	set_rendering(iEntity, kRenderFxNone, 255, 255, 255, kRenderTransAdd, 25);
	set_task(1.0, "TaskSolid", TASK_SOLID + iEntity);
	
	return PLUGIN_HANDLED;
}

public TaskMoveBack(iEntity)
{
	iEntity -= TASK_MOVEBACK;
	
	if ( !is_valid_ent(iEntity) 
	|| entity_get_int(iEntity, EV_INT_iuser2) ) return PLUGIN_HANDLED;
	
	new Float:origin[3];
	pev(iEntity, pev_v_angle, origin);
			
	set_pev(iEntity, pev_velocity, Float:{0.0, 0.0, 0.0});
	engfunc(EngFunc_SetOrigin, iEntity, origin);
	
	return PLUGIN_HANDLED;
}	

public TaskSolid(iEntity)
{
	iEntity -= TASK_SOLID;
	
	if ( !IsBlock(iEntity) ) return PLUGIN_HANDLED;
	
	entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
	
	if ( entity_get_int(iEntity, EV_INT_iuser1) > 0 )
	{
		GroupBlock(0, iEntity);
	}
	else
	{
		static property3[5];
		GetProperty(iEntity, 3, property3);
		
		new transparency = str_to_num(property3);
		if ( !transparency
		|| transparency == 255 )
		{
			new block_type = entity_get_int(iEntity, EV_INT_body);
			SetBlockRendering(iEntity, g_render[block_type], g_red[block_type], g_green[block_type], g_blue[block_type], g_alpha[block_type]);
		}
		else
		{
			SetBlockRendering(iEntity, TRANSALPHA, 255, 255, 255, transparency);
		}
	}
	static property[5];
	GetProperty(iEntity, 4, property);
	if( property[0] == '1' )
		set_task(0.2, "checkstuck");
	
	return PLUGIN_HANDLED;
}

public TaskNotOnIce(id)
{
	id -= TASK_ICE;
	
	clear_bit(g_ice, id);
	
	if ( !get_bit(g_alive, id) ) return PLUGIN_HANDLED;
	
	if ( get_bit(g_bootsofspeed, id) )
	{
		static block, property3[5];
		block = g_boots_of_speed[id];
		GetProperty(block, 3, property3);
		
		entity_set_float(id, EV_FL_maxspeed, str_to_float(property3));
	}
	else
	{
		ResetMaxspeed(id);
	}
	entity_set_float(id, EV_FL_friction, 1.0);
	
	return PLUGIN_HANDLED;
}

public TaskNotInHoney(id)
{
	id -= TASK_HONEY;
	
	g_honey[id] = 0;
	
	if ( !get_bit(g_alive, id) ) return PLUGIN_HANDLED;
	
	if ( g_boots_of_speed[id] )
	{
		static block, property3[5];
		block = g_boots_of_speed[id];
		GetProperty(block, 3, property3);
		
		entity_set_float(id, EV_FL_maxspeed, str_to_float(property3));
	}
	else
	{
		ResetMaxspeed(id);
		//set_user_maxspeed(id, 250.0);
	}
	
	return PLUGIN_HANDLED;
}

public TaskSlowDown(id)
{
	id -= TASK_NOSLOWDOWN;
	
	clear_bit(g_no_slow_down, id);
}

public TaskRemoveInvincibility(id)
{
	id -= TASK_INVINCIBLE;
	
	if ( get_bit(g_alive, id) )
	{
		set_user_godmode(id, 0);
	
		if ( get_gametime() >= g_stealth_time_out[id] )
		{
			set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 16);
		}
	}
	
}

public TaskRemoveStealth(id)
{
	id -= TASK_STEALTH;
	
	if ( get_bit(g_connected, id) )
	{
		if ( get_gametime() <= g_invincibility_time_out[id] )
		{
			set_user_rendering(id, kRenderFxGlowShell, 0, 51, 0, kRenderTransColor, 16);
		}
		else
		{
			set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 255);
		}
	}
	
	clear_bit(g_block_status, id);
}

public TaskRemoveBootsOfSpeed(id)
{
	id -= TASK_BOOTSOFSPEED;
	clear_bit(g_bootsofspeed, id);
	if ( get_bit(g_alive, id) )
	{
		ResetMaxspeed(id);
		//set_user_maxspeed(id, 250.0);
	}
}

public TaskRemoveSuperman(id)
{
	id -= TASK_SUPERMAN;
	
	if ( !get_bit(g_alive, id) ) return PLUGIN_HANDLED;
	
	if ( get_bit(g_connected, id) )
	{
		if ( get_gametime() <= g_superman_time_out[id] )
		{
			set_user_gravity(id, 0.50);
		}
		else
		{
			set_user_gravity(id, 1.0);
		}
	}
	
	return PLUGIN_HANDLED;
}

public TaskSpriteNextFrame(params[])
{
	new iEntity = params[0];
	if ( !is_valid_ent(iEntity) )
	{
		remove_task(TASK_SPRITE + iEntity);
		return PLUGIN_HANDLED;
	}
	
	new frames = params[1];
	new Float:current_frame = entity_get_float(iEntity, EV_FL_frame);
	
	if ( current_frame < 0.0
	|| current_frame >= frames )
	{
		entity_set_float(iEntity, EV_FL_frame, 1.0);
	}
	else
	{
		entity_set_float(iEntity, EV_FL_frame, current_frame + 1.0);
	}
	
	return PLUGIN_HANDLED;
}

public MsgStatusValue()
{
	if ( get_msg_arg_int(1) == 2
	&& get_bit(g_block_status, get_msg_arg_int(2)) )
	{
		set_msg_arg_int(1, get_msg_argtype(1), 1);
		set_msg_arg_int(2, get_msg_argtype(2), 0);
	}
}

public CmdAttack(id)
{
	if(g_block_count >= MAX_BLOCKS) {
		BCM_Print(id, "^1Max block count of^4 %d has already been^3 reached.", MAX_BLOCKS);
		return PLUGIN_HANDLED;
	}
	if ( !IsBlock(g_grabbed[id]) ) return PLUGIN_HANDLED;
	
	if ( IsBlockInGroup(id, g_grabbed[id]) && g_group_count[id] > 1 )
	{
		static block;
		for ( new i = 0; i <= g_group_count[id]; ++i )
		{
			block = g_grouped_blocks[id][i];
			if ( !IsBlockInGroup(id, block) ) continue;
			
			if ( !IsBlockStuck(block) )
			{
				CopyBlock(id, block);
			}
		}
	}
	else
	{
		if ( IsBlockStuck(g_grabbed[id]) )
		{
			BCM_Print(id, "You cannot copy a block that is in a stuck position!");
			return PLUGIN_HANDLED;
		}
		
		new new_block = CopyBlock(id, g_grabbed[id]);
		if ( !new_block ) return PLUGIN_HANDLED;
		
		entity_set_int(g_grabbed[id], EV_INT_iuser2, 0);
		entity_set_int(new_block, EV_INT_iuser2, id);
		g_grabbed[id] = new_block;
	}
	
	return PLUGIN_HANDLED;
}

public CmdAttack2(id)
{
	if ( !IsBlock(g_grabbed[id]) )
	{
		DeleteTeleport(id, g_grabbed[id]);
		return PLUGIN_HANDLED;
	}
	
	if ( !IsBlockInGroup(id, g_grabbed[id])
	|| g_group_count[id] < 2 )
	{
		DeleteBlock(g_grabbed[id]);
		return PLUGIN_HANDLED;
	}
	
	static block;
	for ( new i = 0; i <= g_group_count[id]; ++i )
	{
		block = g_grouped_blocks[id][i];
		if ( !is_valid_ent(block)
		|| !IsBlockInGroup(id, block) ) continue;
		
		DeleteBlock(block);
	}
	
	return PLUGIN_HANDLED;
}

public CmdRotate(id)
{		
	if ( !IsBlock(g_grabbed[id]) ) return PLUGIN_HANDLED;
	
	if ( !IsBlockInGroup(id, g_grabbed[id])
	|| g_group_count[id] < 2 )
	{
		RotateBlock(g_grabbed[id]);
		return PLUGIN_HANDLED;
	}
	
	static block;
	for ( new i = 0; i <= g_group_count[id]; ++i )
	{
		block = g_grouped_blocks[id][i];
		if ( !is_valid_ent(block)
		|| !IsBlockInGroup(id, block) ) continue;
		
		RotateBlock(block);
	}
	
	return PLUGIN_HANDLED;
}

public EventCurWeaponModelView( id ) {
	if( g_grabbed[id] ) {
		entity_get_string( id, EV_SZ_viewmodel, g_szViewModel[id], 31 );
		entity_set_string( id, EV_SZ_viewmodel, "" );
	}
}

public CmdGrab(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	if (get_pcvar_num(g_pCvar_Enable) != 1)
	{
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	g_grab_length[id] = get_user_aiming(id, iEntity, body);
	
	new bool:is_block = IsBlock(iEntity);
	
	if ( !is_block && !IsTeleport(iEntity) ) return PLUGIN_HANDLED;
	
	new grabber = entity_get_int(iEntity, EV_INT_iuser2);
	if ( grabber && grabber != id ) return PLUGIN_HANDLED;
	
	if ( !is_block )
	{
		SetGrabbed(id, iEntity);
		return PLUGIN_HANDLED;
	}
	
	new player = entity_get_int(iEntity, EV_INT_iuser1);
	if ( player && player != id )
	{
		new player_name[32]; 
		get_user_name(player, player_name, charsmax(player_name));
		
		BCM_Print(id, "^1%s^3 currently has this block in their group!", player_name);
		return PLUGIN_HANDLED;
	}
	
	SetGrabbed(id, iEntity);
	
	if ( g_group_count[id] < 2 ) return PLUGIN_HANDLED;
	
	static Float:grabbed_origin[3];
	
	entity_get_vector(iEntity, EV_VEC_origin, grabbed_origin);
	
	static block, Float:origin[3], Float:offset[3];
	for ( new i = 0; i <= g_group_count[id]; ++i )
	{
		block = g_grouped_blocks[id][i];
		if ( !is_valid_ent(block) ) continue;
		
		entity_get_vector(block, EV_VEC_origin, origin);
		
		offset[0] = grabbed_origin[0] - origin[0];
		offset[1] = grabbed_origin[1] - origin[1];
		offset[2] = grabbed_origin[2] - origin[2];
		
		entity_set_vector(block, EV_VEC_vuser1, offset);
		entity_set_int(block, EV_INT_iuser2, id);
	}
	
	return PLUGIN_HANDLED;
}

SetGrabbed(id, iEntity)
{	
	static aiming[3], Float:origin[3], szLastMover[32];

	entity_get_string( id, EV_SZ_viewmodel, g_szViewModel[id], 31 );
	entity_set_string( id, EV_SZ_viewmodel, g_blank );

	
	get_user_origin(id, aiming, 3);
	entity_get_vector(iEntity, EV_VEC_origin, origin);
	get_user_name(id, szLastMover, 31);
	replace_all(szLastMover, 31, "_", " ");
	entity_set_string(iEntity, EV_SZ_target, szLastMover);
	
	g_grabbed[id] = iEntity;
	g_grab_offset[id][0] = origin[0] - aiming[0];
	g_grab_offset[id][1] = origin[1] - aiming[1];
	g_grab_offset[id][2] = origin[2] - aiming[2];
	
	entity_set_int(iEntity, EV_INT_iuser2, id);
}

public CmdRelease(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	else if ( !g_grabbed[id] )
	{
		return PLUGIN_HANDLED;
	}
	
	if ( IsBlock(g_grabbed[id]) )
	{
		if ( IsBlockInGroup(id, g_grabbed[id]) && g_group_count[id] > 1 )
		{
			static i, block;
			
			new bool:group_is_stuck = true;
			
			for ( i = 0; i <= g_group_count[id]; ++i )
			{
				block = g_grouped_blocks[id][i];
				if ( IsBlockInGroup(id, block) )
				{
					entity_set_int(block, EV_INT_iuser2, 0);
					
					if ( group_is_stuck && !IsBlockStuck(block) )
					{
						group_is_stuck = false;
						break;
					}
				}
			}
			
			if ( group_is_stuck )
			{
				for ( i = 0; i <= g_group_count[id]; ++i )
				{
					block = g_grouped_blocks[id][i];
					if ( IsBlockInGroup(id, block) ) DeleteBlock(block);
				}
				
				BCM_Print(id, "Group deleted because all the blocks were stuck!");
			}
		}
		else
		{
			if ( is_valid_ent(g_grabbed[id]) )
			{
				if ( IsBlockStuck(g_grabbed[id]) )
				{
					BCM_Print(id, "Block deleted because it was stuck!");
					new bool:deleted = DeleteBlock(g_grabbed[id]);
					if ( deleted ) BCM_Print(id, "Block deleted because it was stuck!");
				}
				else
				{
					entity_set_int(g_grabbed[id], EV_INT_iuser2, 0);
				}
			}
		}
	}
	
	else if ( IsTeleport(g_grabbed[id]) )
	{
		entity_set_int(g_grabbed[id], EV_INT_iuser2, 0);
	}
	
	entity_set_string(id, EV_SZ_viewmodel, g_szViewModel[id]);
	g_grabbed[id] = 0;
	
	return PLUGIN_HANDLED;
}

public CmdMainMenu(id)
{
	if (get_pcvar_num(g_pCvar_Enable) > 0)
	{
		ShowMainMenu(id);
		return PLUGIN_HANDLED;
	}
	return PLUGIN_HANDLED;
}

ShowMainMenu(id)
{
	new menu[256], col[3];
	
	col = get_bit(g_admin, id) ? "\w" : "\d";	
	
	format(menu, charsmax(menu),\
		g_main_menu,\
		g_config_names[g_current_config],\
		g_block_count,\
		MAX_BLOCKS,\
		col,\
		get_bit(g_noclip, id) ? "\yOn" : "\rOff",\
		col,\
		get_bit(g_godmode, id) ? "\yOn" : "\rOff"
		);
	
	show_menu(id, g_keys_main_menu, menu, -1, "BcmMainMenu");
}

ShowBlockMenu(id)
{
	new menu[256], col[3], size[8];
	
	col = get_bit(g_admin, id) ? "\w" : "\d";
	
	switch ( g_selected_block_size[id] )
	{
		case SMALL:	size = "Small";
		case NORMAL:	size = "Normal";
		case LARGE:	size = "Large";
		case POLE:	size = "Pole";
	}
	
	format(menu, charsmax(menu),\
		g_block_menu,\
		g_block_count,\
		MAX_BLOCKS,\
		g_block_names[g_selected_block_type[id]],\
		col,\
		col,\
		col,\
		col,\
		size,\
		col,\
		col
		);
	
	show_menu(id, g_keys_block_menu, menu, -1, "BcmBlockMenu");
}

ShowBlockSelectionMenu(id)
{
	new menu[256], title[32], entry[32], num;
	
	format(title, charsmax(title), "\yBlock Selection \r%d^n^n", g_block_selection_page[id]);
	add(menu, charsmax(menu), title);
	
	new start_block = ( g_block_selection_page[id] - 1 ) * 8;
	
	for ( new i = start_block; i < start_block + 8; ++i )
	{
		if ( i < TOTAL_BLOCKS )
		{
			num = ( i - start_block ) + 1;
			
			format(entry, charsmax(entry), "\r%d. \w%s^n", num, g_block_names[i]);
		}
		else
		{
			format(entry, charsmax(entry), "^n");
		}
		
		add(menu, charsmax(menu), entry);
	}
	
	if ( g_block_selection_page[id] < g_block_selection_pages_max )
	{
		add(menu, charsmax(menu), "^n\r9. \yMore");
	}
	else
	{
		add(menu, charsmax(menu), "^n");
	}
	
	add(menu, charsmax(menu), "^n\r0. \yBack");
	
	show_menu(id, g_keys_block_selection_menu, menu, -1, "BcmBlockSelectionMenu");
}

ShowPropertiesMenu(id, iEntity)
{
	new menu[256], title[64], entry[128], property[5], line1[3], line2[3], line3[3], line4[3], num, block_type;
	
	block_type = entity_get_int(iEntity, EV_INT_body);
	
	format(title, charsmax(title), "\rSet Properties \yMenu \dv3.5^n^n\wBlock Type: \y%s^n^n", g_block_names[block_type]);
	add(menu, charsmax(menu), title);
	
	if ( g_property1_name[block_type][0] )
	{
		GetProperty(iEntity, 1, property);
		
		switch ( block_type )
		{
			case BHOP, NO_SLOW_DOWN_BHOP: format(entry, charsmax(entry), "\r1. \w%s: %s^n", g_property1_name[block_type], property[0] == '1' ? "\yOn" : "\rOff");
			case MAGIC_CARPET: format(entry, charsmax(entry), "\r1. \w%s: \y%s^n", g_property1_name[block_type], property[0] == '4' ? "Off" : property[0] == '3' ? "All" : property[0] == '2' ? "Counter-Terrorists" : "Terrorists");
			case SLAP: format(entry, charsmax(entry), "\r1. \w%s: \y%s^n", g_property1_name[block_type], property[0] == '3' ? "High" : property[0] == '2' ? "Medium" : "Low");
			case CT_BARRIER, T_BARRIER: format(entry, charsmax(entry), "\r1. \w%s: \y%s^n", g_property1_name[block_type], property[0] == '3' ? "All Admins Only" : property[0] == '2' ? "Team Admins Only" : "Normal");
			case WEAPON_BLOCK: format(entry, charsmax(entry), "\r1. \w%s: \y%s^n", g_property1_name[block_type], property[0] == '9' ? "Famas" : property[0] == '8' ? "AK47" : property[0] == '7' ? "Mac 10" : property[0] == '6' ? "Shotgun" : property[0] == '5' ? "Aug" : property[0] == '4' ? "Tmp" : property[0] == '3' ? "Usp" : property[0] == '2' ? "Deagle" : "Awp");
			case NADE_BLOCK: format(entry, charsmax(entry), "\r1. \w%s: \y%s^n", g_property1_name[block_type], property[0] == '3' ? "Flash Grenade" : property[0] == '2' ? "Frost Grenade" : "HE Grenade");
			default: format(entry, charsmax(entry), "\r1. \w%s: \y%s^n", g_property1_name[block_type], property);
		}
		
		add(menu, charsmax(menu), entry);
	}
	else
	{
		format(line1, charsmax(line1), "^n");
	}
	
	if ( g_property2_name[block_type][0] )
	{
		if ( g_property1_name[block_type][0] )
		{
			num = 2;
		}
		else
		{
			num = 1;
		}
		
		GetProperty(iEntity, 2, property);
		
		format(entry, charsmax(entry), "\r%d. \w%s: \y%s^n", num, g_property2_name[block_type], property);
		
		add(menu, charsmax(menu), entry);
	}
	else
	{
		format(line2, charsmax(line2), "^n");
	}
	
	if ( g_property3_name[block_type][0] )
	{
		if ( g_property1_name[block_type][0] && g_property2_name[block_type][0] )
		{
			num = 3;
		}
		else if ( g_property1_name[block_type][0]
		|| g_property2_name[block_type][0] )
		{
			num = 2;
		}
		else
		{
			num = 1;
		}
		
		GetProperty(iEntity, 3, property);
		
		if ( block_type == BOOTS_OF_SPEED
		|| block_type == BLIND_TRAP
		|| property[0] != '0' && !( property[0] == '2' && property[1] == '5' && property[2] == '5' ) )
		{
			format(entry, charsmax(entry), "\r%d. \w%s: \y%s^n", num, g_property3_name[block_type], property);
		}
		else
		{
			format(entry, charsmax(entry), "\r%d. \w%s: \rOff^n", num, g_property3_name[block_type]);
		}
		
		add(menu, charsmax(menu), entry);
	}
	else
	{
		format(line3, charsmax(line3), "^n");
	}
	
	if ( g_property4_name[block_type][0] )
	{
		if ( g_property1_name[block_type][0] && g_property2_name[block_type][0] && g_property3_name[block_type][0] )
		{
			num = 4;
		}
		else if ( g_property1_name[block_type][0] && g_property2_name[block_type][0]
		|| g_property1_name[block_type][0] && g_property3_name[block_type][0]
		|| g_property2_name[block_type][0] && g_property3_name[block_type][0] )
		{
			num = 3;
		}
		else if ( g_property1_name[block_type][0]
		|| g_property2_name[block_type][0]
		|| g_property3_name[block_type][0] )
		{
			num = 2;
		}
		else
		{
			num = 1;
		}
		
		GetProperty(iEntity, 4, property);
		
		if( block_type == BLIND_TRAP )
		{
			format(entry, charsmax(entry), "\r%d. \w%s: \y%s^n", num, g_property4_name[block_type], property);
		}
		if( block_type == HEALER )
		{
			format(entry, charsmax(entry), "\r%d. \w%s: \y%s^n", num, g_property4_name[block_type], property[0] == '3' ? "Health/Armor" : property[0] == '2' ? "Armor" : "Health");
		}
		else
		{
			format(entry, charsmax(entry), "\r%d. \w%s: %s^n", num, g_property4_name[block_type], property[0] == '1' ? "\yYes" : "\rNo");
		}
		add(menu, charsmax(menu), entry);
	}
	else
	{
		format(line4, charsmax(line4), "^n");
	}
	
	g_property_info[id][1] = iEntity;
	
	add(menu, charsmax(menu), line1);
	add(menu, charsmax(menu), line2);
	add(menu, charsmax(menu), line3);
	add(menu, charsmax(menu), line4);
	add(menu, charsmax(menu), "^n\r0. \wBack");
	
	show_menu(id, g_keys_properties_menu, menu, -1, "BcmPropertiesMenu");
}

ShowTeleportMenu(id)
{
	new menu[256], col[3];
	
	col = get_bit(g_admin, id) ? "\w" : "\d";
	
	format(menu, charsmax(menu),\
		g_teleport_menu,\
		col,\
		g_teleport_start[id] ? "\w" : "\d",\
		col,\
		col,\
		col,\
		get_bit(g_noclip, id) ? "\yOn" : "\rOff",\
		col,\
		get_bit(g_godmode, id) ? "\yOn" : "\rOff"
		);
	
	show_menu(id, g_keys_teleport_menu, menu, -1, "BcmTeleportMenu");
}

ShowConfigMenu(id) {
	new menu[256], col[3];
	
	col = get_bit(g_admin, id) ? "\w" : "\d";

	format(menu, charsmax(menu), g_config_menu,  col, col, col, g_new_file, col, g_config_names[g_current_config]);
	
	show_menu(id, g_keys_config_menu, menu, -1, "BcmConfigMenu");
}

ShowConfigSelectionMenu(id) {
	new menu[256], col[3];
	
	col = get_bit(g_admin, id) ? "\w" : "\d";
	
	new bool:prev = (g_config_menu_page[id] >= 1);
	new bool:next = ((g_config_menu_page[id] * 7 + 7) < g_config_count);
	new len = 0;
	new keys = 0;
	

	len += formatex(menu[len], charsmax(menu), "\yConfig Selection Menu \w(\yCurrent file\w: \r%s\w)^n^n", g_config_names[g_current_config]);
	for(new i = 0; (i < 7) && ((g_config_menu_page[id] * 7 + i) < g_config_count); i++) {
		len += formatex(menu[len], charsmax(menu), "\r%d. \w%s^n", (i + 1), g_config_names[g_config_menu_page[id] * 7 + i]);
		keys |= (1 << i);
	}
	len += formatex(menu[len], charsmax(menu), "^n\r8. %sPrevious^n", prev ? "\w" : "\d");
	keys |= (prev ? B8 : 0);
	len += formatex(menu[len], charsmax(menu), "\r9. %sNext^n^n", next ? "\w" : "\d");
	keys |= (next ? B9 : 0);
	len += formatex(menu[len], charsmax(menu), "\r0. \wBack^n");
	keys |= B0;
	
	
	show_menu(id, keys, menu, -1, "BcmConfigSelectionMenu");
}

ShowOptionsMenu(id, oldMenu)
{
	g_menu_before_options[id] = oldMenu;
	
	new menu[256], col[3], g_auto[6];
	
	col = get_bit(g_admin, id) ? "\w" : "\d";
	
	g_auto = (get_bit(g_auto_block_properties, id) ? "\yOn" : "\rOff");
	
	format(menu, charsmax(menu),\
		g_options_menu,\
		col,\
		get_bit(g_snapping, id) ? "\yOn" : "\rOff",\
		col,\
		g_snapping_gap[id],\
		col,\
		col,\
		col,\
		col,\
		g_auto,\
		col,\
		col
		);
	
	show_menu(id, g_keys_options_menu, menu, -1, "BcmOptionsMenu");
}

ShowChoiceMenu(id, choice, const title[96])
{
	new menu[256];
	
	g_choice_option[id] = choice;
	
	format(menu, charsmax(menu), g_choice_menu, title);
	
	show_menu(id, g_keys_choice_menu, menu, -1, "BcmChoiceMenu");
}

public HandleMainMenu(id, key)
{
	switch ( key )
	{
		case K1: ShowBlockMenu(id);
		case K2: ShowTeleportMenu(id);
		case K3: ShowConfigMenu(id);
		case K6: ToggleNoclip(id);
		case K7: ToggleGodmode(id);
		case K9: ShowOptionsMenu(id, 1);
		case K0: return;
	}
	
	if ( key == K6 || key == K7 ) ShowMainMenu(id);
}

public HandleBlockMenu(id, key)
{
	switch ( key )
	{
		case K1:
		{
			g_block_selection_page[id] = 1;
			ShowBlockSelectionMenu(id);
		}
		case K2: CreateBlockAiming(id, g_selected_block_type[id]);
		case K3: ConvertBlockAiming(id, g_selected_block_type[id]);
		case K4: DeleteBlockAiming(id);
		case K5: RotateBlockAiming(id);
		case K6: ChangeBlockSize(id);
		case K7: SetPropertiesBlockAiming(id);
		case K9: ShowOptionsMenu(id, 2);
		case K0: ShowMainMenu(id);
	}
	
	if ( key != K1 && key != K7 && key != K9 && key != K0 ) ShowBlockMenu(id);
}

public HandleBlockSelectionMenu(id, key)
{
	switch ( key )
	{
		case K9:
		{
			++g_block_selection_page[id];
			
			if ( g_block_selection_page[id] > g_block_selection_pages_max )
			{
				g_block_selection_page[id] = g_block_selection_pages_max;
			}
			
			ShowBlockSelectionMenu(id);
		}
		case K0:
		{
			--g_block_selection_page[id];
			
			if ( g_block_selection_page[id] < 1 )
			{
				ShowBlockMenu(id);
			}
			else
			{
				ShowBlockSelectionMenu(id);
			}
		}
		default:
		{
			key += ( g_block_selection_page[id] - 1 ) * 8;
			
			if ( key < TOTAL_BLOCKS )
			{
				g_selected_block_type[id] = key;
				ShowBlockMenu(id);
			}
			else
			{
				ShowBlockSelectionMenu(id);
			}
		}
	}
}

public HandlePropertiesMenu(id, key)
{
	new iEntity = g_property_info[id][1];
	if ( !is_valid_ent(iEntity) )
	{
		BCM_Print(id, "That block has been deleted!");
		clear_bit(g_viewing_properties_menu, id);
		//g_viewing_properties_menu[id] = false;
		ShowBlockMenu(id);
		return PLUGIN_HANDLED;
	}
	
	new block_type = entity_get_int(iEntity, EV_INT_body);
	
	switch ( key )
	{
		case K1:
		{
			if ( g_property1_name[block_type][0] )
			{
				g_property_info[id][0] = 1;
			}
			else if ( g_property2_name[block_type][0] )
			{
				g_property_info[id][0] = 2;
			}
			else if ( g_property3_name[block_type][0] )
			{
				g_property_info[id][0] = 3;
			}
			else
			{
				g_property_info[id][0] = 4;
			}
			
			if ( g_property_info[id][0] == 1
			&& ( block_type == MAGIC_CARPET
			|| block_type == BHOP
			|| block_type == SLAP
			|| block_type == CT_BARRIER
			|| block_type == T_BARRIER
			|| block_type == NO_SLOW_DOWN_BHOP
			|| block_type == WEAPON_BLOCK
			|| block_type == NADE_BLOCK ) )
			{
				ToggleProperty(id, 1);
			}
			else if ( g_property_info[id][0] == 4 )
			{
				ToggleProperty(id, 4);
			}
			else
			{
				BCM_Print(id, "Type the new property value for the block.%s", g_property_info[id][0] == 3 && block_type != BOOTS_OF_SPEED ? "^1 0^3 and^1 255^3 will turn transparency off." : g_blank);
				client_cmd(id, "messagemode BCM_SetProperty");
			}
		}
		case K2:
		{
			if ( g_property1_name[block_type][0] && g_property2_name[block_type][0]
			|| g_property1_name[block_type][0] && g_property3_name[block_type][0]
			|| g_property1_name[block_type][0] && g_property4_name[block_type][0]
			|| g_property2_name[block_type][0] && g_property3_name[block_type][0]
			|| g_property2_name[block_type][0] && g_property4_name[block_type][0]
			|| g_property3_name[block_type][0] && g_property4_name[block_type][0] )
			{
				if ( g_property1_name[block_type][0] && g_property2_name[block_type][0] )
				{
					g_property_info[id][0] = 2;
				}
				else if ( g_property1_name[block_type][0] && g_property3_name[block_type][0]
				|| g_property2_name[block_type][0] && g_property3_name[block_type][0] )
				{
					g_property_info[id][0] = 3;
				}
				else
				{
					g_property_info[id][0] = 4;
				}
				
				if ( g_property_info[id][0] == 4 )
				{
					ToggleProperty(id, 4);
				}
				else
				{
					BCM_Print(id, "Type the new property value for the block.%s", g_property_info[id][0] == 3 && block_type != BOOTS_OF_SPEED ? "^1 0^3 and^1 255^3 will turn transparency off." : g_blank);
					client_cmd(id, "messagemode BCM_SetProperty");
				}
			}
		}
		case K3:
		{
			if ( g_property1_name[block_type][0] && g_property2_name[block_type][0] && g_property3_name[block_type][0]
			|| g_property1_name[block_type][0] && g_property2_name[block_type][0] && g_property4_name[block_type][0]
			|| g_property1_name[block_type][0] && g_property3_name[block_type][0] && g_property4_name[block_type][0]
			|| g_property2_name[block_type][0] && g_property3_name[block_type][0] && g_property4_name[block_type][0] )
			{
				if ( g_property1_name[block_type][0] && g_property2_name[block_type][0] && g_property3_name[block_type][0] )
				{
					g_property_info[id][0] = 3;
				}
				else
				{
					g_property_info[id][0] = 4;
				}
				
				if ( g_property_info[id][0] == 4 )
				{
					ToggleProperty(id, 4);
				}
				else
				{
					BCM_Print(id, "Type the new property value for the block.%s", g_property_info[id][0] == 3 && block_type != BOOTS_OF_SPEED ? "^1 0^3 and^1 255^3 will turn transparency off." : g_blank);
					client_cmd(id, "messagemode BCM_SetProperty");
				}
			}
		}
		case K4:
		{
			if ( g_property1_name[block_type][0] && g_property2_name[block_type][0] && g_property3_name[block_type][0] && g_property4_name[block_type][0] )
			{
				if( block_type == BLIND_TRAP )
				{
					BCM_Print(id, "Type the new property value for the block");
					client_cmd(id, "messagemode BCM_SetProperty");
					g_property_info[id][0] = 4;
				}
				else
				{
					ToggleProperty(id, 4);
				}
			}
		}
		case K0:
		{
			//g_viewing_properties_menu[id] = false;
			clear_bit(g_viewing_properties_menu, id);
			ShowBlockMenu(id);
		}
	}
	
	if ( key != K0 ) ShowPropertiesMenu(id, iEntity);
	
	return PLUGIN_HANDLED;
}

public HandleTeleportMenu(id, key)
{
	switch ( key )
	{
		case K1: CreateTeleportAiming(id, TELEPORT_START);
		case K2: CreateTeleportAiming(id, TELEPORT_DESTINATION);
		case K3: SwapTeleportAiming(id);
		case K4: DeleteTeleportAiming(id);
		case K6: ToggleNoclip(id);
		case K7: ToggleGodmode(id);
		case K9: ShowOptionsMenu(id, 3);
		case K0: ShowMainMenu(id);
	}

	if (key != K9 && key != K0)
	{
		ShowTeleportMenu(id);
	}
}

public HandleConfigMenu(id, key) {
	g_config_menu_page[id] = 0;
	switch(key) {
		case K1: ShowChoiceMenu(id, CHOICE_LOAD_CONFIG, "Are you sure you want to load another config?");
		case K2: DoEnterValue(id, CONFIG_NAME);
		case K3: ShowChoiceMenu(id, CHOICE_DEL_CONFIG, "Are you sure you wish to remove this config?");
		case K4: { 
			if(g_current_config != 0) { 
				DoEnterValue(id, CONFIG_RENAME); 
			} else { 
				BCM_Print(id, "^1Cannot change the name of the^3 Default^1 config.");
				ShowConfigMenu(id);
			}
		}
		case K0: ShowMainMenu(id);
	}
}

public HandleConfigSelectionMenu(id, key) {
	switch(key) {
		case K0: ShowConfigMenu(id);
		case K9: g_config_menu_page[id]++;
		case K8: g_config_menu_page[id]--;
	}
	
	if(key == K9 || key == K8) {
		ShowConfigSelectionMenu(id);
	} else if(key != K0) {
		new index = (g_config_menu_page[id] * 7) + key;
		GetConfigFileName(g_config_index[index], g_new_file);
		g_current_config = index;
		LoadBlocks(id);
		ShowConfigMenu(id);
	}
}

public EndVote()
{
	g_iTimer--;
	if( g_iTimer >= 0 )
	{
		new iPlayers[32], iNum, ids;
		get_players( iPlayers, iNum );
		for( new i = 0; i < iNum; i++ )
		{
			ids = iPlayers[i];
			//player_menu_info(ids, ShowConfigVoteMenu, ShowConfigVoteMenu, iPage) 
			if(!get_bit(g_iHasVotedAlready, ids))
				ShowConfigVoteMenu(ids);
		}
	}
	if( g_iTimer <= 0 )
	{
		new iPlayers[32], iNum;
		get_players( iPlayers, iNum );
		for( new i = 0; i < iNum; i++ )
		{
			clear_bit(g_iHasVotedAlready, iPlayers[i]);
		}
		remove_task(TASK_TIMER);
	}
}

ShowConfigVoteMenu(id) {
	
	if( !task_exists(TASK_TIMER) )
	{
		g_iTimer = 20;
		set_task( 1.0, "EndVote", TASK_TIMER, _, _, "b" );
	}
	
	new menu[256];
	new bool:prev = (g_config_vote_menu[id] >= 1);
	new bool:next = ((g_config_vote_menu[id] * 7 + 7) < g_config_count);
	new len = 0;
	new keys = 0;

	len += formatex(menu[len], charsmax(menu), "\yVote for a config: \w[\r%i\w]^n^n\yCurrent Config: \w[\r%s\w]^n^n", g_iTimer, g_config_names[g_current_config]);
	for(new i = 0; (i < 7) && ((g_config_vote_menu[id] * 7 + i) < g_config_count); i++)
	{
		len += formatex(menu[len], charsmax(menu), "\r%d. \w%s^n", (i + 1), g_config_names[g_config_vote_menu[id] * 7 + i]);
		keys |= (1 << i);
	}
	
	len += formatex(menu[len], charsmax(menu), "^n\r8. %sPrevious^n", prev ? "\w" : "\d");
	keys |= (prev ? B8 : 0);
	len += formatex(menu[len], charsmax(menu), "\r9. %sNext^n^n", next ? "\w" : "\d");
	keys |= (next ? B9 : 0);
	len += formatex(menu[len], charsmax(menu), "\r0. \wNone^n");
	keys |= B0;

	if( g_iTimer > 1 )
	{
		show_menu(id, keys, menu, -1, "BcmConfigVoteMenu");
	}
	else
	{
		show_menu(id, keys, menu, 1, "BcmConfigVoteMenu");
	}
}

public HandleConfigVoteMenu(id, key) {
	switch(key) {
		case K9: g_config_vote_menu[id]++;
		case K8: g_config_vote_menu[id]--;
	}
	
	if(key == K9 || key == K8) {
		ShowConfigVoteMenu(id);
	} 
	else if( key != K0 && !get_bit(g_iHasVotedAlready, id) && g_iTimer > 0) 
	{
		new index = (g_config_vote_menu[id] * 7) + key;
		g_config_vote[id] = index;
		static name[32];
		get_user_name(id, name, charsmax(name));
		BCM_Print(0, "^3%s ^1voted for [^3%s^1].", name, g_config_names[index]);
		set_bit(g_iHasVotedAlready, id);
	}
	else 
	{
		static name[32];
		get_user_name(id, name, charsmax(name));
		BCM_Print(0, "^3%s ^1voted for [^3None^1].", name);
		set_bit(g_iHasVotedAlready, id);
	}
		
}

DeleteCurrentConfiguration(id) {
	if(g_current_config == 0) {
		BCM_Print(id, "^1Cannot Delete ^3Default^1 configuration.");
		return;
	}
	
	BCM_Print(id, "^1Deleting and loading ^3Default^1 configuration.");
	for(new i = g_current_config; i < g_config_count - 1; i++) {
		g_config_index[i] = g_config_index[i + 1];
		copy(g_config_names[i], 31, g_config_names[i + 1]);
	}
	g_config_count--;
	g_current_config = 0;
	GetConfigFileName(0, g_new_file);
	LoadBlocks(id);
	SaveBlockConfigurations();
}

public HandleOptionsMenu(id, key)
{
	switch ( key )
	{
		case K1: ToggleSnapping(id);
		case K2: ToggleSnappingGap(id);
		case K3: GroupBlockAiming(id);
		case K4: ClearGroup(id);
		case K5:
		{
			if ( get_bit(g_admin, id) )	ShowChoiceMenu(id, CHOICE_DELETE, "\yA Log Will Be Created.^n \wAre you sure you want to delete all blocks and teleports?");
			else			ShowOptionsMenu(id, 6);
		}
		case K6: 
		{ 
			if(!get_bit(g_auto_block_properties, id))
				set_bit(g_auto_block_properties, id);
			else
				clear_bit(g_auto_block_properties, id);
		}
		case K7: SaveBlocks(id);
		case K8:
		{
			if ( get_bit(g_admin, id) )	ShowChoiceMenu(id, CHOICE_LOAD, "\yLoading will delete all blocks and teleports.^n \wdo you want to continue?");
			else			ShowOptionsMenu(id, 7);
		}
		case K0:
		{
			switch (g_menu_before_options[id])
			{
				case 1: ShowMainMenu(id);
				case 2: ShowBlockMenu(id);
				case 3: ShowTeleportMenu(id);
				
				default: log_amx("%sPlayer ID: %d has an invalid g_menu_before_options: %d", PLUGIN_PREFIX, id, g_menu_before_options[id]);
			}
		}
	}
	
	if ( key != K5 && key != K8 && key != K0 ) 
	{
		ShowOptionsMenu(id, g_menu_before_options[id]);
	}
}

public HandleChoiceMenu(id, key)
{
	switch ( key )
	{
		case K1:
		{
			switch ( g_choice_option[id] )
			{
				case CHOICE_DELETE:	{	DeleteAll(id, true);			}
				case CHOICE_LOAD:	{	LoadBlocks(id);				}
				case CHOICE_LOAD_CONFIG:{ 	ShowConfigSelectionMenu(id);		}
				case CHOICE_DEL_CONFIG:	{ 	DeleteCurrentConfiguration(id);  	}

				default:
				{
					log_amx("%sInvalid choice in handleChoiceMenu()", PLUGIN_PREFIX);
				}
			}
		}
		case K2: ShowOptionsMenu(id, 8);
		case K3: DeleteAllBlocks(id, true);
		case K4: DeleteAllTeleports(id, true);
		case K0: ShowOptionsMenu(id, 9);
			
	}
	
	if(g_choice_option[id] == CHOICE_LOAD || g_choice_option[id] == CHOICE_DELETE) {
		ShowOptionsMenu(id, g_menu_before_options[id]);
	}
	if(g_choice_option[id] == CHOICE_DEL_CONFIG) {
		ShowConfigMenu(id);
	}
	if(g_choice_option[id] == CHOICE_LOAD_CONFIG && key == K2) {
		ShowConfigMenu(id);
	}
}

public NewConfigName(id) 
{
	if ( id != 0 && !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	if(g_config_count >= MAX_CONFIGS) 
	{
		BCM_Print(id, "^3 Max configs of %d has already been reached.", MAX_CONFIGS);
		return PLUGIN_HANDLED;
	}
	new args[32];
	read_args(args, charsmax(args)-1);
	remove_quotes(args); 
	new szConfigName[128];
	for(new i = 1; i < 32; i++) {
		GetConfigFileName(i, szConfigName);
		if(!file_exists(szConfigName)) {
			BCM_Print(id, "^x03 file: %s, index: %d", szConfigName, i);
			g_config_index[g_config_count] = i;
			copy(g_config_names[g_config_count], charsmax(args) - 1, args);
			g_current_config = g_config_count;
			g_config_count++;
			DeleteAll(id, false);
			SaveBlockConfigurations();
			GetConfigFileName(i, g_new_file);
			new tempFP = fopen(g_new_file, "wt");
			fclose(tempFP); 
			return PLUGIN_HANDLED;
		}
			
	}
	return PLUGIN_HANDLED;
	
}

public ConfigRename(id) 
{
	if ( id != 0 && !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	if(g_config_count >= MAX_CONFIGS) {
		BCM_Print(id, "Max configs of %d has already been reached.", MAX_CONFIGS);
		return PLUGIN_HANDLED;
	}
		
	if(g_current_config == 0) {
		BCM_Print(id, "Cannot change name of the default config.");
		return PLUGIN_HANDLED;
	}
	new args[32];
	read_args(args, charsmax(args)-1);
	remove_quotes(args); 
	copy(g_config_names[g_current_config], charsmax(args) - 1, args);
	SaveBlockConfigurations();
	return PLUGIN_HANDLED;
}
	
public CmdEnterValue(id) {
	switch(g_value_types[id]) {
		case CONFIG_NAME: { NewConfigName(id); ShowConfigMenu(id); }
		case CONFIG_RENAME: { ConfigRename(id); ShowConfigMenu(id); }
	}
	return PLUGIN_HANDLED;
	
}

ToggleNoclip(id)
{
	static name[32];
	get_user_name(id, name, charsmax(name));

	if(get_bit(g_admin, id) )
	{
		if (get_user_noclip(id))
		{
			set_user_noclip(id, 0);
			clear_bit(g_noclip, id);
			set_task(0.1, "checkstuck");
			if (get_user_team(id) == 3)
			{
				return;
			}
			if (g_pCvar_ShowMessage > 0 || !get_bit(g_admin, id))
			{
				BCM_Print(0, "^1%s ^3Has ^4Disabled ^3Noclip", name);// ^4=Green ^3=Silver ^1=Normal
			}
	
		} else {
			set_user_noclip(id, 1);
			set_bit(g_noclip, id);
			if (get_user_team(id) == 3)
			{
				return;
			}
			if (g_pCvar_ShowMessage > 0 || !get_bit(g_admin, id))
			{
				BCM_Print(0, "^1%s ^3Has ^1Enabled ^3Noclip", name);
			}
		}
	}
}

ToggleGodmode(id)
{
	static name[32];
	get_user_name(id, name, charsmax(name));
    
	if ( get_bit(g_admin, id) )
	{
		if (get_user_godmode(id))
		{
			set_user_godmode(id, 0);
			clear_bit(g_godmode, id);
			if (get_user_team(id) == 3)
			{
				return;
			}
			if (g_pCvar_ShowMessage > 0)
			{
				BCM_Print(0, "^1%s ^3Has ^4Disabled ^3Godmode", name);
			}
	
		} else {
			set_user_godmode(id, 1);
			set_bit(g_godmode, id);
			if (get_user_team(id) == 3)
			{
				return;
			}
			if (g_pCvar_ShowMessage > 0)
			{
				BCM_Print(0, "^1%s ^3Has ^1Enabled ^3Godmode", name);
			}
		}
	}
}

ToggleSnapping(id)
{
	if ( get_bit(g_admin, id) )
	{
		if(!get_bit(g_snapping, id))
			set_bit(g_snapping, id);
		else
			clear_bit(g_snapping, id);
	}
}

ToggleSnappingGap(id)
{
	if ( get_bit(g_admin, id) )
	{
		g_snapping_gap[id] += 4.0;
		
		if ( g_snapping_gap[id] > 40.0 )
		{
			g_snapping_gap[id] = 0.0;
		}	
	}
}

MoveGrabbedEntity(id, Float:move_to[3] = { 0.0, 0.0, 0.0 })
{
	static aiming[3];
	static look[3];
	static Float:float_aiming[3];
	static Float:float_look[3];
	static Float:direction[3];
	static Float:length;
	
	get_user_origin(id, aiming, 1);
	get_user_origin(id, look, 3);
	IVecFVec(aiming, float_aiming);
	IVecFVec(look, float_look);
	
	direction[0] = float_look[0] - float_aiming[0];
	direction[1] = float_look[1] - float_aiming[1];
	direction[2] = float_look[2] - float_aiming[2];
	length = get_distance_f(float_look, float_aiming);
	
	if ( length == 0.0 ) length = 1.0;
	
	move_to[0] = ( float_aiming[0] + direction[0] * g_grab_length[id] / length ) + g_grab_offset[id][0];
	move_to[1] = ( float_aiming[1] + direction[1] * g_grab_length[id] / length ) + g_grab_offset[id][1];
	move_to[2] = ( float_aiming[2] + direction[2] * g_grab_length[id] / length ) + g_grab_offset[id][2];
	move_to[2] = float(floatround(move_to[2], floatround_floor));
	
	MoveEntity(id, g_grabbed[id], move_to, true);

}

MoveEntity(id, iEntity, Float:move_to[3], bool:do_snapping)
{
	if ( do_snapping ) DoSnapping(id, iEntity, move_to);
	
	entity_set_origin(iEntity, move_to);
	
	static block_type;
	block_type = entity_get_int(iEntity, EV_INT_body);
	if( block_type == MAGIC_CARPET )
		set_pev(iEntity, pev_v_angle, move_to);
}
			
CreateBlockAiming(const id, const block_type)
{
	if ( id != 0 && !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	if(g_block_count >= MAX_BLOCKS) {
		BCM_Print(id, "^1Max block count of^4 %d has already been^3 reached.", MAX_BLOCKS);
		return PLUGIN_HANDLED;
	}
	
	static origin[3];
	static Float:float_origin[3];
	static szCreator[32], szLastMover[32];
	
	get_user_name(id, szCreator, 31);
	get_user_name(id, szLastMover, 31);
	get_user_origin(id, origin, 3);
	IVecFVec(origin, float_origin);
	float_origin[2] += 4.0;
	
	CreateBlock(id, block_type, float_origin, Z, g_selected_block_size[id], g_property1_default_value[block_type], g_property2_default_value[block_type], g_property3_default_value[block_type], g_property4_default_value[block_type], szCreator, szLastMover);
	return PLUGIN_HANDLED;
}

CreateBlock(const id, const block_type, Float:origin[3], const axis, const size, const property1[], const property2[], const property3[], const property4[], szCreator[] = "Unknown", szLastMover[] = "Unknown")
{
	new iEntity = create_entity("info_target");
	if ( !is_valid_ent(iEntity) ) return 0;
	entity_set_string(iEntity, EV_SZ_classname, g_block_classname);
	entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
	
	switch ( block_type )
	{
		case MAGIC_CARPET:
		{
			set_pev(iEntity, pev_v_angle, origin); // Original Origin
		}
		case BOUNCE_DEATH:
		{
			set_pev(iEntity, pev_movetype, MOVETYPE_TOSS);
			set_task(0.1,"bounce_death",iEntity);
		}
		case TELEPORT:
		{
			g_teleport_block_start[id] = iEntity;
			if ( id != 0 )
			{
				CreateBlockAiming(id, DESTINATION);
			}
			entity_get_int(iEntity, EV_INT_iuser4);
			entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);
		}
		case DESTINATION:
		{
			entity_set_int(iEntity, EV_INT_iuser4, g_teleport_block_start[id]);
			entity_set_int(g_teleport_block_start[id], EV_INT_iuser4, iEntity);
			entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);		
			g_teleport_block_start[id] = 0;
		}
		default:
		{
			entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);
		}
	}
	
	new block_model[256];
	new Float:size_min[3];
	new Float:size_max[3];
	new Float:angles[3];
	new Float:scale;

	switch ( axis )
	{
		case X:
		{
			if (size == POLE) {
				size_min[0] = -32.0;
				size_min[1] = -4.0;
				size_min[2] = -4.0;
			
				size_max[0] = 32.0;
				size_max[1] = 4.0;
				size_max[2] = 4.0;
			} else {
				size_min[0] = -4.0;
				size_min[1] = -32.0;
				size_min[2] = -32.0;
			
				size_max[0] = 4.0;
				size_max[1] = 32.0;
				size_max[2] = 32.0;	
			}
			angles[0] = 90.0;
		}
		case Y:
		{
			if (size == POLE) {
				size_min[0] = -4.0;
				size_min[1] = -32.0;
				size_min[2] = -4.0;
			
				size_max[0] = 4.0;
				size_max[1] = 32.0;
				size_max[2] = 4.0;
			} else {
				size_min[0] = -32.0;
				size_min[1] = -4.0;
				size_min[2] = -32.0;
			
				size_max[0] = 32.0;
				size_max[1] = 4.0;
				size_max[2] = 32.0;
			}
			angles[0] = 90.0;
			angles[2] = 90.0;
		}
		case Z:
		{
			if (size == POLE) {
				size_min[0] = -4.0;
				size_min[1] = -4.0;
				size_min[2] = -32.0;
			
				size_max[0] = 4.0;
				size_max[1] = 4.0;
				size_max[2] = 32.0;
			} else {
				size_min[0] = -32.0;
				size_min[1] = -32.0;
				size_min[2] = -4.0;
			
				size_max[0] = 32.0;
				size_max[1] = 32.0;
				size_max[2] = 4.0;
			}
			angles[0] = 0.0;
			angles[1] = 0.0;
			angles[2] = 0.0;
		}
	}
	
	switch ( size )
	{
		case SMALL:
		{
			SetBlockModelNameSmall(block_model, g_block_models[block_type], 256);
			scale = 0.25;
		}
		case NORMAL:
		{
			block_model = g_block_models[block_type];
			scale = 1.0;
		}
		case LARGE:
		{
			SetBlockModelNameLarge(block_model, g_block_models[block_type], 256);
			scale = 2.0;
		}
		case POLE:
		{
			SetBlockModelNamePole(block_model, g_block_models[block_type], 256);
			scale = 0.125;
		}
	}
	if (size != POLE) {
		for ( new i = 0; i < 3; ++i )
		{
			if ( size_min[i] != 4.0 && size_min[i] != -4.0 )
			{
				size_min[i] *= scale;
			}
		
			if ( size_max[i] != 4.0 && size_max[i] != -4.0 )
			{
				size_max[i] *= scale;
			}
		}
	}
	set_pev(iEntity, pev_targetname, szCreator, 31);
	set_pev(iEntity, pev_target, szLastMover, 31);
	entity_set_model(iEntity, block_model);
	
	SetBlockRendering(iEntity, g_render[block_type], g_red[block_type], g_green[block_type], g_blue[block_type], g_alpha[block_type]);

	entity_set_vector(iEntity, EV_VEC_angles, angles);
	entity_set_size(iEntity, size_min, size_max);
	entity_set_int(iEntity, EV_INT_body, block_type);
	
	if ( 1 <= id <= g_max_players )
	{
		DoSnapping(id, iEntity, origin);
	}
	
	entity_set_origin(iEntity, origin);
	
	SetProperty(iEntity, 1, property1);
	SetProperty(iEntity, 2, property2);
	SetProperty(iEntity, 3, property3);
	SetProperty(iEntity, 4, property4);
	
	g_block_count ++;
	return iEntity;
}

ConvertBlockAiming(id, const convert_to)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body);
	new szCreator[32], szLastMover[32];
	get_user_name(id, szCreator, 31);
	replace_all(szCreator, 31, " ", "_");
	get_user_name(id, szLastMover, 31);
	replace_all(szLastMover, 31, " ", "_");
	
	if ( !IsBlock(iEntity) ) return PLUGIN_HANDLED;
	
	new grabber = entity_get_int(iEntity, EV_INT_iuser2);
	if ( grabber && grabber != id ) return PLUGIN_HANDLED;
	
	new player = entity_get_int(iEntity, EV_INT_iuser1);
	if ( player && player != id )
	{
		new player_name[32]; 
		get_user_name(player, player_name, charsmax(player_name));
		
		BCM_Print(id, "^1%s^3 currently has this block in their group!", player_name);
		return PLUGIN_HANDLED;
	}
	
	static new_block;
	if ( IsBlockInGroup(id, iEntity) && g_group_count[id] > 1 )
	{
		static i, block, block_count;
		
		block_count = 0;
		for ( i = 0; i <= g_group_count[id]; ++i )
		{
			block = g_grouped_blocks[id][i];
			if ( !IsBlockInGroup(id, block) ) continue;
			
			new_block = ConvertBlock(id, block, convert_to, true);
			if ( new_block != 0 )
			{
				g_grouped_blocks[id][i] = new_block;
				
				GroupBlock(id, new_block);
			}
			else
			{
				++block_count;
			}
		}
		
		if ( block_count > 1 )
		{
			BCM_Print(id, "Couldn't convert^1 %d^3 blocks!", block_count);
		}
	}
	else
	{					
		new_block = ConvertBlock(id, iEntity, convert_to, false, szCreator, szLastMover);
		if ( IsBlockStuck(new_block) )
		{
			new bool:deleted = DeleteBlock(new_block);
			if ( deleted ) BCM_Print(id, "Block deleted because it was stuck!");
		}	
	}
	
	return PLUGIN_HANDLED;
}

ConvertBlock(id, iEntity, const convert_to, const bool:preserve_size, szCreator[] = "Unknown", szLastMover[] = "Unknown")
{
	new axis;
	new block_type;
	new property1[5], property2[5], property3[5], property4[5];
	new Float:origin[3];
	new Float:size_max[3];
	
	block_type = entity_get_int(iEntity, EV_INT_body);
	
	entity_get_vector(iEntity, EV_VEC_origin, origin);
	entity_get_vector(iEntity, EV_VEC_maxs, size_max);
	
	for ( new i = 0; i < 3; ++i )
	{
		if ( size_max[i] == 4.0 )
		{
			axis = i;
			break;
		}
	}
	
	GetProperty(iEntity, 1, property1);
	GetProperty(iEntity, 2, property2);
	GetProperty(iEntity, 3, property3);
	GetProperty(iEntity, 4, property4);
	
	if ( block_type != convert_to )
	{
		copy(property1, charsmax(property1), g_property1_default_value[convert_to]);
		copy(property2, charsmax(property1), g_property2_default_value[convert_to]);
		copy(property3, charsmax(property1), g_property3_default_value[convert_to]);
		copy(property4, charsmax(property1), g_property4_default_value[convert_to]);
	}
	
	DeleteBlock(iEntity);
	
	if ( preserve_size )
	{
		static size, Float:max_size;
		
		max_size = size_max[0] + size_max[1] + size_max[2];
		
		if ( max_size > 128.0 )		size = LARGE;
		else if ( max_size > 64.0 )	size = NORMAL;
		else if ( max_size > 36.0 ) 	size = POLE;
		else				size = SMALL;
		
		return CreateBlock(id, convert_to, origin, axis, size, property1, property2, property3, property4, szCreator, szLastMover);
	}
	else
	{
		return CreateBlock(id, convert_to, origin, axis, g_selected_block_size[id], property1, property2, property3, property4, szCreator, szLastMover);
	}

	return iEntity;
}

DeleteBlockAiming(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body);
	
	if ( !IsBlock(iEntity) ) return PLUGIN_HANDLED;
	
	new grabber = entity_get_int(iEntity, EV_INT_iuser2);
	if ( grabber && grabber != id ) return PLUGIN_HANDLED;
	
	new player = entity_get_int(iEntity, EV_INT_iuser1);
	if ( player && player != id )
	{
		new player_name[32]; 
		get_user_name(player, player_name, charsmax(player_name));
		
		BCM_Print(id, "^1%s^3 currently has this block in their group!", player_name);
		return PLUGIN_HANDLED;
	}
	
	if ( IsBlockInGroup(id, iEntity) && g_group_count[id] > 1 )
	{
		static i, block;
		for ( i = 0; i <= g_group_count[id]; ++i )
		{
			block = g_grouped_blocks[id][i];
			if ( !is_valid_ent(block) ) continue;
			
			DeleteBlock(block);
		}
		
		return PLUGIN_HANDLED;
	}
	
	DeleteBlock(iEntity);
	
	return PLUGIN_HANDLED;
}

bool:DeleteBlock(iEntity)
{
	if ( !IsBlock(iEntity) ) return true;
	
	remove_entity(iEntity);
	g_block_count --;
	return false;
}

RotateBlockAiming(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body);
	
	if ( !IsBlock(iEntity) ) return PLUGIN_HANDLED;
	
	new grabber = entity_get_int(iEntity, EV_INT_iuser2);
	if ( grabber && grabber != id ) return PLUGIN_HANDLED;
	
	new player = entity_get_int(iEntity, EV_INT_iuser1);
	if ( player && player != id )
	{
		static player_name[32]; 
		get_user_name(player, player_name, charsmax(player_name));
		
		BCM_Print(id, "^1%s^3 currently has this block in their group!", player_name);
		return PLUGIN_HANDLED;
	}
	
	if ( IsBlockInGroup(id, iEntity) && g_group_count[id] > 1 )
	{
		static block;
		for ( new i = 0; i <= g_group_count[id]; ++i )
		{
			block = g_grouped_blocks[id][i];
			if ( IsBlockInGroup(id, block) ) RotateBlock(block);
		}
	}
	else
	{
		RotateBlock(iEntity);
	}
	
	return PLUGIN_HANDLED;
}


RotateBlock(iEntity)
{
	if ( !is_valid_ent(iEntity) ) return false;
	
	static Float:angles[3];
	static Float:size_min[3];
	static Float:size_max[3];
	static Float:temp;
	
	entity_get_vector(iEntity, EV_VEC_angles, angles);
	entity_get_vector(iEntity, EV_VEC_mins, size_min);
	entity_get_vector(iEntity, EV_VEC_maxs, size_max);
	
	if ( angles[0] == 0.0 && angles[2] == 0.0 )
	{
		angles[0] = 90.0;
	}
	else if ( angles[0] == 90.0 && angles[2] == 0.0 )
	{
		angles[0] = 90.0;
		angles[2] = 90.0;
	}
	else
	{
		angles[0] = 0.0;
		angles[1] = 0.0;
		angles[2] = 0.0;
	}
	
	temp = size_min[0];
	size_min[0] = size_min[2];
	size_min[2] = size_min[1];
	size_min[1] = temp;
	
	temp = size_max[0];
	size_max[0] = size_max[2];
	size_max[2] = size_max[1];
	size_max[1] = temp;
	
	entity_set_vector(iEntity, EV_VEC_angles, angles);
	entity_set_size(iEntity, size_min, size_max);
	
	return true;
}

ChangeBlockSize(id)
{
	switch ( g_selected_block_size[id] )
	{
		case SMALL:	g_selected_block_size[id] = NORMAL;
		case NORMAL:	g_selected_block_size[id] = LARGE;
		case LARGE:	g_selected_block_size[id] = POLE;
		case POLE:	g_selected_block_size[id] = SMALL;
	}
}

SetPropertiesBlockAiming(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		ShowBlockMenu(id);
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body);
	
	if ( !IsBlock(iEntity) )
	{
		ShowBlockMenu(id);
		return PLUGIN_HANDLED;
	}
	
	new block_type = entity_get_int(iEntity, EV_INT_body);
	
	if ( !g_property1_name[block_type][0]
	&& !g_property2_name[block_type][0]
	&& !g_property3_name[block_type][0]
	&& !g_property4_name[block_type][0] )
	{
		ShowBlockMenu(id);
		return PLUGIN_HANDLED;
	}
	
	//g_viewing_properties_menu[id] = true;
	set_bit(g_viewing_properties_menu, id);
	ShowPropertiesMenu(id, iEntity);
	
	return PLUGIN_HANDLED;
}

public SetPropertyBlock(id)
{
	static arg[5];
	read_argv(1, arg, charsmax(arg));
	
	if ( !strlen(arg) )
	{
		BCM_Print(id, "You can't set a property blank! Please type a new value.");
		client_cmd(id, "messagemode BCM_SetProperty");
		return PLUGIN_HANDLED;
	}
	else if ( !IsStrFloat(arg) )
	{
		BCM_Print(id, "You can't use letters in a property! Please type a new value.");
		client_cmd(id, "messagemode BCM_SetProperty");
		return PLUGIN_HANDLED;
	}
	
	new iEntity = g_property_info[id][1];
	if ( !is_valid_ent(iEntity) )
	{
		BCM_Print(id, "That block has been deleted!");
		clear_bit(g_viewing_properties_menu, id);
		//g_viewing_properties_menu[id] = false;
		ShowBlockMenu(id);
		return PLUGIN_HANDLED;
	}
	
	static block_type;
	static property;
	static Float:property_value;
	
	block_type = entity_get_int(iEntity, EV_INT_body);
	property = g_property_info[id][0];
	property_value = str_to_float(arg);
	
	if ( property == 3
	&& block_type != BOOTS_OF_SPEED
	&& block_type != BLIND_TRAP )
	{
		if ( !( 50 <= property_value <= 200 
		|| property_value == 255
		|| property_value == 0 ) )
		{
			BCM_Print(id, "The property has to be between^1 50^3 and^1 200^3,^1 255^3 or^1 0^3!");
			return PLUGIN_HANDLED;
		}
	}
	else
	{
		switch ( block_type )
		{
			case DAMAGE, HEALER:
			{
				if ( property == 1
				&& !( 1 <= property_value <= 100 ) )
				{
					BCM_Print(id, "The property has to be between^1 1^3 and^1 100^3!");
					return PLUGIN_HANDLED;
				}
				else if ( !( 0.1 <= property_value <= 240 ) )
				{
					BCM_Print(id, "The property has to be between^1 0.1^3 and^1 240^3!");
					return PLUGIN_HANDLED;
				}
			}
			case ICE:
			{
				if ( !( 0.0 <= property_value <= 0.99 ) )
				{
					BCM_Print(id, "The property has to be between^1 0.0^3 and^1 0.99^3!");
					return PLUGIN_HANDLED;
				}
			}
			case TRAMPOLINE:
			{
				if ( property == 2
				&& !( 200 <= property_value <= 2000 ) )
				{
					BCM_Print(id, "The property has to be between^1 200^3 and^1 2000^3!");
					return PLUGIN_HANDLED;
				}
			}
			case SPEED_BOOST:
			{
				if ( property == 1
				&& !( 200 <= property_value <= 2000 ) )
				{
					BCM_Print(id, "The property has to be between^1 200^3 and^1 2000^3!");
					return PLUGIN_HANDLED;
				}
				else if ( !( 0 <= property_value <= 2000 ) )
				{
					BCM_Print(id, "The property has to be between^1 0^3 and^1 2000^3!");
					return PLUGIN_HANDLED;
				}
			}
			case LOW_GRAVITY:
			{
				if ( !( 50 <= property_value <= 750 ) )
				{
					BCM_Print(id, "The property has to be between^1 50^3 and^1 750^3!");
					return PLUGIN_HANDLED;
				}
			}
			case HONEY:
			{
				if ( !( 25 <= property_value <= 200
				|| property_value == 0 ) )
				{
					BCM_Print(id, "The property has to be between^1 25^3 and^1 200^3, or^1 0^3!");
					return PLUGIN_HANDLED;
				}
			}
			case DELAYED_BHOP:
			{
				if ( !( 0.5 <= property_value <= 5 ) )
				{
					BCM_Print(id, "The property has to be between^1 0.5^3 and^1 5^3!");
					return PLUGIN_HANDLED;
				}
			}
			case INVINCIBILITY, STEALTH, BOOTS_OF_SPEED, SUPERMAN:
			{
				if ( property == 1
				&& !( 0.5 <= property_value <= 240 ) )
				{
					BCM_Print(id, "The property has to be between^1 0.5^3 and^1 240^3!");
					return PLUGIN_HANDLED;
				}
				else if ( property == 2
				&& !( 0 <= property_value <= 240 ) )
				{
					BCM_Print(id, "The property has to be between^1 0^3 and^1 240^3!");
					return PLUGIN_HANDLED;
				}
				else if ( property == 3
				&& block_type == BOOTS_OF_SPEED
				&& !( 260 <= property_value <= 2000 ) )
				{
					BCM_Print(id, "The property has to be between^1 260^3 and^1 2000^3!");
					return PLUGIN_HANDLED;
				}
			}
			case BLIND_TRAP:
			{
				if( property == 4 && !( 15 <= property_value <= 255 ) )
				{
					BCM_Print(id, "The property has to be between^1 15^3 and^1 255^3!");
					return PLUGIN_HANDLED;
				}
			}
		}
	}
	
	SetProperty(iEntity, property, arg);
	
	for ( new i = 1; i <= g_max_players; i++ )
	{
		if ( !get_bit(g_connected, i)
		|| !get_bit(g_viewing_properties_menu, i) ) continue;
		
		iEntity = g_property_info[i][1];
		ShowPropertiesMenu(i, iEntity);
	}
	
	return PLUGIN_HANDLED;
}

ToggleProperty(id, property)
{
	new iEntity = g_property_info[id][1];
	if ( !is_valid_ent(iEntity) )
	{
		BCM_Print(id, "That block has been deleted!");
		clear_bit(g_viewing_properties_menu, id);
		ShowBlockMenu(id);
		return PLUGIN_HANDLED;
	}
	
	static property_value[5];
	GetProperty(iEntity, property, property_value);
	
	new block_type = entity_get_int(iEntity, EV_INT_body);
	if ( block_type == WEAPON_BLOCK && property == 1)
	{	
		switch( property_value[0] )
		{
			case '1': copy(property_value, charsmax(property_value), "2");
			case '2': copy(property_value, charsmax(property_value), "3");
			case '3': copy(property_value, charsmax(property_value), "4");
			case '4': copy(property_value, charsmax(property_value), "5");
			case '5': copy(property_value, charsmax(property_value), "6");
			case '6': copy(property_value, charsmax(property_value), "7");
			case '7': copy(property_value, charsmax(property_value), "8");
			case '8': copy(property_value, charsmax(property_value), "9");
			default: copy(property_value, charsmax(property_value), "1");
		}
	}
	else if ( block_type == MAGIC_CARPET && property == 1 )
	{
		switch( property_value[0] )
		{
			case '1': copy(property_value, charsmax(property_value), "2");
			case '2': copy(property_value, charsmax(property_value), "3");
			case '3': copy(property_value, charsmax(property_value), "4");
			default: copy(property_value, charsmax(property_value), "1");
		}
	}	
	else if ( block_type == SLAP && property == 1
	|| block_type == CT_BARRIER && property == 1
	|| block_type == T_BARRIER && property == 1
	|| block_type == NADE_BLOCK && property == 1
	|| block_type == HEALER && property == 4 )
	{
		switch( property_value[0] )
		{
			case '1': copy(property_value, charsmax(property_value), "2");
			case '2': copy(property_value, charsmax(property_value), "3");
			default: copy(property_value, charsmax(property_value), "1");
		}
	}
	else
	{
		if ( property_value[0] == '0' )		copy(property_value, charsmax(property_value), "1");
		else					copy(property_value, charsmax(property_value), "0");
	}
	
	SetProperty(iEntity, property, property_value);
	
	for ( new i = 1; i <= g_max_players; i++ )
	{
		if ( get_bit(g_connected, i) && get_bit(g_viewing_properties_menu, i) )
		{
			iEntity = g_property_info[i][1];
			ShowPropertiesMenu(i, iEntity);
		}
	}
	
	return PLUGIN_HANDLED;
}

GetProperty(iEntity, property, property_value[])
{
	switch ( property )
	{
		case 1: pev(iEntity, pev_message, property_value, 5);
		case 2: pev(iEntity, pev_netname, property_value, 5);
		case 3: pev(iEntity, pev_viewmodel2, property_value, 5);
		case 4: pev(iEntity, pev_weaponmodel2, property_value, 5);
	}
	
	return (strlen(property_value) ? 1 : 0);
}

SetProperty(iEntity, property, const property_value[])
{
	switch ( property )
	{
		case 1: set_pev(iEntity, pev_message, property_value, 5);
		case 2: set_pev(iEntity, pev_netname, property_value, 5);
		case 3:
		{
			set_pev(iEntity, pev_viewmodel2, property_value, 5);
			
			new block_type = entity_get_int(iEntity, EV_INT_body);
			if ( g_property3_name[block_type][0] && block_type != BOOTS_OF_SPEED && block_type != BLIND_TRAP)
			{
				new transparency = str_to_num(property_value);
				if ( !transparency
				|| transparency == 255 )
				{
					SetBlockRendering(iEntity, g_render[block_type], g_red[block_type], g_green[block_type], g_blue[block_type], g_alpha[block_type]);
				}
				else
				{
					SetBlockRendering(iEntity, TRANSALPHA, 255, 255, 255, transparency);
				}
			}
		}
		case 4: set_pev(iEntity, pev_weaponmodel2, property_value, 5);
	}

	return 1;
}

CopyBlock(id, iEntity)
{
	if ( !is_valid_ent(iEntity) ) return 0;
	
	if(g_block_count >= MAX_BLOCKS) {
		client_print(id, print_chat, "Max block count of %d has already been reached.", MAX_BLOCKS);
		return PLUGIN_HANDLED;
	}
	
	new size;
	new axis;
	new property1[5], property2[5], property3[5], property4[5];
	new Float:origin[3];
	new Float:angles[3];
	new Float:size_min[3];
	new Float:size_max[3];
	new Float:max_size;
	new szCreator[32], szLastMover[32];
		
	get_user_name(id, szCreator, 31);
	replace_all(szCreator, 31, " ", "_");
	
	get_user_name(id, szLastMover, 31);
	replace_all(szLastMover, 31, " ", "_");
	
	entity_get_vector(iEntity, EV_VEC_origin, origin);
	entity_get_vector(iEntity, EV_VEC_angles, angles);
	entity_get_vector(iEntity, EV_VEC_mins, size_min);
	entity_get_vector(iEntity, EV_VEC_maxs, size_max);
	
	max_size = size_max[0] + size_max[1] + size_max[2];
	
	if ( max_size > 128.0 )		size = LARGE;
	else if ( max_size > 64.0 )	size = NORMAL;
	else if ( max_size > 36.0 )	size = POLE;
	else				size = SMALL;
	
	for ( new i = 0; i < 3; ++i )
	{
		if ( size_max[i] == 4.0 )
		{
			axis = i;
			break;
		}
	}
	
	GetProperty(iEntity, 1, property1);
	GetProperty(iEntity, 2, property2);
	GetProperty(iEntity, 3, property3);
	GetProperty(iEntity, 4, property4);
	
	
	return CreateBlock(0, entity_get_int(iEntity, EV_INT_body), origin, axis, size, property1, property2, property3, property4, szCreator, szLastMover);
}

GroupBlockAiming(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body);
	
	if ( !IsBlock(iEntity) ) return PLUGIN_HANDLED;
	
	new player = entity_get_int(iEntity, EV_INT_iuser1);
	if ( player == 0 )
	{
		++g_group_count[id];
		g_grouped_blocks[id][g_group_count[id]] = iEntity;
		GroupBlock(id, iEntity);
		
	}
	else if ( player == id )
	{
		UnGroupBlock(iEntity);
	}
	else
	{
		static name[32];
		
		new player = entity_get_int(iEntity, EV_INT_iuser1);
		get_user_name(player, name, charsmax(name));
		
		BCM_Print(id, "Block is already in a group by:^1 %s", name);
	}
	
	return PLUGIN_HANDLED;
}

GroupBlock(id, iEntity)
{
	if ( !is_valid_ent(iEntity) ) return PLUGIN_HANDLED;
	
	if ( id > 0 && id <= g_max_players )
	{
		entity_set_int(iEntity, EV_INT_iuser1, id);
	}
	
	set_rendering(iEntity, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 16);
	
	return PLUGIN_HANDLED;
}

UnGroupBlock(iEntity)
{
	if ( IsBlock(iEntity) ) 
	{
		entity_set_int(iEntity, EV_INT_iuser1, 0);
		new block_type = entity_get_int(iEntity, EV_INT_body);
		SetBlockRendering(iEntity, g_render[block_type], g_red[block_type], g_green[block_type], g_blue[block_type], g_alpha[block_type]);
	}
}

ClearGroup(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static block;
	static block_count = 0;
	static blocks_deleted = 0;
	
	for (new i = 0; i <= g_group_count[id]; ++i )
	{
		block = g_grouped_blocks[id][i];
		if ( IsBlockInGroup(id, block) )
		{
			if ( IsBlockStuck(block) )
			{
				DeleteBlock(block);
				++blocks_deleted;
			}
			else
			{
				UnGroupBlock(block);
				++block_count;
			}
		}
	}
	
	g_group_count[id] = 0;
	
	if ( get_bit(g_connected, id) )
	{
		if ( blocks_deleted > 0 )
		{
			BCM_Print(id, "Removed^1 %d^3 block%s from group. Deleted^1 %d^3 stuck block%s!", block_count, block_count == 1 ? "" : "s", blocks_deleted, blocks_deleted == 1 ? "" : "s");
			block_count = 0;
			blocks_deleted = 0;
		}
		else
		{
			if( block_count > 0 )
			{
				BCM_Print(id, "Removed^1 %d^3 block%s from group!", block_count, block_count == 1 ? "" : "s");
				block_count = 0;
			}
			else 
			{
				BCM_Print(id, "You have^1 No^3 blocks in a group!");
			}
		}
	}
	
	return PLUGIN_HANDLED;
}

SetBlockRendering(iEntity, type, red, green, blue, alpha)
{
	if ( !IsBlock(iEntity) ) return PLUGIN_HANDLED;
	
	switch ( type )
	{
		case GLOWSHELL:		set_rendering(iEntity, kRenderFxGlowShell, red, green, blue, kRenderNormal, alpha);
		case TRANSCOLOR:	set_rendering(iEntity, kRenderFxGlowShell, red, green, blue, kRenderTransColor, alpha);
		case TRANSALPHA:	set_rendering(iEntity, kRenderFxNone, red, green, blue, kRenderTransColor, alpha);
		case TRANSWHITE:	set_rendering(iEntity, kRenderFxNone, red, green, blue, kRenderTransAdd, alpha);
		default:		set_rendering(iEntity, kRenderFxNone, red, green, blue, kRenderNormal, alpha);
	}
	
	return PLUGIN_HANDLED;
}

bool:IsBlock(iEntity)
{
	if ( !is_valid_ent(iEntity) ) return false;
	
	static classname[32];
	entity_get_string(iEntity, EV_SZ_classname, classname, charsmax(classname));
	
	if ( equal(classname, g_block_classname) )
	{
		return true;
	}
	
	return false;
}

bool:IsBlockInGroup(id, iEntity)
{
	if ( !is_valid_ent(iEntity) ) return false;
	
	new player = entity_get_int(iEntity, EV_INT_iuser1);
	if ( player == id ) return true;
	
	return false;
}

bool:IsBlockStuck(iEntity)
{
	if ( !is_valid_ent(iEntity) ) return false;
	new content;
	new Float:origin[3];
	new Float:point[3];
	new Float:size_min[3];
	new Float:size_max[3];
	
	entity_get_vector(iEntity, EV_VEC_mins, size_min);
	entity_get_vector(iEntity, EV_VEC_maxs, size_max);
	
	entity_get_vector(iEntity, EV_VEC_origin, origin);
	
	size_min[0] += 1.0;
	size_min[1] += 1.0;
	size_min[2] += 1.0;
	
	size_max[0] -= 1.0;
	size_max[1] -= 1.0; 
	size_max[2] -= 1.0;
	
	for ( new i = 0; i < 14; ++i )
	{
		point = origin;
		
		switch ( i )
		{
			case 0:
			{
				point[0] += size_max[0];
				point[1] += size_max[1];
				point[2] += size_max[2];
			}
			case 1:
			{
				point[0] += size_min[0];
				point[1] += size_max[1];
				point[2] += size_max[2];
			}
			case 2:
			{
				point[0] += size_max[0];
				point[1] += size_min[1];
				point[2] += size_max[2];
			}
			case 3:
			{
				point[0] += size_min[0];
				point[1] += size_min[1];
				point[2] += size_max[2];
			}
			case 4:
			{
				point[0] += size_max[0];
				point[1] += size_max[1];
				point[2] += size_min[2];
			}
			case 5:
			{
				point[0] += size_min[0];
				point[1] += size_max[1];
				point[2] += size_min[2];
			}
			case 6:
			{
				point[0] += size_max[0];
				point[1] += size_min[1];
				point[2] += size_min[2];
			}
			case 7:
			{
				point[0] += size_min[0];
				point[1] += size_min[1];
				point[2] += size_min[2];
			}
			case 8:	point[0] += size_max[0];
			case 9:	point[0] += size_min[0];
			case 10:point[1] += size_max[1];
			case 11:point[1] += size_min[1];
			case 12:point[2] += size_max[2];
			case 13:point[2] += size_min[2];
		}
		
		content = point_contents(point);
		if ( content == CONTENTS_EMPTY
		|| !content ) return false;
	}
	
	return true;
}

CreateTeleportAiming(id, teleport_type)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static origin[3];
	static Float:float_origin[3];
	
	get_user_origin(id, origin, 3);
	IVecFVec(origin, float_origin);
	float_origin[2] += 36.0;
	
	CreateTeleport(id, teleport_type, float_origin);
	
	return PLUGIN_HANDLED;
}

CreateTeleport(id, teleport_type, Float:origin[3])
{
	new iEntity = create_entity("info_target");
	if ( !is_valid_ent(iEntity) ) return PLUGIN_HANDLED;
	
	switch ( teleport_type )
	{
		case TELEPORT_START:
		{
			if ( g_teleport_start[id] ) remove_entity(g_teleport_start[id]);
			
			entity_set_string(iEntity, EV_SZ_classname, g_start_classname);
			entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
			entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);
			entity_set_model(iEntity, g_sprite_teleport_start);
			entity_set_size(iEntity, Float:{ -16.0, -16.0, -16.0 }, Float:{ 16.0, 16.0, 16.0 });
			entity_set_origin(iEntity, origin);
			
			entity_set_int(iEntity, EV_INT_rendermode, 5);
			entity_set_float(iEntity, EV_FL_renderamt, 255.0);
			
			static params[2];
			params[0] = iEntity;
			params[1] =  g_teleport_start_frames;
			
			set_task(0.1, "TaskSpriteNextFrame", TASK_SPRITE + iEntity, params, 2, "b");
			
			g_teleport_start[id] = iEntity;
		}
		case TELEPORT_DESTINATION:
		{
			if ( !g_teleport_start[id] )
			{
				remove_entity(iEntity);
				return PLUGIN_HANDLED;
			}
			
			entity_set_string(iEntity, EV_SZ_classname, g_destination_classname);
			entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
			entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);
			entity_set_model(iEntity, g_sprite_teleport_destination);
			entity_set_size(iEntity, Float:{ -16.0, -16.0, -16.0 }, Float:{ 16.0, 16.0, 16.0 });
			entity_set_origin(iEntity, origin);
			
			entity_set_int(iEntity, EV_INT_rendermode, 5);
			entity_set_float(iEntity, EV_FL_renderamt, 255.0);
			
			entity_set_int(iEntity, EV_INT_iuser1, g_teleport_start[id]);
			entity_set_int(g_teleport_start[id], EV_INT_iuser1, iEntity);
			
			static params[2];
			params[0] = iEntity;
			params[1] = g_teleport_end_frames;
			
			set_task(0.1, "TaskSpriteNextFrame", TASK_SPRITE + iEntity, params, 2, "b");
			
			g_teleport_start[id] = 0;
		}

	}
	
	return PLUGIN_HANDLED;
}

DeleteTeleportAiming(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body, 9999);
	
	new bool:deleted = DeleteTeleport(id, iEntity);
	if ( deleted ) BCM_Print(id, "Teleport deleted!");
	
	return PLUGIN_HANDLED;
}

bool:DeleteTeleport(id, iEntity)
{
	for ( new i = 0; i < 2; ++i )
	{
		if ( !IsTeleport(iEntity) ) return false;
		
		new tele = entity_get_int(iEntity, EV_INT_iuser1);
		
		if ( g_teleport_start[id] == iEntity
		|| g_teleport_start[id] == tele )
		{
			g_teleport_start[id] = 0;
		}
		
		if ( task_exists(TASK_SPRITE + iEntity) )
		{
			remove_task(TASK_SPRITE + iEntity);
		}
		
		if ( task_exists(TASK_SPRITE + tele) )
		{
			remove_task(TASK_SPRITE + tele);
		}
		
		if ( tele ) remove_entity(tele);
		
		remove_entity(iEntity);
		return true;
	}
	
	return false;
}

SwapTeleportAiming(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, body;
	get_user_aiming(id, iEntity, body, 9999);
	
	if ( !IsTeleport(iEntity) ) return PLUGIN_HANDLED;
	
	SwapTeleport(id, iEntity);
	
	return PLUGIN_HANDLED;
}

SwapTeleport(id, iEntity)
{
	static Float:origin_ent[3];
	static Float:origin_tele[3];
	
	new tele = entity_get_int(iEntity, EV_INT_iuser1);
	if ( !is_valid_ent(tele) )
	{
		BCM_Print(id, "Can't swap teleport positions!");
		return PLUGIN_HANDLED;
	}
	
	entity_get_vector(iEntity, EV_VEC_origin, origin_ent);
	entity_get_vector(tele, EV_VEC_origin, origin_tele);
	
	static classname[32];
	entity_get_string(iEntity, EV_SZ_classname, classname, charsmax(classname));
	
	DeleteTeleport(id, iEntity);
	
	if ( equal(classname, g_start_classname) )
	{
		CreateTeleport(id, TELEPORT_START, origin_tele);
		CreateTeleport(id, TELEPORT_DESTINATION, origin_ent);
	}
	else if ( equal(classname, g_destination_classname) )
	{
		CreateTeleport(id, TELEPORT_START, origin_ent);
		CreateTeleport(id, TELEPORT_DESTINATION, origin_tele);
	}
	
	BCM_Print(id, "Teleports swapped!");
	
	return PLUGIN_HANDLED;
}

bool:IsTeleport(iEntity)
{
	if ( !is_valid_ent(iEntity) ) return false;
	
	static classname[32];
	entity_get_string(iEntity, EV_SZ_classname, classname, charsmax(classname));
	
	if ( equal(classname, g_start_classname)
	|| equal(classname, g_destination_classname) )
	{
		return true;
	}
	
	return false;
}

DoSnapping(id, iEntity, Float:move_to[3])
{
	if ( !get_bit(g_snapping, id) ) return PLUGIN_HANDLED;
	
	new traceline;
	new closest_trace;
	new block_face;
	new Float:snap_size;
	new Float:v_return[3];
	new Float:dist;
	new Float:old_dist;
	new Float:trace_start[3];
	new Float:trace_end[3];
	new Float:size_min[3];
	new Float:size_max[3];
	
	entity_get_vector(iEntity, EV_VEC_mins, size_min);
	entity_get_vector(iEntity, EV_VEC_maxs, size_max);
	
	snap_size = g_snapping_gap[id] + 10.0;
	old_dist = 9999.9;
	closest_trace = 0;
	for ( new i = 0; i < 6; ++i )
	{
		trace_start = move_to;
		
		switch ( i )
		{
			case 0: trace_start[0] += size_min[0];
			case 1: trace_start[0] += size_max[0];
			case 2: trace_start[1] += size_min[1];
			case 3: trace_start[1] += size_max[1];
			case 4: trace_start[2] += size_min[2];
			case 5: trace_start[2] += size_max[2];
		}
		
		trace_end = trace_start;
		
		switch ( i )
		{
			case 0: trace_end[0] -= snap_size;
			case 1: trace_end[0] += snap_size;
			case 2: trace_end[1] -= snap_size;
			case 3: trace_end[1] += snap_size;
			case 4: trace_end[2] -= snap_size;
			case 5: trace_end[2] += snap_size;
		}
		
		traceline = trace_line(iEntity, trace_start, trace_end, v_return);
		if ( IsBlock(traceline)
		&& ( !IsBlockInGroup(id, traceline) || !IsBlockInGroup(id, iEntity) ) )
		{
			dist = get_distance_f(trace_start, v_return);
			if ( dist < old_dist )
			{
				closest_trace = traceline;
				old_dist = dist;
				
				block_face = i;
			}
		}
	}
	
	if ( !is_valid_ent(closest_trace) ) return PLUGIN_HANDLED;
	
	static Float:trace_origin[3];
	static Float:trace_size_min[3];
	static Float:trace_size_max[3];
	
	entity_get_vector(closest_trace, EV_VEC_origin, trace_origin);
	entity_get_vector(closest_trace, EV_VEC_mins, trace_size_min);
	entity_get_vector(closest_trace, EV_VEC_maxs, trace_size_max);
	
	move_to = trace_origin;
	
	if ( block_face == 0 ) move_to[0] += ( trace_size_max[0] + size_max[0] ) + g_snapping_gap[id];
	if ( block_face == 1 ) move_to[0] += ( trace_size_min[0] + size_min[0] ) - g_snapping_gap[id];
	if ( block_face == 2 ) move_to[1] += ( trace_size_max[1] + size_max[1] ) + g_snapping_gap[id];
	if ( block_face == 3 ) move_to[1] += ( trace_size_min[1] + size_min[1] ) - g_snapping_gap[id];
	if ( block_face == 4 ) move_to[2] += ( trace_size_max[2] + size_max[2] ) + g_snapping_gap[id];
	if ( block_face == 5 ) move_to[2] += ( trace_size_min[2] + size_min[2] ) - g_snapping_gap[id];
	
	return PLUGIN_HANDLED;
}

public DeleteAllTask() {
	DeleteAll(0, false);
}

DeleteAll(id, bool:notify)
{
	if ( id != 0 && !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, block_count, tele_count, bool:deleted;	
	iEntity = -1;
	block_count = 0;
	new bool:done = false;

	while ( !done && ( iEntity = find_ent_by_class(iEntity, g_block_classname) ) )
	{
		deleted = DeleteBlock(iEntity);
		if ( deleted )
		{
			++block_count;
		}
		if( block_count >= BLOCK_DELETE_CHUNK ) {
			set_task(0.1, "DeleteAllTask");
			done = true;
		}
	}
	
	iEntity = -1;
	tele_count = 0;
	while ( ( iEntity = find_ent_by_class(iEntity, g_start_classname) ) )
	{
		deleted = DeleteTeleport(id, iEntity);
		if ( deleted )
		{
			++tele_count;
		}
	}
	
	if ( ( block_count
		|| tele_count )
	&& notify )
	{
		static name[32];
		get_user_name(id, name, charsmax(name));
		
		for ( new i = 1; i <= g_max_players; ++i )
		{
			g_grabbed[i] = 0;
			g_teleport_start[i] = 0;
			
			if ( !get_bit(g_connected, i)
			|| !get_bit(g_admin, i) ) continue;
			
			BCM_Print(i, "^3%s ^1deleted^3 %d blocks^1 and^3 %d teleports^1 from the map!", name, block_count, tele_count);
		}
	}
	
	return PLUGIN_HANDLED;
}

DeleteAllBlocks(id, bool:notify)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, block_count, bool:deleted;
	
	iEntity = -1;
	block_count = 0;
	while ( ( iEntity = find_ent_by_class(iEntity, g_block_classname) ) )
	{
		deleted = DeleteBlock(iEntity);
		if ( deleted )
		{
			++block_count;
		}
	}
	
	if ( ( block_count )
	&& notify )
	{
		static name[32];
		get_user_name(id, name, charsmax(name));
		
		for ( new i = 1; i <= g_max_players; ++i )
		{
			g_grabbed[i] = 0;
			g_teleport_start[i] = 0;
			
			if ( !get_bit(g_connected, i)
			|| !get_bit(g_admin, i) ) continue;
			
			BCM_Print(i, "^1%s^3 Deleted^1 %d Blocks ^3from the map!", name, block_count);
		}
	}
	
	return PLUGIN_HANDLED;
}

DeleteAllTeleports(id, bool:notify)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	static iEntity, tele_count, bool:deleted;
	
	iEntity = -1;
	tele_count = 0;
	while ( ( iEntity = find_ent_by_class(iEntity, g_start_classname) ) )
	{
		deleted = DeleteTeleport(id, iEntity);
		if ( deleted )
		{
			++tele_count;
		}
	}

	if ( ( tele_count )
	&& notify )
	{
		static name[32];
		get_user_name(id, name, charsmax(name));
		
		for ( new i = 1; i <= g_max_players; ++i )
		{
			g_grabbed[i] = 0;
			g_teleport_start[i] = 0;
			
			if ( !get_bit(g_connected, i)
			|| !get_bit(g_admin, i) ) continue;
			
			BCM_Print(i, "^1%s^3 Deleted^1 %d Teleports^3 from the map!", name, tele_count);
		}
	}
	
	return PLUGIN_HANDLED;
}

SaveBlocks(id)
{
	if ( !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	
	new iEntity;
	new file = fopen(g_new_file, "wt");
	new data[256];
	new block_count = 0;
	new tele_count = 0;
	new block_type;
	new size;
	new property1[5], property2[5], property3[5], property4[5];
	new tele;
	new Float:origin[3];
	new Float:angles[3];
	new Float:tele_start[3];
	new Float:tele_end[3];
	new Float:max_size;
	new Float:size_max[3];
	new szCreator[32], szLastMover[32];
	
	iEntity = -1;
	while ( ( iEntity = find_ent_by_class(iEntity, g_block_classname) ) )
	{
		block_type = entity_get_int(iEntity, EV_INT_body);
		entity_get_vector(iEntity, EV_VEC_origin, origin);
		entity_get_vector(iEntity, EV_VEC_angles, angles);
		entity_get_vector(iEntity, EV_VEC_maxs, size_max);
		pev(iEntity, pev_targetname, szCreator, 31);
		pev(iEntity, pev_target, szLastMover, 31);
		
		GetProperty(iEntity, 1, property1);
		GetProperty(iEntity, 2, property2);
		GetProperty(iEntity, 3, property3);
		GetProperty(iEntity, 4, property4);
		
		if ( !property1[0] ) copy(property1, charsmax(property1), "/");
		if ( !property2[0] ) copy(property2, charsmax(property2), "/");
		if ( !property3[0] ) copy(property3, charsmax(property3), "/");
		if ( !property4[0] ) copy(property4, charsmax(property4), "/");
		
		max_size = size_max[0] + size_max[1] + size_max[2];
		
		if ( max_size > 128.0 )		size = LARGE;
		else if ( max_size > 64.0 )	size = NORMAL;
		else if ( max_size > 36.0 )	size = POLE;
		else				size = SMALL;
		
		formatex(data, charsmax(data), "%c %f %f %f %f %f %f %d ^"%s^" ^"%s^" ^"%s^" ^"%s^" ^"%s^" ^"%s^" ^n",\
			g_block_save_ids[block_type],\
			origin[0],\
			origin[1],\
			origin[2],\
			angles[0],\
			angles[1],\
			angles[2],\
			size,\
			property1,\
			property2,\
			property3,\
			property4,\
			szCreator,\
			szLastMover
			);
		fputs(file, data);
		
		++block_count;
	}
	
	iEntity = -1;
	while ( ( iEntity = find_ent_by_class(iEntity, g_destination_classname) ) )
	{
		tele = entity_get_int(iEntity, EV_INT_iuser1);
		if ( tele )
		{
			entity_get_vector(tele, EV_VEC_origin, tele_start);
			entity_get_vector(iEntity, EV_VEC_origin, tele_end);
			
			formatex(data, charsmax(data), "* %f %f %f %f %f %f^n",\
				tele_start[0],\
				tele_start[1],\
				tele_start[2],\
				tele_end[0],\
				tele_end[1],\
				tele_end[2]
				);
			fputs(file, data);
			
			++tele_count;
		}
	}
	
	static name[32];
	get_user_name(id, name, charsmax(name));
	
	for ( new i = 1; i <= g_max_players; ++i )
	{
		if ( get_bit(g_connected, i)
		&& ( get_bit(g_admin, i) ) )
		{
			BCM_Print(i, "^3%s^1 saved^3 %d Block%s^1 and^3 %d Teleport%s^1 Entites:^3 %d^1 Config:^3 %s", name, block_count, block_count == 1 ? g_blank : "s", tele_count, tele_count == 1 ? g_blank : "s", entity_count(), g_config_names[g_current_config]);
		}
	}
	
	fclose(file);
	return PLUGIN_HANDLED;
}

LoadBlocks(id)
{
	if ( id != 0 && !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	DeleteAll(id, false);
	g_load_start_line = 0;
	set_task(LOADING_DELAY, "TaskLoad");
				
	if ( 1 <= id <= g_max_players )
	{
		static name[32];
		get_user_name(id, name, charsmax(name));
		
		for ( new i = 1; i <= g_max_players; ++i )
		{
			if ( !get_bit(g_connected, i)
			|| !get_bit(g_admin, i) ) continue;
				
			BCM_Print(i, "%s loaded is loading config: %s (%s)", name, g_config_names[g_current_config], g_new_file);
			BCM_Print(i, "Wait 1.5 seconds for it to load.");
		}
	}
	
	return PLUGIN_HANDLED;
}

newLoad(id)
{
	if ( id != 0 && !get_bit(g_admin, id) )
	{
		console_print(id, "You have no access to that command");
		return PLUGIN_HANDLED;
	}
	else if ( !file_exists(g_file)
	&& 1 <= id <= g_max_players )
	{
		BCM_Print(id, "Couldn't find file:^1 %s", g_file);
		return PLUGIN_HANDLED;
	}
	
	if ( 1 <= id <= g_max_players )
	{
		DeleteAll(id, false);
		//g_load_start_line = 0;
	}
	
	new file;
	new data[256];
	new block_count;
	new tele_count;
	new type[2];
	new block_size[17];
	new origin_x[17];
	new origin_y[17];
	new origin_z[17];
	new angel_x[17];
	new angel_y[17];
	new angel_z[17];
	new block_type;
	new axis;
	new size;
	new property1[5], property2[5], property3[5], property4[5];
	new Float:origin[3];
	new Float:angles[3];
	new szCreator[32], szLastMover[32];
	//new count = 0;
	
	file = fopen(g_new_file, "rt");
	
	block_count = 0;
	tele_count = 0;
	
	while ( !feof(file) )
	{
		type = g_blank;
		fgets(file, data, charsmax(data));
		parse(data,\
			type, charsmax(type),\
			origin_x, charsmax(origin_x),\
			origin_y, charsmax(origin_y),\
			origin_z, charsmax(origin_z),\
			angel_x, charsmax(angel_x),\
			angel_y, charsmax(angel_y),\
			angel_z, charsmax(angel_z),\
			block_size, charsmax(block_size),\
			property1, charsmax(property1),\
			property2, charsmax(property2),\
			property3, charsmax(property3),\
			property4, charsmax(property4),\
			szCreator, charsmax(szCreator),\
			szLastMover, charsmax(szLastMover)
			);
		
		origin[0] =	str_to_float(origin_x);
		origin[1] =	str_to_float(origin_y);
		origin[2] =	str_to_float(origin_z);
		angles[0] =	str_to_float(angel_x);
		angles[1] =	str_to_float(angel_y);
		angles[2] =	str_to_float(angel_z);
		size =		str_to_num(block_size);
		
		if ( strlen(type) > 0 )
		{
			if ( type[0] != '*' )
			{
				if ( angles[0] == 90.0 && angles[1] == 0.0 && angles[2] == 0.0 )
				{
					axis = X;
				}
				else if ( angles[0] == 90.0 && angles[1] == 0.0 && angles[2] == 90.0 )
				{
					axis = Y;
				}
				else
				{
					axis = Z;
				}
			}
			
			switch ( type[0] )
			{
				case 'A': block_type = PLATFORM;
				case 'B': block_type = BHOP;
				case 'C': block_type = DAMAGE;
				case 'D': block_type = HEALER;
				case 'E': block_type = NO_FALL_DAMAGE;
				case 'F': block_type = ICE;
				case 'G': block_type = TRAMPOLINE;
				case 'H': block_type = SPEED_BOOST;
				case 'I': block_type = DEATH;
				case 'J': block_type = LOW_GRAVITY;
				case 'K': block_type = SLAP;
				case 'L': block_type = HONEY;
				case 'M': block_type = CT_BARRIER;
				case 'N': block_type = T_BARRIER;
				case 'O': block_type = GLASS;
				case 'P': block_type = NO_SLOW_DOWN_BHOP;
				case 'Q': block_type = DELAYED_BHOP;
				case 'R': block_type = INVINCIBILITY;
				case 'S': block_type = STEALTH;
				case 'T': block_type = BOOTS_OF_SPEED;
				case 'U': block_type = WEAPON_BLOCK;
				case 'V': block_type = NADE_BLOCK;
				case '3': block_type = DUCK_BLOCK;
				case 'X': block_type = XP_BLOCK;
				case 'Y': block_type = BLIND_TRAP;
				case 'Z': block_type = SUPERMAN;
				case '8': block_type = MONEY;
				case '4': block_type = BOUNCE_DEATH;
				case '5': block_type = TELEPORT;
				case '6': block_type = DESTINATION;
				case '7': block_type = MAGIC_CARPET;
				case '*':
				{
					CreateTeleport(0, TELEPORT_START, origin);
					CreateTeleport(0, TELEPORT_DESTINATION, angles);
					
					++tele_count;
				}
			}
			
			if ( type[0] != '*' && type[0] != '!' )
			{
				CreateBlock(0, block_type, origin, axis, size, property1, property2, property3, property4, szCreator, szLastMover);
				
				++block_count;
			}
		}
	}
	
	fclose(file);
	
	if ( 1 <= id <= g_max_players )
	{
		static name[32];
		get_user_name(id, name, charsmax(name));
		
		for ( new i = 1; i <= g_max_players; ++i )
		{
			if ( !get_bit(g_connected, i)
			|| !get_bit(g_admin, i) ) continue;
			
			BCM_Print(i, "^1%s^3 loaded^1 %d block%s^3,^1 %d teleport%s^3! Total entites in map:^1 %d", name, block_count, block_count == 1 ? g_blank : "s", tele_count, tele_count == 1 ? g_blank : "s", entity_count());
		}
	}
	
	return PLUGIN_HANDLED;
}

public TaskLoad()
{
	if (file_exists(g_new_file))
	{
		new file = fopen(g_new_file, "rt");
		new data[256];
		new block_count = 0;
		new tele_count = 0;
		new type[2];
		new block_size[17];
		new origin_x[17];
		new origin_y[17];
		new origin_z[17];
		new angel_x[17];
		new angel_y[17];
		new angel_z[17];
		new block_type;
		new axis;
		new size;
		new property1[5], property2[5], property3[5], property4[5];
		new Float:origin[3];
		new Float:angles[3];
		new szCreator[32], szLastMover[32];
		new count = 0;
		
		while ( !feof(file) )
		{
			type = g_blank;
			
			fgets(file, data, charsmax(data));
			if(++count < g_load_start_line) {
				continue;
			}
			if(count >= g_load_start_line + 25) {
				g_load_start_line = count;
				set_task(0.5, "TaskLoad");
				fclose(file);
				return;
				
			}
			
			parse(data,\
				type, charsmax(type),\
				origin_x, charsmax(origin_x),\
				origin_y, charsmax(origin_y),\
				origin_z, charsmax(origin_z),\
				angel_x, charsmax(angel_x),\
				angel_y, charsmax(angel_y),\
				angel_z, charsmax(angel_z),\
				block_size, charsmax(block_size),\
				property1, charsmax(property1),\
				property2, charsmax(property2),\
				property3, charsmax(property3),\
				property4, charsmax(property4),\
				szCreator, charsmax(szCreator),\
				szLastMover, charsmax(szLastMover)
				);
			
			origin[0] =	str_to_float(origin_x);
			origin[1] =	str_to_float(origin_y);
			origin[2] =	str_to_float(origin_z);
			angles[0] =	str_to_float(angel_x);
			angles[1] =	str_to_float(angel_y);
			angles[2] =	str_to_float(angel_z);
			size =		str_to_num(block_size);
			
			if ( strlen(type) > 0 )
			{
				if ( type[0] != '*' )
				{
					if ( angles[0] == 90.0 && angles[1] == 0.0 && angles[2] == 0.0 )
					{
						axis = X;
					}
					else if ( angles[0] == 90.0 && angles[1] == 0.0 && angles[2] == 90.0 )
					{
						axis = Y;
					}
					else
					{
						axis = Z;
					}
				}
				
				switch ( type[0] )
				{
					case 'A': block_type = PLATFORM;
					case 'B': block_type = BHOP;
					case 'C': block_type = DAMAGE;
					case 'D': block_type = HEALER;
					case 'E': block_type = NO_FALL_DAMAGE;
					case 'F': block_type = ICE;
					case 'G': block_type = TRAMPOLINE;
					case 'H': block_type = SPEED_BOOST;
					case 'I': block_type = DEATH;
					case 'J': block_type = LOW_GRAVITY;
					case 'K': block_type = SLAP;
					case 'L': block_type = HONEY;
					case 'M': block_type = CT_BARRIER;
					case 'N': block_type = T_BARRIER;
					case 'O': block_type = GLASS;
					case 'P': block_type = NO_SLOW_DOWN_BHOP;
					case 'Q': block_type = DELAYED_BHOP;
					case 'R': block_type = INVINCIBILITY;
					case 'S': block_type = STEALTH;
					case 'T': block_type = BOOTS_OF_SPEED;
					case 'U': block_type = WEAPON_BLOCK;
					case 'V': block_type = NADE_BLOCK;
					case '3': block_type = DUCK_BLOCK;
					case 'X': block_type = XP_BLOCK;
					case 'Y': block_type = BLIND_TRAP;
					case 'Z': block_type = SUPERMAN;
					case '8': block_type = MONEY;
					case '4': block_type = BOUNCE_DEATH;
					case '5': block_type = TELEPORT;
					case '6': block_type = DESTINATION;
					case '7': block_type = MAGIC_CARPET;
					
					case '*':
					{
						CreateTeleport(0, TELEPORT_START, origin);
						CreateTeleport(0, TELEPORT_DESTINATION, angles);
						
						++tele_count;
					}
					default:
					{
						log_amx("%sInvalid block type: %c in: %s", PLUGIN_PREFIX, type[0], g_file);
						
						--block_count;
					}
					
				}
				
				if ( type[0] != '*' && type[0] != '!' )
				{
					CreateBlock(0, block_type, origin, axis, size, property1, property2, property3, property4, szCreator, szLastMover);
					
					++block_count;
				}
	
			}
		}
		fclose(file);
		BCM_Print(0, "^1The config is^4 done loading^1 Good Luck^3 &^1 Have Fun^3!");
		set_task(0.1, "checkstuck");
	}
}

bool:IsStrFloat(string[])
{
	new len = strlen(string);
	for ( new i = 0; i < len; i++ )
	{
		switch ( string[i] )
		{
			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '*':continue;
			default:																						return false;
		}
	}
	
	return true;
}

ResetPlayer(id)
{
	clear_bit(g_no_fall_damage, id);
	clear_bit(g_ice, id);
	clear_bit(g_low_gravity, id);
	clear_bit(g_no_slow_down, id);
	clear_bit(g_block_status, id);
	clear_bit(g_has_hud_text, id);
	clear_bit(g_awp_used, id);
	clear_bit(g_deagle_used, id);
	clear_bit(g_usp_used, id);
	clear_bit(g_tmp_used, id);
	clear_bit(g_aug_used, id);
	clear_bit(g_m3_used, id);
	clear_bit(g_mac10_used, id);
	clear_bit(g_ak47_used, id);
	clear_bit(g_c4_used, id);
	clear_bit(g_hegrenade_used, id);
	clear_bit(g_smokegrenade_used, id);
	clear_bit(g_flashgrenade_used, id);
	clear_bit(g_money_used, id);
	clear_bit(g_bootsofspeed, id);
	
	g_slap[id][0] =			0;
	g_honey[id] = 0;
	g_boots_of_speed[id] =		0;
	
	g_next_damage_time[id] =	0.0;
	g_next_heal_time[id] =		0.0;
	g_invincibility_time_out[id] =	0.0;
	g_invincibility_next_use[id] =	0.0;
	g_stealth_time_out[id] =	0.0;
	g_stealth_next_use[id] =	0.0;
	g_boots_of_speed_time_out[id] =	0.0;
	g_boots_of_speed_next_use[id] =	0.0;
	g_superman_time_out[id] = 	0.0;
	g_superman_next_use[id] = 	0.0;
	g_blind_next_use[id] = 		0.0;
	
	new task_id = TASK_INVINCIBLE + id;
	if ( task_exists(task_id) )
		remove_task(task_id);
	
	task_id = TASK_STEALTH + id;
	if ( task_exists(task_id) )	
		remove_task(task_id);
	
	task_id = TASK_BOOTSOFSPEED + id;
	if ( task_exists(task_id) )	
		remove_task(task_id);
	
	task_id = TASK_SUPERMAN + id;
	if ( task_exists(task_id) )
		TaskRemoveSuperman(id);
	
	if ( get_bit(g_connected, id) )
		set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 255);
	
	set_bit(g_reseted, id);
}

ResetMaxspeed(id)
{
	static Float:max_speed;
	
	switch ( get_user_weapon(id) )
	{
		case CSW_SG550, CSW_AWP, CSW_G3SG1:				max_speed = 210.0;
		case CSW_M249:							max_speed = 220.0;
		case CSW_AK47:							max_speed = 221.0;
		case CSW_M3, CSW_M4A1:						max_speed = 230.0;
		case CSW_SG552:							max_speed = 235.0;
		case CSW_XM1014, CSW_AUG, CSW_GALIL, CSW_FAMAS:			max_speed = 240.0;
		case CSW_P90:							max_speed = 245.0;
		case CSW_HEGRENADE, CSW_FLASHBANG, CSW_SMOKEGRENADE, CSW_KNIFE: 	max_speed = 250.0;
		case CSW_SCOUT:							max_speed = 260.0;
		default:							max_speed = 250.0;
	}
	entity_set_float(id, EV_FL_maxspeed, max_speed);
}

BCM_Print( const client, const szMessageFormat[ ], any:... )
{
	static szMessage[ 192 ], iLen;
	iLen = formatex( szMessage, 191, "^4[^1'%s %s'^4]^3 ", PLUGIN_PREFIX, PLUGIN_VERSION );
	vformat( szMessage[ iLen ], 191 - iLen, szMessageFormat, 3 );
	
	if( client )
	{
		UTIL_SayText( client, client, szMessage );
	}
	else
	{
		static i;
		for( i = 1; i <= g_max_players; i++ )
		{
			if( is_user_connected( i ) )
			{
				UTIL_SayText( i, i, szMessage );
			}
		}
	}
}

DoEnterValue(id, type) {
	g_value_types[id] = type;
	client_cmd(id, "messagemode Enter_Value");
}

GetConfigFileName(index, filename[]) {
	if(index == 0) {
		formatex(filename, 96, "%s/%s.bm", Dir, Map);
	} else {
		formatex(filename, 96, "%s/%s.%d.bm", Dir, Map, index);
	}
}

UTIL_SayText( const iReceiver, const iSender, const szMessage[ ] )
{
	message_begin( iReceiver ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, g_iMsgId_SayText, _, iReceiver );
	write_byte( iSender );
	write_string( szMessage );
	message_end( );
}

new const Float:size[][3] = {
	{0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, {-1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, -1.0},
	{0.0, 0.0, 2.0}, {0.0, 0.0, -2.0}, {0.0, 2.0, 0.0}, {0.0, -2.0, 0.0}, {2.0, 0.0, 0.0}, {-2.0, 0.0, 0.0}, {-2.0, 2.0, 2.0}, {2.0, 2.0, 2.0}, {2.0, -2.0, 2.0}, {2.0, 2.0, -2.0}, {-2.0, -2.0, 2.0}, {2.0, -2.0, -2.0}, {-2.0, 2.0, -2.0}, {-2.0, -2.0, -2.0},
	{0.0, 0.0, 3.0}, {0.0, 0.0, -3.0}, {0.0, 3.0, 0.0}, {0.0, -3.0, 0.0}, {3.0, 0.0, 0.0}, {-3.0, 0.0, 0.0}, {-3.0, 3.0, 3.0}, {3.0, 3.0, 3.0}, {3.0, -3.0, 3.0}, {3.0, 3.0, -3.0}, {-3.0, -3.0, 3.0}, {3.0, -3.0, -3.0}, {-3.0, 3.0, -3.0}, {-3.0, -3.0, -3.0},
	{0.0, 0.0, 4.0}, {0.0, 0.0, -4.0}, {0.0, 4.0, 0.0}, {0.0, -4.0, 0.0}, {4.0, 0.0, 0.0}, {-4.0, 0.0, 0.0}, {-4.0, 4.0, 4.0}, {4.0, 4.0, 4.0}, {4.0, -4.0, 4.0}, {4.0, 4.0, -4.0}, {-4.0, -4.0, 4.0}, {4.0, -4.0, -4.0}, {-4.0, 4.0, -4.0}, {-4.0, -4.0, -4.0},
	{0.0, 0.0, 5.0}, {0.0, 0.0, -5.0}, {0.0, 5.0, 0.0}, {0.0, -5.0, 0.0}, {5.0, 0.0, 0.0}, {-5.0, 0.0, 0.0}, {-5.0, 5.0, 5.0}, {5.0, 5.0, 5.0}, {5.0, -5.0, 5.0}, {5.0, 5.0, -5.0}, {-5.0, -5.0, 5.0}, {5.0, -5.0, -5.0}, {-5.0, 5.0, -5.0}, {-5.0, -5.0, -5.0}
};

public checkstuck() {
	static players[32], pnum, player;
	get_players(players, pnum);
	static Float:origin[3];
	static Float:mins[3], hull;
	static Float:vec[3];
	static o,i;
	for(i=0; i<pnum; i++){
		player = players[i];
		if (get_bit(g_connected, player) && get_bit(g_alive, player)) {
			pev(player, pev_origin, origin);
			hull = pev(player, pev_flags) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN;
			if (!is_hull_vacant(origin, hull,player) && !get_user_noclip(player) && !(pev(player,pev_solid) & SOLID_NOT)) {
				set_bit(stuck, player);
				if(get_bit(stuck, player)) {
					pev(player, pev_mins, mins);
					vec[2] = origin[2];
					for (o=0; o < sizeof size; ++o) {
						vec[0] = origin[0] - mins[0] * size[o][0];
						vec[1] = origin[1] - mins[1] * size[o][1];
						vec[2] = origin[2] - mins[2] * size[o][2];
						if (is_hull_vacant(vec, hull,player)) {
							engfunc(EngFunc_SetOrigin, player, vec);
							set_pev(player,pev_velocity,{0.0,0.0,0.0});
							o = sizeof size;
						}
					}
				}
			}
			else
			{
				clear_bit(stuck, player);
			}
		}
	}
}

stock bool:is_hull_vacant(const Float:origin[3], hull,id) {
	static tr;
	engfunc(EngFunc_TraceHull, origin, origin, 0, hull, id, tr);
	if (!get_tr2(tr, TR_StartSolid) || !get_tr2(tr, TR_AllSolid)) //get_tr2(tr, TR_InOpen))
		return true;
	
	return false;
}
