
public clcmd_fullupdate()
{
	return PLUGIN_HANDLED_MAIN;
}

public fm_cmd_start(id,uc_handle,seed)
{
	if((get_pcvar_num(cvar_bleach) != 1) || (!is_user_alive(id))) return FMRES_IGNORED;
  
	new button = get_uc(uc_handle,UC_Buttons);
	
	if(g_player_frozen[id])
	{
		if(button & IN_JUMP)
		{
			button &= ~IN_JUMP;
			set_uc(uc_handle,UC_Buttons,button);
		}
	}
	
	if(button & IN_USE)
	{
		g_player_use[id]=true;
	}
	else if(button & ~IN_USE)
	{
		g_player_use[id]=false;
	}
	
	return FMRES_HANDLED;
}

public handler_say(id)
{
	if(get_pcvar_num(cvar_bleach) != 1) return PLUGIN_CONTINUE;
	
	static said[32];
	read_args(said,31);
	remove_quotes(said);

	if(equal(said,"/menu"))
	{
		menu_print_main(id);
	}
	else if(equal(said,"/menu2"))
	{
		menu_print_next(id);
	}
	else if(equal(said,"/information"))
	{
		menu_print_information(id);
	}
	else if(equal(said,"/side"))
	{
		menu_print_classes(id);
	}
	else if(equal(said,"/attributes"))
	{
		menu_print_attributes(id);
	}
	else if(equal(said,"/skills"))
	{
		menu_print_skills(id);
	}
	else if(equal(said,"/items"))
	{
		menu_print_items(id);
	}
	else if(equal(said,"/drop"))
	{
		drop_player_item(id);
	}
	else if(equal(said,"/use"))
	{
		item_use(id);
	}
	else if(equal(said,"/attributesinfo"))
	{
		motd_attributes(id);
	}
	else if(equal(said,"/skillsinfo"))
	{
		motd_skills(id);
	}
	else if(equal(said,"/itemsinfo"))
	{
		motd_items(id);
	}
	else if(equal(said,"/character"))
	{
		motd_character(id);
	}
	else if(equal(said,"/reskills"))
	{
		if(g_player_skill_reseted[id])
		{
			client_print(id,print_chat,"%L",id,"L_SKILL_RESELECT_ONCE",PLUGIN_TAG);
		}
		else
		{
			reselect_skills(id);
		}
	}
	else if(equal(said,"/save"))
	{
		if(get_pcvar_num(cvar_savexp) == 1)
		{
			client_print(id,print_chat,"%L",id,"L_USER_SAVE",PLUGIN_TAG);
			save_player(id);
		}
		else
		{
			client_print(id,print_chat,"%L",id,"L_SAVEXP_MANUAL_SAVE_DISABLED",PLUGIN_TAG);
		}
	}
	else if(equal(said,"/help"))
	{
		motd_help(id);
	}
	else if(equal(said,"/about"))
	{
		motd_about(id);
	}
	else if(equal(said,"/commands"))
	{
		motd_commands(id);
	}
	else if(equal(said,"/players"))
	{
		motd_players(id);
	}
	
	return PLUGIN_CONTINUE;
}

public handler_cmd(id,level,cid)
{
	if (!cmd_access(id,level,cid,1))
	{
		return PLUGIN_HANDLED;
	}
	
	static cmd[32],arg1[32],arg2[32];
	read_argv(0,cmd,31);
	
	if((!equal(cmd,"bm_bleach")) && (get_pcvar_num(cvar_bleach) != 1))
	{
		admin_print(id,"%L",id,"L_GAME_NOT_ENABLED",PLUGIN_TAG);
		return PLUGIN_HANDLED;
	}
	
	read_argv(1,arg1,31);
	read_argv(2,arg2,31);
	
	if(equal(cmd,"bm_bleach"))
	{
		if(equal(arg1,"1"))
		{
			if (get_pcvar_num(cvar_bleach) == 1)
			{
				admin_print(id,"%L",id,"L_GAME_ALREADY_ENABLED",PLUGIN_TAG);
			}
			else
			{
				admin_print(id,"%L",id,"L_GAME_ENABLED",PLUGIN_TAG);
				bleach_start();
			}
		}
		else if(equal(arg1,"0"))
		{
			if(get_pcvar_num(cvar_bleach) == 1)
			{
				admin_print(id,"%L",id,"L_GAME_DISABLED",PLUGIN_TAG);
				bleach_stop();
			}
			else
			{
				admin_print(id,"%L",id,"L_GAME_ALREADY_DISABLED",PLUGIN_TAG);
			}
		}
	}
	else if (equal(cmd,"bm_savexp"))
	{
		if (read_argc() < 2)
		{
			admin_print(id,"%L",id,"L_FORMAT_SAVEXP",cmd);
			return PLUGIN_HANDLED;
		}
		
		static savexp[8];
		num_to_str(get_pcvar_num(cvar_savexp),savexp,7);
		
		if(equal(arg1,savexp))
		{
			admin_print(id,"%L",id,"L_SAVEXP_METHOD",PLUGIN_TAG);
			return PLUGIN_HANDLED;
		}
		
		if(str_to_num(arg1) != get_pcvar_num(cvar_savexp))
		{
			save_all_players();
			database_close();
			reset_player_all();
		}

		if(equal(arg1,"1"))
		{
			admin_print(id,"%L",id,"L_SAVEXP_VAULT",PLUGIN_TAG);
			set_pcvar_num(cvar_savexp,1);
		}
		else if(equal(arg1,"2"))
		{
			admin_print(id,"%L",id,"L_SAVEXP_SQL",PLUGIN_TAG);
			set_pcvar_num(cvar_savexp,2);
			database_init();
		}
		else if(equal(arg1,"0"))
		{
			admin_print(id,"%L",id,"L_SAVEXP_DISABLED",PLUGIN_TAG);
			set_pcvar_num(cvar_savexp,0);
		}
	}
	else if (equal(cmd,"bm_givexp"))
	{
		if (read_argc() < 3)
		{
			admin_print(id,"%L",id,"L_FORMAT_XP",cmd);
			return PLUGIN_HANDLED;
		}
		admin_give_xp(id,arg1,str_to_num(arg2));
	}
	else if (equal(cmd,"bm_setxp"))
	{
		if (read_argc() < 3)
		{
			admin_print(id,"%L",id,"L_FORMAT_XP",cmd);
			return PLUGIN_HANDLED;
		}
		admin_set_xp(id,arg1,str_to_num(arg2));
	}
	else if (equal(cmd,"bm_givespr"))
	{
		if (read_argc() < 3)
		{
			admin_print(id,"%L",id,"L_FORMAT_SPIRIT",cmd);
			return PLUGIN_HANDLED;
		}
		admin_give_spirit(id,arg1,str_to_num(arg2));
	}
	else if (equal(cmd,"bm_setspr"))
	{
		if (read_argc() < 3)
		{
			admin_print(id,"%L",id,"L_FORMAT_SPIRIT",cmd);
			return PLUGIN_HANDLED;
		}
		admin_set_spirit(id,arg1,str_to_num(arg2));
	}
	else if(equal(cmd,"bm_giveitem"))
	{
		if (read_argc() < 3)
		{
			admin_print(id,"%L",id,"L_FORMAT_G_ITEM",cmd);
			return PLUGIN_HANDLED;
		}
		admin_give_item(id,arg1,str_to_num(arg2));
	}
	else if(equal(cmd,"bm_dropitem"))
	{
		if (read_argc() < 2)
		{
			admin_print(id,"%L",id,"L_FORMAT_D_ITEM",cmd);
			return PLUGIN_HANDLED;
		}
		admin_drop_item(id,str_to_num(arg1));
	}
	else if (equal(cmd,"bm_resetuser"))
	{
		if (read_argc() < 3)
		{
			admin_print(id,"%L",id,"L_FORMAT_RESET",cmd);
			return PLUGIN_HANDLED;
		}
		admin_reset_player(id,arg1,str_to_num(arg2));
	}
	else if (equal(cmd,"bm_purge"))
	{
		admin_purge(id);
	}
	else if (equal(cmd,"bm_reset"))
	{
		if(g_player_character_reseted[id])
		{
			client_print(id,print_console,"%L",id,"L_USER_RESET_ONCE",PLUGIN_TAG);
		}
		else
		{
			client_print(id,print_console,"%L",id,"L_USER_RESETED",PLUGIN_TAG,g_bleach_classes[g_player_class[id]]);
			
			reset_player(id);
			reset_player_attributes(id);
			reset_player_skills(id);
			restore_cooldowns(id);
			
			validate_max_speed(id);
			validate_gravity(id);
			
			save_player(id);
			print_hud_player(id);
			g_player_character_reseted[id]=true;
		}
	}
	else if(equal(cmd,"bm_item_use"))
	{
		item_use(id);
	}

	return PLUGIN_HANDLED;
}

public handler_skill(id)
{
	if(get_pcvar_num(cvar_bleach) != 1 || !is_user_alive(id)) return PLUGIN_HANDLED;

	new cmd[32];
	read_argv(0,cmd,31);
	
	if(equal(cmd,""))
	{
		return PLUGIN_HANDLED;
	}
	else if(equal(cmd,"bm_skill_next") || equal(cmd,"bm_skill_prev"))
	{
		if(equal(cmd,"bm_skill_next"))
		{
			if(g_player_current_skill[id] < (BLEACH_MAX_SKILLS - 1))
			{
				g_player_current_skill[id] += 1;
			}
			else
			{
				g_player_current_skill[id] = 0;
			}
		}
		else if(equal(cmd,"bm_skill_prev"))
		{
			if(g_player_current_skill[id] > 0)
			{
				g_player_current_skill[id] -= 1;
			}
		}
		

		if(g_player_class[id] == 1)
		{
			print_hud_status(id,"%L",id,"L_STATUS_SKILL_CURRENT",g_dg_skill_names[g_player_current_skill[id]]);
		}
		else if(g_player_class[id] == 2)
		{
			print_hud_status(id,"%L",id,"L_STATUS_SKILL_CURRENT",g_hw_skill_names[g_player_current_skill[id]]);
		}
		
		return PLUGIN_HANDLED;
	}
	else if(equal(cmd,"+bm_skill_use") || equal(cmd,"-bm_skill_use"))
	{
		if(g_player_class[id] == 0)
		{
			return PLUGIN_HANDLED;
		}
		
		static skill;
		skill=g_player_current_skill[id];
		
		if(equal(cmd,"+bm_skill_use"))
		{
			if(g_player_class[id] == 1)
			{
				if(equal(g_dg_skill_p_cmds[skill],"")) return PLUGIN_HANDLED;
				
				format(cmd,31,g_dg_skill_p_cmds[skill]);
			}
			else if(g_player_class[id] == 2)
			{
				if(equal(g_hw_skill_p_cmds[skill],"")) return PLUGIN_HANDLED;
				
				format(cmd,31,g_hw_skill_p_cmds[skill]);
			}
		}
		else if(equal(cmd,"-bm_skill_use"))
		{
			if(g_player_class[id] == 1)
			{
				if(equal(g_dg_skill_n_cmds[skill],"")) return PLUGIN_HANDLED;
				
				format(cmd,31,g_dg_skill_n_cmds[skill]);
			}
			else if(g_player_class[id] == 2)
			{
				if(equal(g_hw_skill_n_cmds[skill],"")) return PLUGIN_HANDLED;
				
				format(cmd,31,g_hw_skill_n_cmds[skill]);
			}
		}
	}
	
	static target,body_part,origin[3],aim_origin[3],Float:time;
	new spirit_cost = 0;
	
	get_user_aiming(id,target,body_part,2500);
	get_user_origin(id,origin);
	get_user_origin(id,aim_origin,3);
	time=get_gametime();
	
	if(equal(cmd,"+bm_spirit"))
	{
		if(skill_active_check(id,1,BLEACH_SKILL_NOVICE_COST,CLASS_NONE))
		{
			skill_spirit_release_start(id);
		}
	}
	else if(equal(cmd,"-bm_spirit"))
	{
		skill_spirit_release_reset(id);
	}
	else if(equal(cmd,"bm_hbullet"))
	{
		if(!skill_active_check(id,g_skill[id][P_SKILL_2],BLEACH_SKILL_NOVICE_COST,CLASS_HOLLOW)) return PLUGIN_HANDLED;
		if(get_cooldown(id,BLEACH_SKILL_NOVICE_CD,g_player_last_event[id][0],true)) return PLUGIN_HANDLED;
		if(check_target(id,target)) return PLUGIN_HANDLED;
			
		g_player_last_event[id][0]=time;
		spirit_cost = BLEACH_SKILL_NOVICE_COST;
		skill_hollow_bullet(id,target,origin,aim_origin);
	}
	else if(equal(cmd,"bm_wlight"))
	{
		if(!skill_active_check(id,g_skill[id][P_SKILL_1],BLEACH_SKILL_NORMAL_COST,CLASS_DEATHGOD)) return PLUGIN_HANDLED;
		if(get_cooldown(id,BLEACH_SKILL_NORMAL_CD,g_player_last_event[id][1],true)) return PLUGIN_HANDLED;
		if(check_target(id,target)) return PLUGIN_HANDLED;
			
		spirit_cost = BLEACH_SKILL_NORMAL_COST;
		g_player_last_event[id][1]=time;
		skill_white_lightning(id,target,body_part,aim_origin);
	}
	else if(equal(cmd,"+bm_cero"))
	{	
		if(!skill_active_check(id,g_skill[id][P_SKILL_4],BLEACH_SKILL_MASTER_COST,CLASS_HOLLOW)) return PLUGIN_HANDLED;
		if(get_cooldown(id,BLEACH_SKILL_MASTER_CD,g_player_last_event[id][2],true)) return PLUGIN_HANDLED;
			
		skill_cero(id);
	}
	else if(equal(cmd,"-bm_cero"))
	{
		skill_cero_activate(id);
	}
	else if(equal(cmd,"bm_icering"))
	{
		if(!skill_active_check(id,g_skill[id][P_SKILL_3],BLEACH_SKILL_GREATER_COST,CLASS_DEATHGOD)) return PLUGIN_HANDLED;
		if(get_cooldown(id,BLEACH_SKILL_GREATER_CD,g_player_last_event[id][3],true)) return PLUGIN_HANDLED;
		
		skill_ice_ring(id);
		g_player_last_event[id][3]=time;
		spirit_cost = BLEACH_SKILL_GREATER_COST;
	}
	else if(equal(cmd,"bm_cherry"))
	{
		if(!skill_active_check(id,g_skill[id][P_SKILL_5],BLEACH_SKILL_MASTER_COST,CLASS_DEATHGOD)) return PLUGIN_HANDLED;
		if(get_cooldown(id,BLEACH_SKILL_MASTER_CD,g_player_last_event[id][0],true)) return PLUGIN_HANDLED;
		
		skill_cherry_blossoms(id);
	}
	else if(equal(cmd,"bm_flame"))
	{
		if(!skill_active_check(id,g_skill[id][P_SKILL_6],BLEACH_SKILL_GREATER_COST,CLASS_HOLLOW)) return PLUGIN_HANDLED;
		
		if(g_player_volcanic_flame[id] >= BLEACH_SKILL_GREATER_COST*3)
		{
			if(get_cooldown(id,BLEACH_SKILL_MASTER_CD,g_player_last_event[id][5],true)) return PLUGIN_HANDLED;
			
			g_player_last_event[id][5]=time;
			g_player_volcanic_flame[id]=0;
		}
		
		skill_volcanic_flame(id);
		spirit_cost = BLEACH_SKILL_GREATER_COST;
		g_player_volcanic_flame[id]+=BLEACH_SKILL_GREATER_COST;
	}
	
	if(spirit_cost > 0)
	{
		spirit_set(id,g_player_spirit[id]-spirit_cost);
	}
	
	return PLUGIN_HANDLED;
}
