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