/* by BAILOPAN, Contributors: Asskicr, FreeCode, Ideas: isbunk
 *
 * csdm_mod.sma
 * Allows for Counter-Strike to be played as DeathMatch.

 * (C)2004 The TCW Organization and David "BAILOPAN" Anderson
 * Creation: 01-02-2004 Last Edit: 02-25-2004
 * Update for AMX Mod X 1.00 - 11-11-2004
 *
 * http://www.tcwonline.org/ - BAILOPAN
 *
 *  Give credit where due.
 *  Share the source - it sets you free
 *  http://www.opensource.org/
 *  http://www.gnu.org/
 */
 
//Tampering with the author and name lines will violate copyrights
new PLUGINNAME[] = "CSDM Mod"
new VERSION[] = "1.70"
new BUILD_VERSION[] = "302a"
new AUTHORS[] = "BAILOPAN"

//KWo - re-wrote a bit for CS1.5
//TROGDOR the MEMORY LEAKER!
#pragma dynamic 131072  // 131072

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fun>

#define MAX_SPAWNS 41
#define MAX_ENTITIES 1200
#define MAX_ENTS 250
#define S_ENTS 13  // originally BAILOPAN had 9
#define MAX_OBJ 100  // KWo

#define MAX_DROP 200
#define MAX_TASKS 500
#define MAXMENUPOS 34
#define MAX_RESTRICTS 30
#define MAX_HOSTAGES 30

#define PISTOL_AMMO 1
#define SHOTGUN_AMMO 2
#define SMG_AMMO 3
#define RIFLE_AMMO 4 
#define AWP_AMMO 5
#define PARA_AMMO 6 

//These variables are for spawn points.
new SPAWN[MAX_SPAWNS+1][3]		//For spawn points
new Float:SpnVec[MAX_SPAWNS+1][3]	//
new Float:SpnAng[MAX_SPAWNS+1][3]	//
new SpnTeam[MAX_SPAWNS+1]			//
new SPAWNS_ENABLED				//
new SPAWNS						//
//For the old spawn points...
new Float:OldSpawns[MAX_SPAWNS+1][3]
new OldSpawnIDs[MAX_SPAWNS+1]
new Float:OldSpawnVecs[MAX_SPAWNS+1][3]
new Float:OldSpawnAngs[MAX_SPAWNS+1][3]
new OLD_SPAWNS
//These variables _PROBABLY_ hold data!
new mapFile[128]					//
new EntList[MAX_ENTS][24]		//For entities
new EntVecs[MAX_ENTS][3]		//
new EntId[MAX_ENTS]				//
new EntCount					//
new EntFile[60]					//
new Origins[33][3]				//Track origins
new bool:Swep[33] = false		//Menus
new g_MenuPos[33] 				//
new g_LastWep[33][2]			//

new g_MenuPage[33] 						// 					KWo
new g_csdm_entlook						// 					KWo
new g_csdm_spawnlook					// 					KWo
new bool:g_showing_spawns			// 					KWo
new bool:g_host_removed				// 					KWo
new bool:g_obj_removed				// 					KWo
new bool:g_just_inited				// 					KWo
new bool:g_csdm_started				//					KWo
new bool:g_old_spawns_stored	// 					KWo

new StripEnts[S_ENTS][] = {"info_hostage_rescue", "info_bomb_target", "func_bomb_target", "func_hostage_rescue",
														"info_vip_start", "func_vip_safetyzone", "func_buyzone","player_weaponstrip", "item_longjump",
													  "item_healthkit", "item_battery", "armoury_entity", "game_player_equip"}
														
new bool:g_getArmor[33]			//
new bool:g_getGrens[33]			//
new bool:ShowMenu[33] = true	//
new bool:isSpawning[33]			//Spawning
new bool:isRespawn[33]			//
new bool:g_CSDM_ACTIVE			// KWo
new bool:g_CSDM_ADD_ITEMS		// KWo
new bool:g_CSDM_DROP_PACKS	// KWo
new bool:g_Kill_All					// KWo
new Float:g_ItemTime				// KWo

new DropId[MAX_DROP]			//Track dropped weapons
new DropTask[MAX_DROP]			//Track dropped weapon remove tasks
new Tasks[MAX_TASKS]			//Track tasks
new PackId[MAX_DROP]			//drop_pack tempents
new PackAmmo[MAX_DROP][6]		//0=pistol, 1=shotgun, 2=smg, 3=rifle, 4=awp, 5=para
new PackGren[MAX_DROP][3]		//0=fb, 1=sg, 2=he
new PackTask[MAX_DROP]			//pack tfasks
new EdictSlot[MAX_ENTITIES]		//Entities
new BlockedWps[MAX_RESTRICTS]
new RestrictWps[MAX_RESTRICTS]	//
new Float:HostageVecs[MAX_HOSTAGES][3]
new HostageEnts[MAX_HOSTAGES]
new hostages

new Float:ObjVecs[MAX_OBJ][3]		// KWo
new ObjEntsClass[MAX_OBJ][24]		// KWo
new	ObjEntsId[MAX_OBJ]	// KWo
new objectives		// KWo

new Blocks
new bool:PackJump[MAX_DROP]		//pack longjumps
new Entities					//entities
new bool:HasLongJump[33] = false
new g_Aliases[MAXMENUPOS][] = {"usp","glock","deagle","p228","elites","fn57","m3","xm1014","mp5","tmp","p90","mac10","ump45","ak47","galil","famas","sg552","m4a1","aug","scout","awp","g3sg1","sg550","m249","vest","vesthelm","flash","hegren","sgren","defuser","nvgs","shield","primammo","secammo"} 
new g_Aliases2[MAXMENUPOS][] = {"km45","9x19mm","nighthawk","228compact","elites","fiveseven","12gauge","autoshotgun","smg","mp","c90","mac10","ump45","cv47","defender","clarion","krieg552","m4a1","bullpup","scout","magnum","d3au1","krieg550","m249","vest","vesthelm","flash","hegren","sgren","defuser","nvgs","shield","primammo","secammo"}
new CurMaxEnt
new bool:Voting
new bool:CancelVote
new Votes
new Float:lastVote
//1=enable/disable 3=norm/freeforall 2=items/!items
new VoteFor

new menuid_1, menuid_2, menuid_3, menuid_4, menuid_5, menuid_6, menuid_7	//KWo & KRoT@L
new bool:csdm_active_memo  // KWo
new csdm_randspawns_memo  // KWo
new csdm_str_rem_memo	// KWo
new csdm_allowradio_memo // KWo
new bool:csdm_killall_memo	// KWo

public plugin_init()
{
	register_plugin(PLUGINNAME, VERSION, AUTHORS)

	register_cvar("csdm_active", "0")			//Enable CSDM?
	register_cvar("csdm_freeze_time", "4")		//Spawn protection time
	register_cvar("csdm_add_items", "0")		//0=Players choose weapons, 1=Players find weapons
	register_cvar("csdm_item_time", "20.0")		//Time until items respawn
	register_cvar("csdm_random_spawns", "1")	//Use random spawns or regular spawns?
	register_cvar("csdm_kill_all", "0")			//0=Use normal teams 1=Free for all
	register_cvar("csdm_drop_packs", "0")		//0=Drop packs on death 1=Drop weapons on death
	register_cvar("csdm_allow_clguns", "0")		//Allows players to choose gun setups with "guns" command
	register_cvar("csdm_drop_weapons", "1")		//allow players to drop weapons?
	register_cvar("csdm_hold_many", "0")		//Allows players to hold more than one of each type.
	register_cvar("csdm_delete_time", "20")		//
	register_cvar("csdm_auto_equip", "0")		//Automatically equip players with armor
	register_cvar("csdm_auto_gren", "0")		//Automatically equip players with grenades
	register_cvar("csdm_spawn_spam", "0")		//gives respawning users a message
	register_cvar("csdm_enable_amenu", "1")		//Enables armor menu
	register_cvar("csdm_enable_gmenu", "1")		//Enables grenade menu
	register_cvar("csdm_spawn_protect", "1")	//Sets CSDM spawn mode
												//0=none
												//1=normal, stops when you move
												//2=high, stops after csdm_freeze_time
	register_cvar("csdm_battery", "15")			//Battery health
	register_cvar("csdm_medkit", "15")			//Medkit health
	register_cvar("csdm_explain", "1")			//Explain some usage, like longjump
	register_cvar("csdm_auto_drop", "1")		//Auto-drop guns
	register_cvar("csdm_pack_jumps", "1")		//Sets whether to pack jumps into drop packs.
	register_cvar("csdm_asskicr", "0")			//Use asskicr's changes:
													//AWP has separate ammo
													//Para has separate ammo
													//New ammo box type
	register_cvar("csdm_allow_radio", "1")		//radio?
	register_cvar("csdm_voting", "2")			//1=public 2=admin_level_a 0=disabled
	register_cvar("csdm_voteflags", "abc")		//a=csdm mod on/off c=norm/freeforall b=items or not
	register_cvar("csdm_ratio", "0.6")			//vote ratio
	register_cvar("csdm_votetime", "45")		//vote length
	register_cvar("csdm_nextvote", "180")		//vote wait time

	register_cvar("csdm_steam", "1")			//Sets for steam or not.	
	register_cvar("csdm_sounds", "1")			//Use sounds?

	register_cvar("csdm_stripper", "abcd")		//flags: "abcd"			// KRoT@L
										//a: removes objectives of the map
										//b: removes buyzone
										//c: removes weapons on floor (like in fy_iceworld, ...)
										//d: removes starting weapon (like in cs_deagle5, ...)
	register_cvar("csdm_stripper_remove", "0")		// KWo  - 0 - hide all objectives/buyzones etc, 1 - remove them

	register_cvar("csdm_enable_file", "") //File to execute when csdm is enabled // KRoT@L
//example: "addons/amxmodx/csdm/csdm_on.cfg"
	register_cvar("csdm_disable_file", "") //File to execute when csdm is disabled // KRoT@L
//example: "addons/amxmodx/csdm/csdm_off.cfg"
	register_cvar("csdm_maxdelmenu_time", "20")			// max waiting time for disappearing any menu to display gun menu - KWo
	register_cvar("csdm_spawn_wave","0")        //play spawn in sound? 0=off/1=on - Riddick51

// KWo
	menuid_1 = register_menuid("CSDM: Equip")
	menuid_2 = register_menuid("CSDM: Primary Weapon")
	menuid_3 = register_menuid("CSDM: Secondary Weapon")
	menuid_4 = register_menuid("CSDM: Armor")
	menuid_5 = register_menuid("CSDM: Grenades")
	register_menucmd(menuid_1,1023,"EquipChoice")
	register_menucmd(menuid_2,1023,"PrimaryWeapon")
	register_menucmd(menuid_3,1023,"SecondWeapon")
	register_menucmd(menuid_4,1023,"ArmorChoice")
	register_menucmd(menuid_5,1023,"GrenChoice")

	register_menucmd(register_menuid("CSDM: Equip"),1023,"EquipChoice")
	register_menucmd(register_menuid("CSDM: Primary Weapon"),1023,"PrimaryWeapon")
	register_menucmd(register_menuid("CSDM: Secondary Weapon"),1023,"SecondWeapon")
	register_menucmd(register_menuid("CSDM: Armor"),1023,"ArmorChoice")
	register_menucmd(register_menuid("CSDM: Grenades"),1023,"GrenChoice")
	
	register_menucmd(register_menuid("CSDM Enable "), (1<<0)|(1<<1), "vote_count")
	register_menucmd(register_menuid("CSDM Which "), (1<<0)|(1<<1), "vote_count")
	register_menucmd(register_menuid("CSDM Free "), (1<<0)|(1<<1), "vote_count")

// KWo
	register_menucmd(register_menuid("CSDM MOD Menu"),1023,"action_csdm_menu")
	register_menucmd(register_menuid("CSDM Settings Menu"),1023,"action_csdm_set_menu")
	register_menucmd(register_menuid("CSDM Cvars Menu"),1023,"action_csdm_cvars_menu")
	register_menucmd(register_menuid("CSDM Voting Menu"),1023,"action_csdm_voting_menu")
	menuid_6 = register_menuid("CSDM Entities Menu")
	register_menucmd(menuid_6,1023,"action_csdm_ent_menu")	
	menuid_7 = register_menuid("CSDM Add Entities Menu")
	register_menucmd(menuid_7,1023,"act_csdm_addent_menu")
	register_menucmd(register_menuid("CSDM Spawn Points Menu"),1023,"action_csdm_spawn_menu")
	register_menucmd(register_menuid("CSDM Add Spawns Menu"),1023,"act_csdm_addsp_menu")

	register_concmd("csdm_enable", "csdm_onoff", ADMIN_LEVEL_C, "Turn CSDM on or off.")
	register_concmd("csdm_items", "csdm_items", ADMIN_LEVEL_C, "Use items or not.")
	register_concmd("csdm_version", "csdm_version", 0, "Show CSDM Version.")
	register_concmd("csdm_setspawn", "csdm_setspawn", ADMIN_LEVEL_D, "Create a CSDM spawn point.")
	register_concmd("csdm_setspawnv", "csdm_setspawnv", ADMIN_LEVEL_D, "Create a CSDM spawn point with angle.")
	register_concmd("csdm_delspawn", "csdm_delspawn", ADMIN_LEVEL_D, "Delete a CSDM spawn point.")
	register_concmd("csdm_setent", "csdm_setent", ADMIN_LEVEL_D, "Add a CSDM entity.")
	register_concmd("csdm_delent", "csdm_delent", ADMIN_LEVEL_D, "Delete a CSDM entity.")
	register_concmd("csdm_ent", "csdm_ent", ADMIN_LEVEL_D, "Find the nearest entity.")
	register_concmd("csdm_spawncount", "csdm_spawncount", ADMIN_LEVEL_D, "See how many spawns there are.")
	register_concmd("csdm_viewspawns", "csdm_viewspawns", ADMIN_LEVEL_D, "View all spawns.")
	register_concmd("csdm_hidespawns", "csdm_hidespawns", ADMIN_LEVEL_D, "Hide all spawns.")
	register_concmd("csdm_rement", "csdm_rement", ADMIN_LEVEL_D, "Delete an entity.")
	register_concmd("csdm_origin", "csdm_origin", 0, "Find your origin for debugging bad spawns.")
	register_concmd("csdm_near", "csdm_near", ADMIN_LEVEL_D, "Shows you the number of the nearest spawn point.")
	register_concmd("csdm_set_amenu", "csdm_set_amenu", ADMIN_LEVEL_B, "Turns armor menus off/on.")
	register_concmd("csdm_set_gmenu", "csdm_set_gmenu", ADMIN_LEVEL_B, "Turns grenade menus off/on.")
	register_concmd("csdm_killall", "csdm_killall", ADMIN_LEVEL_B, "Turns kill everyone mode off/on.")
	register_concmd("csdm_look", "csdm_look", ADMIN_LEVEL_D, "Returns the entity id you are looking at.")
	register_concmd("csdm_spawninfo", "csdm_spawninfo", ADMIN_LEVEL_A, "Returns the classname of an entity id.")
	register_concmd("csdm_entinfo", "csdm_entinfo", ADMIN_LEVEL_A, "Returns the classname of an entity id.")
	register_concmd("csdm_cancelvote", "cancel_vote", ADMIN_LEVEL_A, "Cancels a CSDM vote in session.")
	register_concmd("csdm_vote", "csdm_vote", 0, "Vote for CSDM.")
	register_concmd("vote_csdm", "csdm_vote", 0, "Vote for CSDM.")
	register_concmd("vote_mode", "vote_mode", 0, "Vote for CSDM Mode.")
	register_concmd("vote_freeforall", "vote_freeforall", 0, "Vote for Free-For-All mode.")
	register_concmd("csdm_entdump", "csdm_entdump", ADMIN_LEVEL_D, "Dumps a text file with entity information.")
	register_concmd("csdm_entcount", "csdm_entcount", ADMIN_LEVEL_D, "Returns the number of entities in the map.")

	register_concmd("csdm_view_csdm_sp","csdm_view_csdm_sp", ADMIN_LEVEL_D, "View all CSDM spawns.")  // KWo
	register_clcmd("csdm_menu", "csdm_disp_menu", ADMIN_LEVEL_C,"- displays menus")		// KWo	

	register_clcmd("drop", "hook_drop")
	register_clcmd("respawn", "hook_respawn")
	register_clcmd("guns", "hook_guns")
	register_clcmd("give", "hook_give")
	register_clcmd("enable_menu", "hook_menu")
	register_clcmd("say guns", "hook_guns")
	register_clcmd("say respawn", "hook_respawn")
	register_clcmd("say menu", "hook_menu")
	register_clcmd("say enablemenu", "hook_menu")
	register_clcmd("say enable_menu", "hook_menu")

	// from AssKicr
	register_clcmd("buy", "hook_block")
	register_clcmd("buyammo1", "hook_block")
	register_clcmd("buyammo2", "hook_block")
	register_clcmd("buyequip", "hook_block")
	register_clcmd("radio1", "hook_block_radio")
	register_clcmd("radio2", "hook_block_radio")
	register_clcmd("radio3", "hook_block_radio")	
	register_clcmd("nightvision", "hook_block")
	register_clcmd("cl_setautobuy","hook_block") 
	register_clcmd("cl_autobuy","hook_block") 
	register_clcmd("cl_setrebuy","hook_block") 
	register_clcmd("cl_rebuy","hook_block")
	register_clcmd("say csdm_vote", "csdm_votesay")
	register_clcmd("say vote_csdm", "csdm_votesay")
	register_clcmd("say vote_mode", "vote_modesay")
	register_clcmd("say vote mode", "vote_modesay")
	register_clcmd("say vote_freeforall", "vote_freeforallsay")
	register_clcmd("say vote freeforall", "vote_freeforallsay")
	//
	register_event("ResetHUD","hook_hud","be")
	register_event("DeathMsg", "hook_death", "a")
   	//from dm autopilot, which took from jailbreak
	register_menucmd(register_menuid("Terrorist_Select"), 1023, "hook_skin")
	register_menucmd(register_menuid("CT_Select"), 1023, "hook_skin")
	register_menucmd(-26,1023, "hook_skin")      // VGUI
	register_menucmd(-27,1023, "hook_skin")      // VGUI
	register_event("ShowMenu", "hook_team", "b", "4&Team_Select")
	register_event("VGUIMenu", "hook_team", "b", "1=2")
	register_event("CurWeapon","hook_changeweapon","be","1=1","2=6")
	register_event("Damage", "event_damage", "b", "2!0")  // KRoT@L

	register_event("StatusIcon", "hook_gotbomb", "be", "1=1", "1=2", "2=c4")				// KWo
	register_event("StatusIcon", "hook_buyzone", "be", "1=1", "1=2", "2=buyzone")		// KWo
	
	set_task(0.5, "start_map")
	set_task(10.0, "check_players", 652, "", 0, "b")	// KWo - new task number
	
	//oink.
	register_logevent("hook_roundstart", 2, "0=World triggered", "1=Round_Start")

	g_just_inited=true		// KWo

	return PLUGIN_CONTINUE
}

public plugin_precache()
{
	precache_model("models/w_medkit.mdl")
	precache_model("models/w_battery.mdl")
	precache_model("models/w_357ammobox.mdl")	//Pistol Ammo
	precache_model("models/w_shotbox.mdl")		//Shotgun Ammo
	precache_model("models/w_9mmclip.mdl")		//SMG Ammo
	precache_model("models/w_9mmarclip.mdl")	//Rifle Ammo
	precache_model("models/w_crossbow_clip.mdl")//Awp Ammo
	precache_model("models/w_isotopebox.mdl")	//Full ammo
	precache_model("models/w_isotopeboxt.mdl")	//Full ammo
	precache_model("models/w_chainammo.mdl")	//Full ammo
	precache_model("models/w_suit.mdl")			//Suit
	precache_model("models/w_suitt.mdl")		//
	precache_model("models/player/terror/terror.mdl")	// KWo
	precache_model("models/player/urban/urban.mdl")		// KWo
	precache_model("models/player/arctic/arctic.mdl")	// KWo
	precache_model("models/player/sas/sas.mdl")				// KWo
	precache_model("models/w_weaponbox.mdl")	//Drop pack
	precache_model("models/w_assault.mdl")		//assaultsuit
	precache_model("models/w_longjump.mdl")		//longjump - thanks asskicr
	precache_model("models/w_longjumpt.mdl")	//"
	precache_model("models/gman.mdl")
	precache_model("models/gmant.mdl")
	precache_sound("items/smallmedkit1.wav")
	precache_sound("items/gunpickup2.wav")
	precache_sound("items/suitchargeok1.wav")
	precache_sound("items/ammopickup2.wav")
	precache_sound("items/clipinsert1.wav")
	precache_sound("debris/metal3.wav")
	precache_sound("radio/letsgo.wav")	// Riddick51
	precache_sound("radio/locknload.wav") 	// Riddick51
	
	return PLUGIN_CONTINUE
}

bool:isValidSubOwner(oid)
{
	if (oid > 32 && oid) {
		return true
	}
	
	return false
}

bool:checkMod()
{
	new mod[16]
	
	get_modname(mod, 16)
	
	if (!equali(mod, "cstrike") && !equali(mod, "czero")) {
		log_message("[CSDM] Not running on cstrike/czero, plugin disabled.")
		set_cvar_string("csdm_active", "0")
		
		return false
	} else {
		if (get_cvar_num("csdm_active")==1) {
			set_cvar_num("mp_freezetime", 0)
			if (get_cvar_num("csdm_kill_all")) {
				if (get_cvar_num("mp_tkpunish")>0) {
					set_cvar_num("mp_tkpunish", 0)
				}
				if (get_cvar_num("mp_autokick")>0) {
					set_cvar_num("mp_autokick", 0)
				}
				if (get_cvar_num("mp_autoteambalance")>0) {
					set_cvar_num("mp_autoteambalance",0)
				}
				if (get_cvar_num("mp_friendlyfire")!=1) {
					set_cvar_num("mp_friendlyfire", 1)
				}
				set_msg_block(112, BLOCK_SET)
				client_cmd(0, "hideradar")
			}			// KWo	(removed blocking radio commands and radio text messages and moved the blocking/unblocking to check-active)
		}
	}

	return true
}

bool:destroyPack(pid)
{
	//This function will remove a pack by ENTID and clear index space for it
	if (!pid) {
		return false
	}
	
	new entid = PackId[pid]
	
	destroyTask(PackTask[pid])
	
	PackId[pid] = 0
	PackTask[pid] = 0
	PackAmmo[pid][0] = 0
	PackAmmo[pid][1] = 0
	PackAmmo[pid][2] = 0
	PackAmmo[pid][3] = 0
	PackAmmo[pid][4] = 0
	PackAmmo[pid][5] = 0
	PackGren[pid][0] = 0
	PackGren[pid][1] = 0
	PackGren[pid][2] = 0
	PackJump[pid] = false
	
	safe_rm_ent(entid)
	
	return true
}

bool:isWpBlocked(wp)
{
//	new wpn[24]
	new i
//	get_wpname(wp, wpn, 24)
	for (i=1; i<=Blocks; i++) {
		if (BlockedWps[i] == wp) {
			return true
		}
	}	
	return false
}

bool:canGetAmmo(id, ammo)
{
	new c, a
	switch (ammo) {
		case PISTOL_AMMO:
		{
			get_user_ammo(id, CSW_DEAGLE, c, a)
			if (a<getMaxAmmo(CSW_DEAGLE)) {
				return true
			}
			get_user_ammo(id, CSW_P228, c, a)
			if (a<getMaxAmmo(CSW_P228)) {
				return true
			}
			get_user_ammo(id, CSW_USP, c, a)
			if (a<getMaxAmmo(CSW_USP)) {
				return true
			}
			get_user_ammo(id, CSW_GLOCK18, c, a)
			if (a<getMaxAmmo(CSW_GLOCK18)) {
				return true
			}
			get_user_ammo(id, CSW_FIVESEVEN, c, a)
			if (a<getMaxAmmo(CSW_FIVESEVEN)) {
				return true
			}
		}
		
		case SHOTGUN_AMMO:
		{
			get_user_ammo(id, CSW_XM1014, c, a)
			if (a<getMaxAmmo(CSW_XM1014)) {
				return true
			}
		}
		
		case SMG_AMMO:
		{
			get_user_ammo(id, CSW_P90, c, a)
			if (a<getMaxAmmo(CSW_P90)) {
				return true
			}
			get_user_ammo(id, CSW_MP5NAVY, c, a)
			if (a<getMaxAmmo(CSW_MP5NAVY)) {
				return true
			}
			get_user_ammo(id, CSW_MAC10, c, a)
			if (a<getMaxAmmo(CSW_MAC10)) {
				return true
			}
		}
		
		case RIFLE_AMMO:
		{
			get_user_ammo(id, CSW_M4A1, c, a)
			if (a<getMaxAmmo(CSW_M4A1)) {
				return true
			}
			get_user_ammo(id, CSW_AK47, c, a)
			if (a<getMaxAmmo(CSW_AK47)) {
				return true
			}
			if (!get_cvar_num("csdm_asskicr")) {
				get_user_ammo(id, CSW_AWP, c, a)
				if (a<getMaxAmmo(CSW_AWP)) {
					return true
				}
				get_user_ammo(id, CSW_M249, c, a)
				if (a<getMaxAmmo(CSW_M249)) {
					return true
				}
			}
		}
		
		case AWP_AMMO:
		{
			if (get_cvar_num("csdm_asskicr")) {
				get_user_ammo(id, CSW_AWP, c, a)
				if (a<getMaxAmmo(CSW_AWP)) {
					return true
				}
			}
		}
		case PARA_AMMO:
		{
			if (get_cvar_num("csdm_asskicr")) {
				get_user_ammo(id, CSW_M249, c, a)
				if (a<getMaxAmmo(CSW_M249)) {
					return true
				}
			}
		}
	}
	
	return false
}

bool:isWpOverload(id, g_wp)
{
	new players[32], mPlayers
	new wps[32], wpc
	new pv, i, j, x=0
	new g_max = wp_max(g_wp)
	
	if (g_max < 1) {
		return false
	}
	if (g_CSDM_ADD_ITEMS) {
		get_players(players, mPlayers)
		for (i=0; i<mPlayers; i++) {
			pv = players[i]
			if (pv != id) {
				wpc = 0
				get_user_weapons(pv, wps, wpc)
				for (j=0; j<wpc; i++) {
					if (wps[j] == g_wp) {
						x++
						if (x == g_max) {
							return true
						}
					}
				}
			}
		}
	} else {
		get_players(players, mPlayers)
		for (i=0; i<mPlayers; i++) {
			pv = players[i]
			if (pv != id) {
				if (g_LastWep[pv][1] == g_wp) {
					x++
					if (x == g_max) {
						return true
					}
				}
			}
		}
	}
			
	return false
}

wp_max(g_wp)
{
	new i
	for (i=1; i<=Blocks; i++) {
		if (BlockedWps[i] == g_wp) {
			return RestrictWps[i]
		}
	}
	
	return 0
}

bool:canGetGun(id, g_wp)
{
	new g_slot = getWepSlot(g_wp)
	new wps[32], num, ammo, u_slot, u_max
	new clip
	new bool:has = false		//have this weapon?
	new bool:hold = true		//can hold more in slot?
	new i
	
	if (!g_wp || !id) {
		return false
	}
	
	if (isWpBlocked(g_wp) || isWpOverload(id, g_wp)) {
		return false
	}
	num = 0
	get_user_weapons(id, wps, num)
	
	for (i=0; i<num; i++) {		//does the user have this weapon?
		get_user_ammo(id, wps[i], ammo, clip)
		u_slot = getWepSlot(wps[i])
		if ((u_slot == g_slot) && (g_slot != 4)) {
			if (get_cvar_num("csdm_hold_many")!=1) {
				hold = false
			}
		}
		
		if (wps[i] == g_wp) {		//make sure user has this weapon
			u_max = getMaxAmmo(wps[i])
			if (clip < u_max) {
				return true
			}
			has = true
		}
	}
	
	if (!has) {	//Make sure this user does not have this weapon and has slot room
		if (hold) {
			return true
		} else {
			if (get_cvar_num("csdm_hold_many")) {
				return true
			}
			return false
		}
	} else {
		return false
	}
	
	return false
}

bool:isValidDrop(wp)
{
	switch (wp)
	{
		case CSW_P228:
			return true
		case CSW_SCOUT:
			return true
		case CSW_HEGRENADE:
			return false
		case CSW_XM1014:
			return true
		case CSW_C4:
			return true
		case CSW_MAC10:
			return true
		case CSW_AUG:
			return true
		case CSW_SMOKEGRENADE:
			return false
		case CSW_ELITE:
			return true
		case CSW_FIVESEVEN:
			return true
		case CSW_UMP45:
			return true
		case CSW_SG550:
			return true
		case CSW_GALIL:
			return true
		case CSW_FAMAS:
			return true
		case CSW_USP:
			return true
		case CSW_GLOCK18:
			return true
		case CSW_AWP:
			return true
		case CSW_MP5NAVY:
			return true
		case CSW_M249:
			return true
		case CSW_M3:
			return true
		case CSW_M4A1:
			return true
		case CSW_TMP:
			return true
		case CSW_G3SG1:
			return true
		case CSW_FLASHBANG:
			return false
		case CSW_DEAGLE:
			return true
		case CSW_SG552:
			return true
		case CSW_AK47:
			return true
		case CSW_KNIFE:
			return false
		case CSW_P90:
			return true
	}
	
	return false
}

public csdm_near(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		
		return PLUGIN_HANDLED
	}
	
	new marker, dist=200, cur		// KWo changed from 9999 (to be sure deleted one is desired one)
	new PVec[3]
	new i
	
	marker = -1
	get_user_origin(id, PVec)
	for (i=0; i<=SPAWNS; i++) {
		cur = get_distance(PVec, SPAWN[i])
		if (cur < dist) {
			dist = cur
			marker = i
		}
	}
	g_csdm_spawnlook = marker	
	if (marker != -1) {
		client_print(id, print_console, "[CSDM] The nearest spawn to you is number %d", marker)
		client_print(id, print_chat, "[CSDM] The nearest spawn to you is number %d", marker) // KWo		
	} else {
		client_print(id, print_console, "[CSDM] No spawns found.")
		client_print(id, print_chat, "[CSDM] No spawns found.")  // KWo		
	}
	
	return PLUGIN_HANDLED
}

public check_players()
{
	new players[32], mPlayers
	new i
	if (g_CSDM_ACTIVE) {
		get_players(players, mPlayers)
		for (i=0; i<mPlayers; i++) {
			if (!is_user_alive(players[i]) && ((get_user_team(players[i])==1) || (get_user_team(players[i])==2)) ) {
				//oops!
				new Data[2]
				Data[0] = players[i]
				set_task(0.5, "quick_respawn", 750+players[i], Data, 2)		// KWo = new task number
				isRespawn[players[i]] = true
			}
		}
	}
	
	return PLUGIN_CONTINUE
}

public hook_changeweapon(id)
{
	new data[3]
	if (g_CSDM_ACTIVE) {	
		//houston, we have a c4.
		if (is_user_bot(id)) {
			engclient_cmd(id, "drop", "weapon_c4")
		} else {
			client_cmd(id, "drop weapon_c4")
		}
		data[0] = CSW_C4
		data[1] = 0
		data[2] = id
		set_task(0.2, "timed_replace", 0, data, 3)
	}
	return PLUGIN_CONTINUE
}

public hook_buyzone(id)		// KWo
{

	if (!g_CSDM_ACTIVE) return PLUGIN_CONTINUE
	
	new stripflags[10]
	get_cvar_string("csdm_stripper", stripflags, 9)
	if(!stripflags[0]) return PLUGIN_CONTINUE
	new striptype = read_flags(stripflags)
	if (!(striptype & (1<<1)) ) return PLUGIN_CONTINUE
	
	message_begin(MSG_ONE,get_user_msgid("StatusIcon"),{0,0,0},id)
	write_byte(0) // status (0=hide, 1=show, 2=flash)
	write_string("buyzone") // sprite name
	write_byte(0) // red
	write_byte(0) // green
	write_byte(0) // blue
	message_end()		
	return PLUGIN_CONTINUE
}


//KRoT@L
public event_damage(id)
{
	if(g_CSDM_ACTIVE && g_Kill_All)
	{
		if(get_user_health(id) <= 0)
		{
			return PLUGIN_CONTINUE
		}

		new weapon, body, attacker = get_user_attacker(id, weapon, body)
		if(attacker == 0 || attacker == id || is_user_bot(attacker) || get_user_team(attacker) != get_user_team(id))
		{
			return PLUGIN_CONTINUE
		}

		new damage = read_data(2)
		new health = get_user_health(id) - 2 * damage
		if(health < 1)
		{
			new weapon_name[32]
			get_weaponname(weapon, weapon_name, 31)
			replace(weapon_name, 31, "weapon_", "")
			replace(weapon_name, 31, "hegrenade", "grenade")
			message_begin(MSG_ALL, 83, {0,0,0}, 0)
			write_byte(attacker)
			write_byte(id)
			if(body == 1) write_byte(1) 
			else write_byte(0)
			write_string(weapon_name)
			message_end()

			message_begin(MSG_BROADCAST, 85)
			write_byte(attacker)
			write_short(get_user_frags(attacker) + 1)
			write_short(get_user_deaths(attacker))
			write_short(0)
			write_short(get_user_team(attacker))
			message_end()

			set_user_frags(attacker, get_user_frags(attacker) + 1)

			set_msg_block(83, BLOCK_SET)
			user_kill(id, 1)
			set_msg_block(83, BLOCK_NOT)

			if(get_cvar_num("csdm_steam") == 1)
			{
				if(body == 1) 
				{
					entity_set_int(id, EV_INT_sequence, 104)
				}
				else 
				{
					new death_seq[8] = {101,102,103,105,106,107,108,109}
					entity_set_int(id, EV_INT_sequence, death_seq[random_num(0,7)])
				}
			}
			else
			{
				if(body == 1) 
				{
					entity_set_int(id, EV_INT_sequence, 88)
				}
				else 
				{
					new death_seq[5] = {89,90,91,92,93}
					entity_set_int(id, EV_INT_sequence, death_seq[random_num(0,4)])
				}
			}
			hook_death2(attacker, id)
		}
		else
		{
			set_user_health(id, health)
		}
	}
	return PLUGIN_CONTINUE
}


//KWo
public hook_gotbomb(id)
{
	new data[3]
	if (g_CSDM_ACTIVE) {	
			//houston, we have a c4.
		if (!is_user_bot(id)) {
			client_cmd(id, "drop weapon_c4")
		} else {
			engclient_cmd(id, "drop", "weapon_c4")
		}
		data[0] = CSW_C4
		data[1] = 0
		data[2] = id
		set_task(0.2, "timed_replace", 0, data, 3)
	}
	return PLUGIN_CONTINUE
}

// KWo
public check_active()
{
	g_CSDM_ACTIVE = (get_cvar_num("csdm_active") > 0)
	g_Kill_All = (get_cvar_num("csdm_kill_all") > 0)
	if ( (g_CSDM_ACTIVE) && (!csdm_active_memo) && (!g_just_inited) && (!g_csdm_started) ) // csdm_active has been changed from 0 to 1
	{
		new data[2]	
		data[0] = 0
		set_task(0.1, "introduce", 0, data, 2)	
		client_print(0, print_chat, "CSDM Mode turned on.")
		log_message("[CSDM] CSDM Mode turned on.")
		console_print(0, "There may be some lag as the map is prepared.")
		if(g_Kill_All)
		{
			set_msg_block(112, BLOCK_SET)
			client_cmd(0, "hideradar")			
		}		
		start_map()
	}

	if ( (!g_CSDM_ACTIVE) && (csdm_active_memo) && g_csdm_started && (!g_just_inited) ) // csdm_active has been changed from 1 to 0		//KWo
	{
		console_print(0, "There may be some lag as the map is prepared.")
		client_print(0, print_chat, "CSDM Mode turned off.")
		log_message("[CSDM] CSDM Mode turned off.")
		destroyAllItems()
		restoreSpawns()
		restoreHostages()
		restoreObjectives()
		set_msg_block(112, BLOCK_NOT)
		client_cmd(0, "drawradar")
	
		new file[64]																						
		get_cvar_string("csdm_disable_file", file, 63)					
		if (file_exists(file)) server_cmd("exec %s", file)			
		server_cmd("sv_restartround 2")
		g_csdm_started=false			
	}

	if ( (get_cvar_num("csdm_random_spawns")==1 ) && (csdm_randspawns_memo == 0) && (!g_just_inited) ) // check rising edge of the change of csdm_random_spawns cvar
	{
		setSpawns()
	}
	if ( (get_cvar_num("csdm_random_spawns")==0 ) && (csdm_randspawns_memo == 1) && (!g_just_inited) ) // check falling edge of the change of csdm_random_spawns cvar
	{
		restoreSpawns()
	}
	if ( (get_cvar_num("csdm_allow_radio")==0) && (g_CSDM_ACTIVE) && ( (csdm_allowradio_memo==1) || (!csdm_active_memo) || g_just_inited)) {
		set_msg_block(get_user_msgid("SendAudio"), BLOCK_SET)	// KWo
		set_msg_block(get_user_msgid("TextMsg"), BLOCK_SET)		// KWo
	}
	if ( ( (get_cvar_num("csdm_allow_radio")==1) && (csdm_allowradio_memo==0) ) || ( (!g_CSDM_ACTIVE) && (csdm_active_memo) ) ) {	
		set_msg_block(get_user_msgid("SendAudio"), BLOCK_NOT)	// KWo
		set_msg_block(get_user_msgid("TextMsg"), BLOCK_NOT)		// KWo
	}
	if ( (g_Kill_All) && (g_CSDM_ACTIVE) && ( (!csdm_killall_memo) || (!csdm_active_memo) ) ) {
		set_cvar_num("mp_autokick", 0)
		set_cvar_num("mp_tkpunish", 0)
		set_cvar_num("mp_autoteambalance", 0)
		set_cvar_num("mp_friendlyfire", 1)
		set_msg_block(112, BLOCK_SET)
		client_cmd(0, "hideradar")		
		client_print(0, print_chat, "[CSDM] Free for all mode is now enabled.")
	}
	if ( ( (!g_Kill_All) && (csdm_killall_memo) ) || ( (!g_CSDM_ACTIVE) && (csdm_active_memo) ) ) {
		client_print(0, print_chat, "[CSDM] Free for all mode is now disabled.")
		set_msg_block(112, BLOCK_NOT)
		client_cmd(0, "drawradar")		
	}

	csdm_active_memo = g_CSDM_ACTIVE
	csdm_randspawns_memo = get_cvar_num("csdm_random_spawns")
	csdm_allowradio_memo = get_cvar_num("csdm_allow_radio")
	csdm_killall_memo = g_Kill_All
	g_just_inited=false		// KWo
	
	g_CSDM_ADD_ITEMS = (get_cvar_num("csdm_add_items")==1)
	g_ItemTime = get_cvar_float("csdm_item_time")

	return PLUGIN_CONTINUE
}

public hook_roundstart()
{
	set_task(1.0, "timed_roundstart")
	if (!task_exists(650)) set_task(1.0, "check_active", 650, "", 0, "b") // KWo	- new atsk number
}

public timed_roundstart(data[])
{
	g_host_removed=false	// KWo
	destroyHostages()
}

destroyHostages()
{	
	//look for hostages - and DESTROY THEM!
	/// HA, HA HA HA HA HA HA HA HA AH!
	if (g_host_removed) return	// KWo
	hostages = 0 															// KWo
	if (get_cvar_num("csdm_active")) {
		new tEnt = find_ent_by_class(-1, "hostage_entity")
		new tfEnt
		while (tEnt > 0) {
			tfEnt = find_ent_by_class(tEnt, "hostage_entity")
			if (hostages == MAX_HOSTAGES - 1) {			// KWo
				hostages = 0
			} else {
				hostages++
			}
			entity_get_vector(tEnt, EV_VEC_origin, HostageVecs[hostages])
			HostageEnts[hostages] = tEnt
			hideEnt(tEnt)	//Make it so Dan can't grope them.
			tEnt = tfEnt
		}
		g_host_removed=true	// KWo
	}	
}

restoreHostages()
{
	new i
	for (i=1; i<=hostages; i++) {
		entity_set_int(HostageEnts[i], EV_INT_rendermode, kRenderNormal)
		entity_set_origin(HostageEnts[i], HostageVecs[i])
	}
	hostages = 0
	g_host_removed=false	// KWo
}

destroyObjectives()			// BAILOPAN org + tweaks KWo and KRoT@L
{
//	 {"info_hostage_rescue", "info_bomb_target", "func_bomb_target", "func_hostage_rescue",
//		"info_vip_start", "func_vip_safetyzone", "func_buyzone", "item_longjump", "item_healthkit",
//		"item_battery", "armoury_entity", "game_player_equip", "player_weaponstrip"}
				
//a: removes objectives of the map
//b: removes buyzone
//c: removes weapons on floor (like in fy_iceworld, ...)
//d: removes starting weapon (like in cs_deagle5, ...)


	if (g_obj_removed) return	// KWo

	objectives = 0
	if (get_cvar_num("csdm_active")) {

		csdm_str_rem_memo = get_cvar_num("csdm_stripper_remove")	// KWo		
		new tEnt, tfEnt
		
		new stripflags[10]
		get_cvar_string("csdm_stripper", stripflags, 9)
		if(!stripflags[0] || !(get_cvar_num("csdm_active")) ) return
		new striptype = read_flags(stripflags)

		for (new i=0; i<S_ENTS; i++) {

			if (!(striptype & (1<<0)) && i<6) continue
			if (!(striptype & (1<<1)) && (i==6)  ) continue
			if (!(striptype & (1<<2)) && ( (i>6) || (i<11) ) ) continue
			if (!(striptype & (1<<2)) &&  (i>10) ) continue
			
			tEnt = find_ent_by_class(-1, StripEnts[i])
			while (tEnt > 0) {
				tfEnt = find_ent_by_class(tEnt, StripEnts[i])								
				if (objectives == MAX_OBJ - 1) {  
					objectives = 0
				} else {
					objectives++
				}					
				if (is_valid_ent(tEnt)) {					
					entity_get_vector(tEnt, EV_VEC_origin, ObjVecs[objectives])
					ObjEntsId[objectives]=tEnt
					ObjEntsClass[objectives]=""		
					copy(ObjEntsClass[objectives], 23, StripEnts[i])
					if (csdm_str_rem_memo) {					// KWo
						remove_entity(tEnt)		// KWo
					} else {									// KWo
						hideEnt(tEnt)					// KWo
					}
				}
				tEnt = tfEnt
			}
		}
		g_obj_removed=true		// KWo
	}
}

restoreObjectives()	// KWo
{
	if (!csdm_str_rem_memo) {		// KWo - they has been hidden only - then restore them	
		new i
		for (i=1; i<=objectives; i++) {
			entity_set_int(ObjEntsId[i], EV_INT_rendermode, kRenderNormal)		
			entity_set_origin(ObjEntsId[i], ObjVecs[i])
		}
	}
	objectives = 0
	g_obj_removed=false	// KWo
}

hideEnt(ent)
{
	new Float:Vec[3] = {10000.0,10000.0,10000.0}
	entity_set_int(ent, EV_INT_rendermode, kRenderTransTexture)
	entity_set_origin(ent, Vec)
}

public client_connect(id)
{
	ShowMenu[id] = true
	isSpawning[id] = true
	g_LastWep[id][0] = 0
	g_LastWep[id][1] = 0
	g_getArmor[id] = false
	g_getGrens[id] = false
	isRespawn[id] = true
	HasLongJump[id] = false
	
	return PLUGIN_CONTINUE
}

public client_putinserver(id)
{
	new data[2]
	
	if (get_cvar_num("csdm_active")) {
		data[0] = id
		set_task(10.0, "introduce", 0, data, 2)
	}
	
	return PLUGIN_CONTINUE
}

public client_command(id){ 	//from AssKicr
	if (g_CSDM_ACTIVE && is_user_alive(id)) {

		new stripflags[10]
		get_cvar_string("csdm_stripper", stripflags, 9)
		if(!stripflags[0]) return PLUGIN_CONTINUE
		new striptype = read_flags(stripflags)
		if (!(striptype & (1<<1)) ) return PLUGIN_CONTINUE

		new arg[13]
		if (read_argv(0, arg, 12) > 11)
			return PLUGIN_CONTINUE 
		new a = 0 
		do {
			if (equal(g_Aliases[a], arg) || equal(g_Aliases2[a], arg)) {
				return PLUGIN_HANDLED 
			}
		} while(++a < MAXMENUPOS)
	}
	
	return PLUGIN_CONTINUE 
} 

public introduce(data[])
{
	new id = data[0]
	
	if (get_cvar_num("csdm_active")) {
	
		client_print(id, print_chat, "[CSDM] Welcome to Counter-Strike Deathmatch by BAILOPAN")	
		client_print(id, print_chat, "[CSDM] Visit www.lambdacore.net for more information.")
		client_print(id, print_chat, "[CSDM] Console commands: ^"respawn^" to manually respawn.")
		if (get_cvar_num("csdm_allow_clguns")) {
			client_print(id, print_chat, "[CSDM] ^"guns^" to see a menu and ^"give <name>^" to get a gun.")
		}
	}

	return PLUGIN_CONTINUE
}

public plugin_end()
{
	destroyAllItems()
	
	return PLUGIN_CONTINUE
}

destroyAllItems()
{	
	new i
	
	//kill all ents
	for (i=1; i<EntCount; i++) {
		if (EntId[i] > 32) {
			if (is_valid_ent(EntId[i])) {
				safe_rm_ent(EntId[i])
			}
			EntId[i] = 0
		}
	}

	for (i=1; i<MAX_DROP; i++) {
		destroyPack(i)
	}
	
	for (i=1; i<MAX_ENTITIES; i++) {
		if (EdictSlot[i] && is_valid_ent(EdictSlot[i])) {
			safe_rm_ent(EdictSlot[i])
		}
	}
}

public start_map()
{
	if (get_cvar_num("csdm_active") && (!g_csdm_started) ) {	// KWo
		checkMod()
		readMapFile()
		readWeaponsFile()
		setSpawns()
		g_showing_spawns=false  // KWo
		readEntsFile()
		setEnts()
		g_csdm_started=true		// KWo
		destroyHostages()
		destroyObjectives()
		
		new file[64]																					// KRoT@L
		get_cvar_string("csdm_enable_file", file, 63)					// KRoT@L
		if (file_exists(file)) server_cmd("exec %s", file) 		// KRoT@L
		server_cmd("sv_restartround 2")
	}
	g_CSDM_ACTIVE = (get_cvar_num("csdm_active") > 0) // KWo
	g_CSDM_ADD_ITEMS = (get_cvar_num("csdm_add_items") > 0) // KWo
	g_CSDM_DROP_PACKS = (get_cvar_num("csdm_drop_packs") > 0) // KWo
	g_ItemTime = get_cvar_float("csdm_item_time") // KWo
	g_Kill_All = (get_cvar_num("csdm_kill_all") > 0) // KWo
}


public csdm_killall(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_B)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		
		return PLUGIN_HANDLED
	}
	
	if (get_cvar_num("csdm_kill_all")) {
//		client_print(id, print_console, "[CSDM] Free for all mode is now disabled.")		// KWo - printed in check_active
		set_cvar_num("csdm_kill_all", 0)
		set_msg_block(112, BLOCK_NOT)
		client_cmd(0, "drawradar")		
		checkMod()
		return PLUGIN_HANDLED
	} else {
//		client_print(id, print_console, "[CSDM] Free for all mode is now enabled.")			// KWo - printed in check_active
		set_cvar_num("csdm_kill_all", 1)
		set_cvar_num("mp_autokick", 0)
		set_cvar_num("mp_tkpunish", 0)
		set_cvar_num("mp_autoteambalance", 0)
		set_cvar_num("mp_friendlyfire", 1)
		set_msg_block(112, BLOCK_SET)
		client_cmd(0, "hideradar")		
		return PLUGIN_HANDLED
	}

	return PLUGIN_HANDLED
}

public csdm_set_amenu(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_B)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		
		return PLUGIN_HANDLED
	}
	
	if (get_cvar_num("csdm_enable_amenu")) {
		client_print(id, print_console, "[CSDM] Armor menu is now disabled.")
		set_cvar_num("csdm_enable_amenu", 0)
		return PLUGIN_HANDLED
	} else {
		client_print(id, print_console, "[CSDM] Armor menu is now enabled.")
		set_cvar_num("csdm_enable_amenu", 1)
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_HANDLED
}

public csdm_set_gmenu(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_B)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		
		return PLUGIN_HANDLED
	}
	
	if (get_cvar_num("csdm_enable_gmenu")) {
		client_print(id, print_console, "[CSDM] Grenade menu is now disabled.")
		set_cvar_num("csdm_enable_gmenu", 0)
		return PLUGIN_HANDLED
	} else {
		client_print(id, print_console, "[CSDM] Grenade menu is now enabled.")
		set_cvar_num("csdm_enable_gmenu", 1)
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_HANDLED
}

public hook_team(id)
{
	if (g_CSDM_ACTIVE) {
		new tID[2]
		tID[0] = id
		set_task(6.0, "quick_respawn", 0, tID, 2)
	}

	return PLUGIN_CONTINUE
}

public hook_skin(id)		//from dm autopilot
{
	if (!g_CSDM_ACTIVE) {
		return PLUGIN_CONTINUE
	}
	
	new parm[2]
	parm[0]=id
	set_task(6.0, "wait_alive", 651, parm, 2)	// KWo - new task number

	return PLUGIN_CONTINUE
}

public wait_alive(parm[])	//from dm autopilot
{	
	new id = parm[0]
	if (!is_user_alive(id) && ((get_user_team(id)==1) || (get_user_team(id)==2))) {
		new svIndex[2]
		svIndex[0] = id
		set_task(0.5, "quick_respawn", 0, svIndex, 2)
	}
	return PLUGIN_CONTINUE
}

public csdm_origin(id)
{
	new Vec[3]
	
	get_user_origin(id, Vec)
	client_print(id, print_console, "[CSDM] Your origin is (%d, %d, %d).", Vec[0], Vec[1], Vec[2])
	client_print(id, print_chat, "[CSDM] Your origin is (%d, %d, %d).", Vec[0], Vec[1], Vec[2])		// KWo
	
	return PLUGIN_HANDLED
}

public hook_block_radio(id)
{
	if (g_CSDM_ACTIVE && !get_cvar_num("csdm_allow_radio")) {
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_CONTINUE
}

public hook_block(id)
{
	if (!g_CSDM_ACTIVE) return PLUGIN_CONTINUE

	new stripflags[10]
	get_cvar_string("csdm_stripper", stripflags, 9)
	if(!stripflags[0]) return PLUGIN_CONTINUE
	new striptype = read_flags(stripflags)
	if (!(striptype & (1<<1)) ) return PLUGIN_CONTINUE

	return PLUGIN_HANDLED
}

public hook_menu(id)
{
	if (!g_CSDM_ACTIVE) {
		return PLUGIN_HANDLED
	}
	if (ShowMenu[id]) {
		ShowMenu[id] = false
		client_print(id, print_console, "[CSDM] Weapons menu is now off.")
		if (get_cvar_num("csdm_allow_clguns")) {
			client_print(id, print_console, "[CSDM] You can use ^"guns^" and ^"give <gun>^" to get weapons.")
		}
		return PLUGIN_HANDLED
	} else {
		ShowMenu[id] = true
		client_print(id, print_console, "[CSDM] Weapons menu is now on.")
		if (get_cvar_num("csdm_allow_clguns")) {
			client_print(id, print_console, "[CSDM] You can use ^"guns^" and ^"give <gun>^" to get weapons.")
		}
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_HANDLED
}

public hook_respawn(id)
{
	if (!g_CSDM_ACTIVE) {
		return PLUGIN_HANDLED
	}
	if (!is_user_alive(id) && id) {
		new Data[2]
		Data[0] = id
		respawn(Data)
	}
	
	return PLUGIN_HANDLED
}

public hook_give(id)
{
	if (!id) return PLUGIN_HANDLED
	if (!is_user_alive(id)) return PLUGIN_HANDLED
	if (!g_CSDM_ACTIVE) {
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_allow_clguns") && !g_CSDM_ADD_ITEMS) {
		new data[16], wpn[24], wp
		read_argv(1, data, 16)
		format(wpn, 23, "weapon_%s", data)
		wp = getWepId(wpn)
		if (!wp) {
			client_print(id, print_console, "[CSDM] Invalid gun!")

			return PLUGIN_HANDLED
		} else {
			if (get_cvar_num("csdm_hold_many")) {
				giveGun(id, wp, 2)
			} else {
//				if (canGetGun(id, wp)) {
				giveGun(id, wp, 2)
//				} else {
//					client_print(id, print_console, "[CSDM] Sorry, you can't hold this weapon.")
					
//					return PLUGIN_HANDLED
//				}
			}
		}
	} else {
		client_print(id, print_console, "[CSDM] Client gun commands are disabled.")
	}

	return PLUGIN_HANDLED
}

public hook_guns(id)
{
	if (!g_CSDM_ACTIVE) {
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_allow_clguns") && !g_CSDM_ADD_ITEMS) {
		if (is_user_alive(id)) {
			EquipMenu(id)
		}
	} else {
		client_print(id, print_chat, "[CSDM] Sorry, client gun menu command is disabled.")
	}
	
	return PLUGIN_HANDLED
}


public hook_drop(id)
{
	if (g_CSDM_ACTIVE) {
		new wp, c, a, Drop[3]
		
		wp = get_user_weapon(id, c, a)
		Drop[0] = wp
		if (get_cvar_num("csdm_drop_weapons")) {
			Drop[1] = 0
		} else {
			Drop[1] = 1
		}
		Drop[2] = id

		set_task(0.2, "timed_replace", 0, Drop, 3)
	}
	return PLUGIN_CONTINUE
}

force_drop_all(id)
{
	new drop[3]
	
	if (is_user_alive(id)) {
		if (get_user_team(id) == 1) {
			if (is_user_bot(id)) { 
				engclient_cmd(id, "drop", "weapon_glock18")
			} else {
				client_cmd(id, "drop %s", "weapon_glock18")
			}
			drop[0] = CSW_GLOCK18
			drop[1] = 1
			drop[2] = id
			set_task(0.2, "timed_replace", 0, drop, 3)
		} else if (get_user_team(id) == 2) {
			if (is_user_bot(id)) { 
				engclient_cmd(id, "drop", "weapon_usp")
			} else {
				client_cmd(id, "drop %s", "weapon_usp")
			}
			drop[0] = CSW_USP
			drop[1] = 1
			drop[2] = id
			set_task(0.2, "timed_replace", 0, drop, 3)
		}
	}
}

public csdm_rement(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		
		return PLUGIN_HANDLED
	}
	
	new S[4]
	new s
	
	read_argv(1, S, 4)
	s = str_to_num(S)
	
	client_print(id, print_console, "Removing entity #%d", s)
	remove_entity(s)
	
	return PLUGIN_HANDLED
}

public timed_rem_drop(data[])
{
	new id = data[0]
	
	destroyDrop(id)
	
	return PLUGIN_CONTINUE	
}

public timed_replace(data[])
{
	new wp = data[0]
	new hide = data[1]
	new p = data[2]
	
	if (!hide) {
		replaceWeapons(wp, 0, p)
	} else {
		replaceWeapons(wp, 1, p)
	}
	
	return PLUGIN_CONTINUE
}

replaceWeapons(wp, hide=0, p)
{
	new model[32], wmodel[32]
	new Float:RVec[3], Float:AVec[3]
	new entid
	new Float:Vel[3]
	new oid, tEnt, tfEnt
	new x = 0
	
	getWepModel(wp, model, 32)
	
	if (wp && strlen(model) && isValidDrop(wp)) {
		tEnt = find_ent_by_class(-1, "weaponbox")
		while (tEnt > 0) {
			tfEnt = find_ent_by_class(tEnt, "weaponbox")
			entity_get_string(tEnt, EV_SZ_model, wmodel, 32)
			if (equali(model, wmodel)) {
				oid = entity_get_edict(tEnt, EV_ENT_owner)
				if (oid == p) {
					//Do not recreate C4.
					if (wp != CSW_C4) {
						entity_get_vector(tEnt, EV_VEC_origin, RVec)
						if (get_cvar_num("csdm_drop_weapons") && !hide && !isWpBlocked(wp)) {
							entity_get_vector(tEnt, EV_VEC_angles, AVec)
							entity_get_vector(tEnt, EV_VEC_velocity, Vel)
							entid = makeWeapon(wp, RVec, AVec, Vel)
							if (entid) {
								createDrop(entid)
							}
						}
					}
					//this may or may not work.
					safe_rmweapon(wp, tEnt)
				} else {
					if (wp == CSW_C4) {
						safe_rmweapon(wp, tEnt)
					}
				}
			}
			tEnt = tfEnt
		}
	}

	return x	//number of ents removed
}

//Nine out of ten people agree that BAILOPAN is actually insane.
safe_rmweapon(wp, entid)
{
	new wEnt, wfEnt, name[24]
	new woEnt
	
	remove_entity(entid)
	get_weaponname(wp, name, 24)
	wEnt = find_ent_by_class(-1, name)
	while (wEnt > 0) {
		wfEnt = find_ent_by_class(wEnt, name)
		woEnt = entity_get_edict(wEnt, EV_ENT_owner)
		if (isValidSubOwner(woEnt) && woEnt == entid) {
			remove_entity(wEnt)
		}
		wEnt = wfEnt
	}
	
	return 1
}

public hook_hud(id)
{
	if (!g_CSDM_ACTIVE) return PLUGIN_CONTINUE		// KWo
	new param[1]
	param[0] = id
	if (!id) return PLUGIN_CONTINUE	
	
	if (!ShowMenu[id]) {
		set_task(0.4, "hook_hud_delayed", 800+id, param, 1) // KWo	- new task number
		return PLUGIN_CONTINUE
	}

	new menuid, keys
	get_user_menu(id, menuid, keys)
	
	new Float:max_delay_time = get_cvar_float("csdm_maxdelmenu_time")	// KWo
	if (max_delay_time<1.0)	{	// KWo
		max_delay_time = 1.0		
		set_cvar_num("csdm_maxdelmenu_time", 1)
	}
	if ( (menuid>0) && (menuid!=menuid_1) && (menuid!=menuid_2) && (menuid!=menuid_3) && (menuid!=menuid_4) && (menuid!=menuid_5) ) {		// KWo
		set_task(1.0,	"checkmenu",	850+id,	param,	1,	"b")	// KWo - new task number
		set_task(max_delay_time, "menu_delayed", 700+id, param, 1)	// KWo - new task number
	}
	else {
		set_task(0.4, "hook_hud_delayed", 800+id, param, 1) // KWo - new task number
	}
	return PLUGIN_CONTINUE
}

public checkmenu(param[]) // KWo
{
	new id = param[0]
	if (!id)
	{
		if (task_exists(850+id)) remove_task(850+id)		// KWo - new task number
		return PLUGIN_CONTINUE
	}
	
	new menuid, keys
	get_user_menu(id, menuid, keys)
		
	if ( (menuid>0) && (menuid!=menuid_1) && (menuid!=menuid_2) && (menuid!=menuid_3) && (menuid!=menuid_4) && (menuid!=menuid_5) ) {
		return PLUGIN_CONTINUE
	}
	else {
		set_task(0.4, "hook_hud_delayed", 800+id, param, 1) // KWo - new task number
		if (task_exists(850+id)) remove_task(850+id)				// KWo - new task number
		if (task_exists(700+id)) remove_task(700+id)				// KWo - new task number		
	}
	return PLUGIN_CONTINUE
}

public menu_delayed(param[]) // KWo - it's a task which will overwrite by gun menu any manu already displayed 
{															//	if the max time we are waiting for disappearing it has expired (cvar - csdm_maxdelmenu_time)
	new id = param[0]
	if (!id)
	{
		if (task_exists(700+id)) remove_task(700+id)			// KWo - new task number
		return PLUGIN_HANDLED
	}
	set_task(0.4, "hook_hud_delayed", 800+id, param, 1) // KWo - new task number
	if (task_exists(700+id))	remove_task(700+id)				// KWo - new task number
	return PLUGIN_HANDLED	
}

public hook_hud_delayed(param[])
{
	new id = param[0]
	if (!id) return PLUGIN_CONTINUE
	if (!is_user_alive(id)) return PLUGIN_CONTINUE
	if (g_CSDM_ACTIVE) {
		if (!g_CSDM_ADD_ITEMS) {
			if (isRespawn[id]) {
				isRespawn[id] = false
				force_drop_all(id)
				set_task(0.4, "hook_hud_delayed", 800+id, param, 1)		// KWo - new task number

				return PLUGIN_CONTINUE
			}
			if (ShowMenu[id]) {
				EquipMenu(id)
			} else {
				if (g_LastWep[id][0]) giveGun(id, g_LastWep[id][0], 1)
				if (g_LastWep[id][1]) giveGun(id, g_LastWep[id][1], 0)
				if (g_getArmor[id] || get_cvar_num("csdm_auto_equip")) {
					set_user_armor(id, 100)
					give_item(id, "item_assaultsuit")
				}
				if (g_getGrens[id] || get_cvar_num("csdm_auto_gren")) {
					giveGun(id, CSW_HEGRENADE, 2)
					giveGun(id, CSW_SMOKEGRENADE, 2)
					giveGun(id, CSW_FLASHBANG, 2)
					giveGun(id, CSW_FLASHBANG, 2)
				}
				if (get_cvar_num("csdm_spawn_spam") && !get_cvar_num("csdm_allow_clguns")) {
					client_print(id, print_chat, "[CSDM] Type ^"enable_menu^" to enable weapon menu, or ^"guns^" to bring up menu.")
				}
			}
		}
		else {
			if (get_cvar_num("csdm_auto_equip")) {
				set_user_armor(id, 100)
				give_item(id, "item_assaultsuit")
			}
			if (get_cvar_num("csdm_auto_gren")) {
				giveGun(id, CSW_HEGRENADE, 2)
				giveGun(id, CSW_SMOKEGRENADE, 2)
				giveGun(id, CSW_FLASHBANG, 2)
				giveGun(id, CSW_FLASHBANG, 2)
			}
		}		
		if (HasLongJump[id]) {
			give_item(id, "item_longjump")
		}
	}
	
	return PLUGIN_CONTINUE
}

public hook_death()
{
	new pk = read_data(1)
	new pv = read_data(2)
	new Vec[3]
	new svIndex[2], wps[32], Drop[3], num

	if (g_CSDM_ACTIVE) {
		svIndex[0] = pv
		set_task(0.5, "quick_respawn", 0, svIndex, 2)
		isSpawning[pv] = true
		get_user_origin(pv, Vec)
		if (g_CSDM_DROP_PACKS && g_CSDM_ADD_ITEMS) {
			createPack(pv, Vec)
		}
		if (g_Kill_All) {
			if (get_user_team(pk) == get_user_team(pv) && pk != pv) {
				set_user_frags(pk, get_user_frags(pk)+2)
			}
			client_cmd(0, "hideradar")
		}
		HasLongJump[pv] = false
		num = 0
		get_user_weapons(pv, wps, num)		//catch every dropped weapon!
		new i
		for (i=0; i<num; i++) {
			if (isValidDrop(wps[i])) {
				Drop[0] = wps[i]
				Drop[2] = pv
				if (get_cvar_num("csdm_drop_weapons")) {
					Drop[1] = 0
				} else {
					if (g_CSDM_DROP_PACKS && g_CSDM_ADD_ITEMS) {
						Drop[1] = 1
					} else {
						Drop[1] = 0
					}
				}
				set_task(0.2, "timed_replace", 0, Drop, 3)
			}
		}
		isRespawn[pv] = true
	}
	
	return PLUGIN_CONTINUE
}

public hook_death2(pk, pv)
{
	new Vec[3]
	new svIndex[2], wps[32], Drop[3], num

	if (g_CSDM_ACTIVE) {
		svIndex[0] = pv
		set_task(0.5, "quick_respawn", 0, svIndex, 2)
		isSpawning[pv] = true
		get_user_origin(pv, Vec)
		if (g_CSDM_DROP_PACKS && g_CSDM_ADD_ITEMS) {
			createPack(pv, Vec)
		}
		if (g_Kill_All) {
			client_cmd(0, "hideradar")
		}
		HasLongJump[pv] = false
		num = 0
		get_user_weapons(pv, wps, num)		//catch every dropped weapon!
		new i
		for (i=0; i<num; i++) {
			if (isValidDrop(wps[i])) {
				Drop[0] = wps[i]
				Drop[2] = pv
				if (get_cvar_num("csdm_drop_weapons")) {
					Drop[1] = 0
				} else {
					if (g_CSDM_DROP_PACKS && g_CSDM_ADD_ITEMS) {
						Drop[1] = 1
					} else {
						Drop[1] = 0
					}
				}
				set_task(0.2, "timed_replace", 0, Drop, 3)
			}
		}
		isRespawn[pv] = true
	}
	
	return PLUGIN_CONTINUE
}

public quick_respawn(svIndex[])
{
	new vIndex = svIndex[0]
	if (!is_user_alive(vIndex) && ((get_user_team(vIndex)==1) || (get_user_team(vIndex)==2))) {
		spawn(vIndex)
		set_task(0.1, "respawn", 0, svIndex, 2)
		if (task_exists(750+vIndex)) remove_task(750+vIndex)		// KWo - new task number
	}	
	return PLUGIN_CONTINUE
}

public respawn(svIndex[])
{
	new vIndex = svIndex[0]
	
	if (get_user_team(vIndex)==3) {
		return PLUGIN_CONTINUE
	} else {
		if (get_user_team(vIndex) == 1 || get_user_team(vIndex) == 2) {
			spawn(vIndex)
			if ( (get_cvar_num("csdm_spawn_wave")) && (!is_user_bot(vIndex)) ) {		// Riddick51 & little change by KWo
				if ( get_user_team(vIndex)==1 )	client_cmd(vIndex,"spk radio/letsgo")
				else	client_cmd(vIndex,"spk radio/locknload")
			}

			isSpawning[vIndex] = true
			new Float:Time = get_cvar_float("csdm_freeze_time")
			get_user_origin(vIndex, Origins[vIndex])
			if (get_cvar_num("csdm_spawn_protect")==0)
				set_task(0.05, "unfreeze", 0, svIndex, 2)
			else
				set_task(Time, "unfreeze", 147258+vIndex, svIndex, 2)
			if (get_cvar_num("csdm_spawn_spam")) {
				client_print(vIndex, print_chat, "[CSDM] Counter-Strike Deathmatch by BAILOPAN")	
				client_print(vIndex, print_chat, "[CSDM] Console commands: ^"respawn^" to manually respawn.")
				if (get_cvar_num("csdm_allow_clguns")) {
					client_print(vIndex, print_chat, "[CSDM] ^"guns^" to see a menu and ^"give <name>^" to get a gun.")
				}
			}
			if (get_cvar_num("csdm_spawn_protect")>0) {
        set_user_health(vIndex, 10239)
        if (g_Kill_All) {
          set_user_rendering(vIndex, kRenderFxGlowShell, 0, 255, 0, kRenderNormal, 30)
        } else {
          if (get_user_team(vIndex) == 1)
            set_user_rendering(vIndex, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 30)
          else if (get_user_team(vIndex) == 2)
            set_user_rendering(vIndex, kRenderFxGlowShell, 0, 0, 255, kRenderNormal, 30)
        }
        if (get_cvar_num("csdm_spawn_protect")==1) {
          set_task(0.2, "check_move", 0, svIndex, 2, "a", floatround(Time/0.21))
        }
      } 
		} else {
			return PLUGIN_CONTINUE
		}
	}

	return PLUGIN_CONTINUE
}

public check_move(svIndex[])
{
	new vIndex = svIndex[0]
	new Origin[3]
	
	if (isSpawning[vIndex]) {
	
		get_user_origin(vIndex, Origin)
		
		if (Origins[vIndex][0] != Origin[0]) {
			if(task_exists(147258+vIndex)) {	// KRoT@L
				remove_task(147258+vIndex)		
			}
			unfreeze(svIndex)
		} else if (Origins[vIndex][1] != Origin[1]) {
			if(task_exists(147258+vIndex)) {	// KRoT@L
				remove_task(147258+vIndex)
			}
			unfreeze(svIndex)
		}
	}
	
	return PLUGIN_CONTINUE
}

public unfreeze(svIndex[])
{
	new vIndex = svIndex[0]
	
	if (!is_user_connected(vIndex))
		return PLUGIN_CONTINUE
		
	if (get_cvar_num("csdm_spawn_protect")>0) {
		set_user_health(vIndex, 100)
		set_user_rendering(vIndex, kRenderFxNone, 0, 0, 0, kRenderNormal, 0)
	}
	if (g_CSDM_ADD_ITEMS) {
		if (get_cvar_num("csdm_auto_equip")) {
			give_item(vIndex, "item_assaultsuit")
			set_user_armor(vIndex, 100)
		}
/*		
		if (get_cvar_num("csdm_auto_gren")) {
			giveGun(vIndex, CSW_HEGRENADE, 2)			// KWo
			giveGun(vIndex, CSW_SMOKEGRENADE, 2)	// KWo
			giveGun(vIndex, CSW_FLASHBANG, 2)			// KWo
			giveGun(vIndex, CSW_FLASHBANG, 2)			// KWo
		}
*/
	}

	isSpawning[vIndex] = false
	
	return PLUGIN_CONTINUE
}

public csdm_version(id)
{
	console_print(id, "[CSDM] Counter-Strike Deathmatch Version %s, build %s.", VERSION, BUILD_VERSION)
	console_print(id, "[CSDM] Made by BAILOPAN.")
	client_print(id,print_chat,"[CSDM] Counter-Strike Deathmatch Version %s, build %s.", VERSION, BUILD_VERSION)		// KWo
	client_print(id,print_chat, "[CSDM] Made by BAILOPAN.")			// KWo
	return PLUGIN_HANDLED
}

public csdm_entcount(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")	// KWo	
		return PLUGIN_HANDLED
	}
	
	console_print(id, "[CSDM] There are currently %d entities in the edict table.", entity_count())
	console_print(id, "[CSDM] There are currently %d defined entities in the map.", EntCount-1)
	client_print(id,print_chat,"[CSDM] There are currently %d entities in the edict table.", entity_count()) // KWo
	client_print(id,print_chat,"[CSDM] There are currently %d defined entities in the map.", EntCount-1)	 // KWo
	return PLUGIN_HANDLED
}

public csdm_entdump(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		// KWo
		return PLUGIN_HANDLED
	}
	
	new S[4]
	new s
	
	read_argv(1, S, 4)
	s = str_to_num(S)
	
	new i
	new model[32]
	new owner
	new class[32]
	new Text[128]
	new entid, pid, did
	log_to_file("csdm-ents.txt", "[CSDM] Entity dump output.")
	for (i=s; i<=entity_count(); i++) {
		if (is_valid_ent(i)) {
			entity_get_string(i, EV_SZ_classname, class, 32)
			entity_get_string(i, EV_SZ_model, model, 32)
			entid = findEntId(i)
			pid = findPackId(i)
			did = findDrop(i)
			owner = entity_get_edict(i, EV_ENT_owner)
			format(Text, 127, "[%d] (%d,%d,%d,%d) ^"%s^" ^"%s^"", i, owner, entid, pid, did, class, model)
			write_file("addons\amxmodx\logs\csdm-ents.txt", Text, -1)
		}
	}
	client_print(id, print_chat, "[CSDM] The file with entities list created - addons\amx\logs\csdm-ents.txt")	
	return PLUGIN_HANDLED
}

public csdm_entinfo(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		// KWo
		return PLUGIN_HANDLED
	}
	
	new ptrClass[32]
	new S[4]
	new s
	
	read_argv(1, S, 4)
	s = str_to_num(S)
	
	if (s>EntCount || s<1) {
		client_print(id, print_console, "[CSDM] That entity was not found.")
		client_print(id, print_chat, "[CSDM] That entity was not found.")		// KWo
		return PLUGIN_HANDLED
	}
	
	if (EntId[s]) {
		entity_get_string(EntId[s], EV_SZ_classname, ptrClass, 32)
	
		client_print(id, print_console, "[CSDM] Entity (%d) has classname ^"%s^".", s, ptrClass)
		client_print(id, print_chat, "[CSDM] Entity (%d) has classname ^"%s^".", s, ptrClass)		// KWo
	} else {
		client_print(id, print_console, "[CSDM] Entity (%d) is not currently spawned.", s)
		client_print(id, print_chat, "[CSDM] Entity (%d) is not currently spawned.", s)		// KWo
	}
	
	return PLUGIN_HANDLED
}

public csdm_spawninfo(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		// KWo
		return PLUGIN_HANDLED
	}
	
	new S[4]
	new s
	
	read_argv(1, S, 4)
	s = str_to_num(S)

	if (s>0 && s<=SPAWNS) {
		new teamname[10]
		switch (SpnTeam[s])
		{
			case 0:
			{
				teamname="random"
			}
			case 1:
			{
				teamname="Terrorist"
			}
			case 2:
			{
				teamname="CT"
			}
		}		
		console_print(id, "[CSDM] Spawn %d has defs (%d %d %d) [%d %d %d] and it's for %s team", s, SPAWN[s][0], SPAWN[s][1], SPAWN[s][2], floatround(SpnVec[s][0]), floatround(SpnVec[s][1]), floatround(SpnVec[s][2]), teamname)
		client_print(id, print_chat, "[CSDM] Spawn %d has defs (%d %d %d) [%d %d %d] and it's for %s team", s, SPAWN[s][0], SPAWN[s][1], SPAWN[s][2], floatround(SpnVec[s][0]), floatround(SpnVec[s][1]), floatround(SpnVec[s][2]), teamname)		// KWo				
	}
	
	return PLUGIN_HANDLED
}

public csdm_look(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		// KWo
		return PLUGIN_HANDLED
	}
	
	new marker, dist=100, cur, PVec[3]
	new i
	
	marker = -1
	get_user_origin( id, PVec, 3)

	for (i=1; i<EntCount; i++) {
		cur = get_distance(PVec, EntVecs[i])
		if (cur < dist) {
			dist = cur
			marker = i
		}
	}
	g_csdm_entlook = marker																// KWo
	if (marker!=-1) {
		client_print(id, print_console, "[CSDM] CSDM Entity found: id=%d distance=%d entid=%d", marker, dist, EntId[marker])
		client_print(id, print_chat, "[CSDM] CSDM Entity found: id=%d distance=%d entid=%d", marker, dist, EntId[marker])  // KWo
	}else{
		client_print(id, print_console, "[CSDM] No Entity found.")
		client_print(id, print_chat, "[CSDM] No Entity found.")	// KWo
	}

	return PLUGIN_HANDLED
}

public csdm_ent(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		
		return PLUGIN_HANDLED
	}
		
	new marker, dist=9999, cur
	new PVec[3]
	new i
	
	marker = -1
	get_user_origin(id, PVec)

	for (i=1; i<EntCount; i++) {
		cur = get_distance(PVec, EntVecs[i])
		if (cur < dist) {
			dist = cur
			marker = i
		}
	}
	
	if (marker != -1) {
		client_print(id, print_console, "[CSDM] The nearest entity to you is number %d", marker)
		client_print(id, print_chat, "[CSDM] The nearest entity to you is number %d", marker)		// KWo
	} else {
		client_print(id, print_console, "[CSDM] No entities found.")
		client_print(id, print_chat, "[CSDM] No entities found.")		// KWo
	}
		
	return PLUGIN_HANDLED
}

public csdm_delent(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")				// KWo		
		return PLUGIN_HANDLED
	}
	
	new Text[64]
	new S[4]
	new s
	new i
	
	read_argv(1, S, 4)
	s = str_to_num(S)
	
	if (s>EntCount || s<1) {
		client_print(id, print_console, "[CSDM] That entity was not found.")
		client_print(id, print_chat, "[CSDM] That entity was not found.")		// KWo
		return PLUGIN_HANDLED
	}
	
	new entid = EntId[s]
	
	rment(entid)
	
	if (s == EntCount-1) {
		EntList[s][0] = 0
		EntVecs[s][0] = 0
		EntVecs[s][1] = 0
		EntVecs[s][2] = 0
		EntId[s] = 0
	} else if (s == EntCount-2) {
		copy(EntList[s], 24, EntList[s+1])
		EntVecs[s][0] = EntVecs[s+1][0]
		EntVecs[s][1] = EntVecs[s+1][1]
		EntVecs[s][2] = EntVecs[s+1][2]
		EntId[s] = EntId[s+1]
	} else if (s < EntCount - 2) {
		for (i=s; i<EntCount-1; i++) {
			copy(EntList[i], 24, EntList[i+1])
			EntVecs[i][0] = EntVecs[i+1][0]
			EntVecs[i][1] = EntVecs[i+1][1]
			EntVecs[i][2] = EntVecs[i+1][2]
			EntId[i] = EntId[i+1]
		}
	}
	EntCount--
	delete_file(EntFile)
	for (i=1; i<EntCount; i++) {
		format(Text, 63, "%s %d %d %d", EntList[i], EntVecs[i][0], EntVecs[i][1], EntVecs[i][2])
		write_file(EntFile, Text, -1)
	}

	client_print(id, print_console, "[CSDM] Entity %d removed.", s)
	client_print(id, print_console, "[CSDM] There are now %d entities defined.", EntCount)
	client_print(id, print_chat, "[CSDM] Entity %d removed.", s)	// KWo
	client_print(id, print_chat, "[CSDM] There are now %d entities defined.", EntCount)  // KWo
	
	return PLUGIN_HANDLED
}

public csdm_delspawn(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		// KWo
		return PLUGIN_HANDLED
	}
	
	new Text[64]
	new S[4]
	new s
	new i
	
	read_argv(1, S, 4)
	s = str_to_num(S)
	
	if (s>SPAWNS) {
		client_print(id, print_console, "[CSDM] That spawn point was not found.")
		client_print(id, print_chat, "[CSDM] That spawn point was not found.")  // KWo
		return PLUGIN_HANDLED
	}
	
	for (i=s; i<SPAWNS; i++) {
		SPAWN[i][0] = SPAWN[i+1][0]
		SPAWN[i][1] = SPAWN[i+1][1]
		SPAWN[i][2] = SPAWN[i+1][2]
		SpnVec[i][0] = SpnVec[i+1][0]
		SpnVec[i][1] = SpnVec[i+1][1]
		SpnVec[i][2] = SpnVec[i+1][2]
		SpnAng[i][0] = SpnAng[i+1][0]
		SpnAng[i][1] = SpnAng[i+1][1]
		SpnAng[i][2] = SpnAng[i+1][2]
		SpnTeam[i] = SpnTeam[i+1]
	}
	
	SPAWNS--
	delete_file(mapFile)
	for (i=1; i<=SPAWNS; i++) {
		format(Text, 63, "%d %d %d %d %d %d %d %d %d %d", SPAWN[i][0], SPAWN[i][1], SPAWN[i][2], floatround(SpnVec[i][0]), floatround(SpnVec[i][1]), floatround(SpnVec[i][2]), SpnTeam[i], floatround(SpnAng[i][0]), floatround(SpnAng[i][1]), floatround(SpnAng[i][2]))
		write_file(mapFile, Text, -1)
	}
	readMapFile()
	setSpawns()

	if (g_showing_spawns) {								// KWo
		csdm_hidespawns(id)
		console_cmd(id,"csdm_view_csdm_sp")
	}

	client_print(id, print_console, "[CSDM] Spawn point %d removed.", s)
	client_print(id, print_console, "[CSDM] There are now %d spawns defined.", SPAWNS)
	client_print(id, print_chat, "[CSDM] Spawn point %d removed.", s)	// KWo
	client_print(id, print_chat, "[CSDM] There are now %d spawns defined.", SPAWNS)	// KWo

	return PLUGIN_HANDLED
}

public csdm_setspawnv(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")	// KWo
		return PLUGIN_HANDLED
	}
	
	new IDVec[3]
	new Text[64]
	new Float:vAngle[3]
	new Float:oAngle[3]
	new team[4]
	new iTeam
	
	read_argv(1, team, 4)
	iTeam = str_to_num(team)
	
	if (SPAWNS == 0 || !SPAWNS_ENABLED) {
		SPAWNS_ENABLED = 1
	}
	if (SPAWNS == MAX_SPAWNS) {
		client_print(id, print_console, "[CSDM] Spawn limit reached at %d.", MAX_SPAWNS)
		client_print(id, print_chat, "[CSDM] Spawn limit reached at %d.", MAX_SPAWNS)		// KWo
		return PLUGIN_HANDLED
	}

	get_user_origin(id, IDVec)
	entity_get_vector(id, EV_VEC_v_angle, vAngle)
	entity_get_vector(id, EV_VEC_angles, oAngle)
	IDVec[2] += 15
	format(Text, 63, "%d %d %d %d %d %d %d %d %d %d", IDVec[0], IDVec[1], IDVec[2], floatround(vAngle[0]), floatround(vAngle[1]), floatround(vAngle[2]), iTeam, floatround(oAngle[0]), floatround(oAngle[1]), floatround(oAngle[2]))
	write_file(mapFile, Text, SPAWNS)
	SPAWNS++
	SPAWN[SPAWNS][0] = IDVec[0]
	SPAWN[SPAWNS][1] = IDVec[1]
	SPAWN[SPAWNS][2] = IDVec[2]
	SpnVec[SPAWNS][0] = vAngle[0]
	SpnVec[SPAWNS][1] = vAngle[1]
	SpnVec[SPAWNS][2] = vAngle[2]
	SpnAng[SPAWNS][0] = oAngle[0]
	SpnAng[SPAWNS][1] = oAngle[1]
	SpnAng[SPAWNS][2] = oAngle[2]
	SpnTeam[SPAWNS] = iTeam
	set_user_origin(id, SPAWN[SPAWNS])

	if (g_showing_spawns) {								// KWo
		csdm_hidespawns(id)
		console_cmd(id,"csdm_view_csdm_sp")
	}

	client_print(id, print_console, "[CSDM] There are now %d spawns defined.", SPAWNS)
	client_print(id, print_chat, "[CSDM] There are now %d spawns defined.", SPAWNS)  // KWo
	return PLUGIN_HANDLED
}

public csdm_setspawn(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")	// KWo		
		return PLUGIN_HANDLED
	}
	
	new IDVec[3]
	new Text[64]
	new Float:vAngle[3]
	new Float:oAngle[3]
	new team[4]
	new iTeam
	
	read_argv(1, team, 4)
	iTeam = str_to_num(team)
	
	if (SPAWNS == 0 || !SPAWNS_ENABLED) {
		SPAWNS_ENABLED = 1
	}
	if (SPAWNS == MAX_SPAWNS) {
		client_print(id, print_console, "[CSDM] Spawn limit reached at %d.", MAX_SPAWNS)
		client_print(id, print_chat, "[CSDM] Spawn limit reached at %d.", MAX_SPAWNS)		// KWo
		return PLUGIN_HANDLED
	}
	
	get_user_origin(id, IDVec)
	entity_get_vector(id, EV_VEC_v_angle, vAngle)
	entity_get_vector(id, EV_VEC_angles, oAngle)
	IDVec[2] += 15
	format(Text, 63, "%d %d %d %d %d %d %d %d %d %d", IDVec[0], IDVec[1], IDVec[2], floatround(vAngle[0]), floatround(vAngle[1]), floatround(vAngle[2]), iTeam, floatround(oAngle[0]), floatround(oAngle[1]), floatround(oAngle[2]))
	write_file(mapFile, Text, -1)
	SPAWNS++
	SPAWN[SPAWNS][0] = IDVec[0]
	SPAWN[SPAWNS][1] = IDVec[1]
	SPAWN[SPAWNS][2] = IDVec[2]
	SpnVec[SPAWNS][0] = vAngle[0]
	SpnVec[SPAWNS][1] = vAngle[1]
	SpnVec[SPAWNS][2] = vAngle[2]
	SpnAng[SPAWNS][0] = oAngle[0]
	SpnAng[SPAWNS][1] = oAngle[1]
	SpnAng[SPAWNS][2] = oAngle[2]
	SpnTeam[SPAWNS] = iTeam
	set_user_origin(id, SPAWN[SPAWNS])

	if (g_showing_spawns) {								// KWo
		csdm_hidespawns(id)
		console_cmd(id,"csdm_view_csdm_sp")
	}
	
	client_print(id, print_console, "[CSDM] There are now %d spawns defined.", SPAWNS)
	client_print(id, print_chat, "[CSDM] There are now %d spawns defined.", SPAWNS)  // KWo
		
	return PLUGIN_HANDLED
}

public csdm_hidespawns(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")  // KWo
		return PLUGIN_HANDLED
	}
	
	new tEnt
	g_showing_spawns=false		// KWo	
	tEnt = find_ent_by_class(-1, "view_spawn")
	while (tEnt > 0) {
		safe_rm_ent(tEnt)
		tEnt = find_ent_by_class(-1, "view_spawn")
	}
	
	client_print(id, print_console, "[CSDM] Spawn markers removed.")
	client_print(id, print_chat, "[CSDM] Spawn markers removed.")  // KWo
	return PLUGIN_HANDLED
}

public csdm_spawncount(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")		// KWo
		return PLUGIN_HANDLED
	}
	new tEnt, tfEnt
	new i=0
	
	tEnt = find_ent_by_class(-1, "info_player_deathmatch")
	while (tEnt > 0) {
		tfEnt = find_ent_by_class(tEnt, "info_player_deathmatch")
		tEnt = tfEnt
		i++
	}
	
	tEnt = find_ent_by_class(-1, "info_player_start")
	while (tEnt > 0) {
		tfEnt = find_ent_by_class(tEnt, "info_player_start")
		tEnt = tfEnt
		i++
	}
	new RD_num=0, TR_num=0, CT_num=0
	for (new k=1; k<SPAWNS; k++)
	{
		if (SpnTeam[k]==0) RD_num++
		if (SpnTeam[k]==1) TR_num++
		if (SpnTeam[k]==2) CT_num++
	}
	
	console_print(id, "[CSDM] %d original spawns found.", i)
	console_print(id, "[CSDM] there is %d random , %d T and %d CT CSDM spawns found.", RD_num, TR_num, CT_num)  // KWo
	client_print(id, print_chat, "[CSDM] %d original spawns found.", i)  // KWo
	client_print(id, print_chat, "[CSDM] there is %d random , %d T and %d CT CSDM spawns found.", RD_num, TR_num, CT_num)	
	
	return PLUGIN_HANDLED
}

public csdm_view_csdm_sp(id, level, cid)		// KWo
{
	new entid, Float:Ang[3], Float:Vec[3], Float:vAng[3]	
	new i=0
	for (i=1; i<=SPAWNS; i++) {
		Vec[0]=float(SPAWN[i][0])
		Vec[1]=float(SPAWN[i][1])
		Vec[2]=float(SPAWN[i][2])
		Ang[0]=SpnAng[i][0]
		Ang[1]=SpnAng[i][1]
		Ang[2]=SpnAng[i][2]
		vAng[0]=SpnVec[i][0]
		vAng[1]=SpnVec[i][1]
		vAng[2]=SpnVec[i][2]
		
		switch (SpnTeam[i]) {		
			case 0: /* CSDM random spawn point */			
			{
				entid = create_entity("info_target")
				entity_set_string(entid, EV_SZ_classname, "view_spawn")
				entity_set_model(entid, "models/w_suit.mdl")
				entity_set_origin(entid, Vec)
				entity_set_vector(entid, EV_VEC_angles, Ang)
				entity_set_vector(entid, EV_VEC_v_angle, vAng)
				entity_set_int(entid, EV_INT_solid, 1)
				entity_set_int(entid, EV_INT_movetype, 6)
				set_rendering(entid, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 127)				
			}
			case 1: /* CSDM terrorist spawn point */
			{
				entid = create_entity("info_target")
				entity_set_string(entid, EV_SZ_classname, "view_spawn")
				entity_set_origin(entid, Vec)				
				entity_set_model(entid, "models/player/terror/terror.mdl")
				entity_set_vector(entid, EV_VEC_angles, Ang)
				entity_set_vector(entid, EV_VEC_v_angle, vAng)
				entity_set_int(entid,EV_INT_sequence,1)
				set_rendering(entid, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 127)
			}
			case 2: /* CSDM CT spawn point */
			{
				entid = create_entity("info_target")
				entity_set_string(entid, EV_SZ_classname, "view_spawn")
				entity_set_origin(entid, Vec)
				entity_set_model(entid, "models/player/urban/urban.mdl")
				entity_set_vector(entid, EV_VEC_angles, Ang)
				entity_set_vector(entid, EV_VEC_v_angle, vAng)
				entity_set_int(entid,EV_INT_sequence,1)
				set_rendering(entid, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 127)
			}
		}
	}
	g_showing_spawns=true		// KWo			
	console_print(id, "[CSDM] %d spawns marked.", SPAWNS)
	client_print(id, print_chat, "[CSDM] %d spawns marked.", SPAWNS)  // KWo
	return PLUGIN_HANDLED
}

public csdm_viewspawns(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")  // KWo
		return PLUGIN_HANDLED
	}
	new entid, Float:Ang[3], Float:Vec[3], Float:vAng[3]
	new tEnt, tfEnt
	new i=0

	tEnt = find_ent_by_class(-1, "info_player_deathmatch")
	while (tEnt > 0) {
		tfEnt = find_ent_by_class(tEnt, "info_player_deathmatch")
		entity_get_vector(tEnt, EV_VEC_angles, Ang)
		entity_get_vector(tEnt, EV_VEC_origin, Vec)
		entity_get_vector(tEnt, EV_VEC_v_angle, vAng)
		entid = create_entity("info_target")
		entity_set_string(entid, EV_SZ_classname, "view_spawn")
		entity_set_origin(entid, Vec)		
//		entity_set_model(entid, "models/w_suit.mdl")		
		entity_set_model(entid, "models/player/arctic/arctic.mdl")	// KWo
//		entity_set_model(entid, "models/player/terror/terror.mdl")
		entity_set_vector(entid, EV_VEC_angles, Ang)	
		entity_set_vector(entid, EV_VEC_v_angle, vAng)
		entity_set_int(entid,EV_INT_sequence,1)		// KWo
		set_rendering(entid, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 127) // KWo
//		entity_set_int(entid, EV_INT_solid, 1)
//		entity_set_int(entid, EV_INT_movetype, 6)
		tEnt = tfEnt
		i++
	}

	tEnt = find_ent_by_class(-1, "info_player_start")
	while (tEnt > 0) {
		tfEnt = find_ent_by_class(tEnt, "info_player_start")
		entity_get_vector(tEnt, EV_VEC_angles, Ang)
		entity_get_vector(tEnt, EV_VEC_origin, Vec)
		entity_get_vector(tEnt, EV_VEC_v_angle, vAng)
		entid = create_entity("info_target")
		entity_set_string(entid, EV_SZ_classname, "view_spawn")
		entity_set_origin(entid, Vec)				
//		entity_set_model(entid, "models/gman.mdl")		
		entity_set_model(entid, "models/player/sas/sas.mdl") // KWo
//		entity_set_model(entid, "models/player/urban/urban.mdl")	// KWo
		entity_set_vector(entid, EV_VEC_angles, Ang)
		entity_set_vector(entid, EV_VEC_v_angle, vAng)
		entity_set_int(entid,EV_INT_sequence,1)		// KWo
		set_rendering(entid, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 127)  // KWo
//		entity_set_int(entid, EV_INT_solid, 1)
//		entity_set_int(entid, EV_INT_movetype, 6)
		tEnt = tfEnt
		i++
	}
	
	console_print(id, "[CSDM] %d active spawns marked.", i)
	client_print(id, print_chat, "[CSDM] %d active spawns marked.", i)  // KWo
	return PLUGIN_HANDLED
}

public csdm_setent(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_D)) {
		client_print(id, print_console, "[CSDM] You do not have appropriate access.")
		client_print(id, print_chat, "[CSDM] You do not have appropriate access.")  // KWo
		return PLUGIN_HANDLED
	}
	
	if (EntCount == MAX_ENTS) {
		client_print(id, print_console, "[CSDM] Entity limit reached at %d", MAX_ENTS)
		client_print(id, print_chat, "[CSDM] Entity limit reached at %d", MAX_ENTS)  // KWo
		return PLUGIN_HANDLED
	}
	
	if (!g_CSDM_ADD_ITEMS) {
		client_print(id, print_console, "[CSDM] You must have csdm_add_items set to 1.")
		client_print(id, print_console, "[CSDM] Set it to 1 and restart the map.")
		client_print(id, print_chat, "[CSDM] You must have csdm_add_items set to 1.")  // KWo
		client_print(id, print_chat, "[CSDM] Set it to 1 and restart the map.")  // KWo
		
		return PLUGIN_HANDLED
	}
	
	new IDVec[3]
	new gEnt[24]
	new Text[64]
	
	read_argv(1, gEnt, 24)
	get_user_origin(id, IDVec)
	format(Text, 63, "%s %d %d %d", gEnt, IDVec[0], IDVec[1], IDVec[2])

	copy(EntList[EntCount], 24, gEnt)
	EntVecs[EntCount][0] = IDVec[0]
	EntVecs[EntCount][1] = IDVec[1]
	EntVecs[EntCount][2] = IDVec[2]
	EntId[EntCount] = makeEnt(EntCount)

	if (EntId[EntCount] > 0) {
		write_file(EntFile, Text, -1)
		EntCount++
		client_print(id, print_console, "[CSDM] There are now %d entities defined.", EntCount)
		client_print(id, print_chat, "[CSDM] There are now %d entities defined.", EntCount)		// KWo
	} else {
		client_print(id, print_console, "[CSDM] Entity ^"%s^" did not init properly.", gEnt)
		client_print(id, print_chat, "[CSDM] Entity ^"%s^" did not init properly.", gEnt)		// KWo
		EntVecs[EntCount][0] = 0
		EntVecs[EntCount][1] = 0
		EntVecs[EntCount][2] = 0
		EntId[EntCount] = 0
		copy(EntList[EntCount], 24, "")
	}

	return PLUGIN_HANDLED
}

public csdm_items(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_C)) {
		return PLUGIN_HANDLED
	}
	
	new Bits[4], bit
	
	read_argv(1, Bits, 4)
	bit = str_to_num(Bits)
	
	if (!strlen(Bits)) {
		client_print(id, print_console, "csdm_items [1|0] (1=on, 0=off)")
		client_print(id, print_chat, "[CSDM] csdm_items [1|0] (1=on, 0=off)")		
		return PLUGIN_HANDLED
	}
	
	if (bit == 0) {
		set_cvar_num("csdm_add_items", 0)
		client_print(id, print_console, "Item mode has been turned off.  Reverting to menus.")
		client_print(id, print_chat, "[CSDM] Item mode has been turned off.  Reverting to menus.")		
		destroyAllItems()
		return PLUGIN_HANDLED
	} else {
		set_cvar_num("csdm_add_items", 1)
		client_print(id, print_console, "Item mode has been turned on.  There may be lag as the items are initialized.")
		client_print(id, print_chat, "[CSDM] Item mode has been turned on.  There may be lag as the items are initialized.")		
		setEnts()
		if (get_cvar_num("csdm_allow_clguns")) {
			client_print(id, print_console, "csdm_allow_clguns is chaotic in csdm_add_items mode and is being turned off.")
			set_cvar_num("csdm_allow_clguns", 0)
		}
		return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

public csdm_onoff(id, level, cid)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_C)) {
		return PLUGIN_HANDLED
	}
	
	new Bits[4], bit
	
	read_argv(1, Bits, 4)
	bit = str_to_num(Bits)
	
	if (!strlen(Bits)) {
		client_print(id, print_console, "csdm_enable [1|0] (1=on, 0=off)")
		return PLUGIN_HANDLED
	}
	
	if ( (bit == 0) && (get_cvar_num("csdm_active") )	)	{	// KWo
		set_cvar_num("csdm_active", 0)
		console_print(id, "CSDM Mode turned off.")
		console_print(id, "There may be some lag as the map is prepared.")
		client_print(0, print_chat, "CSDM Mode turned off.")
		log_message("[CSDM] CSDM Mode turned off.")
		destroyAllItems()
		restoreSpawns()
		restoreHostages()
		restoreObjectives()
//		if(g_Kill_All)	//	KWo - removed this check
//		{
		set_msg_block(112, BLOCK_NOT)
		client_cmd(0, "drawradar")
//		}
		new file[64]																						// KRoT@L
		get_cvar_string("csdm_disable_file", file, 63)					// KRoT@L
		if (file_exists(file)) server_cmd("exec %s", file)			// KRoT@L
		server_cmd("sv_restartround 2")
		g_csdm_started=false			// KWo
		return PLUGIN_HANDLED
	} else {
		if (!get_cvar_num("csdm_active") )	{	// KWo
			set_cvar_num("csdm_active", 1)
			console_print(id, "CSDM Mode turned on.")
			client_print(0, print_chat, "CSDM Mode turned on.")
			new data[2]			// KWo
			data[0] = 0			// KWo
			set_task(0.1, "introduce", 0, data, 2)	/// KWo
			log_message("[CSDM] CSDM Mode turned on.")
			console_print(id, "There may be some lag as the map is prepared.")
			if(g_Kill_All)
			{
				set_msg_block(112, BLOCK_SET)
				client_cmd(0, "hideradar")
			}
			start_map()
			g_csdm_started=true			// KWo
			return PLUGIN_HANDLED
		}
	}
	return PLUGIN_HANDLED
}

bool:cwrap(string1[], string2[])
{
	if (containi(string1, string2)!=-1) {
		return true
	}
		
	return false
}

//This is basically the reverse of the setSpawns() algorithm
//Basically, it finds all of the spawns in play and 
restoreSpawns()
{
	new tEnt
	new i

	if (SPAWNS_ENABLED) {
		for (i=0; i<OLD_SPAWNS; i++) {
			tEnt = OldSpawnIDs[i]
			if (tEnt) {
				entity_set_origin(tEnt, OldSpawns[i])
				entity_set_vector(tEnt, EV_VEC_v_angle, OldSpawnVecs[i])
				entity_set_vector(tEnt, EV_VEC_angles, OldSpawnAngs[i])
			}
		}
	}
	OLD_SPAWNS = 0
	g_old_spawns_stored=false	// KWo
}

//The new spawning engine
setSpawns()
{
	new OldSpawnEnts[MAX_SPAWNS+1]
	new OldSpawnTeams[MAX_SPAWNS+1]
	new tEnt, tfEnt, t=0
	new Float:Vec[3]
	new f, g, i
	
	if (SPAWNS_ENABLED && get_cvar_num("csdm_active") && (!g_old_spawns_stored) ) {
		//Find old spawn points to move 'round
		tEnt = find_ent_by_class(-1, "info_player_start")
		while (tEnt > 0 && t<=50) {
			tfEnt = find_ent_by_class(tEnt, "info_player_start")
			OldSpawnEnts[t] = tEnt
			OldSpawnTeams[t] = 2			
			t++			
			if (is_valid_ent(tEnt)) {
				//We have a valid entity.  Save the original data.
				if (!g_old_spawns_stored)		// KWo
				{
					OldSpawnIDs[OLD_SPAWNS] = tEnt	//Record the entity # of this old spawn!
					entity_get_vector(tEnt, EV_VEC_origin, OldSpawns[OLD_SPAWNS])
					entity_get_vector(tEnt, EV_VEC_v_angle, OldSpawnVecs[OLD_SPAWNS])
					entity_get_vector(tEnt, EV_VEC_angles, OldSpawnAngs[OLD_SPAWNS])
					OLD_SPAWNS++			//Increase number of old spawns found!				
				}				
			}
			tEnt = tfEnt
		}
		tEnt = find_ent_by_class(-1, "info_player_deathmatch")
		while (tEnt > 0 && t<=50) {
			tfEnt = find_ent_by_class(tEnt, "info_player_deathmatch")
			OldSpawnEnts[t] = tEnt
			OldSpawnTeams[t] = 1
			t++
			if (is_valid_ent(tEnt)) {
				//We have a valid entity.  Save the original data.				
				if (!g_old_spawns_stored)		// KWo
				{
					OldSpawnIDs[OLD_SPAWNS] = tEnt	//Record the entity # of this old spawn!
					entity_get_vector(tEnt, EV_VEC_origin, OldSpawns[OLD_SPAWNS])
					entity_get_vector(tEnt, EV_VEC_v_angle, OldSpawnVecs[OLD_SPAWNS])
					entity_get_vector(tEnt, EV_VEC_angles, OldSpawnAngs[OLD_SPAWNS])					
					OLD_SPAWNS++			//Increase number of old spawns found!				
				}
			}
			tEnt = tfEnt
		}
		g_old_spawns_stored=true
		new chosen[MAX_SPAWNS+1], s  // KWo
		
		for (i=1; i<=SPAWNS && i<=OLD_SPAWNS; i++) {
			f = random_num(1, SPAWNS)
			while (chosen[f]) {
				f = random_num(1, SPAWNS)
			}
			chosen[f] = 1
			IVecFVec(SPAWN[f], Vec)
			if (SpnTeam[f] == 1) {
				g = 1
			} else if (SpnTeam[f] == 2) {
				g = 2
			} else {
				g = i%2 + 1
			}
			s = findNextSpawn(OldSpawnTeams, g)			
			tEnt = OldSpawnEnts[s]
			
			OldSpawnEnts[s] = 0
//			OLD_SPAWNS++			//Increase number of old spawns found!		// KWo
			if (is_valid_ent(tEnt)) {
				//We have a valid entity.  Save the original data.
/*				if (!g_old_spawns_stored)		// KWo
				{
					OldSpawnIDs[s] = tEnt	//Record the entity # of this old spawn!
					entity_get_vector(tEnt, EV_VEC_origin, OldSpawns[s])
					entity_get_vector(tEnt, EV_VEC_v_angle, OldSpawnVecs[s])
					entity_get_vector(tEnt, EV_VEC_angles, OldSpawnAngs[s])
					g_old_spawns_stored=true
				}
*/
				if (!get_cvar_num("csdm_random_spawns")) return    //KWo - added affecting it by this cvar right here
				
				//NOW we can set the new values.
				entity_set_origin(tEnt, Vec)
				entity_set_vector(tEnt, EV_VEC_v_angle, SpnVec[f])
				entity_set_vector(tEnt, EV_VEC_angles, SpnAng[f])
			}
		}

		if (!get_cvar_num("csdm_steam")) {
			for (i=1; i<MAX_SPAWNS; i++) {
				if (OldSpawnEnts[s]) {
					remove_entity(OldSpawnEnts[s])
				}
			}
		}		
	}
}

findNextSpawn(Ents[MAX_SPAWNS+1], team)
{
	new i
	for (i=1; i<MAX_SPAWNS; i++) {
		if (Ents[i] == team) {
			Ents[i] = 0
			return i
		}
	}
	
	return 0
}

setEnts()
{
	new i
	if ((get_cvar_num("csdm_add_items")) && EntCount && get_cvar_num("csdm_active")) {
		for (i=1; i<EntCount; i++) {
			EntId[i] = makeEnt(i)
		}
	}
}

makeWeapon(wp, Float:Origin[3], Float:Angles[3]={0.0,0.0,0.0}, Float:Vel[3]={0.0,0.0,0.0})
{
	new model_name[32]
	new name[20]
	
	if (isWpBlocked(wp)) {
		return 0
	}
	
	getWepModel(wp, model_name, 32)
	getCSDMWp(wp, name, 20)
	
	new entid = mkent()
	if (entid) {
		entity_set_string(entid, EV_SZ_classname, name)
		entity_set_model(entid, model_name)
		entity_set_origin(entid, Origin)
		entity_set_int(entid, EV_INT_solid, 1)
		entity_set_int(entid, EV_INT_movetype, 6)
		entity_set_vector(entid, EV_VEC_angles, Angles)
		entity_set_vector(entid, EV_VEC_velocity, Vel)
	} else {
		entid = 0
	}
	
	return entid
}

makeEnt(id)
{
	new Float:Vec[3]
	new entid
	
	IVecFVec(EntVecs[id], Vec)
	
	if ((!(g_CSDM_ACTIVE)) || (!(g_CSDM_ADD_ITEMS))) {
		return 0
	}
	
	if (cwrap(EntList[id], "weapon_")) {
		new wp = getWepId(EntList[id])
		entid = makeWeapon(wp, Vec)
	} else if (cwrap(EntList[id], "item_longjump")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_longjump")
			entity_set_model(entid, "models/w_longjump.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "item_healthkit")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_medkit")
			entity_set_model(entid, "models/w_medkit.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "item_battery")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_battery")
			entity_set_model(entid, "models/w_battery.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "pistol_ammo")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_pistolammo")
			entity_set_model(entid, "models/w_357ammobox.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "rifle_ammo")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_rifleammo")
			entity_set_model(entid, "models/w_9mmarclip.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "shotgun_ammo")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_shotammo")
			entity_set_model(entid, "models/w_shotbox.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "smg_ammo")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_smgammo")
			entity_set_model(entid, "models/w_9mmclip.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "full_ammo")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_fullammo")
			if (get_cvar_num("csdm_asskicr")) {
				entity_set_model(entid, "models/w_isotopebox.mdl")
			} else {
				entity_set_model(entid, "models/w_chainammo.mdl")
			}
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "armor")) {
		entid = mkent()
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, "csdm_armor")
			entity_set_model(entid, "models/w_assault.mdl")
			entity_set_origin(entid, Vec)
			entity_set_int(entid, EV_INT_solid, 1)
			entity_set_int(entid, EV_INT_movetype, 6)
		}
	} else if (cwrap(EntList[id], "awp_ammo")) {
		if (get_cvar_num("csdm_asskicr")) {
			entid = mkent()
			if (entid) {
				entity_set_string(entid, EV_SZ_classname, "csdm_awpammo")
				entity_set_model(entid, "models/w_crossbow_clip.mdl")
				entity_set_origin(entid, Vec)
				entity_set_int(entid, EV_INT_solid, 1)
				entity_set_int(entid, EV_INT_movetype, 6)
			}
		}
	} else if (cwrap(EntList[id], "para_ammo")) {
		if (get_cvar_num("csdm_asskicr")) {
			entid = mkent()
			if (entid) {
				entity_set_string(entid, EV_SZ_classname, "csdm_paraammo")
				entity_set_model(entid, "models/w_chainammo.mdl")
				entity_set_origin(entid, Vec)
				entity_set_int(entid, EV_INT_solid, 1)
				entity_set_int(entid, EV_INT_movetype, 6)
			}
		}
	} else {
		entid = mkent(EntList[id])
		if (entid) {
			entity_set_string(entid, EV_SZ_classname, EntList[id])
			entity_set_origin(entid, Vec)
		}
	}
	

	if (entid) {
		return entid
	} else {
		return 0
	}
	
	return entid
}

readEntsFile()
{
	new Map[49]
	new Text[192]
	
	get_mapname(Map, 48)
	if (get_cvar_num("csdm_asskicr")) {
		format(EntFile, 59, "addons\amxmodx\csdm\asskicr\ents_%s.cfg", Map)
	}else{
		format(EntFile, 59, "addons\amxmodx\csdm\ents_%s.cfg", Map)
	}
	EntCount = 0
	if (file_exists(EntFile)) {
		new i=0, temp
		new Data[32]
		new x,y,z
		new Name[32]
		new TempB1[32]
		new TempB2[32]
		new TempB3[32]
		while (i<MAX_ENTS && read_file(EntFile, i, Data, 32, temp)) {
			strbreak(Data, Name, 32, TempB3, 32)
			strbreak(TempB3, TempB1, 32, TempB2, 32)
			x = str_to_num(TempB1)
			strbreak(TempB2, TempB1, 32, TempB3, 32)
			y = str_to_num(TempB1)
			strbreak(TempB3, TempB1, 32, TempB2, 32)
			z = str_to_num(TempB1)
			if (strlen(Name)>2) {
				EntCount++
				EntVecs[EntCount][0] = x
				EntVecs[EntCount][1] = y
				EntVecs[EntCount][2] = z
				copy(EntList[EntCount], 24, Name)
			}
			i++
		}
		format(Text, 191, "[CSDM] loaded %d entities for %s.", EntCount, Map)
		EntCount++	//Move the entity pointer up by one
		log_message(Text)
	} else {
		format(Text, 191, "[CSDM] warning: map %s not set up for entities.", Map)
		log_message(Text)
		EntCount = 0
	}
}

readWeaponsFile()
{
	new FileName[] = "addons\amxmodx\csdm\blocked.cfg"
	new Data[48], temp
	new log[192]
	new Name[24], Number[24]
	new temp2[32]
	
	new ptr = 0, i
	Blocks = 0
	if (file_exists(FileName)) {
		while (i<MAX_RESTRICTS && read_file(FileName, i, Data, 48, temp)) {
			if (strlen(Data) >= 2) {
				strbreak(Data, Name, 24, Number, 24)
				format(temp2, 31, "weapon_%s", Name)
				BlockedWps[++ptr] = getWepId(temp2)
				RestrictWps[ptr] = str_to_num(Number)
			}
			i++
		}
		Blocks = ptr
		format(log, 191, "[CSDM] loaded %d weapon blocks.", Blocks)
		log_message(log)
	}
}

readMapFile()	//taken from Bail's Root Plugin
{
	new Map[32]
	new Text[192]
	new TempB[12][8]
	
	get_mapname(Map, 32)
	if (!get_cvar_num("csdm_steam")) {
		if (cwrap(Map, "de_aztec")) {
			format(mapFile, 127, "addons/amxmodx/csdm/csdm_%s15.cfg", Map)
		} else {
			format(mapFile, 127, "addons/amxmodx/csdm/csdm_%s.cfg", Map)
		}
	} else {
		format(mapFile, 127, "addons/amxmodx/csdm/csdm_%s.cfg", Map)
	}

	SPAWNS = 0
	if (file_exists(mapFile)) {
		SPAWNS_ENABLED = 1
		new i=0, temp
		new Data[128]
		while (SPAWNS<MAX_SPAWNS && read_file(mapFile, i, Data, 128, temp)) {
			if (strlen(Data)>2) {
				parse(Data,TempB[1],8,TempB[2],8,TempB[3],8,TempB[4],8,TempB[5],8,TempB[6],8,TempB[7],8,TempB[8],8,TempB[9],8,TempB[10],8)
				SPAWNS++
				SPAWN[SPAWNS][0] = str_to_num(TempB[1])
				SPAWN[SPAWNS][1] = str_to_num(TempB[2])
				SPAWN[SPAWNS][2] = str_to_num(TempB[3])
				SpnVec[SPAWNS][0] = float(str_to_num(TempB[4]))
				SpnVec[SPAWNS][1] = float(str_to_num(TempB[5]))
				SpnVec[SPAWNS][2] = float(str_to_num(TempB[6]))
				SpnTeam[SPAWNS] = str_to_num(TempB[7])
				SpnAng[SPAWNS][0] = float(str_to_num(TempB[8]))
				SpnAng[SPAWNS][1] = float(str_to_num(TempB[9]))
				SpnAng[SPAWNS][2] = float(str_to_num(TempB[10]))
			}
			i++
		}
		format(Text, 191, "[CSDM] loaded %d spawns for %s.", SPAWNS, Map)
		log_message(Text)
	} else {
		format(Text, 191, "[CSDM] warning: map %s not set up for spawn points.", Map)
		log_message(Text)
		SPAWNS_ENABLED = 0
	}
}

/*
* Old code for giveGun function
public giveGun(id,wpn,s)
{
	if (!id || !wpn) return PLUGIN_CONTINUE
	
	new wpn_id[32], num
	new wepname[32]
	new i
	num = 0
	
	get_user_weapons(id,wpn_id,num)
	for(i = 0; i<num; i++)
	{
		if(wpn_id[i] != wpn)
		{
			if (canGetGun(id, wpn)) {
				get_weaponname(wpn,wepname,31)
				if(is_user_alive(id)) {		
					while (canGetGun(id, wpn)) {
						give_item(id, wepname)
					}
				}
				if (s==1) {
					g_LastWep[id][0] = wpn
				} else if (s==0) {
					g_LastWep[id][1] = wpn
				}
			} else {
				new n
				new bool:slotfree = false	// KWo
				for (n=0; n<num; n++) {
					if ( (getWepSlot(wpn_id[i]) == getWepSlot(wpn)) && (wpn!=CSW_HEGRENADE) && (wpn!=CSW_SMOKEGRENADE) && (wpn!=CSW_FLASHBANG) ) {  // KWo
						
						new name[32], drop[3]						
						get_weaponname(wpn_id[i], name, 31)

						if (is_user_bot(id)) {							// KWo
							engclient_cmd(id, "drop", name)							
						} else {							
							client_cmd(id, "drop %s", name)
						}
						console_print(id,"Dropped %s", name)
						drop[0] = wpn_id[i]
						drop[1] = 1
						drop[2] = id
						set_task(0.2, "timed_replace", 0, drop, 3)						
						slotfree=true  // KWo
					}
				}
				get_weaponname(wpn,wepname,31)
				if(is_user_alive(id)) {
					if (slotfree || canGetGun(id, wpn)) { // KWo (added because amxmodx doesn't see yet the slot is already free)
//					while (canGetGun(id, wpn)) {
						give_item(id, wepname)
					}
				}
				if (s==1) {
					g_LastWep[id][0] = wpn
				} else if (s==0) {
					g_LastWep[id][1] = wpn
				}
			}
		}
	}
	return PLUGIN_HANDLED
}
*/

public giveGun(id,weapon,s)
{
	if(!is_user_alive(id)) return PLUGIN_CONTINUE
	if((weapon < 0) || (weapon > 30) || (weapon == 2) || (weapon == 6) ) return PLUGIN_CONTINUE
	if (isWpBlocked(weapon) || isWpOverload(id, weapon))	return PLUGIN_CONTINUE

	new bool:hold
	if (get_cvar_num("csdm_hold_many")) 
	{
		hold=true
	} 
	else
	{
		hold=false
	}
	
	if (!hold)
	{	
		new wpn_id[32], num
		new u_slot
		u_slot=getWepSlot(weapon)  	
		new i
		num = 0
		get_user_weapons(id,wpn_id,num)
		for(i = 0; i<num; i++)
  	{
			if ( (getWepSlot(wpn_id[i]) == u_slot) && (wpn_id[i]!=weapon) ) 
			{
				if(wpn_id[i] != 4 && wpn_id[i] != 9 && wpn_id[i] != 25 && wpn_id[i] != 29)
				{
					new name[32], drop[3]
					get_weaponname(wpn_id[i], name, 31)
					if (is_user_bot(id)) {
						engclient_cmd(id, "drop", name)
					} else {
						client_cmd(id, "drop %s", name)
					}
					drop[0] = wpn_id[i]
					drop[1] = 1
					drop[2] = id
					set_task(0.2, "timed_replace", 0, drop, 3)
				}
			}
		}
	}

	switch(weapon)
	{
		case 1:
		{
			give_item(id,"weapon_p228")
			give_item(id,"ammo_357sig")
			give_item(id,"ammo_357sig")
			give_item(id,"ammo_357sig")
			give_item(id,"ammo_357sig")
			give_item(id,"ammo_357sig")
			give_item(id,"ammo_357sig")	
		}
		case 3:
		{
			give_item(id,"weapon_scout")
			give_item(id,"ammo_762nato")
			give_item(id,"ammo_762nato")
			give_item(id,"ammo_762nato")	
		}
		case 4:
		{
			give_item(id,"weapon_hegrenade")
		}
		case 5:
		{
			give_item(id,"weapon_xm1014")
			give_item(id,"ammo_buckshot")
			give_item(id,"ammo_buckshot")
			give_item(id,"ammo_buckshot")
			give_item(id,"ammo_buckshot")
		}
		case 7:
		{
			give_item(id,"weapon_mac10")
			give_item(id,"weapon_mac10")
			give_item(id,"weapon_mac10")
			give_item(id,"weapon_mac10")	
			give_item(id,"weapon_mac10")									
		}
		case 8:
		{
			give_item(id,"weapon_aug")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
		}
		case 9:
		{ 
			give_item(id,"weapon_smokegrenade")
		}
		case 10:
		{
			give_item(id,"weapon_elite")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")	
		}
		case 11:
		{
			give_item(id,"weapon_fiveseven")
			give_item(id,"ammo_57mm")
			give_item(id,"ammo_57mm")
			give_item(id,"ammo_57mm")
			give_item(id,"ammo_57mm")	
		}
		case 12:
		{
			give_item(id,"weapon_ump45")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
		}
		case 13:
		{
			give_item(id,"weapon_sg550")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
		}
		case 14:
		{
			give_item(id,"weapon_galil")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
		}
		case 15:
		{
			give_item(id,"weapon_famas")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
		}
		case 16:
		{
			give_item(id,"weapon_usp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")
			give_item(id,"ammo_45acp")		
			give_item(id,"ammo_45acp")
		}
		case 17:
		{
			give_item(id,"weapon_glock18")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")	
		}
		case 18:
		{
			give_item(id,"weapon_awp")
			give_item(id,"ammo_338magnum")
			give_item(id,"ammo_338magnum")
			give_item(id,"ammo_338magnum")	
		}
		case 19:
		{
			give_item(id,"weapon_mp5navy")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")			
		}
		case 20:
		{
			give_item(id,"weapon_m249")
			give_item(id,"weapon_m249")
			give_item(id,"weapon_m249")
			give_item(id,"weapon_m249")
			give_item(id,"weapon_m249")
		}
		case 21:
		{	
			give_item(id,"weapon_m3")
			give_item(id,"ammo_buckshot")
			give_item(id,"ammo_buckshot")
			give_item(id,"ammo_buckshot")
			give_item(id,"ammo_buckshot")
		}
		case 22:
		{
			give_item(id,"weapon_m4a1")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")	
		}
		case 23:
		{
			give_item(id,"weapon_tmp")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
			give_item(id,"ammo_9mm")
		}
		case 24:
		{
			give_item(id,"weapon_g3sg1")
			give_item(id,"ammo_762nato")
			give_item(id,"ammo_762nato")
			give_item(id,"ammo_762nato")	
		}
		case 25:
		{
			give_item(id,"weapon_flashbang")
		}
		case 26:
		{
			give_item(id,"weapon_deagle")
			give_item(id,"ammo_50ae")
			give_item(id,"ammo_50ae")
			give_item(id,"ammo_50ae")
			give_item(id,"ammo_50ae")
			give_item(id,"ammo_50ae")
			give_item(id,"ammo_50ae")
			give_item(id,"ammo_50ae")	
		}
		case 27:
		{
			give_item(id,"weapon_sg552")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")
			give_item(id,"ammo_556nato")	
		}
		case 28:
		{
			give_item(id,"weapon_ak47")
			give_item(id,"ammo_762nato")
			give_item(id,"ammo_762nato")
			give_item(id,"ammo_762nato")	
		}
		case 29: give_item(id,"weapon_knife")
		case 30:
		{
			give_item(id,"weapon_p90")
			give_item(id,"ammo_57mm")
			give_item(id,"ammo_57mm")
			give_item(id,"ammo_57mm")
			give_item(id,"ammo_57mm")
		}

/*		
		case 31:
		{
			give_item(id,"weapon_shield")
		}
		case 32:
		{
			give_item(id,"item_assaultsuit")
		}
		case 33:
		{
			cs_set_user_nvg(id,1)
		}
*/		
	}
	if (s==1) {
		g_LastWep[id][0] = weapon
	} else if (s==0) {
		g_LastWep[id][1] = weapon
	} 
	return PLUGIN_CONTINUE
}

public ArmorMenu(id)
{
	if (is_user_alive(id)) {
		if (get_cvar_num("csdm_enable_amenu") && !(get_cvar_num("csdm_auto_equip")) ) {		// KWo
			new menuBody[192]
			new key
			
			if (!is_user_bot(id)) {
				format(menuBody, 191, "\rCSDM: Armor\R^n^n\y1.\w Yes, armor up^n\y2.\w No armor")
				key = (1<<0)|(1<<1)
				show_menu(id, key, menuBody)
			} else {
				new param[1]
				param[0]=id
				set_task(1.0,"bot_armor_menu",100+id,param,1)
			}			
		} else {
			if (get_cvar_num("csdm_auto_equip")) {			// KWo auto-equip		
				set_user_armor(id, 100)
				give_item(id, "item_assaultsuit")
			}
			GrenadeMenu(id)
		}
	}
}

public GrenadeMenu(id)
{
	if (is_user_alive(id)) {
		if (get_cvar_num("csdm_enable_gmenu") && !(get_cvar_num("csdm_auto_gren")) ) {	// KWo
			new menuBody[192]
			new key

			if (!is_user_bot(id))
			{
				format(menuBody, 191, "\rCSDM: Grenades\R^n^n\y1.\w All Grenades^n\y2.\w No grenades")
				key = (1<<0)|(1<<1)		
				show_menu(id, key, menuBody)
			} else {
				new param[1]
				param[0]=id
				set_task(1.0,"bot_gren_menu",200+id,param,1)
			}			
		} else {
			if (get_cvar_num("csdm_auto_gren")) {
				giveGun(id, CSW_HEGRENADE, 2)
				giveGun(id, CSW_SMOKEGRENADE, 2)
				giveGun(id, CSW_FLASHBANG, 2)
				giveGun(id, CSW_FLASHBANG, 2)
			}
		}		
	}
}

public EquipMenu(id)
{
	if (is_user_alive(id)) {
		new menuBody[192] 
		new key
		
		if (!is_user_bot(id))
		{
			format(menuBody, 191, "\rCSDM: Equip\R^n^n\y1.\w New Weapons^n\y2.\w Previous Setup^n\y3.\w 2+Don't show menu again")
			key = (1<<0)|(1<<1)|(1<<2)
			show_menu(id, key, menuBody)
		} else {
			new param[1]
			param[0]=id
			set_task(1.0,"bot_equip_menu",300+id,param,1)
		}			
	}
}

public pWeaponMenu(id,mpage)	//By Freecode
{
	g_MenuPos[id] = mpage
	new menuBody[1024]
	new len
	new key
	
	if (!is_user_bot(id)) 
	{
		if(mpage == 1)
		{
			if (get_cvar_num("csdm_steam")) {
				len = format(menuBody,1023,"\rCSDM: Primary Weapon\R^n^n\y1.\w M4A1^n\y2.\w AK47^n\y3.\w AUG^n\y4.\w SG552^n\y5.\w Galil^n\y6.\w Famas")
				len += format(menuBody[len],1023-len,"^n\y7.\w Next^n\y8.\w None")
				key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)
			} else {
				len = format(menuBody,1023,"\rCSDM: Primary Weapon\R^n^n\y1.\w M4A1^n\y2.\w AK47^n\y3.\w AUG^n\y4.\w SG552")
				len += format(menuBody[len],1023-len,"^n\y5.\w Next^n\y6.\w None")
				key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)
			}
		} else if(mpage == 2) {
			len = format(menuBody,1023,"\rCSDM: Primary Weapon\R^n^n\y1.\w Scout^n\y2.\w AWP^n\y3.\w SG550^n\y4.\w M249^n\y5.\w G3SG1^n\y6.\w Back^n\y7.\w Next")
			len += format(menuBody[len],1023-len,"^n\y8.\w Exit")
			key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)
		} else if(mpage == 3) {
			len = format(menuBody,1023,"\rCSDM: Primary Weapon\R^n^n\y1.\w UMP 45^n\y2.\w MP5 Navy^n\y3.\w M3^n\y4.\w XM1014^n\y5.\w TMP^n\y6.\w Mac 10")
			len += format(menuBody[len],1023-len,"^n\y7.\w P90^n\y8.\w Back^n\y9.\w Exit")
			key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)
		}
		show_menu(id,key,menuBody)
	} else {
		new param[1]
		param[0]=id
		set_task(1.0,"bot_prim_weap",400+id+32*mpage,param,1)  // KWo - new task number
	}
}

public sWeaponMenu(id)	//By Freecode
{
	new menuB[1024]
	new key
	if (!is_user_bot(id))
	{
		format(menuB,1023,"\rCSDM: Secondary Weapon\R^n^n\y1.\w USP^n\y2.\w Glock^n\y3.\w Deagle^n\y4.\w P228t^n\y5.\w Elite^n\y6.\w Five Seven^n\y7.\w None")
		key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)
		show_menu(id,key,menuB)
	} else {
		new param[1]
		param[0]=id
		set_task(1.0,"bot_sec_weap",600+id,param,1)
	}
}

public ArmorChoice(id, key)
{
	if (!id) return	// KWo
	if (!is_user_alive(id)) return	// KWo - both changes because of bots - their task are delayed, so they may not happen if bot get kicked
	new key_arm = 0
	if (is_user_bot(id)) 
		key_arm = random_num(0,1)
	else 
		key_arm = key 
	switch(key_arm)
	{
		case 0:
		{
			set_user_armor(id, 100)
			give_item(id, "item_assaultsuit")
			g_getArmor[id] = true
		}
		case 1:
		{
			g_getArmor[id] = false
		}	
	}
	GrenadeMenu(id)
}

public GrenChoice(id, key)
{
// KWo like above, but use "key_gre"
	if (!id) return // KWo
	if (!is_user_alive(id)) return // KWo - reason above
	new key_gre = 0
	if (is_user_bot(id)) 
		key_gre = random_num(0,1)
	else 
		key_gre = key 

	switch(key_gre)
	{
		case 0:
		{
			giveGun(id, CSW_HEGRENADE, 2)
			giveGun(id, CSW_SMOKEGRENADE, 2)
			giveGun(id, CSW_FLASHBANG, 2)
			giveGun(id, CSW_FLASHBANG, 2)
			g_getGrens[id] = true
		}
		case 1:
		{
			g_getGrens[id] = false
		}
	}
}

public EquipChoice(id, key)
{
// KWo - like above, but I use "key_equ"
	if (!id) return
	if (!is_user_alive(id)) return
	new key_equ = 0
	if (is_user_bot(id)) key_equ = 0
	else key_equ = key 

	switch(key_equ)
	{
		case 0:
		{
			sWeaponMenu(id)
		}
		case 1:
		{
			if (g_LastWep[id][0] > 0) giveGun(id, g_LastWep[id][0], 1)  // KRoT@L
			if (g_LastWep[id][1] > 0) giveGun(id, g_LastWep[id][1], 0)  // KRoT@L
			if (g_getArmor[id] || get_cvar_num("csdm_auto_equip")) {  // added by KWo
				set_user_armor(id, 100)
				give_item(id, "item_assaultsuit")
			}
			if (g_getGrens[id] || get_cvar_num("csdm_auto_gren")) {  // added by KWo
				giveGun(id, CSW_HEGRENADE, 2)
				giveGun(id, CSW_SMOKEGRENADE, 2)
				giveGun(id, CSW_FLASHBANG, 2)
				giveGun(id, CSW_FLASHBANG, 2)
			}
		}
		case 2:
		{
			if (g_LastWep[id][0] > 0) giveGun(id, g_LastWep[id][0], 1) // KRoT@L
			if (g_LastWep[id][1] > 0) giveGun(id, g_LastWep[id][1], 0) // KRoT@L
			if (g_getArmor[id] || get_cvar_num("csdm_auto_equip")) { // added by KWo
				set_user_armor(id, 100)
				give_item(id, "item_assaultsuit")
			}
			if (g_getGrens[id] || get_cvar_num("csdm_auto_gren")) {  // added by KWo
				giveGun(id, CSW_HEGRENADE, 2)
				giveGun(id, CSW_SMOKEGRENADE, 2)
				giveGun(id, CSW_FLASHBANG, 2)
				giveGun(id, CSW_FLASHBANG, 2)
			}			
			ShowMenu[id] = false
			client_print(id, print_chat, "[CSDM] Type ^"enable_menu^" to re-enable, or ^"guns^" to bring up.")
		}
	}
}

public PrimaryWeapon(id,key)	//By Freecode
{
	if (!id) return PLUGIN_HANDLED
	if (!is_user_alive(id)) return PLUGIN_HANDLED
	Swep[id] = false
	new plname[32]
	get_user_name(id,plname,31)

// KWo - like above but here and few line after I use "key_pwp"

	if(g_MenuPos[id] == 1)
	{
		new key_pwp = 0
		if (is_user_bot(id)) 
		{	
			if (!get_cvar_num("csdm_steam")) key_pwp = random_num(0,8)
			else key_pwp = random_num(0,10)
			if (!get_cvar_num("csdm_steam") && (key_pwp == 4 || key_pwp == 5) ) key_pwp = 6
			if (key_pwp > 5) key_pwp = 6
		} else {
			key_pwp = key
		}
		switch (key_pwp)
		{
			case 0:
			{
				if (isWpBlocked(CSW_M4A1) || isWpOverload(id, CSW_M4A1)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_M4A1,0)
					ArmorMenu(id)
				}
			}
			case 1: 
			{
				if (isWpBlocked(CSW_AK47) || isWpOverload(id, CSW_AK47)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_AK47,0)
					ArmorMenu(id)
				}
			}
			case 2: 
			{
				if (isWpBlocked(CSW_AUG) || isWpOverload(id, CSW_AUG)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_AUG,0)
					ArmorMenu(id)
				}
			}
			case 3:
			{
				if (isWpBlocked(CSW_SG552) || isWpOverload(id, CSW_SG552)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_SG552,0)
					ArmorMenu(id)
				}
			}
			case 4:
			{
				if (get_cvar_num("csdm_steam")) {
					if (isWpBlocked(CSW_GALIL) || isWpOverload(id, CSW_GALIL)) {
						client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
						pWeaponMenu(id, 1)
					} else {
						giveGun(id,CSW_GALIL,0)
						ArmorMenu(id)
					}
				} else {
					pWeaponMenu(id, 2)
				}
			}
			case 5:
			{
				if (get_cvar_num("csdm_steam")) {
					if (isWpBlocked(CSW_FAMAS) || isWpOverload(id, CSW_FAMAS)) {
						client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
						pWeaponMenu(id, 1)
					} else {				
						giveGun(id,CSW_FAMAS,0)
						ArmorMenu(id)
					}
				} else {
					ArmorMenu(id)
				}
			}
			case 6: pWeaponMenu(id,2)
			case 7: ArmorMenu(id)
		}
	}
	else if(g_MenuPos[id] == 2)
	{
		new key_pwp = 0
		if (is_user_bot(id)) {
			key_pwp = random_num(0,5)
			if (key_pwp > 4) key_pwp = 6
		}
		else key_pwp = key
		switch (key_pwp)
		{
			case 0:
			{
				if (isWpBlocked(CSW_SCOUT) || isWpOverload(id, CSW_SCOUT)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_SCOUT,0)									
					ArmorMenu(id)
				}
			}
			case 1:
			{
				if (isWpBlocked(CSW_AWP) || isWpOverload(id, CSW_AWP)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_AWP,0)
					ArmorMenu(id)
				}
			}
			case 2:
			{
				if (isWpBlocked(CSW_SG550) || isWpOverload(id, CSW_SG550)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_SG550,0)
					ArmorMenu(id)
				}
			}
			case 3:
			{
				if (isWpBlocked(CSW_M249) || isWpOverload(id, CSW_M249)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_M249,0)
					ArmorMenu(id)
				}
			}
			case 4:
			{
				if (isWpBlocked(CSW_G3SG1) || isWpOverload(id, CSW_G3SG1)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_G3SG1,0)
					ArmorMenu(id)
				}
			}
			case 5: pWeaponMenu(id,1)
			case 6: pWeaponMenu(id,3)
			case 7: ArmorMenu(id)
		}
	}
	else if(g_MenuPos[id] == 3)
	{
		new key_pwp = 0
		if (is_user_bot(id)) 
			key_pwp = random_num(0,6)
		else 
			key_pwp = key
		switch (key_pwp)
		{
			case 0:
			{
				if (isWpBlocked(CSW_UMP45) || isWpOverload(id, CSW_UMP45)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_UMP45,0)
					ArmorMenu(id)
				}
			}
			case 1:
			{
				if (isWpBlocked(CSW_MP5NAVY) || isWpOverload(id, CSW_MP5NAVY)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_MP5NAVY,0)
					ArmorMenu(id)
				}
			}
			case 2:
			{
				if (isWpBlocked(CSW_M3) || isWpOverload(id, CSW_M3)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_M3,0)
					ArmorMenu(id)
				}
			}
			case 3:
			{
				if (isWpBlocked(CSW_XM1014) || isWpOverload(id, CSW_XM1014)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_XM1014,0)
					ArmorMenu(id)
				}
			}
			case 4:
			{
				if (isWpBlocked(CSW_TMP) || isWpOverload(id, CSW_TMP)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_TMP,0)
					ArmorMenu(id)
				}
			}
			case 5: 
			{
				if (isWpBlocked(CSW_MAC10) || isWpOverload(id, CSW_MAC10)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_MAC10,0)
					ArmorMenu(id)
				}
			}
			case 6: 
			{
				if (isWpBlocked(CSW_P90) || isWpOverload(id, CSW_P90)) {
					client_print(id, print_chat, "[CSDM] This weapon is unavailable!")
					pWeaponMenu(id, 1)
				} else {
					giveGun(id,CSW_P90,0)
					ArmorMenu(id)
				}
			}
			case 7: pWeaponMenu(id,2)
			case 8:	ArmorMenu(id)
		}
	}
	return PLUGIN_HANDLED
}

public SecondWeapon(id,key)	//By Freecode
{
	if (!id) return
	if (!is_user_alive(id)) return
	Swep[id] = false
	
	new key_swp = 0
	if (is_user_bot(id)) 
		key_swp = random_num(0,6)
	else 
		key_swp = key 
	
	switch (key_swp)
	{
		case 0: 
			{
				giveGun(id,CSW_USP,1)
				pWeaponMenu(id, 1)
			}
		case 1: 
			{
				giveGun(id,CSW_GLOCK18,1)
				pWeaponMenu(id, 1)
			}
		case 2:
			{
				giveGun(id,CSW_DEAGLE,1)
				pWeaponMenu(id, 1)
			}
		case 3: 
			{
				giveGun(id,CSW_P228,1)
				pWeaponMenu(id, 1)
			}
		case 4: 
			{
				giveGun(id,CSW_ELITE,1)
				pWeaponMenu(id, 1)
			}
		case 5:
			{
				giveGun(id,CSW_FIVESEVEN,1)
				pWeaponMenu(id, 1)
			}
		case 6:
			{
				pWeaponMenu(id, 1)
			}
	}
}

public pfn_touch(ptr, ptd)
{
	new ptrClass[32]
	new ptdClass[32]
	new name[32]
	new Float:Time = g_ItemTime
	new g_wp
	new Item[2], id, x, y
	new i

	if (!g_CSDM_ACTIVE) {  // KWo
		return PLUGIN_CONTINUE
	}

	if (ptd > get_maxplayers() || ptd < 1 || ptr < 1 )  //  KWo
	{
		return PLUGIN_CONTINUE
	}
	if ( (!is_valid_ent(ptr)) || (!is_valid_ent(ptd)) ) return PLUGIN_CONTINUE
	entity_get_string(ptr, EV_SZ_classname, ptrClass, 32)
	entity_get_string(ptd, EV_SZ_classname, ptdClass, 32)

	if (cwrap(ptrClass, "csdmw_") && equal(ptdClass, "player")) {
		new menuid, keys		// KWo

		if (is_user_alive(ptd)) {		
			get_user_menu(ptd, menuid, keys) // KWo
			if ( (menuid==menuid_6) || (menuid==menuid_7) )  return PLUGIN_CONTINUE		// KWo	- player is using entities menu
		} 
		if (!is_user_connected(ptd)) return PLUGIN_CONTINUE  // KWo
		
		g_wp = getCSDMWpId(ptrClass)
		get_weaponname(g_wp, name, 32)
		id = findEntId(ptr)
		if (id && g_wp) {
			if (canGetGun(ptd, g_wp)) {
				safe_rm_ent(ptr)
				give_item(ptd, name)
				EntId[id] = 0
				Item[0] = id
				set_task(Time, "replenish", 0, Item, 2)
			}
		} else {
			if (canGetGun(ptd, g_wp)) {
				//Do not replenish, THIS IS A TEMPENT			
				new dropid = findDrop(ptr)
				give_item(ptd, name)
				if (dropid) {
					destroyDrop(dropid)
				} else {
					safe_rm_ent(ptr)
				}
			}
		}
	}
	
	if (!g_CSDM_ADD_ITEMS) {
		return PLUGIN_CONTINUE
	}
	
	if (cwrap(ptrClass, "csdm_") && equal(ptdClass, "player")) {
		//THIS WEAPON WAS SET IN THE MAP THROUGH CSDM_SETENT - PERMANENT
		id = findEntId(ptr)
		if (id) {
			if (cwrap(EntList[id], "pistol_ammo")) {
				if (canGetAmmo(ptd, PISTOL_AMMO)) {
					giveAmmoType(ptd, PISTOL_AMMO)
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "shotgun_ammo")) {
				if (canGetAmmo(ptd, SHOTGUN_AMMO)) {
					giveAmmoType(ptd, SHOTGUN_AMMO)
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "smg_ammo")) {
				if (canGetAmmo(ptd, SMG_AMMO)) {
					giveAmmoType(ptd, SMG_AMMO)
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "rifle_ammo")) {
				if (canGetAmmo(ptd, RIFLE_AMMO)) {
					giveAmmoType(ptd, RIFLE_AMMO)
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "full_ammo")) {
					new bool:GetAmmo=false
					if(get_cvar_num("csdm_asskicr")) {
						if (canGetAmmo(ptd, 1) || canGetAmmo(ptd, 2) || canGetAmmo(ptd, 2) || canGetAmmo(ptd, 4) || canGetAmmo(ptd, 5) || canGetAmmo(ptd, 6)) {
							GetAmmo=true
						}
					}else{
						if (canGetAmmo(ptd, 1) || canGetAmmo(ptd, 2) || canGetAmmo(ptd, 2) || canGetAmmo(ptd, 4) ) {
							GetAmmo=true
						}
					}
					if (GetAmmo) {
						if (canGetAmmo(ptd, 1)) giveAmmoType(ptd, PISTOL_AMMO)
						if (canGetAmmo(ptd, 2)) giveAmmoType(ptd, SHOTGUN_AMMO)
						if (canGetAmmo(ptd, 3)) giveAmmoType(ptd, SMG_AMMO)
						if (canGetAmmo(ptd, 4)) giveAmmoType(ptd, RIFLE_AMMO)
						if (get_cvar_num("csdm_asskicr")) {
							if (canGetAmmo(ptd, 5)) giveAmmoType(ptd, AWP_AMMO)
							if (canGetAmmo(ptd, 6)) giveAmmoType(ptd, PARA_AMMO)
						}
						safe_rm_ent(ptr)
						EntId[id] = 0
						Item[0] = id
						set_task(Time, "replenish", 0, Item, 2)
					}
			} else if (cwrap(EntList[id], "armor")) {
				if (get_user_armor(ptd) < 100) {
					give_item(ptd, "item_assaultsuit")
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "battery")) {
				y = get_cvar_num("csdm_battery")
				x = get_user_armor(ptd)
				if (x < 100) {
					if (x+y > 100) {
						set_user_armor(ptd, 100)
					} else {
						set_user_armor(ptd, x+y)
					}
					if (get_cvar_num("csdm_sounds")) {
						emit_sound(ptr, CHAN_ITEM, "items/gunpickup2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
					}
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "healthkit")) {
				y = get_cvar_num("csdm_medkit")
				x = get_user_health(ptd)
				if (x < 100) {
					if (x+y > 100) {
						set_user_health(ptd, 100)
					} else {
						set_user_health(ptd, x+y)
					}
					if (get_cvar_num("csdm_sounds")) {
						emit_sound(ptr, CHAN_ITEM, "items/smallmedkit1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
					}
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
				}
			} else if (cwrap(EntList[id], "longjump")) {
				if (!HasLongJump[ptd]) {
					give_item(ptd, "item_longjump")
					HasLongJump[ptd] = true
					if (get_cvar_num("csdm_sounds")) {
						emit_sound(ptr, CHAN_ITEM, "items/clipinsert1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
					}
					safe_rm_ent(ptr)
					EntId[id] = 0
					Item[0] = id
					set_task(Time, "replenish", 0, Item, 2)
					if (get_cvar_num("csdm_explain")) {
						client_print(ptd, print_chat, "[CSDM] To use LongJump, press DUCK+JUMP while moving FORWARD!")
					}
				}
			} else if (cwrap(EntList[id], "awp_ammo")) {
				if (get_cvar_num("csdm_asskicr")) {
					if (canGetAmmo(ptd, AWP_AMMO)) {
						giveAmmoType(ptd, AWP_AMMO)
						safe_rm_ent(ptr)
						EntId[id] = 0
						Item[0] = id
						set_task(Time, "replenish", 0, Item, 2)
					}
				}
			} else if (cwrap(EntList[id], "para_ammo")) {
				if (get_cvar_num("csdm_asskicr")) {
					if (canGetAmmo(ptd, PARA_AMMO)) {
						giveAmmoType(ptd, PARA_AMMO)
						safe_rm_ent(ptr)
						EntId[id] = 0
						Item[0] = id
						set_task(Time, "replenish", 0, Item, 2)
					}
				}
			}
		}
	} else if (equali(ptrClass, "drop_pack") && equali(ptdClass, "player")) {
		//Go through pack contents and award bonii
		new pid = findPackId(ptr)
		if (pid) {
			if (get_user_health(ptd)+15>100) {
				set_user_health(ptd, 100)
			} else {
				set_user_health(ptd, get_user_health(ptd)+15)
			}
			if (get_user_armor(ptd)+15>100) {
				set_user_armor(ptd, 100)
			} else {
				set_user_armor(ptd, get_user_armor(ptd)+15)
			}
			if (get_cvar_num("csdm_sounds")) {
				emit_sound(ptd, CHAN_ITEM, "items/ammopickup2.wav", 0.85, ATTN_NORM, 0, 150)
			}
			new iType
			if (get_cvar_num("csdm_asskicr")) {
				iType=6 
			}else{
				iType=4
			}
			for (i=0; i<iType; i++) {
				g_wp = PackAmmo[pid][i]
				if (g_wp) {
					if (canGetGun(ptd, g_wp)) {
						get_weaponname(g_wp, name, 20)
						give_item(ptd, name)
					}
					giveAmmoType(ptd, i+1)
				}
			}
			for (i=0; i<3; i++) {
				g_wp = PackGren[pid][i]
				if (g_wp) {
					if (canGetGun(ptd, g_wp)) {
						get_weaponname(g_wp, name, 20)
						give_item(ptd, name)
					}
				}
			}
			if (!HasLongJump[ptd]) {
				if (PackJump[pid]) {
					give_item(ptd, "item_longjump")
					HasLongJump[ptd] = true
					if (get_cvar_num("csdm_explain")) {
						client_print(ptd, print_chat, "[CSDM] To use LongJump, press DUCK+JUMP while moving FORWARD!")
					}
				}
			}
			//Get rid of pack
			destroyPack(pid)
		}
	}
	      
	return PLUGIN_CONTINUE
}

public replenish(Item[])
{
	new id = Item[0]

	if (id) {
		EntId[id] = makeEnt(id)
		if (EntId[id]) {
			if (get_cvar_num("csdm_sounds")) {
				emit_sound(EntId[id], CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM, 0, 150)
			}
		} else {
			//failed to replenish, make a new one
			new Float:Time = g_ItemTime
			set_task(Time, "replenish", 0, Item, 2)
		}
	}
}


findNextTask()
{
	new i
	for (i=1; i<MAX_TASKS; i++) {
		if (!Tasks[i]) {
			Tasks[i] = 5000 + i	// KRoT@L
			return i
		}
	}
	destroyTask(1)
	Tasks[1] = 5001		// KRoT@L
	return 1
}

findNextDrop()
{
	new i
	for (i=1; i<MAX_DROP; i++) {
		if (!DropId[i] && !DropTask[i]) {
			return i
		}
	}
	destroyDrop(1)
	return 1
}

createDrop(entid)
{
	if (!entid) {
		return 0
	}
	new id = findNextDrop()
	new taskid = findNextTask()
	new Float:Time = get_cvar_float("csdm_delete_time")
	new Drop[2]
	
	DropId[id] = entid
	DropTask[id] = taskid
	Drop[0] = id
	
	if (Time >= 5.0) {
		set_task(Time, "timed_rem_drop", Tasks[taskid], Drop, 2)
	}
	
	return id
}

findDrop(entid)
{
	new i
	for (i=1; i<MAX_DROP; i++) {
		if (DropId[i] == entid) {
			return i
		}
	}
	
	return 0
}

destroyTask(id)
{
	if (id && Tasks[id]) {
		remove_task(Tasks[id])
		Tasks[id] = 0
	}
	
	return id
}

destroyDrop(id)
{
	new entid = DropId[id]
	new taskid = DropTask[id]
	
	safe_rm_ent(entid)
	destroyTask(taskid)
	DropId[id] = 0
	DropTask[id] = 0	// KRoT@L	
	return id
}

findNextZeroPack()
{
	//This function will search for an index to store pack data
	new ret
	new i
	
	for (i=1; i<MAX_DROP; i++) {
		if (!PackId[i]) {
			return i
		}
	}

	ret = destroyPack(1)
	
	return ret
}

createPack(id, Origin[3])
{
	new Float:Vec[3]
	new Float:Time = get_cvar_float("csdm_delete_time")
	new pid = findNextZeroPack()
	new i
	
	IVecFVec(Origin, Vec)
	
	//Create physical pack
	new entid = mkent()
	//Now, a pack is actually a tempent.
	if (entid) {
		PackId[pid] = entid
		entity_set_string(entid, EV_SZ_classname, "drop_pack")
		entity_set_model(entid, "models/w_weaponbox.mdl")
		entity_set_origin(entid, Vec)
		entity_set_int(entid, EV_INT_solid, 1)
		entity_set_int(entid, EV_INT_movetype, 6)
		entity_set_edict(entid, EV_ENT_owner, id)
		new wps[32], num, type
		num = 0
		get_user_weapons(id, wps, num)
		for (i=0; i<num; i++) {
			//populate the pack
			type = getWepAmmoType(wps[i])
			new iType
			if (get_cvar_num("csdm_asskicr")) {
				iType=7
			}else{
				iType=5
			}
			if (type > 0 && type < iType) { 
				PackAmmo[pid][type-1] = wps[i]
			}
			if (type == iType) {
				if (wps[i] == CSW_HEGRENADE) {
					PackGren[pid][2] = CSW_HEGRENADE
				}
				if (wps[i] == CSW_SMOKEGRENADE) {
					PackGren[pid][1] = CSW_SMOKEGRENADE
				}
				if (wps[i] == CSW_FLASHBANG) {
					PackGren[pid][0] = CSW_FLASHBANG
				}
			}
		}
		if (HasLongJump[id]) {
			if (get_cvar_num("csdm_pack_jumps")) {
				PackJump[pid] = true
			} else {
				PackJump[pid] = false
			}
		} else {
			PackJump[pid] = false
		}
		if (Time > 30.0) {
			Time = 30.0
		}
		new Drop[2]
		Drop[0] = pid
		new taskid = findNextTask()
		PackTask[pid] = taskid
	
		set_task(Time, "delete_drop_pack", Tasks[taskid], Drop, 2)
	}
	
	return pid
}

public delete_drop_pack(data[])
{
	new pid = data[0]
	
	destroyPack(pid)

	return PLUGIN_CONTINUE
}

findPackId(entid)
{
	//Given an entity id, this will return the index to it in the pack list
	new id = 0
	new i
	
	if (!entid) {
		return 0
	}
	
	for (i=0; i<MAX_DROP; i++) {
		if (PackId[i] == entid) {
			id = i
		}
	}
	
	return id
}

findEntId(entid)
{
	//Given an entity id, this will return the index to it in the entity list
	new id = 0
	new i
	
	if (!entid) {
		return 0
	}
	
	for (i=1; i<EntCount; i++) {
		if (EntId[i] == entid) {
			id = i
		}
	}
	
	return id
}

getWepModel(wp, model[], imax)
{
	switch (wp) {
		case CSW_P228:
			copy(model, imax, "models/w_p228.mdl")
		case CSW_SCOUT:
			copy(model, imax, "models/w_scout.mdl")
		case CSW_HEGRENADE:
			copy(model, imax, "models/w_hegrenade.mdl")
		case CSW_XM1014:
			copy(model, imax, "models/w_xm1014.mdl")
		case CSW_C4:
			copy(model, imax, "models/w_backpack.mdl")
		case CSW_MAC10:
			copy(model, imax, "models/w_mac10.mdl")
		case CSW_AUG:
			copy(model, imax, "models/w_aug.mdl")
		case CSW_SMOKEGRENADE:
			copy(model, imax, "models/w_smokegrenade.mdl")
		case CSW_ELITE:
			copy(model, imax, "models/w_elite.mdl")
		case CSW_FIVESEVEN:
			copy(model, imax, "models/w_fiveseven.mdl")
		case CSW_UMP45:
			copy(model, imax, "models/w_ump45.mdl")
		case CSW_SG550:
			copy(model, imax, "models/w_sg550.mdl")
		case CSW_GALIL:
			copy(model, imax, "models/w_galil.mdl")
		case CSW_FAMAS:
			copy(model, imax, "models/w_famas.mdl")
		case CSW_USP:
			copy(model, imax, "models/w_usp.mdl")
		case CSW_GLOCK18:
			copy(model, imax, "models/w_glock18.mdl")
		case CSW_AWP:
			copy(model, imax, "models/w_awp.mdl")
		case CSW_MP5NAVY:
			copy(model, imax, "models/w_mp5.mdl")
		case CSW_M249:
			copy(model, imax, "models/w_m249.mdl")
		case CSW_M3:
			copy(model, imax, "models/w_m3.mdl")
		case CSW_M4A1:
			copy(model, imax, "models/w_m4a1.mdl")
		case CSW_TMP:
			copy(model, imax, "models/w_tmp.mdl")
		case CSW_G3SG1:
			copy(model, imax, "models/w_g3sg1.mdl")
		case CSW_FLASHBANG:
			copy(model, imax, "models/w_flashbang.mdl")
		case CSW_DEAGLE:
			copy(model, imax, "models/w_deagle.mdl")
		case CSW_SG552:
			copy(model, imax, "models/w_sg552.mdl")
		case CSW_AK47:
			copy(model, imax, "models/w_ak47.mdl")
		case CSW_KNIFE:
			copy(model, imax, "models/w_knife.mdl")
		case CSW_P90:
			copy(model, imax, "models/w_p90.mdl")			
	}
	
	return 1
}

getCSDMWp(wp, model[], imax)
{
	switch (wp) {
		case CSW_P228:
			copy(model, imax, "csdmw_p228")
		case CSW_SCOUT:
			copy(model, imax, "csdmw_scout")
		case CSW_HEGRENADE:
			copy(model, imax, "csdmw_hegrenade")
		case CSW_XM1014:
			copy(model, imax, "csdmw_xm1014")
		case CSW_C4:
			copy(model, imax, "csdmw_c4")
		case CSW_MAC10:
			copy(model, imax, "csdmw_mac10")
		case CSW_AUG:
			copy(model, imax, "csdmw_aug")
		case CSW_SMOKEGRENADE:
			copy(model, imax, "csdmw_smokegrenade")
		case CSW_ELITE:
			copy(model, imax, "csdmw_elite")
		case CSW_FIVESEVEN:
			copy(model, imax, "csdmw_fiveseven")
		case CSW_UMP45:
			copy(model, imax, "csdmw_ump45")
		case CSW_SG550:
			copy(model, imax, "csdmw_sg550")
		case CSW_GALIL:
			copy(model, imax, "csdmw_galil")
		case CSW_FAMAS:
			copy(model, imax, "csdmw_famas")
		case CSW_USP:
			copy(model, imax, "csdmw_usp")
		case CSW_GLOCK18:
			copy(model, imax, "csdmw_glock18")
		case CSW_AWP:
			copy(model, imax, "csdmw_awp")
		case CSW_MP5NAVY:
			copy(model, imax, "csdmw_mp5navy")
		case CSW_M249:
			copy(model, imax, "csdmw_m249")
		case CSW_M3:
			copy(model, imax, "csdmw_m3")
		case CSW_M4A1:
			copy(model, imax, "csdmw_m4a1")
		case CSW_TMP:
			copy(model, imax, "csdmw_tmp")
		case CSW_G3SG1:
			copy(model, imax, "csdmw_g3sg1")
		case CSW_FLASHBANG:
			copy(model, imax, "csdmw_flashbang")
		case CSW_DEAGLE:
			copy(model, imax, "csdmw_deagle")
		case CSW_SG552:
			copy(model, imax, "csdmw_sg552")
		case CSW_AK47:
			copy(model, imax, "csdmw_ak47")
		case CSW_KNIFE:
			copy(model, imax, "csdmw_knife")
		case CSW_P90:
			copy(model, imax, "csdmw_p90")
	}
	
	return 1
}

/*
get_wpname(wp, name[], imax)
{
	switch (wp) {
		case CSW_P228:
			copy(name, imax, "p228")
		case CSW_SCOUT:
			copy(name, imax, "scout")
		case CSW_HEGRENADE:
			copy(name, imax, "hegrenade")
		case CSW_XM1014:
			copy(name, imax, "xm1014")
		case CSW_C4:
			copy(name, imax, "c4")
		case CSW_MAC10:
			copy(name, imax, "mac10")
		case CSW_AUG:
			copy(name, imax, "aug")
		case CSW_SMOKEGRENADE:
			copy(name, imax, "smokegrenade")
		case CSW_ELITE:
			copy(name, imax, "elite")
		case CSW_FIVESEVEN:
			copy(name, imax, "fiveseven")
		case CSW_UMP45:
			copy(name, imax, "ump45")
		case CSW_SG550:
			copy(name, imax, "sg550")
		case CSW_GALIL:
			copy(name, imax, "galil")
		case CSW_FAMAS:
			copy(name, imax, "famas")
		case CSW_USP:
			copy(name, imax, "usp")
		case CSW_GLOCK18:
			copy(name, imax, "glock18")
		case CSW_AWP:
			copy(name, imax, "awp")
		case CSW_MP5NAVY:
			copy(name, imax, "mp5navy")
		case CSW_M249:
			copy(name, imax, "m249")
		case CSW_M3:
			copy(name, imax, "m3")
		case CSW_M4A1:
			copy(name, imax, "m4a1")
		case CSW_TMP:
			copy(name, imax, "tmp")
		case CSW_G3SG1:
			copy(name, imax, "g3sg1")
		case CSW_FLASHBANG:
			copy(name, imax, "flashbang")
		case CSW_DEAGLE:
			copy(name, imax, "deagle")
		case CSW_SG552:
			copy(name, imax, "sg552")
		case CSW_AK47:
			copy(name, imax, "ak47")
		case CSW_KNIFE:
			copy(name, imax, "knife")
		case CSW_P90:
			copy(name, imax, "p90")
	}
	
	return 1
}
*/

getCSDMWpId(wp[])
{
	if (equali(wp, "csdmw_p228")) {
		return CSW_P228
	} else if (equali(wp, "csdmw_scout")) {
		return CSW_SCOUT
	} else if (equali(wp, "csdmw_hegrenade")) {
		return CSW_HEGRENADE
	} else if (equali(wp, "csdmw_xm1014")) {
		return CSW_XM1014
	} else if (equali(wp, "csdmw_c4")) {
		return CSW_C4
	} else if (equali(wp, "csdmw_mac10")) {
		return CSW_MAC10
	} else if (equali(wp, "csdmw_aug")) {
		return CSW_AUG
	} else if (equali(wp, "csdmw_smokegrenade")) {
		return CSW_SMOKEGRENADE
	} else if (equali(wp, "csdmw_elite")) {
		return CSW_ELITE
	} else if (equali(wp, "csdmw_fiveseven")) {
		return CSW_FIVESEVEN
	} else if (equali(wp, "csdmw_ump45")) {
		return CSW_UMP45
	} else if (equali(wp, "csdmw_sg550")) {
		return CSW_SG550
	} else if (equali(wp, "csdmw_galil")) {
		return CSW_GALIL
	} else if (equali(wp, "csdmw_famas")) {
		return CSW_FAMAS
	} else if (equali(wp, "csdmw_usp")) {
		return CSW_USP
	} else if (equali(wp, "csdmw_glock18")) {
		return CSW_GLOCK18
	} else if (equali(wp, "csdmw_awp")) {
		return CSW_AWP
	} else if (equali(wp, "csdmw_mp5navy")) {
		return CSW_MP5NAVY
	} else if (equali(wp, "csdmw_m249")) {
		return CSW_M249
	} else if (equali(wp, "csdmw_m3")) {
		return CSW_M3
	} else if (equali(wp, "csdmw_m4a1")) {
		return CSW_M4A1
	} else if (equali(wp, "csdmw_tmp")) {
		return CSW_TMP
	} else if (equali(wp, "csdmw_g3sg1")) {
		return CSW_G3SG1
	} else if (equali(wp, "csdmw_flashbang")) {
		return CSW_FLASHBANG
	} else if (equali(wp, "csdmw_deagle")) {
		return CSW_DEAGLE
	} else if (equali(wp, "csdmw_sg552")) {
		return CSW_SG552
	} else if (equali(wp, "csdmw_ak47")) {
		return CSW_AK47
	} else if (equali(wp, "csdmw_knife")) {
		return CSW_KNIFE
	} else if (equali(wp, "csdmw_p90")) {
		return CSW_P90
	}
	
	return 0
}

getWepId(wp[])
{
	if (equali(wp, "weapon_p228")) {
		return CSW_P228
	} else if (equali(wp, "weapon_scout")) {
		return CSW_SCOUT
	} else if (equali(wp, "weapon_hegrenade")) {
		return CSW_HEGRENADE
	} else if (equali(wp, "weapon_xm1014")) {
		return CSW_XM1014
	} else if (equali(wp, "weapon_c4")) {
		return CSW_C4
	} else if (equali(wp, "weapon_mac10")) {
		return CSW_MAC10
	} else if (equali(wp, "weapon_aug")) {
		return CSW_AUG
	} else if (equali(wp, "weapon_smokegrenade")) {
		return CSW_SMOKEGRENADE
	} else if (equali(wp, "weapon_elite")) {
		return CSW_ELITE
	} else if (equali(wp, "weapon_fiveseven")) {
		return CSW_FIVESEVEN
	} else if (equali(wp, "weapon_ump45")) {
		return CSW_UMP45
	} else if (equali(wp, "weapon_sg550")) {
		return CSW_SG550
	} else if (equali(wp, "weapon_galil")) {
		return CSW_GALIL
	} else if (equali(wp, "weapon_famas")) {
		return CSW_FAMAS
	} else if (equali(wp, "weapon_usp")) {
		return CSW_USP
	} else if (equali(wp, "weapon_glock18")) {
		return CSW_GLOCK18
	} else if (equali(wp, "weapon_awp")) {
		return CSW_AWP
	} else if (equali(wp, "weapon_mp5navy")) {
		return CSW_MP5NAVY
	} else if (equali(wp, "weapon_m249")) {
		return CSW_M249
	} else if (equali(wp, "weapon_m3")) {
		return CSW_M3
	} else if (equali(wp, "weapon_m4a1")) {
		return CSW_M4A1
	} else if (equali(wp, "weapon_tmp")) {
		return CSW_TMP
	} else if (equali(wp, "weapon_g3sg1")) {
		return CSW_G3SG1
	} else if (equali(wp, "weapon_flashbang")) {
		return CSW_FLASHBANG
	} else if (equali(wp, "weapon_deagle")) {
		return CSW_DEAGLE
	} else if (equali(wp, "weapon_sg552")) {
		return CSW_SG552
	} else if (equali(wp, "weapon_ak47")) {
		return CSW_AK47
	} else if (equali(wp, "weapon_knife")) {
		return CSW_KNIFE
	} else if (equali(wp, "weapon_p90")) {
		return CSW_P90
	}
	
	return 0
}

giveAmmoType(id, ammotype)
{
	switch (ammotype) {
		case PISTOL_AMMO:
		{
			give_item(id, "ammo_357sig")
			give_item(id, "ammo_57mm")
			give_item(id, "ammo_45acp")
			give_item(id, "ammo_50ae")
			give_item(id, "ammo_9mm")
		}
		case SHOTGUN_AMMO:
		{
			give_item(id, "ammo_buckshot")
		}
		case SMG_AMMO:
		{
			give_item(id, "ammo_9mm")
			give_item(id, "ammo_45acp")
		}
		case RIFLE_AMMO:
		{
			give_item(id, "ammo_762nato")
			give_item(id, "ammo_556nato")
			if (!get_cvar_num("csdm_asskicr")) {
				give_item(id, "ammo_338magnum")
				give_item(id, "ammo_556natobox")
			}
		}
		case AWP_AMMO:
		{
			if (get_cvar_num("csdm_asskicr")) {
				give_item(id, "ammo_338magnum")
			}
		}
		case PARA_AMMO:
		{
			if (get_cvar_num("csdm_asskicr")) {
				give_item(id, "ammo_556natobox")
			}
		}
	}
}

getWepAmmoType(wp)
{
	switch (wp)
	{
		case CSW_P228:
			return 1
		case CSW_SCOUT:
			return 4
		case CSW_HEGRENADE:
			if (get_cvar_num("csdm_asskicr")) {
				return 7
			} else {
				return 5
			}
		case CSW_XM1014:
			return 2
		case CSW_MAC10:
			return 3
		case CSW_AUG:
			return 4
		case CSW_SMOKEGRENADE:
			if (get_cvar_num("csdm_asskicr")) {
				return 7
			} else {
				return 5
			}
		case CSW_ELITE:
			return 1
		case CSW_FIVESEVEN:
			return 1
		case CSW_UMP45:
			return 3
		case CSW_SG550:
			return 4
		case CSW_GALIL:
			return 4
		case CSW_FAMAS:
			return 4
		case CSW_USP:
			return 1
		case CSW_GLOCK18:
			return 1
		case CSW_AWP:
			if (get_cvar_num("csdm_asskicr")) {
				return 5
			} else {
				return 4
			}
		case CSW_MP5NAVY:
			return 3
		case CSW_M249:
			if (get_cvar_num("csdm_asskicr")) {
				return 6
			} else {
				return 4
			}
		case CSW_M3:
			return 2
		case CSW_M4A1:
			return 4
		case CSW_TMP:
			return 3
		case CSW_G3SG1:
			return 4
		case CSW_FLASHBANG:
			if (get_cvar_num("csdm_asskicr")) {
				return 7
			} else {
				return 5
			}
		case CSW_DEAGLE:
			return 1
		case CSW_SG552:
			return 4
		case CSW_AK47:
			return 4
		case CSW_P90:
			return 3
	}
	
	return 0
}

getWepSlot(wp)
{
	switch (wp)
	{
		case CSW_P228:
			return 3
		case CSW_SCOUT:
			return 2
		case CSW_HEGRENADE:
			return 4
		case CSW_XM1014:
			return 2
		case CSW_C4:
			return 7 // KWo = oryginally it was 5
		case CSW_MAC10:
			return 2
		case CSW_AUG:
			return 2
		case CSW_SMOKEGRENADE:
			return 5
		case CSW_ELITE:
			return 3
		case CSW_FIVESEVEN:
			return 3
		case CSW_UMP45:
			return 2
		case CSW_SG550:
			return 2
		case CSW_GALIL:
			return 2
		case CSW_FAMAS:
			return 2
		case CSW_USP:
			return 3
		case CSW_GLOCK18:
			return 3
		case CSW_AWP:
			return 2
		case CSW_MP5NAVY:
			return 2
		case CSW_M249:
			return 2
		case CSW_M3:
			return 2
		case CSW_M4A1:
			return 2
		case CSW_TMP:
			return 2
		case CSW_G3SG1:
			return 2
		case CSW_FLASHBANG:
			return 6		// KWo = oryginally it was 4
		case CSW_DEAGLE:
			return 3
		case CSW_SG552:
			return 2
		case CSW_AK47:
			return 2
		case CSW_KNIFE:
			return 1
		case CSW_P90:
			return 2
	}
	
	return 0
}


getMaxAmmo(wp)
{
	switch (wp)
	{
		case CSW_P228:
			return 52
		case CSW_SCOUT:
			return 90
		case CSW_HEGRENADE:
			return 1
		case CSW_XM1014:
			return 32
		case CSW_C4:
			return 1
		case CSW_MAC10:
			return 100
		case CSW_AUG:
			return 90
		case CSW_SMOKEGRENADE:
			return 1
		case CSW_ELITE:
			return 120
		case CSW_FIVESEVEN:
			return 100
		case CSW_UMP45:
			return 100
		case CSW_SG550:
			return 90
		case CSW_GALIL:
			return 90
		case CSW_FAMAS:
			return 90
		case CSW_USP:
			return 100
		case CSW_GLOCK18:
			return 120
		case CSW_AWP:
			return 30
		case CSW_MP5NAVY:
			return 120
		case CSW_M249:
			return 200
		case CSW_M3:
			return 32
		case CSW_M4A1:
			return 90
		case CSW_TMP:
			return 120
		case CSW_G3SG1:
			return 90
		case CSW_FLASHBANG:
			return 2
		case CSW_DEAGLE:
			return 35
		case CSW_SG552:
			return 90
		case CSW_AK47:
			return 90
		case CSW_KNIFE:
			return 1
		case CSW_P90:
			return 100
	}
	
	return 0
}


findNextSlot()
{
	new i
	for (i=1; i<MAX_ENTITIES; i++) {
		if (!EdictSlot[i]) {
			return i
		}
	}
	
	safe_rm_ent(EdictSlot[1])
	
	return 1
}

findSlot(entid)
{
	new i
	for (i=1; i<MAX_ENTITIES; i++) {
		if (EdictSlot[i] == entid) {
			return i
		}
	}
	
	return 0
}

//im not deleting this algorithm because it's cool =D
/*findSpawns(SP[])
{
	new T, CT, g
	new i
	
	for (i=1; i<=SPAWNS; i++) {
		if (SP[i] == 1) {
			T++
		} else if (SP[i] == 2) {
			CT++
		}
	}
	
	g = (random_num(3,18) % 2) + 1
	
	if (T > CT + 2) {
		g = 2
	}

	return g
}*/

mkent(ent[]="info_target")
{
	new entid, slot
	
	if ((entity_count() <= 1050) && (CurMaxEnt <= 1050)) {
		entid = create_entity(ent)
		Entities++
		slot = findNextSlot()
		EdictSlot[slot] = entid
	} else {
		return 0
	}

	return entid
}

rment(entid)
{
	new slot
	
	if (entid > 32 && is_valid_ent(entid)) {
		remove_entity(entid)
		slot = findSlot(entid)
		EdictSlot[slot] = 0
		Entities--
	}
	
	return entid
}

public cancel_vote(id)
{
	if (!(get_user_flags(id)&ADMIN_LEVEL_A)){
		client_print(id,print_console,"[CSDM] You do not have appropriate access.")
		client_print(id,print_chat,"[CSDM] You do not have appropriate access.")				
		return PLUGIN_HANDLED
	}
	if (!Voting) {
		return PLUGIN_HANDLED
	}
	CancelVote = true
	client_print(0, print_chat, "[CSDM] The vote was cancelled by an admin.")
	return PLUGIN_HANDLED
}

public vote_freeforallsay(id)
{
	new name[32]

	get_user_name(id,name,31)
	new vflags[5]
	get_cvar_string("csdm_voteflags", vflags, 5)

	if (!get_cvar_num("csdm_voting") || !(cwrap(vflags, "c"))) {
		client_print(id,print_chat,"[CSDM] Free For All voting is not allowed.")
		return PLUGIN_HANDLED
	}
	if (!get_cvar_num("csdm_active")) {
		client_print(id, print_chat, "[CSDM] is not currently enabled!")
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_voting")==2) {
		if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
			client_print(id, print_console, "[CSDM] You do not have appropriate access.")
			return PLUGIN_CONTINUE
		}
	}
	if (get_cvar_num("csdm_voting")) {
		if(Voting) {
			client_print(id, print_chat, "[CSDM] A vote is already taking place!")
			return PLUGIN_CONTINUE
		}
		
		if (get_gametime() < lastVote) {
			client_print(id, print_chat, "[CSDM] Sorry, wait a bit before voting again.")
			return PLUGIN_CONTINUE
		} else {
			client_print(0, print_chat, "[CSDM] %s started a Free For All vote.", name)
			dovote(id, 3)
			return PLUGIN_CONTINUE
		}
	}
    
	return PLUGIN_CONTINUE
}

public vote_freeforall(id)
{
	new name[32]

	get_user_name(id,name,31)
	new vflags[5]
	get_cvar_string("csdm_voteflags", vflags, 5)
	
	if (!get_cvar_num("csdm_voting") || !(cwrap(vflags, "c"))) {
		client_print(id,print_chat,"[CSDM] Free For All voting is not allowed.")
		return PLUGIN_HANDLED
	}
	if (!get_cvar_num("csdm_active")) {
		client_print(id, print_chat, "[CSDM] is not currently enabled!")
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_voting")==2) {
		if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
			client_print(id, print_console, "[CSDM] You do not have appropriate access.")
			return PLUGIN_HANDLED
		}
	}
	if (get_cvar_num("csdm_voting")) {
		if(Voting) {
			client_print(id, print_chat, "[CSDM] A vote is already taking place!")
			return PLUGIN_HANDLED
		}
		
		if (get_gametime() < lastVote) {
			client_print(id, print_chat, "[CSDM] Sorry, wait a bit before voting again.")
			return PLUGIN_HANDLED
		} else {
			client_print(0, print_chat, "[CSDM] %s started a Free For All vote.", name)
			dovote(id, 3)
			return PLUGIN_HANDLED
		}
	}
    
	return PLUGIN_HANDLED
}

public vote_modesay(id)
{
	new name[32]

	get_user_name(id,name,31)
	new vflags[5]
	get_cvar_string("csdm_voteflags", vflags, 5)
	
	if (!get_cvar_num("csdm_voting") || !(cwrap(vflags, "b"))) {
		client_print(id,print_chat,"[CSDM] Mode voting is not allowed.")
		return PLUGIN_HANDLED
	}
	if (!get_cvar_num("csdm_active")) {
		client_print(id, print_chat, "[CSDM] is not currently enabled!")
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_voting")==2) {
		if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
			client_print(id, print_console, "[CSDM] You do not have appropriate access.")
			return PLUGIN_CONTINUE
		}
	}
	if (get_cvar_num("csdm_voting")) {
		if(Voting) {
			client_print(id, print_chat, "[CSDM] A vote is already taking place!")
			return PLUGIN_CONTINUE
		}
		
		if (get_gametime() < lastVote) {
			client_print(id, print_chat, "[CSDM] Sorry, wait a bit before voting again.")
			return PLUGIN_CONTINUE
		} else {
			client_print(0, print_chat, "[CSDM] %s started vote for switching CSDM modes.", name)
			dovote(id, 2)
			return PLUGIN_CONTINUE
		}
	}
    
	return PLUGIN_CONTINUE
}

public vote_mode(id)
{
	new name[32]

	get_user_name(id,name,31)
	new vflags[5]
	get_cvar_string("csdm_voteflags", vflags, 5)
	
	if (!get_cvar_num("csdm_voting") || !(cwrap(vflags, "b"))) {
		client_print(id,print_chat,"[CSDM] Mode voting is not allowed.")
		return PLUGIN_HANDLED
	}
	if (!get_cvar_num("csdm_active")) {
		client_print(id, print_chat, "[CSDM] is not currently enabled!")
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_voting")==2) {
		if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
			client_print(id, print_console, "[CSDM] You do not have appropriate access.")
			return PLUGIN_HANDLED
		}
	}
	if (get_cvar_num("csdm_voting")) {
		if(Voting) {
			client_print(id, print_chat, "[CSDM] A vote is already taking place!")
			return PLUGIN_HANDLED
		}
		
		if (get_gametime() < lastVote) {
			client_print(id, print_chat, "[CSDM] Sorry, wait a bit before voting again.")
			return PLUGIN_HANDLED
		} else {
			client_print(0, print_chat, "[CSDM] %s started vote for switching CSDM modes.", name)
			dovote(id, 2)
			return PLUGIN_HANDLED
		}
	}
    
	return PLUGIN_HANDLED
}

public csdm_votesay(id)
{
	new name[32]

	get_user_name(id,name,31)
	new vflags[5]
	get_cvar_string("csdm_voteflags", vflags, 5)
	
	if (!get_cvar_num("csdm_voting") || !(cwrap(vflags, "a"))) {
		client_print(id,print_chat,"[CSDM] Deathmatch voting is not allowed.")
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_voting")==2) {
		if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
			client_print(id, print_console, "[CSDM] You do not have appropriate access.")
			return PLUGIN_CONTINUE
		}
	}
	if (get_cvar_num("csdm_voting")) {
		if(Voting) {
			client_print(id, print_chat, "[CSDM] A vote is already taking place!")
			return PLUGIN_CONTINUE
		}
		
		if (get_gametime() < lastVote) {
			client_print(id, print_chat, "[CSDM] Sorry, wait a bit before voting again.")
			return PLUGIN_CONTINUE
		} else {
			client_print(0, print_chat, "[CSDM] %s started a deathmatch vote", name)
			dovote(id, 1)
			return PLUGIN_CONTINUE
		}
	}
    
	return PLUGIN_CONTINUE
}

public csdm_vote(id)
{
	new name[32]

	get_user_name(id,name,31)
	new vflags[5]
	get_cvar_string("csdm_voteflags", vflags, 5)
	
	if (!get_cvar_num("csdm_voting") || !(cwrap(vflags, "a"))) {
		client_print(id,print_chat,"[CSDM] Deathmatch voting is not allowed.")
		return PLUGIN_HANDLED
	}
	if (get_cvar_num("csdm_voting")==2) {
		if (!(get_user_flags(id)&ADMIN_LEVEL_A)) {
			client_print(id, print_console, "[CSDM] You do not have appropriate access.")
			return PLUGIN_HANDLED
		}
	}
	if (get_cvar_num("csdm_voting")) {
		if(Voting) {
			client_print(id, print_chat, "[CSDM] A vote is already taking place!")
			return PLUGIN_HANDLED
		}
		
		if (get_gametime() < lastVote) {
			client_print(id, print_chat, "[CSDM] Sorry, wait a bit before voting again.")
			return PLUGIN_HANDLED
		} else {
			client_print(0, print_chat, "[CSDM] %s started vote for enabling deathmatch", name)
			dovote(id, 1)
			return PLUGIN_HANDLED
		}
	}
    
	return PLUGIN_HANDLED
}

public vote_count(id,key)
{
	if(CancelVote) {
		return PLUGIN_HANDLED
	}
	
	if (!key) {
		Votes++
	}
	
	return PLUGIN_HANDLED
}

public votes_timer()
{
	lastVote = get_gametime() + get_cvar_float("csdm_nextvote")
	if(CancelVote) {
		client_print(0, print_chat, "[CSDM] Vote cancelled.")
		CancelVote = false
		return PLUGIN_HANDLED
	}
	new players[32], mPlayers
	get_players(players, mPlayers, "c")
	new Float:voteRatio = get_cvar_float("csdm_ratio")
	new Float:results = mPlayers ? (float(Votes) / float(mPlayers)) : 0.0
	new n = VoteFor
	if (n==1) {
		if (results>=voteRatio) {
			if (!get_cvar_num("csdm_active")) {
				client_print(0, print_chat, "[CSDM] Vote passed! CSDM will be enabled.")
				log_message("[CSDM] CSDM Mode turned on.")
				client_print(0, print_console, "[CSDM] There may be some lag as the map is prepared.")
				set_cvar_num("csdm_active", 1)
				set_task(1.0, "start_map")
			} else {
				client_print(0, print_chat, "[CSDM] Vote passed! CSDM will stay enabled.")
			}
		} else {
			if (get_cvar_num("csdm_active")) {
				client_print(0, print_chat, "[CSDM] Vote failed.")
				client_print(0, print_chat, "[CSDM] Disabling CSDM.")
				log_message("[CSDM] CSDM Mode turned off.")
				set_cvar_num("csdm_active", 0)
				destroyAllItems()
				restoreSpawns()
				restoreHostages()
				restoreObjectives()			// KWo
				new file[64]																								// KRoT@L
				get_cvar_string("csdm_disable_file", file, 63)							// KRoT@L
				if (file_exists(file)) server_cmd("exec %s", file) 					// KRoT@L
				server_cmd("sv_restartround 2")
			} else {
				client_print(0, print_chat, "[CSDM] Vote finished! CSDM will stay disabled.")
			}
		}
	} else if (n==2) {
		if (results>=voteRatio) {
			if (get_cvar_num("csdm_add_items")) {
				client_print(0, print_chat, "[CSDM] Vote finished! Switching to Menu mode.")
				destroyAllItems()
				set_cvar_num("csdm_add_items", 0)
				log_message("[CSDM] Switching to menu mode.")
			} else {
				client_print(0, print_chat, "[CSDM] Vote finished! Keeping Menu mode.")
			}
		} else {
			if (get_cvar_num("csdm_add_items")) {
				client_print(0, print_chat, "[CSDM] Vote finished! Keeping Find Item mode.")
			} else {
				client_print(0, print_chat, "[CSDM] Vote finished! Switching to Find Item mode.")
				log_message("[CSDM] Switching to item mode.")
				set_cvar_num("csdm_add_items", 1)
				set_cvar_num("csdm_allow_clguns", 0)
				setEnts()
			}
		}
	} else if (n==3) {
		if (results>=voteRatio) {
			if (g_Kill_All) {
				client_print(0, print_chat, "[CSDM] Vote finished! Keeping Free For All mode.")
			} else {
				client_print(0, print_chat, "[CSDM] Vote finished! Switching to Free For All mode.  Kill everyone!")
				set_cvar_num("csdm_kill_all", 1)
				set_cvar_num("mp_autokick", 0)
				set_cvar_num("mp_tkpunish", 0)
				set_cvar_num("mp_autoteambalance", 0)
				set_cvar_num("mp_friendlyfire", 1)
				set_msg_block(112, BLOCK_SET)
				client_cmd(0, "hideradar")				
				log_message("[CSDM] Enabling free-for-all.")
			}
		} else {
			if (g_Kill_All) {
				client_print(0, print_chat, "[CSDM] Vote finished! Free For All mode is now disabled.")
				log_message("[CSDM] Disabling free-for-all.")
				set_cvar_num("csdm_kill_all", 0)
				set_cvar_num("mp_friendlyfire", 0)
				set_msg_block(112, BLOCK_NOT)
				client_cmd(0, "drawradar")				
			} else {
				client_print(0, print_chat, "[CSDM] Vote finished! Free For All mode will stay disabled.")
			}
		}
	}
	VoteFor = 0
	Voting = false

	return PLUGIN_HANDLED
}

public dovote(id, n)
{
	Votes = 0
	Voting = true
	new menu[256]
	//there was a little toolshed where he made us suffer
	if (n==1) {
		format(menu, 255, "CSDM Enable Deathmatch Mod?  \w^n^n1. Yes^n2.  No")
	} else if (n==2) {
		format(menu, 255, "CSDM Which Mode?  \w^n^n1. Menu^n2.  Find Items")
	} else if (n==3) {
		format(menu, 255, "CSDM Free for all?  \w^n^n1. Yes^n2.  No")
	} else {
		client_print(id, print_chat, "[CSDM] Invalid vote.")
	}
	VoteFor = n
	show_menu(0, (1<<0)|(1<<1), menu, floatround(get_cvar_float("csdm_votetime")))
	new Float:Time = get_cvar_float("csdm_votetime")
	set_task(Time, "votes_timer")
	
	return PLUGIN_CONTINUE
}

safe_rm_ent(id)
{
	new class[32]
	
	if (is_valid_ent(id)) {
	
		entity_get_string(id, EV_SZ_classname, class, 32)
		if (cwrap(class,"csdm")||cwrap(class,"view")||cwrap(class,"drop")||cwrap(class,"ammo")||cwrap(class,"armor")||cwrap(class,"shield")) {	//KWo
			rment(id)
			return 1
		}
	}
		
	return 0
}

// KWo - some actions for menus called by KWo's CSDM menu :)

public del_csdm_gen_menu(param[])
{
	new pl_id=param[0]
	show_gen_menu(pl_id)
	return PLUGIN_CONTINUE  	
}

public action_csdm_set_menu(pl_id,key)
{
	switch(g_MenuPage[pl_id])
	{
		case 1:		/* PAGE 1*/
		{
			switch(key)
			{
				case 0: /* Option 1 - CSDM enabled/disabled */
				{	
					if (get_cvar_num("csdm_active")) 
					{
						console_cmd(pl_id,"csdm_enable 0")					
						
					} else
					{
						console_cmd(pl_id,"csdm_enable 1")
					}
					new data[1]
					data[0] = pl_id
					set_task(0.2, "del_csdm_gen_menu", 0, data, 1)
				}
				case 1: /* Option 2 - Players find/choose weapons */
				{
					if (get_cvar_num("csdm_add_items"))
					{
						console_cmd(pl_id, "csdm_items 0")
					} else
					{ 
						console_cmd(pl_id, "csdm_items 1")
					}
					new data[1]
					data[0] = pl_id
					set_task(0.2, "del_csdm_gen_menu", 0, data, 1)					
				}
				case 2: /* Option 3 - Use random/regular spawns */
				{
					if (get_cvar_num("csdm_random_spawns"))
					{
						set_cvar_num("csdm_random_spawns",0)
					} else
					{ 
						set_cvar_num("csdm_random_spawns",1)
					}
					show_gen_menu(pl_id)
				}
				case 3: /* Option 4 - Enable/disable armor menu */
				{
					if (get_cvar_num("csdm_enable_amenu"))
					{
						set_cvar_num("csdm_enable_amenu",0)
					} else
					{ 
						set_cvar_num("csdm_enable_amenu",1)
					}
					show_gen_menu(pl_id)
				}
				case 4: /* Option 5 - Enable/disable grenade menu */
				{
					if (get_cvar_num("csdm_enable_gmenu"))
					{
						set_cvar_num("csdm_enable_gmenu",0)
					} else
					{ 
						set_cvar_num("csdm_enable_gmenu",1)
					}
					show_gen_menu(pl_id)
				}
				case 5: /* Option 6 - Enable/disable autoequip players with armor */
				{
					if (get_cvar_num("csdm_auto_equip"))
					{
						set_cvar_num("csdm_auto_equip",0)
					} else
					{ 
						set_cvar_num("csdm_auto_equip",1)
					}
					show_gen_menu(pl_id)
				}
				case 6: /* Option 7 - Enable/disable autoequip players with grenades */
				{
					if (get_cvar_num("csdm_auto_gren"))
					{
						set_cvar_num("csdm_auto_gren",0)
					} else
					{ 
						set_cvar_num("csdm_auto_gren",1)
					}
					show_gen_menu(pl_id)
				}
				case 7: /* Option 8 - Allow/disallow players to drop weapons */
				{
					if (get_cvar_num("csdm_drop_weapons"))
					{
						set_cvar_num("csdm_drop_weapons",0)
					} else
					{ 
						set_cvar_num("csdm_drop_weapons",1)
					}
					show_gen_menu(pl_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl_id] = 2
					show_gen_menu(pl_id)
				}
				case 9: /* Option 0 - Back */
				{
					show_csdm_menu(pl_id)
				}
			}
		}
		case 2:		/* PAGE 2*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Allow/disallow players to use >guns< command */
				{	
					if (get_cvar_num("csdm_allow_clguns")) 
					{
						set_cvar_num("csdm_allow_clguns",0)
					} else
					{ 
						set_cvar_num("csdm_allow_clguns",1)
					}
					show_gen_menu(pl_id)
				}
				case 1: /* Option 2 - Enable/disable spam message at respawn */
				{	
					if (get_cvar_num("csdm_spawn_spam")) 
					{
						set_cvar_num("csdm_spawn_spam",0)
					} else
					{ 
						set_cvar_num("csdm_spawn_spam",1)
					}
					show_gen_menu(pl_id)
				}
				case 2: /* Option 3 - Drop weapon/pack on death */
				{	
					if (get_cvar_num("csdm_drop_packs")) 
					{
						set_cvar_num("csdm_drop_packs",0)
					} else
					{ 
						set_cvar_num("csdm_drop_packs",1)
					}
					show_gen_menu(pl_id)
				}
				case 3: /* Option 4 - Enable/disable killing all without TK punishment */
				{	
					if (get_cvar_num("csdm_kill_all")) 
					{
						set_cvar_num("csdm_kill_all",0)
					} else
					{ 
						set_cvar_num("csdm_kill_all",1)
					}
					show_gen_menu(pl_id)
				}
				case 4: /* Option 5 - Enable/disable sounds for weapons */
				{	
					if (get_cvar_num("csdm_sounds")) 
					{
						set_cvar_num("csdm_sounds",0)
					} else
					{ 
						set_cvar_num("csdm_sounds",1)
					}
					show_gen_menu(pl_id)
				}
				case 5: /* Option 6 - Allow/disallow use radio */
				{	
					if (get_cvar_num("csdm_allow_radio")) 
					{
						set_cvar_num("csdm_allow_radio",0)
					} else
					{ 
						set_cvar_num("csdm_allow_radio",1)
					}
					show_gen_menu(pl_id)
				}
				case 6: /* Option 7 - Allow/disallow hold more than one of each type of weapon */
				{	
					if (get_cvar_num("csdm_hold_many")) 
					{
						set_cvar_num("csdm_hold_many",0)
					} else
					{ 
						set_cvar_num("csdm_hold_many",1)
					}
					show_gen_menu(pl_id)
				}
				case 7: /* Option 8 - Enable/disable explanation of longjump usage */
				{	
					if (get_cvar_num("csdm_explain")) 
					{
						set_cvar_num("csdm_explain",0)
					} else
					{ 
						set_cvar_num("csdm_explain",1)
					}
					show_gen_menu(pl_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl_id] = 3
					show_gen_menu(pl_id)
				}
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl_id] = 1
					show_gen_menu(pl_id)
				}
			}
		}
		case 3:		/* PAGE 3*/
		{
			new stripflags[10]
			get_cvar_string("csdm_stripper", stripflags, 9)
			new striptype = read_flags(stripflags)
			
			switch(key)
			{
				case 0: /* Option 1 - Enable/disable auto-drop guns */
				{	
					if (get_cvar_num("csdm_auto_drop")) 
					{
						set_cvar_num("csdm_auto_drop",0)
					} else
					{ 
						set_cvar_num("csdm_auto_drop",1)
					}
					show_gen_menu(pl_id)
				}
				case 1: /* Option 2 - Enable/disable whether to pack jumps into drop packs */
				{	
					if (get_cvar_num("csdm_pack_jumps")) 
					{
						set_cvar_num("csdm_pack_jumps",0)
					} else
					{ 
						set_cvar_num("csdm_pack_jumps",1)
					}
					show_gen_menu(pl_id)
				}
				case 2: /* Option 3 - Enable/disable Asskicr's changes */
				{	
					if (get_cvar_num("csdm_asskicr")) 
					{
						set_cvar_num("csdm_asskicr",0)
					} else
					{ 
						set_cvar_num("csdm_asskicr",1)
					}
					show_gen_menu(pl_id)
				}
				case 3: /* Option 4 - Enable/disable playing intro wave on player's respawn */
				{	
					if (get_cvar_num("csdm_spawn_wave")) 
					{
						set_cvar_num("csdm_spawn_wave",0)
					} else
					{ 
						set_cvar_num("csdm_spawn_wave",1)
					}
					show_gen_menu(pl_id)
				}
				
				case 4: /* Option 5 - Objectives, buyzones at CSDM start removed/hidden */	
				{				// KWo
					if (get_cvar_num("csdm_stripper_remove")) 
					{
						set_cvar_num("csdm_stripper_remove",0)
					} else
					{ 
						set_cvar_num("csdm_stripper_remove",1)
					}
					show_gen_menu(pl_id)
				}
				
				case 5: /* Option 6 - Remove bomb/hostage rescue/vip zones from the map enabled/disabled */
				{				// KWo	
					if (striptype & (1<<0)) 
					{
						striptype = striptype - 1
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					} else
					{ 
						striptype = striptype + 1
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					}
					show_gen_menu(pl_id)
				}
				case 6: /* Option 7 - Remove buyzones from the map enabled/disabled */
				{				// KWo	
					if (striptype & (1<<1)) 
					{
						striptype = striptype - 2
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					} else
					{ 
						striptype = striptype + 2
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					}
					show_gen_menu(pl_id)
				}
				case 7: /* Option 8 - Remove weapons on the floor enabled/disabled */
				{				// KWo
					if (striptype & (1<<2)) 
					{
						striptype = striptype - 4
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					} else
					{ 
						striptype = striptype + 4
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					}
					show_gen_menu(pl_id)
				}
				case 8: /* Option 9 - Remove starting weapons enabled/disabled */
				{					
					if (striptype & (1<<3)) 
					{			// KWo
						striptype = striptype - 8
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					} else
					{ 
						striptype = striptype + 8
						get_flags(striptype,stripflags,9)
						set_cvar_string("csdm_stripper", stripflags)
					}
					show_gen_menu(pl_id)
				}
				
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl_id] = 2
					show_gen_menu(pl_id)
				}
			}
		}
	}
	return PLUGIN_HANDLED
}

public action_csdm_cvars_menu(pl_id,key)
{
	new temp
	switch(key)
	{
		case 0: /* Option 1 - Set CSDM protection time */
		{	
			temp = get_cvar_num("csdm_freeze_time")
			if (temp >= 10) 
			{
				set_cvar_num("csdm_freeze_time",0)
			} else
			{ 
				set_cvar_num("csdm_freeze_time",temp + 1)
			}
			show_cvars_menu(pl_id)
		}
		case 1: /* Option 2 - Set time until items respawn */
		{	
			temp = get_cvar_num("csdm_item_time")
			if (temp >= 60) 
			{
				set_cvar_num("csdm_item_time",0)
			} else
			{ 
				set_cvar_num("csdm_item_time",temp + 1)
			}
			show_cvars_menu(pl_id)
		}
		case 2: /* Option 3 - Set time until to disappear weapon after drop */
		{	
			temp = get_cvar_num("csdm_delete_time")
			if (temp >= 60) 
			{
				set_cvar_num("csdm_delete_time",0)
			} else
			{ 
				set_cvar_num("csdm_delete_time",temp + 1)
			}
			show_cvars_menu(pl_id)
		}
		case 3: /* Option 4 - Set CSDM spawn mode */
		{	
			temp = get_cvar_num("csdm_spawn_protect")
			if (temp >= 2) 
			{
				set_cvar_num("csdm_spawn_protect",0)
			} else
			{ 
				set_cvar_num("csdm_spawn_protect",temp + 1)
			}
			show_cvars_menu(pl_id)
		}
		case 4: /* Option 5 - Set battery health */
		{	
			temp = get_cvar_num("csdm_battery")
			if (temp >= 100) 
			{
				set_cvar_num("csdm_battery",5)
			} else
			{ 
				set_cvar_num("csdm_battery",temp + 5)
			}
			show_cvars_menu(pl_id)
		}
		case 5: /* Option 6 - Set medkit health */
		{	
			temp = get_cvar_num("csdm_medkit")
			if (temp >= 100) 
			{
				set_cvar_num("csdm_medkit",5)
			} else
			{ 
				set_cvar_num("csdm_medkit",temp + 5)
			}
			show_cvars_menu(pl_id)
		}
		case 6: /* Option 7 - Set max waiting time for gun menu */			// new by KWo
		{	
			temp = get_cvar_num("csdm_maxdelmenu_time")
			if (temp >= 60) 
			{
				set_cvar_float("csdm_maxdelmenu_time",0.01)
			} else
			{ 
				set_cvar_num("csdm_maxdelmenu_time",temp + 5)
			}
			show_cvars_menu(pl_id)
		}
		case 9: /* Option 0 - Back */
		{
			show_csdm_menu(pl_id)		
		}
	}
	return PLUGIN_HANDLED
}


public action_csdm_voting_menu(pl_id,key)
{
	switch(key)
	{
		case 0: /* Option 1 - Set CSDM voting */
		{	
			new temp
			temp = get_cvar_num("csdm_voting")
			if (temp >= 2) 
			{
				set_cvar_num("csdm_voting",0)
			} else
			{ 
				set_cvar_num("csdm_voting",temp + 1)
			}
			show_voting_menu(pl_id)
		}
		case 1: /* Option 2 - Set CSDM vote flags */
		{	
			new voteflags[10]
			get_cvar_string("csdm_voteflags", voteflags, 9)

			if(equal(voteflags, "")) set_cvar_string("csdm_voteflags","c")
			if(equal(voteflags, "c")) set_cvar_string("csdm_voteflags","b")
			if(equal(voteflags, "b")) set_cvar_string("csdm_voteflags","bc")
			if(equal(voteflags, "bc")) set_cvar_string("csdm_voteflags","a")
			if(equal(voteflags, "a")) set_cvar_string("csdm_voteflags","ac")
			if(equal(voteflags, "ac")) set_cvar_string("csdm_voteflags","ab")
			if(equal(voteflags, "ab")) set_cvar_string("csdm_voteflags","abc")
			if(equal(voteflags, "abc")) set_cvar_string("csdm_voteflags","")

			show_voting_menu(pl_id)
		}
		case 2: /* Option 3 - Set CSDM vote ratio */
		{	
			new Float:temp
			temp = get_cvar_float("csdm_ratio")
			if (temp >= 1.0) 
			{
				set_cvar_float("csdm_ratio",0.1)
			} else
			{ 
				temp = temp + 0.1
				set_cvar_float("csdm_ratio",temp)
			}
			show_voting_menu(pl_id)
		}
		case 3: /* Option 4 - Set CSDM vote time */
		{	
			new temp
			temp = get_cvar_num("csdm_votetime")
			if (temp >= 120) 
			{
				set_cvar_num("csdm_votetime",10)
			} else
			{ 
				set_cvar_num("csdm_votetime",temp + 5)
			}
			show_voting_menu(pl_id)
		}
		case 4: /* Option 5 - Set time for CSDM nextvote */
		{	
			new temp
			temp = get_cvar_num("csdm_nextvote")
			if (temp >= 600) 
			{
				set_cvar_num("csdm_nextvote",0)
			} else
			{ 
				set_cvar_num("csdm_nextvote",temp + 30)
			}
			show_voting_menu(pl_id)
		}
		case 5: /* Option 6 - CSDM vote for CSDM >on< */
		{
			csdm_vote(pl_id)
		}
		case 6: /* Option 7 - CSDM vote for CSDM >mode< */
		{
			vote_mode(pl_id)
		}
		case 7: /* Option 8 - CSDM vote for CSDM >Free-For-All mode< */
		{
			vote_freeforall(pl_id)
		}
		case 8: /* Option 9 - CSDM cancel vote for CSDM */
		{
			cancel_vote(pl_id)
		}
		case 9: /* Option 0 - Back */
		{
			show_csdm_menu(pl_id)
		}
	}
	return PLUGIN_HANDLED
}


public action_csdm_ent_menu(pl_id,key)
{
	switch(key)
	{
		case 0: /*   Option 1 - Add a CSDM entity */
		{
			g_MenuPage[pl_id]=1
			show_addent_menu(pl_id)
		}
		case 1: /* Option 2 - Delete a CSDM entity */
		{
			csdm_look(pl_id)
			if (g_csdm_entlook>-1){
				console_cmd(pl_id,"csdm_delent %d", g_csdm_entlook)
			}
			show_entit_menu(pl_id)
		}
		case 2: /* Option 3 - Find the nearest entity */
		{
			csdm_ent(pl_id)
			show_entit_menu(pl_id)
		}
		case 3: /* Option 4 - Return the entity id you are looking at */
		{
			csdm_look(pl_id)
			show_entit_menu(pl_id)
		}
		case 4: /* Option 5 - Return the classname of an entity id */
		{
			csdm_look(pl_id)
			if (g_csdm_entlook>-1){
				console_cmd(pl_id,"csdm_entinfo %d", g_csdm_entlook)
			}					
			show_entit_menu(pl_id)
		}
		case 5: /* Option 6 - Dump a text file with entity information */
		{
			csdm_entdump(pl_id)
			show_entit_menu(pl_id)
		}
		case 6: /* Option 7 - Return the number of entities in the map */
		{
			csdm_entcount(pl_id)
			show_entit_menu(pl_id)
		}
		case 9: /* Option 0 - Back */
		{
			show_csdm_menu(pl_id)
		}
	}
	return PLUGIN_HANDLED
}

public action_csdm_spawn_menu(pl_id,key)
{
	switch(key)
	{
		case 0: /* Option 1 - Create a CSDM spawn point */
		{
			show_addsp_menu(pl_id)
		}
		case 1: /* Option 2 - Delete a CSDM spawn point */
		{
			csdm_near(pl_id)
			if (g_csdm_spawnlook>-1){			
				console_cmd(pl_id, "csdm_delspawn %d", g_csdm_spawnlook)
			}
			show_spawns_menu(pl_id)
		}
		case 2: /* Option 3 - See how many spawns there are */
		{
			console_cmd(pl_id,"csdm_spawncount")
			show_spawns_menu(pl_id)
		}
		case 3: /* Option 4 - View all CSDM spawns */
		{
			csdm_hidespawns(pl_id)
			console_cmd(pl_id,"csdm_view_csdm_sp")
			show_spawns_menu(pl_id)
		}
		case 4: /* Option 5 - View active spawns */
		{
			csdm_hidespawns(pl_id)
			console_cmd(pl_id,"csdm_viewspawns")
			show_spawns_menu(pl_id)
		}
		case 5: /* Option 6 - Hide all spawns */
		{
			csdm_hidespawns(pl_id)
			show_spawns_menu(pl_id)
		}
		case 6: /* Option 7 - Shows you the number of the nearest spawn point */
		{
			csdm_near(pl_id)
			show_spawns_menu(pl_id)
		}
		case 7: /* Option 8 - Find your origin for debugging bad spawns */
		{
			csdm_origin(pl_id)
			show_spawns_menu(pl_id)
		}
		case 8: /* Option 9 - Return the classname of a spawn */
		{
			csdm_near(pl_id)
			if (g_csdm_spawnlook>-1){			
				console_cmd(pl_id, "csdm_spawninfo %d", g_csdm_spawnlook)
			}			
			show_spawns_menu(pl_id)
		}
		case 9: /* Option 0 - Back */
		{
			show_csdm_menu(pl_id)
		}
	}
	return PLUGIN_HANDLED
}

public act_csdm_addsp_menu(pl2_id,key)
{
	switch(key)
	{
		case 0: /* Option 1 - Create a random CSDM spawn point (no angle) */
		{
			console_cmd(pl2_id,"csdm_setspawn 0")		
			show_addsp_menu(pl2_id)
		}	
		case 1: /* Option 2 - Create a T CSDM spawn point (no angle) */
		{
			console_cmd(pl2_id,"csdm_setspawn 1")		
			show_addsp_menu(pl2_id)
		}
		case 2: /* Option 3 - Create a CT CSDM spawn point (no angle) */
		{
			console_cmd(pl2_id,"csdm_setspawn 2")		
			show_addsp_menu(pl2_id)
		}
		case 3: /* Option 4 - Create a random CSDM spawn point (with angle) */
		{
			console_cmd(pl2_id,"csdm_setspawnv 0")		
			show_addsp_menu(pl2_id)
		}
		case 4: /* Option 5 - Create a T CSDM spawn point (with angle) */
		{
			console_cmd(pl2_id,"csdm_setspawnv 1")		
			show_addsp_menu(pl2_id)
		}
		case 5: /* Option 6 - Create a CT CSDM spawn point (with angle) */
		{
			console_cmd(pl2_id,"csdm_setspawnv 2")		
			show_addsp_menu(pl2_id)
		}
		case 9: /* Option 0 - Back */
		{
			show_spawns_menu(pl2_id)
		}
	}
	return PLUGIN_HANDLED
}


public act_csdm_addent_menu(pl3_id,key)
{
	switch(g_MenuPage[pl3_id])
	{
		case 1:		/* PAGE 1*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Add glock18 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_glock18")
					show_addent_menu(pl3_id)
				}
				case 1: /* Option 2 - Add usp */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_usp")
					show_addent_menu(pl3_id)
				}
				case 2: /* Option 3 - Add elite */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_elite")
					show_addent_menu(pl3_id)
				}
				case 3: /* Option 4 - Add fiveseven */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_fiveseven")
					show_addent_menu(pl3_id)
				}
				case 4: /* Option 5 - Add deagle */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_deagle")
					show_addent_menu(pl3_id)
				}
				case 7: /* Option 8 - Add pistol ammo */
				{	
					console_cmd(pl3_id,"csdm_setent pistol_ammo")
					show_addent_menu(pl3_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl3_id] = 2
					show_addent_menu(pl3_id)
				}
				case 9: /* Option 0 - Back */
				{
					show_entit_menu(pl3_id)
				}
			}
		}
		case 2:		/* PAGE 2*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Add p90 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_p90")
					show_addent_menu(pl3_id)
				}
				case 1: /* Option 2 - Add tmp */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_tmp")
					show_addent_menu(pl3_id)
				}
				case 2: /* Option 3 - Add ump45 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_ump45")
					show_addent_menu(pl3_id)
				}
				case 3: /* Option 4 - Add mac10 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_mac10")
					show_addent_menu(pl3_id)
				}
				case 4: /* Option 5 - Add mp5navy */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_mp5navy")
					show_addent_menu(pl3_id)
				}
				case 7: /* Option 8 - Add smg ammo */
				{	
					console_cmd(pl3_id,"csdm_setent smg_ammo")
					show_addent_menu(pl3_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl3_id] = 3
					show_addent_menu(pl3_id)
				}
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl3_id] = 1
					show_addent_menu(pl3_id)
				}
			}
		}
		case 3:		/* PAGE 3*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Add ak47 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_ak47")
					show_addent_menu(pl3_id)
				}
				case 1: /* Option 2 - Add m4a1 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_m4a1")
					show_addent_menu(pl3_id)
				}
				case 2: /* Option 3 - Add aug */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_aug")
					show_addent_menu(pl3_id)
				}
				case 3: /* Option 4 - Add sg552 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_sg552")
					show_addent_menu(pl3_id)
				}
				case 4: /* Option 5 - Add scout */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_scout")
					show_addent_menu(pl3_id)
				}
				case 5: /* Option 6 - Add sg550 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_sg550")
					show_addent_menu(pl3_id)
				}
				case 7: /* Option 8 - Add rifle ammo */
				{	
					console_cmd(pl3_id,"csdm_setent rifle_ammo")
					show_addent_menu(pl3_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl3_id] = 4
					show_addent_menu(pl3_id)
				}
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl3_id] = 2
					show_addent_menu(pl3_id)
				}
			}
		}
		case 4:		/* PAGE 4*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Add g3sg1 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_g3sg1")
					show_addent_menu(pl3_id)
				}
				case 1: /* Option 2 - Add galil */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_galil")
					show_addent_menu(pl3_id)
				}
				case 2: /* Option 3 - Add famas */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_famas")
					show_addent_menu(pl3_id)
				}
				case 3: /* Option 4 - Add rifle ammo */
				{	
					console_cmd(pl3_id,"csdm_setent rifle_ammo")
					show_addent_menu(pl3_id)
				}
				case 5: /* Option 6 - Add awp */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_awp")
					show_addent_menu(pl3_id)
				}
				case 7: /* Option 8 - Add awp ammo */
				{	
					console_cmd(pl3_id,"csdm_setent awp_ammo")
					show_addent_menu(pl3_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl3_id] = 5
					show_addent_menu(pl3_id)
				}
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl3_id] = 3
					show_addent_menu(pl3_id)
				}
			}
		}
		case 5:		/* PAGE 5*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Add xm1014 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_xm1014")
					show_addent_menu(pl3_id)
				}
				case 1: /* Option 2 - Add m3 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_m3")
					show_addent_menu(pl3_id)
				}
				case 3: /* Option 4 - Add shotgun ammo */
				{	
					console_cmd(pl3_id,"csdm_setent shotgun_ammo")
					show_addent_menu(pl3_id)
				}
				case 5: /* Option 6 - Add m249 */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_m249")
					show_addent_menu(pl3_id)
				}
				case 7: /* Option 8 - Add para ammo */
				{	
					console_cmd(pl3_id,"csdm_setent para_ammo")
					show_addent_menu(pl3_id)
				}
				case 8: /* Option 9 - More */
				{
					g_MenuPage[pl3_id] = 6
					show_addent_menu(pl3_id)
				}
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl3_id] = 4
					show_addent_menu(pl3_id)
				}
			}
		}
		case 6:		/* PAGE 6*/
		{
			switch(key)
			{
				case 0: /* Option 1 - Add item longjump */
				{	
					console_cmd(pl3_id,"csdm_setent item_longjump")
					show_addent_menu(pl3_id)
				}
				case 1: /* Option 2 - Add item healthkit */
				{	
					console_cmd(pl3_id,"csdm_setent item_healthkit")
					show_addent_menu(pl3_id)
				}
				case 2: /* Option 3 - Add armor */
				{	
					console_cmd(pl3_id,"csdm_setent armor")
					show_addent_menu(pl3_id)
				}
				case 3: /* Option 4 - Add item battery */
				{	
					console_cmd(pl3_id,"csdm_setent item_battery")
					show_addent_menu(pl3_id)
				}
				case 4: /* Option 5 - Add full ammo */
				{	
					console_cmd(pl3_id,"csdm_setent full_ammo")
					show_addent_menu(pl3_id)
				}
				case 6: /* Option 7 - Add hegrenade */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_hegrenade")
					show_addent_menu(pl3_id)
				}
				case 7: /* Option 8 - Add flashbang */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_flashbang")
					show_addent_menu(pl3_id)
				}
				case 8: /* Option 9 - Add smokegrenade */
				{	
					console_cmd(pl3_id,"csdm_setent weapon_smokegrenade")
					show_addent_menu(pl3_id)
				}
				case 9: /* Option 0 - Back */
				{
					g_MenuPage[pl3_id] = 5
					show_addent_menu(pl3_id)
				}
			}
		}						
	}
	return PLUGIN_HANDLED
}


// KWo - general menu for CSDM

public show_gen_menu(id)
{
	new menuoption[10][64]
	new menu[8]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	
	switch(g_MenuPage[id])
	{
		case 1:		/* PAGE 1*/
		{
			copy(menu, 7, "1/3")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (1<<5)
			keys |= (1<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)
			
			format(menuoption[0], 63, "1. CSDM is %s", (get_cvar_num("csdm_active")) ? "enabled" : "disabled")
			format(menuoption[1], 63, "2. Players %s weapons", (get_cvar_num("csdm_add_items")) ? "find" : "choose")
			format(menuoption[2], 63, "3. Use random spawns %s", (get_cvar_num("csdm_random_spawns")) ? "enabled" : "disabled")
			format(menuoption[3], 63, "4. Armor menu %s", (get_cvar_num("csdm_enable_amenu")) ? "enabled" : "disabled")
			format(menuoption[4], 63, "5. Grenade menu %s", (get_cvar_num("csdm_enable_gmenu")) ? "enabled" : "disabled")
			format(menuoption[5], 63, "6. Auto-equip players with armor %s", (get_cvar_num("csdm_auto_equip")) ? "enabled" : "disabled")
			format(menuoption[6], 63, "7. Auto-equip players with grenades %s", (get_cvar_num("csdm_auto_gren")) ? "enabled" : "disabled")
			format(menuoption[7], 63, "8. Allow players to drop weapons %s", (get_cvar_num("csdm_drop_weapons")) ? "enabled" : "disabled")
			format(menuoption[8], 63, "9. More")
			format(menuoption[9], 63, "0. Back")			
		}

		case 2:		/* PAGE 2*/
		{
			copy(menu, 7, "2/3")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (1<<5)
			keys |= (1<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)
		
			format(menuoption[0], 63, "1. Allows players to use >guns< cmd %s", (get_cvar_num("csdm_allow_clguns")) ? "enabled" : "disabled")
			format(menuoption[1], 63, "2. Spam message at respawn %s", (get_cvar_num("csdm_spawn_spam")) ? "enabled" : "disabled")
			format(menuoption[2], 63, "3. Drop %s on death", (get_cvar_num("csdm_drop_packs")) ? "weapon" : "pack")
			format(menuoption[3], 63, "4. Killing all without TK punishment %s", (get_cvar_num("csdm_kill_all")) ? "enabled" : "disabled")
			format(menuoption[4], 63, "5. Use sounds for weapons %s", (get_cvar_num("csdm_sounds")) ? "enabled" : "disabled")
			format(menuoption[5], 63, "6. Allow use radio %s", (get_cvar_num("csdm_allow_radio")) ? "enabled" : "disabled")
			format(menuoption[6], 63, "7. Allow more than one type of weapon %s", (get_cvar_num("csdm_hold_many")) ? "enabled" : "disabled")
			format(menuoption[7], 63, "8. Explain usage for longjump %s", (get_cvar_num("csdm_explain")) ? "enabled" : "disabled")			
			format(menuoption[8], 63, "9. More")
			format(menuoption[9], 63, "0. Back")
		}

		case 3:		/* PAGE 3*/
		{
			copy(menu, 7, "3/3")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (1<<5)
			keys |= (1<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)

			new stripflags[10]
			get_cvar_string("csdm_stripper", stripflags, 9)
			new striptype=read_flags(stripflags)

			format(menuoption[0], 63, "1. Auto-drop guns %s", (get_cvar_num("csdm_auto_drop")) ? "enabled" : "disabled")
			format(menuoption[1], 63, "2. Pack jumps into drop packs %s", (get_cvar_num("csdm_pack_jumps")) ? "enabled" : "disabled")
			format(menuoption[2], 63, "3. Use Asskicr's changes %s", (get_cvar_num("csdm_asskicr")) ? "enabled" : "disabled")
			format(menuoption[3], 63, "4. Play intro wave on player's respawn %s", (get_cvar_num("csdm_spawn_wave")) ? "enabled" : "disabled")
			format(menuoption[4], 63, "5. Objectives, buzones etc at CSDM start %s",	(get_cvar_num("csdm_stripper_remove")) ? "removed" : "hidden" )
			format(menuoption[5], 63, "6. Remove bomb/hostage rescue/vip zones from the map %s", (striptype & (1<<0)) ? "enabled" : "disabled")
			format(menuoption[6], 63, "7. Remove buyzones from the map %s", (striptype & (1<<1)) ? "enabled" : "disabled")
			format(menuoption[7], 63, "8. Remove weapons on the floor %s", (striptype & (1<<2)) ? "enabled" : "disabled")
			format(menuoption[8], 63, "9. Remove starting weapons %s", (striptype & (1<<3)) ? "enabled" : "disabled")
			format(menuoption[9], 63, "0. Back")
		}
	}
	format(menubody, 511, "\yCSDM Settings Menu %s:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menu, menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody, -1, "CSDM Settings Menu")
	return PLUGIN_HANDLED
}


// KWo - cvars menu for CSDM

public show_cvars_menu(id)
{
	new menuoption[10][64]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	keys |= (1<<0)
	keys |= (1<<1)
	keys |= (1<<2)
	keys |= (1<<3)
	keys |= (1<<4)
	keys |= (1<<5)
	keys |= (1<<6)
	keys |= (0<<7)
	keys |= (0<<8)
	keys |= (1<<9)

	format(menuoption[0], 63, "1. Spawn protection time %d", get_cvar_num("csdm_freeze_time"))
	format(menuoption[1], 63, "2. Time until items delete %d", get_cvar_num("csdm_item_time"))
	format(menuoption[2], 63, "3. Weapon disappears after drop after %d sec", get_cvar_num("csdm_delete_time"))
	format(menuoption[3], 63, "4. CSDM spawn mode %d", get_cvar_num("csdm_spawn_protect"))
	format(menuoption[4], 63, "5. Battery health %d", get_cvar_num("csdm_battery"))
	format(menuoption[5], 63, "6. Medkit health %d", get_cvar_num("csdm_medkit"))
	format(menuoption[6], 63, "7. Max wait time for gun menu %d", get_cvar_num("csdm_maxdelmenu_time"))
	format(menuoption[9], 63, "0. Back")

	format(menubody, 511, "\yCSDM Cvars Menu:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody, -1, "CSDM Cvars Menu")
	return PLUGIN_HANDLED
}

public show_voting_menu(id)
{
	new menuoption[10][64]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	keys |= (1<<0)
	keys |= (1<<1)
	keys |= (1<<2)
	keys |= (1<<3)
	keys |= (1<<4)
	keys |= (1<<5)
	keys |= (1<<6)
	keys |= (1<<7)
	keys |= (1<<8)
	keys |= (1<<9)

	format(menuoption[0], 63, "1. CSDM voting %d", get_cvar_num("csdm_voting"))
	new vote_string[10]
	get_cvar_string("csdm_voteflags", vote_string, 9)
	format(menuoption[1], 63, "2. CSDM voteflags %s", vote_string)
	format(menuoption[2], 63, "3. CSDM vote ratio %f", get_cvar_float("csdm_ratio"))
	format(menuoption[3], 63, "4. CSDM vote time lenght %d", get_cvar_num("csdm_votetime"))
	format(menuoption[4], 63, "5. CSDM next vote wait time %d", get_cvar_num("csdm_nextvote"))
	format(menuoption[5], 63, "6. CSDM vote for >on<")
	format(menuoption[6], 63, "7. CSDM vote for >mode<")
	format(menuoption[7], 63, "8. CSDM vote for >Free-For-All mode<")
	format(menuoption[8], 63, "9. CSDM cancel vote")	
	format(menuoption[9], 63, "0. Back")

	format(menubody, 511, "\yCSDM Voting Menu:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody, -1, "CSDM Voting Menu:")
	return PLUGIN_HANDLED
}

public show_entit_menu(id)
{
	new menuoption[10][64]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	keys |= (1<<0)
	keys |= (1<<1)
	keys |= (1<<2)
	keys |= (1<<3)
	keys |= (1<<4)
	keys |= (1<<5)
	keys |= (1<<6)
	keys |= (0<<7)
	keys |= (0<<8)
	keys |= (1<<9)
			
	format(menuoption[0], 63, "1. Add a CSDM entity")
	format(menuoption[1], 63, "2. Delete a CSDM entity")
	format(menuoption[2], 63, "3. Find the nearest entity")
	format(menuoption[3], 63, "4. Return the entity id you are looking at")
	format(menuoption[4], 63, "5. Return the classname of an entity id")
	format(menuoption[5], 63, "6. Dump a text file with entity information")
	format(menuoption[6], 63, "7. Return the number of entities in the map")
	format(menuoption[9], 63, "0. Back")			
	
	format(menubody, 511, "\yCSDM Entities Menu:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody, -1, "CSDM Entities Menu:")
	return PLUGIN_HANDLED	
}

public show_spawns_menu(id)
{
	new menuoption[10][64]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	keys |= (1<<0)
	keys |= (1<<1)
	keys |= (1<<2)
	keys |= (1<<3)
	keys |= (1<<4)
	keys |= (1<<5)
	keys |= (1<<6)
	keys |= (1<<7)
	keys |= (1<<8)
	keys |= (1<<9)
			
	format(menuoption[0], 63, "1. Create a CSDM spawn point")
	format(menuoption[1], 63, "2. Delete a CSDM spawn point")
	format(menuoption[2], 63, "3. See how many spawns there are")
	format(menuoption[3], 63, "4. View all CSDM spawns")
	format(menuoption[4], 63, "5. View active spawns")
	format(menuoption[5], 63, "6. Hide all spawns")
	format(menuoption[6], 63, "7. Shows you the number of the nearest spawn point")
	format(menuoption[7], 63, "8. Find your origin for debugging bad spawns")
	format(menuoption[8], 63, "9. Return the classname of a spawn")	
	format(menuoption[9], 63, "0. Back")			
	
	format(menubody, 511, "\yCSDM Spawn Points Menu:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody, -1, "CSDM Spawn Points Menu")
	return PLUGIN_HANDLED	
}


public show_addsp_menu(id)
{
	new menuoption[10][64]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	keys |= (1<<0)
	keys |= (1<<1)
	keys |= (1<<2)
	keys |= (1<<3)
	keys |= (1<<4)
	keys |= (1<<5)
	keys |= (1<<6)
	keys |= (0<<7)
	keys |= (0<<8)
	keys |= (1<<9)

	format(menuoption[0], 63, "1. Add a random CSDM spawn point (no angle)")			
	format(menuoption[1], 63, "2. Add a T CSDM spawn point (no angle)")
	format(menuoption[2], 63, "3. Add a CT CSDM spawn point (no angle)")
	format(menuoption[3], 63, "4. Add a random CSDM spawn point (with angle)")	
	format(menuoption[4], 63, "5. Add a T CSDM spawn point (with angle)")
	format(menuoption[5], 63, "6. Add a CT CSDM spawn point (with angle)")
	
	format(menuoption[9], 63, "0. Back")			
	
	format(menubody, 511, "\yCSDM Add Spawns Menu:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody, -1, "CSDM Add Spawns Menu")
	return PLUGIN_HANDLED	
}

public show_addent_menu(pl2_id)
{
	new menuoption[10][64]
	new menu[8]
	new keys
	new menubody[512]
	// Clear string
	for(new z = 0; z < 10; ++z)
	{
		menuoption[z][0] = 0
	}
	
	switch(g_MenuPage[pl2_id])
	{
		case 1:		/* PAGE 1*/
		{		
			copy(menu, 7, "1/6")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (0<<5)
			keys |= (0<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)
			
			format(menuoption[0], 63, "1. Add glock18")
			format(menuoption[1], 63, "2. Add usp")
			format(menuoption[2], 63, "3. Add elite")
			format(menuoption[3], 63, "4. Add fiveseven")
			format(menuoption[4], 63, "5. Add deagle")
			format(menuoption[7], 63, "8. Add pistol ammo")
			format(menuoption[8], 63, "9. More")
			format(menuoption[9], 63, "0. Back")			
		}

		case 2:		/* PAGE 2*/
		{
			copy(menu, 7, "2/6")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (0<<5)
			keys |= (0<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)
		
			format(menuoption[0], 63, "1. Add p90")
			format(menuoption[1], 63, "2. Add tmp")
			format(menuoption[2], 63, "3. Add ump45")
			format(menuoption[3], 63, "4. Add mac10")
			format(menuoption[4], 63, "5. Add mp5navy")
			format(menuoption[7], 63, "8. Add smg ammo")			
			format(menuoption[8], 63, "9. More")
			format(menuoption[9], 63, "0. Back")
		}

		case 3:		/* PAGE 3*/
		{
			copy(menu, 7, "3/6")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (1<<5)
			keys |= (0<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)

			format(menuoption[0], 63, "1. Add ak47")
			format(menuoption[1], 63, "2. Add m4a1")
			format(menuoption[2], 63, "3. Add aug")
			format(menuoption[3], 63, "4. Add sg552")			
			format(menuoption[4], 63, "5. Add scout")			
			format(menuoption[5], 63, "6. Add sg550")
			format(menuoption[7], 63, "8. Add rifle ammo")			
			format(menuoption[8], 63, "9. More")			
			format(menuoption[9], 63, "0. Back")			
		}
		case 4:		/* PAGE 4*/
		{
			copy(menu, 7, "4/6")
			keys |= (1<<0)
			if (get_cvar_num("csdm_steam"))
			{						
				keys |= (1<<1)
				keys |= (1<<2)
			} else {
				keys |= (0<<1)
				keys |= (0<<2)
			}
			keys |= (1<<3)
			keys |= (0<<4)
			keys |= (1<<5)
			keys |= (0<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)

			format(menuoption[0], 63, "1. Add g3sg1")
			if (get_cvar_num("csdm_steam")){			
				format(menuoption[1], 63, "2. Add galil")
				format(menuoption[2], 63, "3. Add famas")
			}
			format(menuoption[3], 63, "4. Add rifle ammo")						
			format(menuoption[5], 63, "6. Add awp")
			format(menuoption[7], 63, "8. Add awp ammo")			
			format(menuoption[8], 63, "9. More")			
			format(menuoption[9], 63, "0. Back")			
		}
		case 5:		/* PAGE 5*/
		{
			copy(menu, 7, "5/6")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (0<<2)
			keys |= (1<<3)
			keys |= (0<<4)
			keys |= (1<<5)
			keys |= (0<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)

			format(menuoption[0], 63, "1. Add xm1014")
			format(menuoption[1], 63, "2. Add m3")
			format(menuoption[3], 63, "4. Add shotgun ammo")					
			format(menuoption[5], 63, "6. Add m249")
			format(menuoption[7], 63, "8. Add para ammo")			
			format(menuoption[8], 63, "9. More")			
			format(menuoption[9], 63, "0. Back")			
		}
		case 6:		/* PAGE 6*/
		{
			copy(menu, 7, "6/6")
			keys |= (1<<0)
			keys |= (1<<1)
			keys |= (1<<2)
			keys |= (1<<3)
			keys |= (1<<4)
			keys |= (0<<5)
			keys |= (1<<6)
			keys |= (1<<7)
			keys |= (1<<8)
			keys |= (1<<9)

			format(menuoption[0], 63, "1. Add longjump")
			format(menuoption[1], 63, "2. Add healthkit")
			format(menuoption[2], 63, "3. Add armor")			
			format(menuoption[3], 63, "4. Add battery")
			format(menuoption[4], 63, "5. Add full ammo")
			format(menuoption[6], 63, "7. Add hegrenade")
			format(menuoption[7], 63, "8. Add flashbang")			
			format(menuoption[8], 63, "9. Add smokegrenade")			
			format(menuoption[9], 63, "0. Back")			
		}		
	}
	format(menubody, 511, "\yCSDM Add Entities Menu %s:\w^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menu, menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(pl2_id, keys, menubody, -1, "CSDM Add Entities Menu")
	return PLUGIN_HANDLED
}



public action_csdm_menu(id,key)
{
	new pl_id=id
	switch(key)
	{
		case 0: /* Option 1 - General settings */
		{	
			g_MenuPage[pl_id]=1	
			show_gen_menu(pl_id)
		}
		case 1: /* Option 2 - CSDM cvars */
		{		
			show_cvars_menu(pl_id)
		}		
		case 2: /* Option 3 - CSDM voting */
		{		
			show_voting_menu(pl_id)
		}		
		case 3: /* Option 4 - Entities commands */
		{
			show_entit_menu(pl_id)
		}
		case 4: /* Option 5 - Spawn points commands */
		{
			show_spawns_menu(pl_id)
		}
		case 5: /* Option 6 - CSDM version */
		{
			csdm_version(pl_id)
			show_csdm_menu(id)
		}		
		case 9: /* Option 9 - Exit */
		{
		}
	}
	return PLUGIN_HANDLED
}

public show_csdm_menu(id)
{
	new menuoption[7][64]
	new menubody[512] 
	new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<9)
		// Clear string
	for(new z = 0; z < 7; ++z)
	{
		menuoption[z][0] = 0
	}
	
	format(menuoption[0], 63, "1. General settings")
	format(menuoption[1], 63, "2. CSDM cvars")
	format(menuoption[2], 63, "3. CSDM voting")
	format(menuoption[3], 63, "4. Entities commands")
	format(menuoption[4], 63, "5. Spawn points commands")
	format(menuoption[5], 63, "6. CSDM version")
	format(menuoption[6], 63, "0. Exit")
	format(menubody, 511, "\yCSDM MOD Menu :\w^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
			menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6])
	show_menu(id, keys, menubody, -1, "CSDM MOD Menu")
	return PLUGIN_HANDLED
}

public csdm_disp_menu(id,level,cid)
{
  if (cmd_access(id,level,cid,1))
    show_csdm_menu(id)
  return PLUGIN_HANDLED
} 



// KWo - here I've added some functions called from tasks to let bots be equpied by armor, grenades,
// primary and secondary weapon

public bot_armor_menu(param[])
{
	new bot_index=param[0]	
	ArmorChoice(bot_index,1)
	remove_task(100+bot_index)	
	return PLUGIN_CONTINUE  
}	

public bot_gren_menu(param[])
{
	new bot_index=param[0]	
	GrenChoice(bot_index,1)
	remove_task(200+bot_index)	
	return PLUGIN_CONTINUE  
}	

public bot_equip_menu(param[])
{
	new bot_index=param[0]	
	EquipChoice(bot_index,1)
	remove_task(300+bot_index)	
	return PLUGIN_CONTINUE  
}

public bot_prim_weap(param[])
{
	new bot_index=param[0]	
	new bot_page=g_MenuPos[bot_index]
	new bot_name[32]
	get_user_name(bot_index,bot_name,31)
	PrimaryWeapon(bot_index,bot_page)		
	remove_task(400+bot_index+32*bot_page)	
	return PLUGIN_CONTINUE  
}

public bot_sec_weap(param[])
{
	new bot_index=param[0]	
	SecondWeapon(bot_index,1)
	remove_task(600+bot_index)
	return PLUGIN_CONTINUE  
}

public plugin_modules()
{
	require_module("engine")
	require_module("fun")
}