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