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