scripting/dm_equipment.sp
author Ruben Gonzalez <drifter01620@gmail.com>
Thu Feb 13 12:42:56 2014 -0500 (2014-02-13)
changeset 172 f7f4cb013eaf
parent 92 52cc55d67b2f
permissions -rw-r--r--
Change SetEntData to SetEntProp, Fix giving helmet wrongly.
     1 /**
     2  * dm_equipment.sp
     3  * Adds preset spawning to CS:S DM.
     4  * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
     5  * by David "BAILOPAN" Anderson, http://www.bailopan.net/cssdm/
     6  *
     7  * This program is free software; you can redistribute it and/or
     8  * modify it under the terms of the GNU General Public License
     9  * as published by the Free Software Foundation; either version 2
    10  * of the License, or (at your option) any later version.
    11  *
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  * 
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program; if not, write to the Free Software
    19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20  *
    21  * Version: $Id$
    22  */
    23 
    24 #pragma semicolon 1
    25 #include <sourcemod>
    26 #include <sdktools>
    27 #include <cssdm>
    28 
    29 #define CSSDM_GUNMENU_NO		0
    30 #define CSSDM_GUNMENU_YES		1
    31 #define CSSDM_GUNMENU_RANDOM	2
    32 
    33 /** Plugin Stuff */
    34 new Handle:cssdm_enable_equipment;					/** cssdm_enable_equipment cvar */
    35 new Handle:g_SpawnTimers[MAXPLAYERS+1];				/* Post-spawn timers */
    36 new Handle:g_hPrimaryMenu = INVALID_HANDLE;			/* Priamry menu Handle */
    37 new Handle:g_hSecondaryMenu = INVALID_HANDLE;		/* Secondary menu Handle */
    38 new Handle:g_hEquipMenu = INVALID_HANDLE;			/* Main equipment menu */
    39 new bool:g_IsEnabled = false;						/* Whether the plugin should work */
    40 new g_PrimaryChoices[MAXPLAYERS+1];					/* Primary weapon selections */
    41 new g_SecondaryChoices[MAXPLAYERS+1];				/* Secondary weapon selections */
    42 new bool:g_GunMenuEnabled[MAXPLAYERS+1];			/* Whether the gun menu is enabled */
    43 new bool:g_GunMenuAvailable[MAXPLAYERS+1];			/* Whether the gun menu is available */
    44 new bool:g_bIsGo = false;							/* Are we running on CS:GO? */
    45 
    46 /** HUMAN CONFIGS */
    47 new g_PrimaryList[CSSDM_MAX_WEAPONS];
    48 new g_SecondaryList[CSSDM_MAX_WEAPONS];
    49 new g_PrimaryCount = 0;
    50 new g_SecondaryCount = 0;
    51 new g_PrimaryMenu = CSSDM_GUNMENU_YES;
    52 new g_SecondaryMenu = CSSDM_GUNMENU_YES;
    53 new bool:g_AllowBuy = false;
    54 new g_ArmorAmount = 100;
    55 new bool:g_Helmets = true;
    56 new g_Flashes = 0;
    57 new bool:g_Smokes = false;
    58 new bool:g_HEs = false;
    59 new bool:g_NightVision = false;
    60 new bool:g_DefuseKits = true;
    61 new bool:g_AllowGunCommand = true;
    62 new g_HealthAmount = 100;
    63 //CSGO
    64 new bool:g_Decoy = false;
    65 new bool:g_Taser = true;
    66 
    67 /** BOT CONFIGS */
    68 new g_BotPrimaryList[CSSDM_MAX_WEAPONS];
    69 new g_BotSecondaryList[CSSDM_MAX_WEAPONS];
    70 new g_BotPrimaryCount = 0;
    71 new g_BotSecondaryCount = 0;
    72 new g_BotArmor = 100;
    73 new bool:g_BotHelmets = false;
    74 new g_BotFlashes = 0;
    75 new bool:g_BotSmokes = false;
    76 new bool:g_BotHEs = false;
    77 new bool:g_BotDefuseKits = true;
    78 new g_BotHealthAmount = 100;
    79 //CSGO
    80 new bool:g_BotDecoy = false;
    81 new bool:g_BotTaser = true;
    82 
    83 /** PUBLIC INFO */
    84 public Plugin:myinfo = 
    85 {
    86 	name = "CS:S DM Equipment",
    87 	author = "AlliedModders LLC",
    88 	description = "Adds gun menu/equipment to CS:S DM",
    89 	version = CSSDM_VERSION,
    90 	url = "http://www.bailopan.net/cssdm/"
    91 };
    92 
    93 /******************
    94  * IMPLEMENTATION *
    95  ******************/
    96  
    97 public OnPluginStart()
    98 {
    99 	new String:game[64];
   100 	GetGameFolderName(game, sizeof(game));
   101 	if (StrEqual(game, "csgo", false))
   102 	{
   103 		g_bIsGo = true;
   104 	}
   105 	
   106 	LoadTranslations("cssdm.phrases");
   107 	
   108 	RegConsoleCmd("say", Command_Say);
   109 	RegConsoleCmd("say_team", Command_Say);
   110 	
   111 	cssdm_enable_equipment = CreateConVar("cssdm_enable_equipment", "1", "Sets whether the equipment plugin is enabled");
   112 	HookConVarChange(cssdm_enable_equipment, OnEquipmentEnableChange);
   113 	
   114 	g_hEquipMenu = CreateMenu(Menu_EquipHandler, MenuAction_DrawItem|MenuAction_DisplayItem);
   115 	SetMenuTitle(g_hEquipMenu, "Weapon Options:");
   116 	SetMenuExitButton(g_hEquipMenu, false);
   117 	AddMenuItem(g_hEquipMenu, "", "New weapons");
   118 	AddMenuItem(g_hEquipMenu, "", "Same weapons");
   119 	AddMenuItem(g_hEquipMenu, "", "Same weapons every time");
   120 	AddMenuItem(g_hEquipMenu, "", "Random weapons");
   121 	AddMenuItem(g_hEquipMenu, "", "Random weapons every time");
   122 }
   123 
   124 public OnEquipmentEnableChange(Handle:convar, const String:oldValue[], const String:newValue[])
   125 {
   126 	g_IsEnabled = StringToInt(newValue) ? true : false;
   127 }
   128 
   129 public OnConfigsExecuted()
   130 {
   131 	LoadDefaults();
   132 	
   133 	if ((g_IsEnabled = LoadConfigFile("cfg/cssdm/cssdm.equip.txt")) == false)
   134 	{
   135 		LogError("[CSSDM] Could not find equipment file \"%s\"", "cfg/cssdm/cssdm.equip.txt");
   136 		return;
   137 	}
   138 	
   139 	if (!GetConVarInt(cssdm_enable_equipment))
   140 	{
   141 		g_IsEnabled = false;
   142 		return;
   143 	}
   144 	
   145 	/** See if there is a map version */
   146 	decl String:map[64];
   147 	decl String:path[255];
   148 	GetCurrentMap(map, sizeof(map));
   149 	Format(path, sizeof(path), "cfg/cssdm/maps/%s.equip.txt", map);
   150 	
   151 	if (FileExists(path))
   152 	{
   153 		LoadConfigFile(path);
   154 	}
   155 }
   156 
   157 public Action:DM_OnClientDeath(client)
   158 {
   159 	if (g_SpawnTimers[client] != INVALID_HANDLE)
   160 	{
   161 		KillTimer(g_SpawnTimers[client]);
   162 		g_SpawnTimers[client] = INVALID_HANDLE;
   163 	}
   164 	g_GunMenuAvailable[client] = true;
   165 }
   166 
   167 public OnClientPutInServer(client)
   168 {
   169 	g_GunMenuEnabled[client] = true;
   170 	g_GunMenuAvailable[client] = true;
   171 	g_PrimaryChoices[client] = -1;
   172 	g_SecondaryChoices[client] = -1;
   173 }
   174 
   175 public OnClientDisconnect(client)
   176 {
   177 	if (g_SpawnTimers[client] != INVALID_HANDLE)
   178 	{
   179 		KillTimer(g_SpawnTimers[client]);
   180 		g_SpawnTimers[client] = INVALID_HANDLE;
   181 	}
   182 }
   183 
   184 public DM_OnClientSpawned(client)
   185 {
   186 	if (!ShouldRun())
   187 	{
   188 		return;
   189 	}
   190 	
   191 	if (!IsFakeClient(client))
   192 	{
   193 		if (g_ArmorAmount > 0)
   194 		{
   195 			GivePlayerItem(client, "item_kevlar");
   196 			GivePlayerItem(client, "item_kevlar");
   197 			SetClientArmor(client, g_ArmorAmount);
   198 		}
   199 		if (g_HealthAmount > 0)
   200 		{
   201 			SetClientHealth(client, g_HealthAmount);
   202 		}
   203 		if (g_Helmets)
   204 		{
   205 			if (g_ArmorAmount > 0)
   206 			{
   207 				GivePlayerItem(client, "item_assaultsuit");
   208 				GivePlayerItem(client, "item_assaultsuit");
   209 				SetClientArmor(client, g_ArmorAmount);
   210 			}
   211 			GiveHelmet(client);
   212 		}
   213 		GiveGrenades(client, g_Flashes, g_HEs, g_Smokes, g_Decoy);
   214 		if (g_NightVision)
   215 		{
   216 			GiveNightVision(client);
   217 		}
   218 		if (g_bIsGo && g_Taser)
   219 		{
   220 			GivePlayerItem(client, "weapon_taser");
   221 		}
   222 	}
   223 	else
   224 	{
   225 		/* See if we'll need to strip this bot */
   226 		if (g_BotSecondaryCount || g_BotPrimaryCount)
   227 		{
   228 			DM_StripBotItems(client);
   229 		}
   230 		if (g_BotArmor > 0)
   231 		{
   232 			GivePlayerItem(client, "item_kevlar");
   233 			GivePlayerItem(client, "item_kevlar");
   234 			SetClientArmor(client, g_BotArmor);
   235 		} else {
   236 			/* Make sure bot didn't buy armor */
   237 			SetClientArmor(client, 0);
   238 		}
   239 		if (g_BotHealthAmount > 0)
   240 		{
   241 			SetClientHealth(client, g_BotHealthAmount);
   242 		}
   243 		if (g_BotHelmets)
   244 		{
   245 			if (g_BotArmor > 0)
   246 			{
   247 				GivePlayerItem(client, "item_assaultsuit");
   248 				GivePlayerItem(client, "item_assaultsuit");
   249 				SetClientArmor(client, g_BotArmor);
   250 			}
   251 			GiveHelmet(client);
   252 		}
   253 		if (g_bIsGo && g_BotTaser)
   254 		{
   255 			GivePlayerItem(client, "weapon_taser");
   256 		}
   257 		GiveGrenades(client, g_BotFlashes, g_BotHEs, g_BotSmokes, g_BotDecoy);
   258 	}
   259 	if (!g_AllowBuy && g_SpawnTimers[client] == INVALID_HANDLE)
   260 	{
   261 		/* Small delay - we want to avoid ResetHUD */
   262 		g_SpawnTimers[client] = CreateTimer(0.1, PlayerPostSpawn, client);
   263 	}
   264 }
   265 
   266 public Action:PlayerPostSpawn(Handle:timer, any:client)
   267 {
   268 	g_SpawnTimers[client] = INVALID_HANDLE;
   269 	
   270 	if (!ShouldRun())
   271 	{
   272 		return Plugin_Stop;
   273 	}
   274 	
   275 	if (IsFakeClient(client))
   276 	{
   277 		if (g_BotSecondaryCount > 0)
   278 		{
   279 			new index;
   280 			if (g_BotSecondaryCount == 1)
   281 			{
   282 				index = g_BotSecondaryList[0];
   283 			} else {
   284 				index = GetRandomInt(0, g_BotSecondaryCount-1);
   285 				index = g_BotSecondaryList[index];
   286 			}
   287 			decl String:classname[64];
   288 			DM_GetWeaponClassname(index, classname, sizeof(classname));
   289 			GivePlayerItem(client, classname);
   290 		}
   291 		if (g_BotPrimaryCount > 0)
   292 		{
   293 			new index;
   294 			if (g_BotPrimaryCount == 1)
   295 			{
   296 				index = g_BotPrimaryList[0];
   297 			} else {
   298 				index = GetRandomInt(0, g_BotPrimaryCount-1);
   299 				index = g_BotPrimaryList[index];
   300 			}
   301 			decl String:classname[64];
   302 			DM_GetWeaponClassname(index, classname, sizeof(classname));
   303 			GivePlayerItem(client, classname);
   304 		}
   305 		if (g_BotDefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
   306 		{
   307 			GivePlayerItem(client, "item_defuser");
   308 		}
   309 	} else {
   310 		if (g_DefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
   311 		{
   312 			GivePlayerItem(client, "item_defuser");
   313 		}
   314 		
   315 		new numGiven = 0;
   316 		/* First, check if we should only be giving one of something automatically */
   317 		if ((g_SecondaryMenu == CSSDM_GUNMENU_RANDOM || g_SecondaryMenu == CSSDM_GUNMENU_YES)
   318 			&& g_SecondaryCount == 1)
   319 		{
   320 			GiveSecondary(client, 0);
   321 			numGiven++;
   322 		} else if (g_PrimaryMenu == CSSDM_GUNMENU_RANDOM && g_PrimaryCount > 1) {
   323 			GivePrimary(client, g_PrimaryCount);
   324 			numGiven++;
   325 		}
   326 		
   327 		if ((g_PrimaryMenu == CSSDM_GUNMENU_RANDOM || g_PrimaryMenu == CSSDM_GUNMENU_YES)
   328 			&& g_PrimaryCount == 1)
   329 		{
   330 			GivePrimary(client, 0);
   331 			numGiven++;
   332 		} else if (g_SecondaryMenu == CSSDM_GUNMENU_RANDOM && g_SecondaryCount > 1) {
   333 			GiveSecondary(client, g_SecondaryCount);
   334 			numGiven++;
   335 		}
   336 		
   337 		/* If we've already given two weapons, there is no need for a menu. */
   338 		if (numGiven == 2)
   339 		{
   340 			return Plugin_Stop;
   341 		}
   342 		
   343 		if (g_GunMenuEnabled[client])
   344 		{
   345 			DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
   346 		} else {
   347 			GiveBothFromChoices(client);
   348 		}
   349 	}
   350 	
   351 	return Plugin_Stop;
   352 }
   353 
   354 public Action:Command_Say(client, args)
   355 {
   356 	if (!ShouldRun())
   357 	{
   358 		return Plugin_Continue;
   359 	}
   360 	
   361 	new String:text[192];
   362 	GetCmdArg(1, text, sizeof(text));
   363 	
   364 	if (strcmp(text, "guns") == 0)
   365 	{
   366 		if (!g_AllowGunCommand)
   367 		{
   368 			PrintToChat(client, "[CSSDM] %t", "GunsMenuDisabled");
   369 			return Plugin_Handled;
   370 		}
   371 		
   372 		if (!ChooseFromSecondary() && !ChooseFromPrimary())
   373 		{
   374 			PrintToChat(client, "[CSSDM] %t", "GunsMenuNotAvailable");
   375 			return Plugin_Handled;
   376 		}
   377 		
   378 		if (g_GunMenuEnabled[client])
   379 		{
   380 			PrintToChat(client, "[CSSDM] %t", "GunsMenuAlreadyEnabled");
   381 			return Plugin_Handled;
   382 		}
   383 		
   384 		g_GunMenuEnabled[client] = true;
   385 		if (!g_GunMenuAvailable[client])
   386 		{
   387 			PrintToChat(client, "[CSSDM] %t", "GunsMenuReactivated");
   388 		} else {
   389 			DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
   390 		}
   391 		
   392 		return Plugin_Handled;
   393 	}
   394 	
   395 	return Plugin_Continue;
   396 }
   397 
   398 public Action:OnClientCommand(client, args)
   399 {
   400 	if (!ShouldRun() || g_AllowBuy)
   401 	{
   402 		return Plugin_Continue;
   403 	}
   404 	
   405 	decl String:cmd[32];
   406 	GetCmdArg(0, cmd, sizeof(cmd));
   407 	
   408 	if (StrEqual(cmd, "buy")
   409 		|| StrEqual(cmd, "autobuy")
   410 		|| StrEqual(cmd, "rebuy")
   411 		|| StrEqual(cmd, "buyequip")
   412 		|| StrEqual(cmd, "buymenu"))
   413 	{
   414 		return Plugin_Handled;
   415 	}
   416 	
   417 	return Plugin_Continue;
   418 }
   419 
   420 public Menu_EquipHandler(Handle:menu, MenuAction:action, param1, param2)
   421 {
   422 	if (!ShouldRun())
   423 	{
   424 		return 0;
   425 	}
   426 	
   427 	if (action == MenuAction_DrawItem)
   428 	{
   429 		if (param2 == 1 || param2 == 2)
   430 		{
   431 			if (g_PrimaryChoices[param1] == -1 && g_SecondaryChoices[param1] == -1)
   432 			{
   433 				return ITEMDRAW_DISABLED;
   434 			}
   435 		}
   436 		return ITEMDRAW_DEFAULT;
   437 	}
   438 	else if (action == MenuAction_Select)
   439 	{
   440 		if (param2 == 0)
   441 		{
   442 			if (ChooseFromSecondary())
   443 			{
   444 				DisplayMenu(g_hSecondaryMenu, param1, MENU_TIME_FOREVER);
   445 			} else if (ChooseFromPrimary()) {
   446 				DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
   447 			}
   448 		} else if (param2 == 1) {
   449 			GiveBothFromChoices(param1);
   450 		} else if (param2 == 2) {
   451 			GiveBothFromChoices(param1);
   452 			g_GunMenuEnabled[param1] = false;
   453 			PrintToChat(param1, "[CSSDM] %t", "SayGunsNotify");
   454 		} else if (param2 == 3) {
   455 			GivePrimary(param1, g_PrimaryCount);
   456 			GiveSecondary(param1, g_SecondaryCount);
   457 		} else if (param2 == 4) {
   458 			GivePrimary(param1, g_PrimaryCount);
   459 			GiveSecondary(param1, g_SecondaryCount);
   460 			GiveBothFromChoices(param1);
   461 			g_GunMenuEnabled[param1] = false;
   462 			PrintToChat(param1, "[CSSDM] %t", "SayGunsNotify");
   463 		}
   464 		g_GunMenuAvailable[param1] = false;
   465 	}
   466 	else if (action == MenuAction_DisplayItem)
   467 	{
   468 		decl style;
   469 		decl String:info[12], String:lang_phrase[32];
   470 		
   471 		if (!GetMenuItem(menu, param2, info, sizeof(info), style, lang_phrase, sizeof(lang_phrase)))
   472 		{
   473 			return 0;
   474 		}
   475 		
   476 		decl String:t_phrase[64];
   477 		Format(t_phrase, sizeof(t_phrase), "%T", lang_phrase, param1);
   478 		
   479 		return RedrawMenuItem(t_phrase);
   480 	}
   481 	
   482 	return 0;
   483 }
   484 
   485 public Menu_PrimaryHandler(Handle:menu, MenuAction:action, param1, param2)
   486 {
   487 	if (!ShouldRun())
   488 	{
   489 		return 0;
   490 	}
   491 	
   492 	if (action == MenuAction_DrawItem)
   493 	{
   494 		return ITEMDRAW_DEFAULT;
   495 	}
   496 	else if (action == MenuAction_Select)
   497 	{
   498 		GivePrimary(param1, param2);
   499 	}
   500 	else if (action == MenuAction_Display)
   501 	{
   502 		new Handle:hPanel = Handle:param2;
   503 		decl String:title[128];
   504 		
   505 		Format(title, sizeof(title), "%T:", "Primary weapon", param1);
   506 		
   507 		SetPanelTitle(hPanel, title);
   508 	}
   509 	
   510 	return 0;
   511 }
   512 
   513 public Menu_SecondaryHandler(Handle:menu, MenuAction:action, param1, param2)
   514 {
   515 	if (!ShouldRun())
   516 	{
   517 		return 0;
   518 	}
   519 	
   520 	if (action == MenuAction_DrawItem)
   521 	{
   522 		return ITEMDRAW_DEFAULT;
   523 	}
   524 	else if (action == MenuAction_Select)
   525 	{
   526 		GiveSecondary(param1, param2);
   527 		if (ChooseFromPrimary())
   528 		{
   529 			DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
   530 		}
   531 	}
   532 	else if (action == MenuAction_Cancel
   533 			 && param2 == MenuCancel_Exit)
   534 	{
   535 		if (ChooseFromPrimary())
   536 		{
   537 			DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
   538 		}
   539 	}
   540 	else if (action == MenuAction_Display)
   541 	{
   542 		new Handle:hPanel = Handle:param2;
   543 		decl String:title[128];
   544 		
   545 		Format(title, sizeof(title), "%T:", "Secondary weapon", param1);
   546 		
   547 		SetPanelTitle(hPanel, title);
   548 	}
   549 	
   550 	return 0;
   551 }
   552 
   553 bool:ChooseFromPrimary()
   554 {
   555 	return (g_PrimaryMenu == CSSDM_GUNMENU_YES
   556 			&& g_PrimaryCount > 1);
   557 }
   558 
   559 bool:ChooseFromSecondary()
   560 {
   561 	return (g_SecondaryMenu == CSSDM_GUNMENU_YES
   562 			&& g_SecondaryCount > 1);
   563 }
   564 
   565 GiveWeapon(client, index)
   566 {
   567 	if (!IsPlayerAlive(client))
   568 	{
   569 		return;
   570 	}
   571 
   572 	new DmWeaponType:type = DM_GetWeaponType(index);
   573 	
   574 	new entity = DM_GetClientWeapon(client, type);
   575 	if (entity != -1)
   576 	{
   577 		DM_DropWeapon(client, entity);
   578 	}
   579 	
   580 	new String:cls[64];
   581 	DM_GetWeaponClassname(index, cls, sizeof(cls));
   582 	
   583 	GivePlayerItem(client, cls);
   584 }
   585 
   586 GiveBothFromChoices(client)
   587 {
   588 	if (ChooseFromPrimary())
   589 	{
   590 		GivePrimary(client, g_PrimaryChoices[client]);
   591 	}
   592 	
   593 	if (ChooseFromSecondary())
   594 	{
   595 		GiveSecondary(client, g_SecondaryChoices[client]);
   596 	}
   597 }
   598 
   599 /**
   600  * Gives a primary weapon to a client.
   601  * If the list_index is > the count, we choose one randomly.
   602  * This is a hack so we can append "Random" to the choice list.
   603  */
   604 GivePrimary(client, list_index)
   605 {
   606 	if (list_index < 0)
   607 	{
   608 		return;
   609 	}
   610 	
   611 	new weapon_index;
   612 	if (list_index >= g_PrimaryCount)
   613 	{
   614 		if (g_PrimaryCount > 1)
   615 		{
   616 			weapon_index = GetRandomInt(0, g_PrimaryCount-1);
   617 			weapon_index = g_PrimaryList[weapon_index];
   618 		} else if (g_PrimaryCount == 1) {
   619 			weapon_index = g_PrimaryList[0];
   620 		} else {
   621 			return;
   622 		}
   623 	} else {
   624 		weapon_index = g_PrimaryList[list_index];
   625 	}
   626 	
   627 	g_PrimaryChoices[client] = list_index;
   628 	
   629 	GiveWeapon(client, weapon_index);
   630 }
   631 
   632 /**
   633  * Gives a secondary weapon to a client.
   634  * If the list_index is > the count, we choose one randomly.
   635  * This is a hack so we can append "Random" to the choice list.
   636  */
   637 GiveSecondary(client, list_index)
   638 {
   639 	if (list_index < 0)
   640 	{
   641 		return;
   642 	}
   643 	
   644 	new weapon_index;
   645 	if (list_index >= g_SecondaryCount)
   646 	{
   647 		if (g_SecondaryCount > 1)
   648 		{
   649 			weapon_index = GetRandomInt(0, g_SecondaryCount-1);
   650 			weapon_index = g_SecondaryList[weapon_index];
   651 		} else if (g_SecondaryCount == 1) {
   652 			weapon_index = g_SecondaryList[0];
   653 		} else {
   654 			return;
   655 		}
   656 	} else {
   657 		weapon_index = g_SecondaryList[list_index];
   658 	}
   659 	
   660 	g_SecondaryChoices[client] = list_index;
   661 	
   662 	GiveWeapon(client, weapon_index);
   663 }
   664 
   665 bool:ShouldRun()
   666 {
   667 	return (DM_IsRunning() && g_IsEnabled);
   668 }
   669 
   670 bool:KvGetYesOrNo(Handle:kv, const String:key[], bool:curdefault)
   671 {
   672 	decl String:value[12];
   673 	KvGetString(kv, key, value, sizeof(value), curdefault ? "yes" : "no");
   674 	return (strcmp(value, "yes") == 0);
   675 }
   676 
   677 KvGetGunMenu(Handle:kv, const String:key[], def)
   678 {
   679 	decl String:sdef[12];
   680 	if (def == CSSDM_GUNMENU_YES)
   681 	{
   682 		strcopy(sdef, sizeof(sdef), "yes");
   683 	} else if (def == CSSDM_GUNMENU_RANDOM) {
   684 		strcopy(sdef, sizeof(sdef), "random");
   685 	} else {
   686 		strcopy(sdef, sizeof(sdef), "no");
   687 	}
   688 	
   689 	decl String:value[12];
   690 	KvGetString(kv, key, value, sizeof(value), sdef);
   691 	
   692 	if (strcmp(value, "yes") == 0)
   693 	{
   694 		return CSSDM_GUNMENU_YES;
   695 	} else if (strcmp(value, "random") == 0) {
   696 		return CSSDM_GUNMENU_RANDOM;
   697 	}
   698 	
   699 	return CSSDM_GUNMENU_NO;
   700 }
   701 
   702 LoadDefaults()
   703 {
   704 	g_PrimaryMenu = CSSDM_GUNMENU_YES;
   705 	g_SecondaryMenu = CSSDM_GUNMENU_YES;
   706 	g_AllowBuy = false;
   707 	g_ArmorAmount = 100;
   708 	g_Helmets = true;
   709 	g_Flashes = 0;
   710 	g_Smokes = false;
   711 	g_HEs = false;
   712 	g_NightVision = false;
   713 	g_DefuseKits = true;
   714 	g_HealthAmount = 100;
   715 	g_AllowGunCommand = true;
   716 }
   717 
   718 bool:LoadConfigFile(const String:path[])
   719 {
   720 	new Handle:kv = CreateKeyValues("Equipment");
   721 	if (!FileToKeyValues(kv, path))
   722 	{
   723 		return false;
   724 	}
   725 	
   726 	decl String:value[255];
   727 	
   728 	/* Load settings */
   729 	if (KvJumpToKey(kv, "Settings"))
   730 	{
   731 		g_AllowGunCommand = KvGetYesOrNo(kv, "guns_command", g_AllowGunCommand);
   732 		KvGoBack(kv);
   733 	}
   734 	
   735 	/* Load menu options */
   736 	if (KvJumpToKey(kv, "Menus"))
   737 	{
   738 		g_PrimaryMenu = KvGetGunMenu(kv, "primary", g_PrimaryMenu);
   739 		g_SecondaryMenu = KvGetGunMenu(kv, "secondary", g_SecondaryMenu);
   740 		g_AllowBuy = KvGetYesOrNo(kv, "buy", g_AllowBuy);
   741 		KvGoBack(kv);
   742 	}
   743 	
   744 	/* Load automatic stuff */
   745 	if (KvJumpToKey(kv, "AutoItems"))
   746 	{
   747 		g_ArmorAmount = KvGetNum(kv, "armor", g_ArmorAmount);
   748 		g_Flashes = KvGetNum(kv, "flashbangs", g_Flashes);
   749 		g_Helmets = KvGetYesOrNo(kv, "helmet", g_Helmets);
   750 		g_Smokes = KvGetYesOrNo(kv, "smokegrenade", g_Smokes);
   751 		g_HEs = KvGetYesOrNo(kv, "hegrenade", g_HEs);
   752 		g_NightVision = KvGetYesOrNo(kv, "nightvision", g_NightVision);
   753 		g_DefuseKits = KvGetYesOrNo(kv, "defusekits", g_DefuseKits);
   754 		g_HealthAmount = KvGetNum(kv, "health", g_HealthAmount);
   755 		g_Decoy = KvGetYesOrNo(kv, "decoy", g_Decoy);
   756 		g_Taser = KvGetYesOrNo(kv, "taser", g_Taser);
   757 		KvGoBack(kv);
   758 	}
   759 	
   760 	/* Load bot items */
   761 	if (KvJumpToKey(kv, "BotItems"))
   762 	{
   763 		/* Clear out old lists first */
   764 		g_BotPrimaryCount = 0;
   765 		g_BotSecondaryCount = 0;
   766 		
   767 		if (KvGotoFirstSubKey(kv, false))
   768 		{
   769 			do
   770 			{
   771 				KvGetSectionName(kv, value, sizeof(value));
   772 				if (strcmp(value, "weapon") == 0)
   773 				{
   774 					KvGetString(kv, NULL_STRING, value, sizeof(value));
   775 					new index = DM_GetWeaponID(value);
   776 					if (index != -1)
   777 					{
   778 						new DmWeaponType:type = DM_GetWeaponType(index);
   779 						if (type == DmWeapon_Primary && g_BotPrimaryCount < CSSDM_MAX_WEAPONS)
   780 						{
   781 							g_BotPrimaryList[g_BotPrimaryCount++] = index;
   782 						} else if (type == DmWeapon_Secondary && g_BotSecondaryCount < CSSDM_MAX_WEAPONS) {
   783 							g_BotSecondaryList[g_BotSecondaryCount++] = index;
   784 						}
   785 					}					
   786 				} else if (strcmp(value, "armor") == 0) {
   787 					g_BotArmor = KvGetNum(kv, NULL_STRING, 100);
   788 				} else if (strcmp(value, "helmet") == 0) {
   789 					g_BotHelmets = KvGetYesOrNo(kv, NULL_STRING, true);
   790 				} else if (strcmp(value, "flashbangs") == 0) {
   791 					g_BotFlashes = KvGetNum(kv, NULL_STRING);
   792 				} else if (strcmp(value, "smokegrenade") == 0) {
   793 					g_BotSmokes = KvGetYesOrNo(kv, NULL_STRING, false);
   794 				} else if (strcmp(value, "hegrenade") == 0) {
   795 					g_BotHEs = KvGetYesOrNo(kv, NULL_STRING, false);
   796 				} else if (strcmp(value, "defusekits") == 0) {
   797 					g_BotDefuseKits = KvGetYesOrNo(kv, NULL_STRING, true);
   798 				} else if (strcmp(value, "health") == 0) {
   799 					g_BotHealthAmount = KvGetNum(kv, NULL_STRING, 100);
   800 				} else if (strcmp(value, "decoy") == 0) {
   801 					g_BotDecoy = KvGetYesOrNo(kv, NULL_STRING, false);
   802 				} else if (strcmp(value, "taser") == 0) {
   803 					g_BotTaser = KvGetYesOrNo(kv, NULL_STRING, true);
   804 				}
   805 			} while (KvGotoNextKey(kv, false));
   806 			KvGoBack(kv);
   807 		}
   808 		KvGoBack(kv);
   809 	}
   810 	
   811 	/* Load secondary weapons */
   812 	if (KvJumpToKey(kv, "SecondaryMenu"))
   813 	{
   814 		/* Clear out old list first */
   815 		g_SecondaryCount = 0;
   816 		
   817 		if (KvGotoFirstSubKey(kv, false))
   818 		{
   819 			do
   820 			{
   821 				KvGetSectionName(kv, value, sizeof(value));
   822 				if (strcmp(value, "weapon") == 0)
   823 				{
   824 					KvGetString(kv, NULL_STRING, value, sizeof(value));
   825 					new index = DM_GetWeaponID(value);
   826 					if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Secondary)
   827 					{
   828 						g_SecondaryList[g_SecondaryCount++] = index;
   829 					}
   830 				}
   831 			} while (KvGotoNextKey(kv, false) && g_SecondaryCount < CSSDM_MAX_WEAPONS);
   832 			KvGoBack(kv);
   833 		}
   834 		KvGoBack(kv);
   835 	}
   836 	
   837 	/* Load primary weapons */
   838 	if (KvJumpToKey(kv, "PrimaryMenu"))
   839 	{
   840 		/* Clear out old list first */
   841 		g_PrimaryCount = 0;
   842 		
   843 		if (KvGotoFirstSubKey(kv, false))
   844 		{
   845 			do
   846 			{
   847 				KvGetSectionName(kv, value, sizeof(value));
   848 				if (strcmp(value, "weapon") == 0)
   849 				{
   850 					KvGetString(kv, NULL_STRING, value, sizeof(value));
   851 					new index = DM_GetWeaponID(value);
   852 					if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Primary)
   853 					{
   854 						g_PrimaryList[g_PrimaryCount++] = index;
   855 					}
   856 				}
   857 			} while (KvGotoNextKey(kv, false) && g_PrimaryCount < CSSDM_MAX_WEAPONS);
   858 			KvGoBack(kv);
   859 		}
   860 		KvGoBack(kv);
   861 	}
   862 	
   863 	CloseHandle(kv);
   864 	
   865 	/* Build the primary menu */
   866 	if (g_hPrimaryMenu != INVALID_HANDLE)
   867 	{
   868 		CloseHandle(g_hPrimaryMenu);
   869 	}
   870 	g_hPrimaryMenu = CreateMenu(Menu_PrimaryHandler, MenuAction_DrawItem|MenuAction_Display);
   871 	SetMenuTitle(g_hPrimaryMenu, "Primary weapon:");
   872 	for (new i=0; i<g_PrimaryCount; i++)
   873 	{
   874 		new index = g_PrimaryList[i];
   875 		DM_GetWeaponName(index, value, sizeof(value));
   876 		AddMenuItem(g_hPrimaryMenu, "", value);
   877 	}
   878 	AddMenuItem(g_hPrimaryMenu, "", "Random");
   879 	
   880 	/* Build the secondary menu */
   881 	if (g_hSecondaryMenu != INVALID_HANDLE)
   882 	{
   883 		CloseHandle(g_hSecondaryMenu);
   884 	}
   885 	g_hSecondaryMenu = CreateMenu(Menu_SecondaryHandler, MenuAction_DrawItem|MenuAction_Display);
   886 	SetMenuTitle(g_hSecondaryMenu, "Secondary weapon:");
   887 	for (new i=0; i<g_SecondaryCount; i++)
   888 	{
   889 		new index = g_SecondaryList[i];
   890 		DM_GetWeaponName(index, value, sizeof(value));
   891 		AddMenuItem(g_hSecondaryMenu, "", value);
   892 	}
   893 	AddMenuItem(g_hSecondaryMenu, "", "Random");
   894 	
   895 	return true;
   896 }
   897 
   898 SetClientArmor(client, armor)
   899 {
   900 	SetEntProp(client, Prop_Send, "m_ArmorValue", armor);
   901 }
   902 
   903 SetClientHealth(client, health)
   904 {
   905 	SetEntProp(client, Prop_Send, "m_iHealth", health);
   906 }
   907 
   908 GiveGrenades(client, flashnum, bool:he, bool:smoke, bool:decoy)
   909 {
   910 	if (!IsPlayerAlive(client))
   911 	{
   912 		return;
   913 	}
   914 
   915 	if (he)
   916 	{
   917 		GivePlayerItem(client, "weapon_hegrenade");
   918 	}
   919 	for (new i=0; i<flashnum; i++)
   920 	{
   921 		GivePlayerItem(client, "weapon_flashbang");
   922 	}
   923 	if (smoke)
   924 	{
   925 		GivePlayerItem(client, "weapon_smokegrenade");
   926 	}
   927 	if (g_bIsGo && decoy)
   928 	{
   929 		GivePlayerItem(client, "weapon_decoy");
   930 	}
   931 }
   932 
   933 GiveNightVision(client)
   934 {
   935 	SetEntProp(client, Prop_Send, "m_bHasNightVision", true);
   936 }
   937 GiveHelmet(client)
   938 {
   939 	SetEntProp(client, Prop_Send, "m_bHasHelmet", true);
   940 }