#include <amxmodx>
#include <kz>

/*
 * This plugin does not block people from entering the rooms by using no clip.
 * This plugin remove options to allow people from entering pornographic rooms
 * by removing teleports, buttons, triggers, etc.
 *
 * Maps that are supported by this plugins are ... (Put the map list here)
 */


#if defined DEBUG
new maxplayers;
#endif

new kz_enabled;

public plugin_init()
{
	register_plugin("Kz 18 and Under Safe", KZ_VERSION, "teame06");

	#if defined DEBUG
	register_clcmd("show_brush", "cmdBrush", ADMIN_BAN);
	maxplayers = get_maxplayers();
	#endif

	kz_enabled = get_cvar_pointer("kz_enabled");
}

public kz_Init(_state)
{
	if(!_state)
	{
		pause("a");
		return;
	}

	if(!get_pcvar_num(kz_enabled))
		return;

	new mapname[32];
	get_mapname(mapname, 31);

	new class[32] = "classname";

	if(equali(mapname, "kz_man_lost_island"))
	{
		find_buttons("func_button", class, "porte");
	}
	else if(equali(mapname, "kz_wsp_marioland"))
	{
		find_buttons("trigger_changetarget", class, "room2_button");
	}
	else if(equali(mapname, "kz_man_dragon"))
	{
		find_buttons("func_rot_button", class, "lockbouton");
	}
}

find_buttons(classname[], type[], _target[])
{
	new ent = engfunc(EngFunc_FindEntityByString, -1, type, classname);

	while(ent > 0)
	{
		new target[32];
		pev(ent, pev_target, target, 31);
		if(containi(target, _target) != -1)
		{
			engfunc(EngFunc_RemoveEntity, ent);
		}
		ent = engfunc(EngFunc_FindEntityByString, ent, type, classname);
	}
}

#if defined DEBUG
public cmdBrush(id)
{
	new index, body;
	get_user_aiming(id, index, body);
	if(index > maxplayers && pev_valid(index))
	{
		new model[32];
		new classname[32];
		new targetname[32]
		new target[32];
		new globalname[32];
		new netname[32];
		new message[32];

		pev(index, pev_classname, classname, 31);
		pev(index, pev_globalname, globalname, 31);
		pev(index, pev_model, model, 31);
		pev(index, pev_target, target , 31);
		pev(index, pev_targetname, targetname, 31);
		pev(index, pev_netname, netname, 31);
		pev(index, pev_message, message, 31);

		client_print(id, print_chat, "classname: %s globalname: %s model: %s target: %s targetname: %s netname: %s message %s",
			classname, globalname, model, target, targetname, netname, message);

		log_amx("classname: %s globalname: %s model: %s target: %s targetname: %s netname: %s message %s",
			classname, globalname, model, target, targetname, netname, message);
	}
	return PLUGIN_HANDLED;
}
#endif