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