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