1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripting/equipment.sp Sun Jun 24 21:58:09 2007 +0000
1.3 @@ -0,0 +1,800 @@
1.4 +/**
1.5 + * equip_menu.sp
1.6 + * Adds preset spawning to CS:S DM.
1.7 + * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License
1.11 + * as published by the Free Software Foundation; either version 2
1.12 + * of the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.22 + *
1.23 + * Version: $Id$
1.24 + */
1.25 +
1.26 +#pragma semicolon 1
1.27 +#include <sourcemod>
1.28 +#include <sdktools>
1.29 +#include <cssdm>
1.30 +
1.31 +#define CSSDM_GUNMENU_NO 0
1.32 +#define CSSDM_GUNMENU_YES 1
1.33 +#define CSSDM_GUNMENU_RANDOM 2
1.34 +
1.35 +/** Plugin Stuff */
1.36 +new Handle:g_hEquipCfg = INVALID_HANDLE; /* cssdm_equip_cfg cvar */
1.37 +new g_ArmorOffset = -1; /* m_ArmorValue offset */
1.38 +new g_NVOffset = -1; /* m_bHasNightVision offset */
1.39 +new Handle:g_SpawnTimers[MAXPLAYERS+1]; /* Post-spawn timers */
1.40 +new Handle:g_hPrimaryMenu = INVALID_HANDLE; /* Priamry menu Handle */
1.41 +new Handle:g_hSecondaryMenu = INVALID_HANDLE; /* Secondary menu Handle */
1.42 +new Handle:g_hEquipMenu = INVALID_HANDLE; /* Main equipment menu */
1.43 +new bool:g_IsEnabled = false; /* Whether the plugin should work */
1.44 +new g_PrimaryChoices[MAXPLAYERS+1]; /* Primary weapon selections */
1.45 +new g_SecondaryChoices[MAXPLAYERS+1]; /* Secondary weapon selections */
1.46 +new bool:g_GunMenuEnabled[MAXPLAYERS+1]; /* Whether the gun menu is enabled */
1.47 +new bool:g_GunMenuAvailable[MAXPLAYERS+1]; /* Whether the gun menu is available */
1.48 +new bool:g_AllowGunCommand = true; /* Whether the gun menu command is enabled */
1.49 +
1.50 +/** HUMAN CONFIGS */
1.51 +new g_PrimaryList[CSSDM_MAX_WEAPONS];
1.52 +new g_SecondaryList[CSSDM_MAX_WEAPONS];
1.53 +new g_PrimaryCount = 0;
1.54 +new g_SecondaryCount = 0;
1.55 +new g_PrimaryMenu = CSSDM_GUNMENU_YES;
1.56 +new g_SecondaryMenu = CSSDM_GUNMENU_YES;
1.57 +new bool:g_AllowBuy = false;
1.58 +new g_ArmorAmount = 100;
1.59 +new bool:g_Helmets = true;
1.60 +new g_Flashes = 0;
1.61 +new bool:g_Smokes = false;
1.62 +new bool:g_HEs = false;
1.63 +new bool:g_NightVision = false;
1.64 +new bool:g_DefuseKits = true;
1.65 +
1.66 +/** BOT CONFIGS */
1.67 +new g_BotPrimaryList[CSSDM_MAX_WEAPONS];
1.68 +new g_BotSecondaryList[CSSDM_MAX_WEAPONS];
1.69 +new g_BotPrimaryCount = 0;
1.70 +new g_BotSecondaryCount = 0;
1.71 +new g_BotArmor = 100;
1.72 +new bool:g_BotHelmets = false;
1.73 +new g_BotFlashes = 0;
1.74 +new bool:g_BotSmokes = false;
1.75 +new bool:g_BotHEs = false;
1.76 +new bool:g_BotDefuseKits = true;
1.77 +
1.78 +/** PUBLIC INFO */
1.79 +public Plugin:myinfo =
1.80 +{
1.81 + name = "CS:S DM Equipment",
1.82 + author = "AlliedModders LLC",
1.83 + description = "Adds gun menu/equipment to CS:S DM",
1.84 + version = CSSDM_VERSION,
1.85 + url = "http://www.bailopan.net/cssdm/"
1.86 +};
1.87 +
1.88 +/******************
1.89 + * IMPLEMENTATION *
1.90 + ******************/
1.91 +
1.92 +public OnPluginStart()
1.93 +{
1.94 + RegConsoleCmd("say", Command_Say);
1.95 + RegConsoleCmd("say_team", Command_Say);
1.96 +
1.97 + g_hEquipCfg = CreateConVar("cssdm_equip_cfg", "cssdm.equip.txt", "CS:S DM Equipment Config File");
1.98 + g_ArmorOffset = FindSendPropOffs("CCSPlayer", "m_ArmorValue");
1.99 + g_NVOffset = FindSendPropOffs("CCSPlayer", "m_bHasNightVision");
1.100 +
1.101 + g_hEquipMenu = CreateMenu(Menu_EquipHandler, MenuAction_DrawItem);
1.102 + SetMenuTitle(g_hEquipMenu, "Weapon Options:");
1.103 + SetMenuExitButton(g_hEquipMenu, false);
1.104 + AddMenuItem(g_hEquipMenu, "", "New weapons");
1.105 + AddMenuItem(g_hEquipMenu, "", "Same weapons");
1.106 + AddMenuItem(g_hEquipMenu, "", "Same weapons every time");
1.107 + AddMenuItem(g_hEquipMenu, "", "Random weapons");
1.108 + AddMenuItem(g_hEquipMenu, "", "Random weapons every time");
1.109 +}
1.110 +
1.111 +public OnConfigsExecuted()
1.112 +{
1.113 + decl String:cvar[64];
1.114 + GetConVarString(g_hEquipCfg, cvar, sizeof(cvar));
1.115 +
1.116 + if (cvar[0] == '\0')
1.117 + {
1.118 + return;
1.119 + }
1.120 +
1.121 + decl String:path[255];
1.122 + Format(path, sizeof(path), "cfg/cssdm/%s", cvar);
1.123 +
1.124 + if ((g_IsEnabled = LoadConfigFile(path)) == false)
1.125 + {
1.126 + LogError("[CSSDM] Could not find equipment file \"%s\"", path);
1.127 + return;
1.128 + }
1.129 +
1.130 + if (strcmp(cvar, "cssdm.equip.txt") == 0)
1.131 + {
1.132 + /** See if there is a map version */
1.133 + decl String:map[64];
1.134 + GetCurrentMap(map, sizeof(map));
1.135 + Format(path, sizeof(path), "cfg/cssdm/%s/cssdm.equip.txt", map);
1.136 +
1.137 + if (FileExists(path))
1.138 + {
1.139 + LoadConfigFile(path);
1.140 + }
1.141 + }
1.142 +}
1.143 +
1.144 +public Action:DM_OnClientDeath(client)
1.145 +{
1.146 + if (g_SpawnTimers[client] != INVALID_HANDLE)
1.147 + {
1.148 + KillTimer(g_SpawnTimers[client]);
1.149 + g_SpawnTimers[client] = INVALID_HANDLE;
1.150 + }
1.151 + g_GunMenuAvailable[client] = true;
1.152 +}
1.153 +
1.154 +public OnClientPutInServer(client)
1.155 +{
1.156 + g_GunMenuEnabled[client] = true;
1.157 + g_GunMenuAvailable[client] = true;
1.158 + g_PrimaryChoices[client] = -1;
1.159 + g_SecondaryChoices[client] = -1;
1.160 +}
1.161 +
1.162 +public OnClientDisconnect(client)
1.163 +{
1.164 + if (g_SpawnTimers[client] != INVALID_HANDLE)
1.165 + {
1.166 + KillTimer(g_SpawnTimers[client]);
1.167 + g_SpawnTimers[client] = INVALID_HANDLE;
1.168 + }
1.169 +}
1.170 +
1.171 +public DM_OnClientSpawned(client)
1.172 +{
1.173 + if (!IsFakeClient(client))
1.174 + {
1.175 + if (g_ArmorAmount > 0)
1.176 + {
1.177 + GivePlayerItem(client, "item_assaultsuit");
1.178 + GivePlayerItem(client, "item_assaultsuit");
1.179 + SetClientArmor(client, g_ArmorAmount);
1.180 + }
1.181 + if (g_Helmets)
1.182 + {
1.183 + GivePlayerItem(client, "item_kevlar");
1.184 + GivePlayerItem(client, "item_kevlar");
1.185 + }
1.186 + GiveGrenades(client, g_Flashes, g_HEs, g_Smokes);
1.187 + if (g_NightVision)
1.188 + {
1.189 + GiveNightVision(client);
1.190 + }
1.191 + } else {
1.192 + /* See if we'll need to strip this bot */
1.193 + if (g_BotSecondaryCount || g_BotPrimaryCount)
1.194 + {
1.195 + DM_StripBotItems(client);
1.196 + }
1.197 + if (g_BotArmor > 0)
1.198 + {
1.199 + GivePlayerItem(client, "item_assaultsuit");
1.200 + GivePlayerItem(client, "item_assaultsuit");
1.201 + SetClientArmor(client, g_BotArmor);
1.202 + } else {
1.203 + /* Make sure bot didn't buy armor */
1.204 + SetClientArmor(client, 0);
1.205 + }
1.206 + if (g_BotHelmets)
1.207 + {
1.208 + GivePlayerItem(client, "item_kevlar");
1.209 + GivePlayerItem(client, "item_kevlar");
1.210 + }
1.211 + GiveGrenades(client, g_BotFlashes, g_BotHEs, g_BotSmokes);
1.212 + }
1.213 + if (g_SpawnTimers[client] == INVALID_HANDLE)
1.214 + {
1.215 + /* Small delay - we want to avoid ResetHUD */
1.216 + g_SpawnTimers[client] = CreateTimer(0.1, PlayerPostSpawn, client);
1.217 + }
1.218 +}
1.219 +
1.220 +public Action:PlayerPostSpawn(Handle:timer, any:client)
1.221 +{
1.222 + g_SpawnTimers[client] = INVALID_HANDLE;
1.223 +
1.224 + if (!ShouldRun())
1.225 + {
1.226 + return Plugin_Stop;
1.227 + }
1.228 +
1.229 + if (IsFakeClient(client))
1.230 + {
1.231 + if (g_BotSecondaryCount > 0)
1.232 + {
1.233 + new index;
1.234 + if (g_BotSecondaryCount == 1)
1.235 + {
1.236 + index = g_BotSecondaryList[0];
1.237 + } else {
1.238 + index = GetRandomInt(0, g_BotSecondaryCount-1);
1.239 + index = g_BotSecondaryList[index];
1.240 + }
1.241 + decl String:classname[64];
1.242 + DM_GetWeaponClassname(index, classname, sizeof(classname));
1.243 + GivePlayerItem(client, classname);
1.244 + }
1.245 + if (g_BotPrimaryCount > 0)
1.246 + {
1.247 + new index;
1.248 + if (g_BotPrimaryCount == 1)
1.249 + {
1.250 + index = g_BotPrimaryList[0];
1.251 + } else {
1.252 + index = GetRandomInt(0, g_BotPrimaryCount-1);
1.253 + index = g_BotPrimaryList[index];
1.254 + }
1.255 + decl String:classname[64];
1.256 + DM_GetWeaponClassname(index, classname, sizeof(classname));
1.257 + GivePlayerItem(client, classname);
1.258 + }
1.259 + if (g_BotDefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
1.260 + {
1.261 + GivePlayerItem(client, "item_defuser");
1.262 + }
1.263 + } else {
1.264 + if (g_DefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
1.265 + {
1.266 + GivePlayerItem(client, "item_defuser");
1.267 + PrintToChat(client, "Oh my god, you have a defuse kit");
1.268 + }
1.269 +
1.270 + new numGiven = 0;
1.271 + /* First, check if we should only be giving one of something automatically */
1.272 + if ((g_SecondaryMenu == CSSDM_GUNMENU_RANDOM || g_SecondaryMenu == CSSDM_GUNMENU_YES)
1.273 + && g_SecondaryCount == 1)
1.274 + {
1.275 + GiveSecondary(client, 0);
1.276 + numGiven++;
1.277 + } else if (g_PrimaryMenu == CSSDM_GUNMENU_RANDOM && g_PrimaryCount > 1) {
1.278 + GivePrimary(client, g_PrimaryCount);
1.279 + numGiven++;
1.280 + }
1.281 +
1.282 + if ((g_PrimaryMenu == CSSDM_GUNMENU_RANDOM || g_PrimaryMenu == CSSDM_GUNMENU_YES)
1.283 + && g_PrimaryCount == 1)
1.284 + {
1.285 + GivePrimary(client, 0);
1.286 + numGiven++;
1.287 + } else if (g_SecondaryMenu == CSSDM_GUNMENU_RANDOM && g_SecondaryCount > 1) {
1.288 + GiveSecondary(client, g_SecondaryCount);
1.289 + numGiven++;
1.290 + }
1.291 +
1.292 + /* If we've already given two weapons, there is no need for a menu. */
1.293 + if (numGiven == 2)
1.294 + {
1.295 + return Plugin_Stop;
1.296 + }
1.297 +
1.298 + if (g_GunMenuEnabled[client])
1.299 + {
1.300 + DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
1.301 + } else {
1.302 + GiveBothFromChoices(client);
1.303 + }
1.304 + }
1.305 +
1.306 + return Plugin_Stop;
1.307 +}
1.308 +
1.309 +public Action:Command_Say(client, args)
1.310 +{
1.311 + if (!ShouldRun())
1.312 + {
1.313 + return Plugin_Continue;
1.314 + }
1.315 +
1.316 + new String:text[192];
1.317 + GetCmdArg(1, text, sizeof(text));
1.318 +
1.319 + if (strcmp(text, "guns") == 0)
1.320 + {
1.321 + if (!g_AllowGunCommand)
1.322 + {
1.323 + PrintToChat(client, "[CSSDM] The guns menu command is disabled.");
1.324 + return Plugin_Handled;
1.325 + }
1.326 +
1.327 + if (!ChooseFromSecondary() && !ChooseFromPrimary())
1.328 + {
1.329 + PrintToChat(client, "[CSSDM] The guns menu is not available.");
1.330 + return Plugin_Handled;
1.331 + }
1.332 +
1.333 + if (g_GunMenuEnabled[client])
1.334 + {
1.335 + PrintToChat(client, "[CSSDM] Your guns menu is already enabled.");
1.336 + return Plugin_Handled;
1.337 + }
1.338 +
1.339 + g_GunMenuEnabled[client] = true;
1.340 + if (!g_GunMenuAvailable[client])
1.341 + {
1.342 + PrintToChat(client, "[CSSDM] Your guns menu has been enabled for your next respawn.");
1.343 + } else {
1.344 + DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
1.345 + }
1.346 +
1.347 + return Plugin_Handled;
1.348 + }
1.349 +
1.350 + return Plugin_Continue;
1.351 +}
1.352 +
1.353 +public Action:OnClientCommand(client, args)
1.354 +{
1.355 + if (!ShouldRun() || g_AllowBuy)
1.356 + {
1.357 + return Plugin_Continue;
1.358 + }
1.359 +
1.360 + decl String:cmd[32];
1.361 + GetCmdArg(0, cmd, sizeof(cmd));
1.362 +
1.363 + if (StrEqual(cmd, "buy")
1.364 + || StrEqual(cmd, "autobuy")
1.365 + || StrEqual(cmd, "rebuy")
1.366 + || StrEqual(cmd, "buyequip")
1.367 + || StrEqual(cmd, "buymenu"))
1.368 + {
1.369 + return Plugin_Handled;
1.370 + }
1.371 +
1.372 + return Plugin_Continue;
1.373 +}
1.374 +
1.375 +public Menu_EquipHandler(Handle:menu, MenuAction:action, param1, param2)
1.376 +{
1.377 + if (!ShouldRun())
1.378 + {
1.379 + return 0;
1.380 + }
1.381 +
1.382 + if (action == MenuAction_DrawItem)
1.383 + {
1.384 + if (param2 == 1 || param2 == 2)
1.385 + {
1.386 + if (g_PrimaryChoices[param1] == -1 && g_PrimaryChoices[param1] == -1)
1.387 + {
1.388 + return ITEMDRAW_DISABLED;
1.389 + }
1.390 + }
1.391 + return ITEMDRAW_DEFAULT;
1.392 + }
1.393 + else if (action == MenuAction_Select)
1.394 + {
1.395 + if (param2 == 0)
1.396 + {
1.397 + if (ChooseFromSecondary())
1.398 + {
1.399 + DisplayMenu(g_hSecondaryMenu, param1, MENU_TIME_FOREVER);
1.400 + } else if (ChooseFromPrimary()) {
1.401 + DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
1.402 + }
1.403 + } else if (param2 == 1) {
1.404 + GiveBothFromChoices(param1);
1.405 + } else if (param2 == 2) {
1.406 + GiveBothFromChoices(param1);
1.407 + g_GunMenuEnabled[param1] = false;
1.408 + PrintToChat(param1, "[CSSDM] Say \"guns\" in chat to re-enable your menu.");
1.409 + } else if (param2 == 3) {
1.410 + GivePrimary(param1, g_PrimaryCount);
1.411 + GiveSecondary(param1, g_SecondaryCount);
1.412 + } else if (param2 == 4) {
1.413 + GivePrimary(param1, g_PrimaryCount);
1.414 + GiveSecondary(param1, g_SecondaryCount);
1.415 + GiveBothFromChoices(param1);
1.416 + g_GunMenuEnabled[param1] = false;
1.417 + PrintToChat(param1, "[CSSDM] Say \"guns\" in chat to re-enable your menu.");
1.418 + }
1.419 + g_GunMenuAvailable[param1] = false;
1.420 + }
1.421 +
1.422 + return 0;
1.423 +}
1.424 +
1.425 +public Menu_PrimaryHandler(Handle:menu, MenuAction:action, param1, param2)
1.426 +{
1.427 + if (!ShouldRun())
1.428 + {
1.429 + return 0;
1.430 + }
1.431 +
1.432 + if (action == MenuAction_DrawItem)
1.433 + {
1.434 + return ITEMDRAW_DEFAULT;
1.435 + }
1.436 + else if (action == MenuAction_Select)
1.437 + {
1.438 + GivePrimary(param1, param2);
1.439 + }
1.440 +
1.441 + return 0;
1.442 +}
1.443 +
1.444 +public Menu_SecondaryHandler(Handle:menu, MenuAction:action, param1, param2)
1.445 +{
1.446 + if (!ShouldRun())
1.447 + {
1.448 + return 0;
1.449 + }
1.450 +
1.451 + if (action == MenuAction_DrawItem)
1.452 + {
1.453 + return ITEMDRAW_DEFAULT;
1.454 + }
1.455 + else if (action == MenuAction_Select)
1.456 + {
1.457 + GiveSecondary(param1, param2);
1.458 + if (ChooseFromPrimary())
1.459 + {
1.460 + DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
1.461 + }
1.462 + }
1.463 +
1.464 + return 0;
1.465 +}
1.466 +
1.467 +bool:ChooseFromPrimary()
1.468 +{
1.469 + return (g_PrimaryMenu == CSSDM_GUNMENU_YES
1.470 + && g_PrimaryCount > 1);
1.471 +}
1.472 +
1.473 +bool:ChooseFromSecondary()
1.474 +{
1.475 + return (g_SecondaryMenu == CSSDM_GUNMENU_YES
1.476 + && g_SecondaryCount > 1);
1.477 +}
1.478 +
1.479 +GiveWeapon(client, index)
1.480 +{
1.481 + new DmWeaponType:type = DM_GetWeaponType(index);
1.482 +
1.483 + new entity = DM_GetClientWeapon(client, type);
1.484 + if (entity != -1)
1.485 + {
1.486 + DM_DropWeapon(client, entity);
1.487 + }
1.488 +
1.489 + new String:cls[64];
1.490 + DM_GetWeaponClassname(index, cls, sizeof(cls));
1.491 +
1.492 + return GivePlayerItem(client, cls);
1.493 +}
1.494 +
1.495 +GiveBothFromChoices(client)
1.496 +{
1.497 + if (ChooseFromPrimary())
1.498 + {
1.499 + GivePrimary(client, g_PrimaryChoices[client]);
1.500 + }
1.501 +
1.502 + if (ChooseFromSecondary())
1.503 + {
1.504 + GiveSecondary(client, g_SecondaryChoices[client]);
1.505 + }
1.506 +}
1.507 +
1.508 +/**
1.509 + * Gives a primary weapon to a client.
1.510 + * If the list_index is > the count, we choose one randomly.
1.511 + * This is a hack so we can append "Random" to the choice list.
1.512 + */
1.513 +GivePrimary(client, list_index)
1.514 +{
1.515 + if (list_index < 0)
1.516 + {
1.517 + return;
1.518 + }
1.519 +
1.520 + new weapon_index;
1.521 + if (list_index >= g_PrimaryCount)
1.522 + {
1.523 + if (g_PrimaryCount > 1)
1.524 + {
1.525 + weapon_index = GetRandomInt(0, g_PrimaryCount-1);
1.526 + weapon_index = g_PrimaryList[weapon_index];
1.527 + } else {
1.528 + weapon_index = g_PrimaryList[0];
1.529 + }
1.530 + } else {
1.531 + weapon_index = g_PrimaryList[list_index];
1.532 + }
1.533 +
1.534 + g_PrimaryChoices[client] = list_index;
1.535 +
1.536 + GiveWeapon(client, weapon_index);
1.537 +}
1.538 +
1.539 +/**
1.540 + * Gives a secondary weapon to a client.
1.541 + * If the list_index is > the count, we choose one randomly.
1.542 + * This is a hack so we can append "Random" to the choice list.
1.543 + */
1.544 +GiveSecondary(client, list_index)
1.545 +{
1.546 + if (list_index < 0)
1.547 + {
1.548 + return;
1.549 + }
1.550 +
1.551 + new weapon_index;
1.552 + if (list_index >= g_SecondaryCount)
1.553 + {
1.554 + if (g_SecondaryCount > 1)
1.555 + {
1.556 + weapon_index = GetRandomInt(0, g_SecondaryCount-1);
1.557 + weapon_index = g_SecondaryList[weapon_index];
1.558 + } else {
1.559 + weapon_index = g_SecondaryList[0];
1.560 + }
1.561 + } else {
1.562 + weapon_index = g_SecondaryList[list_index];
1.563 + }
1.564 +
1.565 + g_SecondaryChoices[client] = list_index;
1.566 +
1.567 + GiveWeapon(client, weapon_index);
1.568 +}
1.569 +
1.570 +bool:ShouldRun()
1.571 +{
1.572 + return (DM_IsRunning() && g_IsEnabled);
1.573 +}
1.574 +
1.575 +bool:KvGetYesOrNo(Handle:kv, const String:key[], const String:def[])
1.576 +{
1.577 + decl String:value[12];
1.578 + KvGetString(kv, key, value, sizeof(value), def);
1.579 + return (strcmp(value, "yes") == 0);
1.580 +}
1.581 +
1.582 +KvGetGunMenu(Handle:kv, const String:key[], const String:def[])
1.583 +{
1.584 + decl String:value[12];
1.585 + KvGetString(kv, key, value, sizeof(value), def);
1.586 +
1.587 + if (strcmp(value, "yes") == 0)
1.588 + {
1.589 + return CSSDM_GUNMENU_YES;
1.590 + } else if (strcmp(value, "random") == 0) {
1.591 + return CSSDM_GUNMENU_RANDOM;
1.592 + }
1.593 +
1.594 + return CSSDM_GUNMENU_NO;
1.595 +}
1.596 +
1.597 +bool:LoadConfigFile(const String:path[])
1.598 +{
1.599 + new Handle:kv = CreateKeyValues("Equipment");
1.600 + if (!FileToKeyValues(kv, path))
1.601 + {
1.602 + return false;
1.603 + }
1.604 +
1.605 + decl String:value[255];
1.606 +
1.607 + /* Load settings */
1.608 + if (KvJumpToKey(kv, "Settings"))
1.609 + {
1.610 + g_AllowGunCommand = KvGetYesOrNo(kv, "guns_command", "yes");
1.611 + KvGoBack(kv);
1.612 + }
1.613 +
1.614 + /* Load menu options */
1.615 + if (KvJumpToKey(kv, "Menus"))
1.616 + {
1.617 + g_PrimaryMenu = KvGetGunMenu(kv, "primary", "yes");
1.618 + g_SecondaryMenu = KvGetGunMenu(kv, "secondary", "yes");
1.619 + g_AllowBuy = KvGetYesOrNo(kv, "buy", "no");
1.620 + KvGoBack(kv);
1.621 + }
1.622 +
1.623 + /* Load automatic stuff */
1.624 + if (KvJumpToKey(kv, "AutoItems"))
1.625 + {
1.626 + g_ArmorAmount = KvGetNum(kv, "armor", 100);
1.627 + g_Flashes = KvGetNum(kv, "flashbangs");
1.628 + g_Helmets = KvGetYesOrNo(kv, "helmet", "yes");
1.629 + g_Smokes = KvGetYesOrNo(kv, "smokegrenade", "no");
1.630 + g_HEs = KvGetYesOrNo(kv, "hegrenade", "no");
1.631 + g_NightVision = KvGetYesOrNo(kv, "nightvision", "no");
1.632 + g_DefuseKits = KvGetYesOrNo(kv, "defusekits", "yes");
1.633 + KvGoBack(kv);
1.634 + }
1.635 +
1.636 + /* Load bot items */
1.637 + if (KvJumpToKey(kv, "BotItems"))
1.638 + {
1.639 + /* Clear out old lists first */
1.640 + g_BotPrimaryCount = 0;
1.641 + g_BotSecondaryCount = 0;
1.642 +
1.643 + if (KvGotoFirstSubKey(kv, false))
1.644 + {
1.645 + do
1.646 + {
1.647 + KvGetSectionName(kv, value, sizeof(value));
1.648 + if (strcmp(value, "weapon") == 0)
1.649 + {
1.650 + KvGetString(kv, NULL_STRING, value, sizeof(value));
1.651 + new index = DM_GetWeaponID(value);
1.652 + if (index != -1)
1.653 + {
1.654 + new DmWeaponType:type = DM_GetWeaponType(index);
1.655 + if (type == DmWeapon_Primary && g_BotPrimaryCount < CSSDM_MAX_WEAPONS)
1.656 + {
1.657 + g_BotPrimaryList[g_BotPrimaryCount++] = index;
1.658 + } else if (type == DmWeapon_Secondary && g_BotSecondaryCount < CSSDM_MAX_WEAPONS) {
1.659 + g_BotSecondaryList[g_BotSecondaryCount++] = index;
1.660 + }
1.661 + }
1.662 + } else if (strcmp(value, "armor") == 0) {
1.663 + g_BotArmor = KvGetNum(kv, NULL_STRING, 100);
1.664 + } else if (strcmp(value, "helmet") == 0) {
1.665 + g_BotHelmets = KvGetYesOrNo(kv, NULL_STRING, "yes");
1.666 + } else if (strcmp(value, "flashbangs") == 0) {
1.667 + g_BotFlashes = KvGetNum(kv, NULL_STRING);
1.668 + } else if (strcmp(value, "smokegrenade") == 0) {
1.669 + g_BotSmokes = KvGetYesOrNo(kv, NULL_STRING, "no");
1.670 + } else if (strcmp(value, "hegrenade") == 0) {
1.671 + g_BotHEs = KvGetYesOrNo(kv, NULL_STRING, "no");
1.672 + } else if (strcmp(value, "defusekits") == 0) {
1.673 + g_DefuseKits = KvGetYesOrNo(kv, NULL_STRING, "yes");
1.674 + }
1.675 + } while (KvGotoNextKey(kv, false));
1.676 + KvGoBack(kv);
1.677 + }
1.678 + KvGoBack(kv);
1.679 + }
1.680 +
1.681 + /* Load secondary weapons */
1.682 + if (KvJumpToKey(kv, "SecondaryMenu"))
1.683 + {
1.684 + /* Clear out old list first */
1.685 + g_SecondaryCount = 0;
1.686 +
1.687 + if (KvGotoFirstSubKey(kv, false))
1.688 + {
1.689 + do
1.690 + {
1.691 + KvGetSectionName(kv, value, sizeof(value));
1.692 + if (strcmp(value, "weapon") == 0)
1.693 + {
1.694 + KvGetString(kv, NULL_STRING, value, sizeof(value));
1.695 + new index = DM_GetWeaponID(value);
1.696 + if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Secondary)
1.697 + {
1.698 + g_SecondaryList[g_SecondaryCount++] = index;
1.699 + }
1.700 + }
1.701 + } while (KvGotoNextKey(kv, false) && g_SecondaryCount < CSSDM_MAX_WEAPONS);
1.702 + KvGoBack(kv);
1.703 + }
1.704 + KvGoBack(kv);
1.705 + }
1.706 +
1.707 + /* Load primary weapons */
1.708 + if (KvJumpToKey(kv, "PrimaryMenu"))
1.709 + {
1.710 + /* Clear out old list first */
1.711 + g_PrimaryCount = 0;
1.712 +
1.713 + if (KvGotoFirstSubKey(kv, false))
1.714 + {
1.715 + do
1.716 + {
1.717 + KvGetSectionName(kv, value, sizeof(value));
1.718 + if (strcmp(value, "weapon") == 0)
1.719 + {
1.720 + KvGetString(kv, NULL_STRING, value, sizeof(value));
1.721 + new index = DM_GetWeaponID(value);
1.722 + if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Primary)
1.723 + {
1.724 + g_PrimaryList[g_PrimaryCount++] = index;
1.725 + }
1.726 + }
1.727 + } while (KvGotoNextKey(kv, false) && g_PrimaryCount < CSSDM_MAX_WEAPONS);
1.728 + KvGoBack(kv);
1.729 + }
1.730 + KvGoBack(kv);
1.731 + }
1.732 +
1.733 + CloseHandle(kv);
1.734 +
1.735 + /* Build the primary menu */
1.736 + if (g_hPrimaryMenu != INVALID_HANDLE)
1.737 + {
1.738 + CloseHandle(g_hPrimaryMenu);
1.739 + }
1.740 + g_hPrimaryMenu = CreateMenu(Menu_PrimaryHandler, MenuAction_DrawItem);
1.741 + SetMenuTitle(g_hPrimaryMenu, "Primary weapon:");
1.742 + for (new i=0; i<g_PrimaryCount; i++)
1.743 + {
1.744 + new index = g_PrimaryList[i];
1.745 + DM_GetWeaponName(index, value, sizeof(value));
1.746 + AddMenuItem(g_hPrimaryMenu, "", value);
1.747 + }
1.748 + AddMenuItem(g_hPrimaryMenu, "", "Random");
1.749 +
1.750 + /* Build the secondary menu */
1.751 + if (g_hSecondaryMenu != INVALID_HANDLE)
1.752 + {
1.753 + CloseHandle(g_hSecondaryMenu);
1.754 + }
1.755 + g_hSecondaryMenu = CreateMenu(Menu_SecondaryHandler, MenuAction_DrawItem);
1.756 + SetMenuTitle(g_hSecondaryMenu, "Secondary weapon:");
1.757 + for (new i=0; i<g_SecondaryCount; i++)
1.758 + {
1.759 + new index = g_SecondaryList[i];
1.760 + DM_GetWeaponName(index, value, sizeof(value));
1.761 + AddMenuItem(g_hSecondaryMenu, "", value);
1.762 + }
1.763 + AddMenuItem(g_hSecondaryMenu, "", "Random");
1.764 +
1.765 + return true;
1.766 +}
1.767 +
1.768 +SetClientArmor(client, armor)
1.769 +{
1.770 + if (g_ArmorOffset == -1)
1.771 + {
1.772 + return;
1.773 + }
1.774 +
1.775 + SetEntData(client, g_ArmorOffset, armor, 4, true);
1.776 +}
1.777 +
1.778 +GiveGrenades(client, flashnum, bool:he, bool:smoke)
1.779 +{
1.780 + if (he)
1.781 + {
1.782 + GivePlayerItem(client, "weapon_hegrenade");
1.783 + }
1.784 + for (new i=0; i<flashnum; i++)
1.785 + {
1.786 + GivePlayerItem(client, "weapon_flashbang");
1.787 + }
1.788 + if (smoke)
1.789 + {
1.790 + GivePlayerItem(client, "weapon_smokegrenade");
1.791 + }
1.792 +}
1.793 +
1.794 +GiveNightVision(client)
1.795 +{
1.796 + if (g_NVOffset == -1)
1.797 + {
1.798 + return;
1.799 + }
1.800 +
1.801 + SetEntData(client, g_NVOffset, true, 1, true);
1.802 +}
1.803 +