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