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