1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripting/dm_basics.sp Sun Jun 24 21:59:51 2007 +0000
1.3 @@ -0,0 +1,266 @@
1.4 +/**
1.5 + * dm_basics.sp
1.6 + * Base CS:S DM admin/control functions.
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 <cssdm>
1.29 +
1.30 +/* Plugin stuff */
1.31 +new Handle:cssdm_respawn_command;
1.32 +new Handle:cssdm_force_mapchanges;
1.33 +new Handle:cssdm_mapchange_file;
1.34 +new Handle:cssdm_refill_ammo;
1.35 +new Handle:mp_timelimit;
1.36 +new Handle:g_ChangeMapTimer = INVALID_HANDLE;
1.37 +new bool:g_AmmoHooks = false;
1.38 +new g_ActiveWepOffs = -1;
1.39 +
1.40 +/* Player stuff */
1.41 +new Float:g_DeathTimes[MAXPLAYERS+1];
1.42 +
1.43 +/** PUBLIC INFO */
1.44 +public Plugin:myinfo =
1.45 +{
1.46 + name = "CS:S DM Basics",
1.47 + author = "AlliedModders LLC",
1.48 + description = "Basic CS:S DM Commands/Features",
1.49 + version = CSSDM_VERSION,
1.50 + url = "http://www.bailopan.net/cssdm/"
1.51 +};
1.52 +
1.53 +public OnPluginStart()
1.54 +{
1.55 + LoadTranslations("cssdm.phrases");
1.56 +
1.57 + RegConsoleCmd("say", Command_Say);
1.58 + RegConsoleCmd("say_team", Command_Say);
1.59 +
1.60 + cssdm_respawn_command = CreateConVar("cssdm_respawn_command", "1", "Sets whether clients can manually respawn");
1.61 + cssdm_force_mapchanges = CreateConVar("cssdm_force_mapchanges", "0", "Sets whether CS:S DM should force mapchanges");
1.62 + cssdm_mapchange_file = CreateConVar("cssdm_mapchange_file", "mapcycle.txt", "Sets the mapchange file for CS:S DM");
1.63 + cssdm_refill_ammo = CreateConVar("cssdm_refill_ammo", "1", "Sets whether CS:S DM automatically refills ammo");
1.64 + mp_timelimit = FindConVar("mp_timelimit");
1.65 +
1.66 + HookConVarChange(cssdm_force_mapchanges, CvarChange_RestartMapTimer);
1.67 + HookConVarChange(mp_timelimit, CvarChange_RestartMapTimer);
1.68 + HookConVarChange(cssdm_refill_ammo, CvarChange_RefillAmmo);
1.69 +
1.70 + g_ActiveWepOffs = FindSendPropOffs("CCSPlayer", "m_hActiveWeapon");
1.71 +}
1.72 +
1.73 +public OnConfigsExecuted()
1.74 +{
1.75 + RestartMapTimer();
1.76 +
1.77 + g_AmmoHooks = GetConVarInt(cssdm_refill_ammo) ? true : false;
1.78 + if (g_AmmoHooks && g_ActiveWepOffs > 0)
1.79 + {
1.80 + HookEvent("weapon_reload", Event_CheckDepleted);
1.81 + HookEvent("weapon_fire_on_reload", Event_CheckDepleted);
1.82 + }
1.83 +}
1.84 +
1.85 +public OnMapEnd()
1.86 +{
1.87 + if (g_ChangeMapTimer != INVALID_HANDLE)
1.88 + {
1.89 + CloseHandle(g_ChangeMapTimer);
1.90 + g_ChangeMapTimer = INVALID_HANDLE;
1.91 + }
1.92 + if (g_AmmoHooks)
1.93 + {
1.94 + UnhookEvent("weapon_reload", Event_CheckDepleted);
1.95 + UnhookEvent("weapon_fire_on_reload", Event_CheckDepleted);
1.96 + }
1.97 +}
1.98 +
1.99 +public CvarChange_RefillAmmo(Handle:cvar, const String:oldvalue[], const String:newvalue[])
1.100 +{
1.101 + if (GetConVarInt(cvar) && !g_AmmoHooks && g_ActiveWepOffs > 0)
1.102 + {
1.103 + HookEvent("weapon_reload", Event_CheckDepleted);
1.104 + HookEvent("weapon_fire_on_reload", Event_CheckDepleted);
1.105 + } else if (!GetConVarInt(cvar) && g_AmmoHooks) {
1.106 + UnhookEvent("weapon_reload", Event_CheckDepleted);
1.107 + UnhookEvent("weapon_fire_on_reload", Event_CheckDepleted);
1.108 + }
1.109 +}
1.110 +
1.111 +public Event_CheckDepleted(Handle:event, const String:name[], bool:dontBroadcast)
1.112 +{
1.113 + new client = GetClientOfUserId(GetEventInt(event, "userid"));
1.114 + if (!client || !IsClientInGame(client))
1.115 + {
1.116 + return;
1.117 + }
1.118 +
1.119 + new entity = GetEntDataEnt(client, g_ActiveWepOffs);
1.120 + if (entity < 1)
1.121 + {
1.122 + return;
1.123 + }
1.124 +
1.125 + new ammoType = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");
1.126 +
1.127 + /* Give something reasonable -- the game will chop it off */
1.128 + DM_GiveClientAmmo(client, ammoType, 30, false);
1.129 +}
1.130 +
1.131 +public CvarChange_RestartMapTimer(Handle:cvar, const String:oldvalue[], const String:newvalue[])
1.132 +{
1.133 + RestartMapTimer();
1.134 +}
1.135 +
1.136 +RestartMapTimer()
1.137 +{
1.138 + if (g_ChangeMapTimer != INVALID_HANDLE)
1.139 + {
1.140 + CloseHandle(g_ChangeMapTimer);
1.141 + g_ChangeMapTimer = INVALID_HANDLE;
1.142 + }
1.143 +
1.144 + if (GetConVarInt(cssdm_force_mapchanges))
1.145 + {
1.146 + /* Find how much time is left in the map */
1.147 + new Float:seconds = (GetConVarInt(mp_timelimit) * 60.0) - GetGameTime();
1.148 + g_ChangeMapTimer = CreateTimer(seconds, Timer_ChangeMap);
1.149 + }
1.150 +}
1.151 +
1.152 +public Action:Timer_ChangeMap(Handle:timer)
1.153 +{
1.154 + g_ChangeMapTimer = INVALID_HANDLE;
1.155 +
1.156 + decl String:changefile[64];
1.157 + GetConVarString(cssdm_mapchange_file, changefile, sizeof(changefile));
1.158 +
1.159 + new Handle:file = OpenFile(changefile, "rt");
1.160 + if (!file)
1.161 + {
1.162 + LogError("[CSSDM] Could not open mapchange file \"%s\"", changefile);
1.163 + return Plugin_Stop;
1.164 + }
1.165 +
1.166 + decl String:curmap[64];
1.167 + GetCurrentMap(curmap, sizeof(curmap));
1.168 +
1.169 + new String:firstmap[64];
1.170 + new String:lastmap[64];
1.171 + decl String:buffer[64];
1.172 + new bool:matched = false;
1.173 + while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
1.174 + {
1.175 + TrimString(buffer);
1.176 + if (buffer[0] == '\0' || (!IsCharAlpha(buffer[0]) && !IsCharNumeric(buffer[0])))
1.177 + {
1.178 + continue;
1.179 + }
1.180 + if (!IsMapValid(buffer))
1.181 + {
1.182 + continue;
1.183 + }
1.184 + if (firstmap[0] == '\0')
1.185 + {
1.186 + strcopy(firstmap, sizeof(firstmap), buffer);
1.187 + }
1.188 + strcopy(lastmap, sizeof(lastmap), buffer);
1.189 + if (strcmp(buffer, curmap) == 0)
1.190 + {
1.191 + matched = true;
1.192 + } else if (matched) {
1.193 + break;
1.194 + }
1.195 + }
1.196 + CloseHandle(file);
1.197 +
1.198 + if (!matched || (strcmp(buffer, curmap) == 0))
1.199 + {
1.200 + strcopy(lastmap, sizeof(lastmap), firstmap);
1.201 + }
1.202 +
1.203 + if (lastmap[0] != '\0')
1.204 + {
1.205 + ServerCommand("changelevel %s", lastmap);
1.206 + }
1.207 +
1.208 + return Plugin_Stop;
1.209 +}
1.210 +
1.211 +public OnClientPutInServer(client)
1.212 +{
1.213 + g_DeathTimes[client] = 0.0;
1.214 +}
1.215 +
1.216 +public Action:DM_OnClientDeath(client)
1.217 +{
1.218 + g_DeathTimes[client] = GetGameTime();
1.219 + return Plugin_Continue;
1.220 +}
1.221 +
1.222 +public Action:Command_Say(client, args)
1.223 +{
1.224 + if (!DM_IsRunning() || !GetConVarInt(cssdm_respawn_command))
1.225 + {
1.226 + return Plugin_Continue;
1.227 + }
1.228 +
1.229 + decl String:command[32];
1.230 + GetCmdArg(1, command, sizeof(command));
1.231 +
1.232 + if (strcmp(command, "respawn") == 0)
1.233 + {
1.234 + if (!IsClientInGame(client))
1.235 + {
1.236 + PrintToChat(client, "[CSSDM] %t", "NoRespawn NotInGame");
1.237 + return Plugin_Handled;
1.238 + }
1.239 +
1.240 + if (DM_IsClientAlive(client))
1.241 + {
1.242 + PrintToChat(client, "[CSSDM] %t", "NoRespawn Alive");
1.243 + return Plugin_Handled;
1.244 + }
1.245 +
1.246 + new team = GetClientTeam(client);
1.247 + if (team != CSSDM_TEAM_T && team != CSSDM_TEAM_CT)
1.248 + {
1.249 + PrintToChat(client, "[CSSDM] %t", "NoRespawn Team");
1.250 + return Plugin_Handled;
1.251 + }
1.252 +
1.253 + new Float:elapsed = GetGameTime() - g_DeathTimes[client];
1.254 + new Float:wait_time = DM_GetSpawnWaitTime();
1.255 + if (elapsed < wait_time)
1.256 + {
1.257 + PrintToChat(client, "[CSSDM] %t", "NoRespawn Wait", wait_time - elapsed);
1.258 + return Plugin_Handled;
1.259 + }
1.260 +
1.261 + /* We passed the tests... respawn! */
1.262 + DM_RespawnClient(client);
1.263 +
1.264 + return Plugin_Handled;
1.265 + }
1.266 +
1.267 + return Plugin_Continue;
1.268 +}
1.269 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/scripting/dm_equipment.sp Sun Jun 24 21:59:51 2007 +0000
2.3 @@ -0,0 +1,852 @@
2.4 +/**
2.5 + * dm_equipment.sp
2.6 + * Adds preset spawning to CS:S DM.
2.7 + * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
2.8 + *
2.9 + * This program is free software; you can redistribute it and/or
2.10 + * modify it under the terms of the GNU General Public License
2.11 + * as published by the Free Software Foundation; either version 2
2.12 + * of the License, or (at your option) any later version.
2.13 + *
2.14 + * This program is distributed in the hope that it will be useful,
2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 + * GNU General Public License for more details.
2.18 + *
2.19 + * You should have received a copy of the GNU General Public License
2.20 + * along with this program; if not, write to the Free Software
2.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2.22 + *
2.23 + * Version: $Id$
2.24 + */
2.25 +
2.26 +#pragma semicolon 1
2.27 +#include <sourcemod>
2.28 +#include <sdktools>
2.29 +#include <cssdm>
2.30 +
2.31 +#define CSSDM_GUNMENU_NO 0
2.32 +#define CSSDM_GUNMENU_YES 1
2.33 +#define CSSDM_GUNMENU_RANDOM 2
2.34 +
2.35 +/** Plugin Stuff */
2.36 +new Handle:g_hEquipCfg = INVALID_HANDLE; /* cssdm_equip_cfg cvar */
2.37 +new g_ArmorOffset = -1; /* m_ArmorValue offset */
2.38 +new g_NVOffset = -1; /* m_bHasNightVision offset */
2.39 +new g_HealthOffset = -1; /* m_iHealth offset */
2.40 +new Handle:g_SpawnTimers[MAXPLAYERS+1]; /* Post-spawn timers */
2.41 +new Handle:g_hPrimaryMenu = INVALID_HANDLE; /* Priamry menu Handle */
2.42 +new Handle:g_hSecondaryMenu = INVALID_HANDLE; /* Secondary menu Handle */
2.43 +new Handle:g_hEquipMenu = INVALID_HANDLE; /* Main equipment menu */
2.44 +new bool:g_IsEnabled = false; /* Whether the plugin should work */
2.45 +new g_PrimaryChoices[MAXPLAYERS+1]; /* Primary weapon selections */
2.46 +new g_SecondaryChoices[MAXPLAYERS+1]; /* Secondary weapon selections */
2.47 +new bool:g_GunMenuEnabled[MAXPLAYERS+1]; /* Whether the gun menu is enabled */
2.48 +new bool:g_GunMenuAvailable[MAXPLAYERS+1]; /* Whether the gun menu is available */
2.49 +
2.50 +/** HUMAN CONFIGS */
2.51 +new g_PrimaryList[CSSDM_MAX_WEAPONS];
2.52 +new g_SecondaryList[CSSDM_MAX_WEAPONS];
2.53 +new g_PrimaryCount = 0;
2.54 +new g_SecondaryCount = 0;
2.55 +new g_PrimaryMenu = CSSDM_GUNMENU_YES;
2.56 +new g_SecondaryMenu = CSSDM_GUNMENU_YES;
2.57 +new bool:g_AllowBuy = false;
2.58 +new g_ArmorAmount = 100;
2.59 +new bool:g_Helmets = true;
2.60 +new g_Flashes = 0;
2.61 +new bool:g_Smokes = false;
2.62 +new bool:g_HEs = false;
2.63 +new bool:g_NightVision = false;
2.64 +new bool:g_DefuseKits = true;
2.65 +new bool:g_AllowGunCommand = true;
2.66 +new g_HealthAmount = 100;
2.67 +
2.68 +/** BOT CONFIGS */
2.69 +new g_BotPrimaryList[CSSDM_MAX_WEAPONS];
2.70 +new g_BotSecondaryList[CSSDM_MAX_WEAPONS];
2.71 +new g_BotPrimaryCount = 0;
2.72 +new g_BotSecondaryCount = 0;
2.73 +new g_BotArmor = 100;
2.74 +new bool:g_BotHelmets = false;
2.75 +new g_BotFlashes = 0;
2.76 +new bool:g_BotSmokes = false;
2.77 +new bool:g_BotHEs = false;
2.78 +new bool:g_BotDefuseKits = true;
2.79 +new g_BotHealthAmount = 100;
2.80 +
2.81 +/** PUBLIC INFO */
2.82 +public Plugin:myinfo =
2.83 +{
2.84 + name = "CS:S DM Equipment",
2.85 + author = "AlliedModders LLC",
2.86 + description = "Adds gun menu/equipment to CS:S DM",
2.87 + version = CSSDM_VERSION,
2.88 + url = "http://www.bailopan.net/cssdm/"
2.89 +};
2.90 +
2.91 +/******************
2.92 + * IMPLEMENTATION *
2.93 + ******************/
2.94 +
2.95 +public OnPluginStart()
2.96 +{
2.97 + RegConsoleCmd("say", Command_Say);
2.98 + RegConsoleCmd("say_team", Command_Say);
2.99 +
2.100 + g_hEquipCfg = CreateConVar("cssdm_equip_cfg", "cssdm.equip.txt", "CS:S DM Equipment Config File");
2.101 + g_ArmorOffset = FindSendPropOffs("CCSPlayer", "m_ArmorValue");
2.102 + g_NVOffset = FindSendPropOffs("CCSPlayer", "m_bHasNightVision");
2.103 + g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
2.104 +
2.105 + g_hEquipMenu = CreateMenu(Menu_EquipHandler, MenuAction_DrawItem);
2.106 + SetMenuTitle(g_hEquipMenu, "Weapon Options:");
2.107 + SetMenuExitButton(g_hEquipMenu, false);
2.108 + AddMenuItem(g_hEquipMenu, "", "New weapons");
2.109 + AddMenuItem(g_hEquipMenu, "", "Same weapons");
2.110 + AddMenuItem(g_hEquipMenu, "", "Same weapons every time");
2.111 + AddMenuItem(g_hEquipMenu, "", "Random weapons");
2.112 + AddMenuItem(g_hEquipMenu, "", "Random weapons every time");
2.113 +}
2.114 +
2.115 +public OnConfigsExecuted()
2.116 +{
2.117 + LoadDefaults();
2.118 +
2.119 + decl String:cvar[64];
2.120 + GetConVarString(g_hEquipCfg, cvar, sizeof(cvar));
2.121 +
2.122 + if (cvar[0] == '\0')
2.123 + {
2.124 + return;
2.125 + }
2.126 +
2.127 + decl String:path[255];
2.128 + Format(path, sizeof(path), "cfg/cssdm/%s", cvar);
2.129 +
2.130 + if ((g_IsEnabled = LoadConfigFile(path)) == false)
2.131 + {
2.132 + LogError("[CSSDM] Could not find equipment file \"%s\"", path);
2.133 + return;
2.134 + }
2.135 +
2.136 + if (strcmp(cvar, "cssdm.equip.txt") == 0)
2.137 + {
2.138 + /** See if there is a map version */
2.139 + decl String:map[64];
2.140 + GetCurrentMap(map, sizeof(map));
2.141 + Format(path, sizeof(path), "cfg/cssdm/%s/cssdm.equip.txt", map);
2.142 +
2.143 + if (FileExists(path))
2.144 + {
2.145 + LoadConfigFile(path);
2.146 + }
2.147 + }
2.148 +}
2.149 +
2.150 +public Action:DM_OnClientDeath(client)
2.151 +{
2.152 + if (g_SpawnTimers[client] != INVALID_HANDLE)
2.153 + {
2.154 + KillTimer(g_SpawnTimers[client]);
2.155 + g_SpawnTimers[client] = INVALID_HANDLE;
2.156 + }
2.157 + g_GunMenuAvailable[client] = true;
2.158 +}
2.159 +
2.160 +public OnClientPutInServer(client)
2.161 +{
2.162 + g_GunMenuEnabled[client] = true;
2.163 + g_GunMenuAvailable[client] = true;
2.164 + g_PrimaryChoices[client] = -1;
2.165 + g_SecondaryChoices[client] = -1;
2.166 +}
2.167 +
2.168 +public OnClientDisconnect(client)
2.169 +{
2.170 + if (g_SpawnTimers[client] != INVALID_HANDLE)
2.171 + {
2.172 + KillTimer(g_SpawnTimers[client]);
2.173 + g_SpawnTimers[client] = INVALID_HANDLE;
2.174 + }
2.175 +}
2.176 +
2.177 +public DM_OnClientSpawned(client)
2.178 +{
2.179 + if (!IsFakeClient(client))
2.180 + {
2.181 + if (g_ArmorAmount > 0)
2.182 + {
2.183 + GivePlayerItem(client, "item_assaultsuit");
2.184 + GivePlayerItem(client, "item_assaultsuit");
2.185 + SetClientArmor(client, g_ArmorAmount);
2.186 + }
2.187 + if (g_HealthAmount > 0)
2.188 + {
2.189 + SetClientHealth(client, g_HealthAmount);
2.190 + }
2.191 + if (g_Helmets)
2.192 + {
2.193 + GivePlayerItem(client, "item_kevlar");
2.194 + GivePlayerItem(client, "item_kevlar");
2.195 + }
2.196 + GiveGrenades(client, g_Flashes, g_HEs, g_Smokes);
2.197 + if (g_NightVision)
2.198 + {
2.199 + GiveNightVision(client);
2.200 + }
2.201 + } else {
2.202 + /* See if we'll need to strip this bot */
2.203 + if (g_BotSecondaryCount || g_BotPrimaryCount)
2.204 + {
2.205 + DM_StripBotItems(client);
2.206 + }
2.207 + if (g_BotArmor > 0)
2.208 + {
2.209 + GivePlayerItem(client, "item_assaultsuit");
2.210 + GivePlayerItem(client, "item_assaultsuit");
2.211 + SetClientArmor(client, g_BotArmor);
2.212 + } else {
2.213 + /* Make sure bot didn't buy armor */
2.214 + SetClientArmor(client, 0);
2.215 + }
2.216 + if (g_BotHealthAmount > 0)
2.217 + {
2.218 + SetClientHealth(client, g_BotHealthAmount);
2.219 + }
2.220 + if (g_BotHelmets)
2.221 + {
2.222 + GivePlayerItem(client, "item_kevlar");
2.223 + GivePlayerItem(client, "item_kevlar");
2.224 + }
2.225 + GiveGrenades(client, g_BotFlashes, g_BotHEs, g_BotSmokes);
2.226 + }
2.227 + if (g_SpawnTimers[client] == INVALID_HANDLE)
2.228 + {
2.229 + /* Small delay - we want to avoid ResetHUD */
2.230 + g_SpawnTimers[client] = CreateTimer(0.1, PlayerPostSpawn, client);
2.231 + }
2.232 +}
2.233 +
2.234 +public Action:PlayerPostSpawn(Handle:timer, any:client)
2.235 +{
2.236 + g_SpawnTimers[client] = INVALID_HANDLE;
2.237 +
2.238 + if (!ShouldRun())
2.239 + {
2.240 + return Plugin_Stop;
2.241 + }
2.242 +
2.243 + if (IsFakeClient(client))
2.244 + {
2.245 + if (g_BotSecondaryCount > 0)
2.246 + {
2.247 + new index;
2.248 + if (g_BotSecondaryCount == 1)
2.249 + {
2.250 + index = g_BotSecondaryList[0];
2.251 + } else {
2.252 + index = GetRandomInt(0, g_BotSecondaryCount-1);
2.253 + index = g_BotSecondaryList[index];
2.254 + }
2.255 + decl String:classname[64];
2.256 + DM_GetWeaponClassname(index, classname, sizeof(classname));
2.257 + GivePlayerItem(client, classname);
2.258 + }
2.259 + if (g_BotPrimaryCount > 0)
2.260 + {
2.261 + new index;
2.262 + if (g_BotPrimaryCount == 1)
2.263 + {
2.264 + index = g_BotPrimaryList[0];
2.265 + } else {
2.266 + index = GetRandomInt(0, g_BotPrimaryCount-1);
2.267 + index = g_BotPrimaryList[index];
2.268 + }
2.269 + decl String:classname[64];
2.270 + DM_GetWeaponClassname(index, classname, sizeof(classname));
2.271 + GivePlayerItem(client, classname);
2.272 + }
2.273 + if (g_BotDefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
2.274 + {
2.275 + GivePlayerItem(client, "item_defuser");
2.276 + }
2.277 + } else {
2.278 + if (g_DefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
2.279 + {
2.280 + GivePlayerItem(client, "item_defuser");
2.281 + }
2.282 +
2.283 + new numGiven = 0;
2.284 + /* First, check if we should only be giving one of something automatically */
2.285 + if ((g_SecondaryMenu == CSSDM_GUNMENU_RANDOM || g_SecondaryMenu == CSSDM_GUNMENU_YES)
2.286 + && g_SecondaryCount == 1)
2.287 + {
2.288 + GiveSecondary(client, 0);
2.289 + numGiven++;
2.290 + } else if (g_PrimaryMenu == CSSDM_GUNMENU_RANDOM && g_PrimaryCount > 1) {
2.291 + GivePrimary(client, g_PrimaryCount);
2.292 + numGiven++;
2.293 + }
2.294 +
2.295 + if ((g_PrimaryMenu == CSSDM_GUNMENU_RANDOM || g_PrimaryMenu == CSSDM_GUNMENU_YES)
2.296 + && g_PrimaryCount == 1)
2.297 + {
2.298 + GivePrimary(client, 0);
2.299 + numGiven++;
2.300 + } else if (g_SecondaryMenu == CSSDM_GUNMENU_RANDOM && g_SecondaryCount > 1) {
2.301 + GiveSecondary(client, g_SecondaryCount);
2.302 + numGiven++;
2.303 + }
2.304 +
2.305 + /* If we've already given two weapons, there is no need for a menu. */
2.306 + if (numGiven == 2)
2.307 + {
2.308 + return Plugin_Stop;
2.309 + }
2.310 +
2.311 + if (g_GunMenuEnabled[client])
2.312 + {
2.313 + DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
2.314 + } else {
2.315 + GiveBothFromChoices(client);
2.316 + }
2.317 + }
2.318 +
2.319 + return Plugin_Stop;
2.320 +}
2.321 +
2.322 +public Action:Command_Say(client, args)
2.323 +{
2.324 + if (!ShouldRun())
2.325 + {
2.326 + return Plugin_Continue;
2.327 + }
2.328 +
2.329 + new String:text[192];
2.330 + GetCmdArg(1, text, sizeof(text));
2.331 +
2.332 + if (strcmp(text, "guns") == 0)
2.333 + {
2.334 + if (!g_AllowGunCommand)
2.335 + {
2.336 + PrintToChat(client, "[CSSDM] %t", "GunsMenuDisabled");
2.337 + return Plugin_Handled;
2.338 + }
2.339 +
2.340 + if (!ChooseFromSecondary() && !ChooseFromPrimary())
2.341 + {
2.342 + PrintToChat(client, "[CSSDM] %t", "GunsMenuNotAvailable");
2.343 + return Plugin_Handled;
2.344 + }
2.345 +
2.346 + if (g_GunMenuEnabled[client])
2.347 + {
2.348 + PrintToChat(client, "[CSSDM] %t", "GunsMenuAlreadyEnabled");
2.349 + return Plugin_Handled;
2.350 + }
2.351 +
2.352 + g_GunMenuEnabled[client] = true;
2.353 + if (!g_GunMenuAvailable[client])
2.354 + {
2.355 + PrintToChat(client, "[CSSDM] %t", "GunsMenuReactivated");
2.356 + } else {
2.357 + DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
2.358 + }
2.359 +
2.360 + return Plugin_Handled;
2.361 + }
2.362 +
2.363 + return Plugin_Continue;
2.364 +}
2.365 +
2.366 +public Action:OnClientCommand(client, args)
2.367 +{
2.368 + if (!ShouldRun() || g_AllowBuy)
2.369 + {
2.370 + return Plugin_Continue;
2.371 + }
2.372 +
2.373 + decl String:cmd[32];
2.374 + GetCmdArg(0, cmd, sizeof(cmd));
2.375 +
2.376 + if (StrEqual(cmd, "buy")
2.377 + || StrEqual(cmd, "autobuy")
2.378 + || StrEqual(cmd, "rebuy")
2.379 + || StrEqual(cmd, "buyequip")
2.380 + || StrEqual(cmd, "buymenu"))
2.381 + {
2.382 + return Plugin_Handled;
2.383 + }
2.384 +
2.385 + return Plugin_Continue;
2.386 +}
2.387 +
2.388 +public Menu_EquipHandler(Handle:menu, MenuAction:action, param1, param2)
2.389 +{
2.390 + if (!ShouldRun())
2.391 + {
2.392 + return 0;
2.393 + }
2.394 +
2.395 + if (action == MenuAction_DrawItem)
2.396 + {
2.397 + if (param2 == 1 || param2 == 2)
2.398 + {
2.399 + if (g_PrimaryChoices[param1] == -1 && g_PrimaryChoices[param1] == -1)
2.400 + {
2.401 + return ITEMDRAW_DISABLED;
2.402 + }
2.403 + }
2.404 + return ITEMDRAW_DEFAULT;
2.405 + }
2.406 + else if (action == MenuAction_Select)
2.407 + {
2.408 + if (param2 == 0)
2.409 + {
2.410 + if (ChooseFromSecondary())
2.411 + {
2.412 + DisplayMenu(g_hSecondaryMenu, param1, MENU_TIME_FOREVER);
2.413 + } else if (ChooseFromPrimary()) {
2.414 + DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
2.415 + }
2.416 + } else if (param2 == 1) {
2.417 + GiveBothFromChoices(param1);
2.418 + } else if (param2 == 2) {
2.419 + GiveBothFromChoices(param1);
2.420 + g_GunMenuEnabled[param1] = false;
2.421 + PrintToChat(param1, "[CSSDM] %t", "SayGunsNotify");
2.422 + } else if (param2 == 3) {
2.423 + GivePrimary(param1, g_PrimaryCount);
2.424 + GiveSecondary(param1, g_SecondaryCount);
2.425 + } else if (param2 == 4) {
2.426 + GivePrimary(param1, g_PrimaryCount);
2.427 + GiveSecondary(param1, g_SecondaryCount);
2.428 + GiveBothFromChoices(param1);
2.429 + g_GunMenuEnabled[param1] = false;
2.430 + PrintToChat(param1, "[CSSDM] %t", "SayGunsNotify");
2.431 + }
2.432 + g_GunMenuAvailable[param1] = false;
2.433 + }
2.434 +
2.435 + return 0;
2.436 +}
2.437 +
2.438 +public Menu_PrimaryHandler(Handle:menu, MenuAction:action, param1, param2)
2.439 +{
2.440 + if (!ShouldRun())
2.441 + {
2.442 + return 0;
2.443 + }
2.444 +
2.445 + if (action == MenuAction_DrawItem)
2.446 + {
2.447 + return ITEMDRAW_DEFAULT;
2.448 + }
2.449 + else if (action == MenuAction_Select)
2.450 + {
2.451 + GivePrimary(param1, param2);
2.452 + }
2.453 +
2.454 + return 0;
2.455 +}
2.456 +
2.457 +public Menu_SecondaryHandler(Handle:menu, MenuAction:action, param1, param2)
2.458 +{
2.459 + if (!ShouldRun())
2.460 + {
2.461 + return 0;
2.462 + }
2.463 +
2.464 + if (action == MenuAction_DrawItem)
2.465 + {
2.466 + return ITEMDRAW_DEFAULT;
2.467 + }
2.468 + else if (action == MenuAction_Select)
2.469 + {
2.470 + GiveSecondary(param1, param2);
2.471 + if (ChooseFromPrimary())
2.472 + {
2.473 + DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
2.474 + }
2.475 + }
2.476 +
2.477 + return 0;
2.478 +}
2.479 +
2.480 +bool:ChooseFromPrimary()
2.481 +{
2.482 + return (g_PrimaryMenu == CSSDM_GUNMENU_YES
2.483 + && g_PrimaryCount > 1);
2.484 +}
2.485 +
2.486 +bool:ChooseFromSecondary()
2.487 +{
2.488 + return (g_SecondaryMenu == CSSDM_GUNMENU_YES
2.489 + && g_SecondaryCount > 1);
2.490 +}
2.491 +
2.492 +GiveWeapon(client, index)
2.493 +{
2.494 + new DmWeaponType:type = DM_GetWeaponType(index);
2.495 +
2.496 + new entity = DM_GetClientWeapon(client, type);
2.497 + if (entity != -1)
2.498 + {
2.499 + DM_DropWeapon(client, entity);
2.500 + }
2.501 +
2.502 + new String:cls[64];
2.503 + DM_GetWeaponClassname(index, cls, sizeof(cls));
2.504 +
2.505 + return GivePlayerItem(client, cls);
2.506 +}
2.507 +
2.508 +GiveBothFromChoices(client)
2.509 +{
2.510 + if (ChooseFromPrimary())
2.511 + {
2.512 + GivePrimary(client, g_PrimaryChoices[client]);
2.513 + }
2.514 +
2.515 + if (ChooseFromSecondary())
2.516 + {
2.517 + GiveSecondary(client, g_SecondaryChoices[client]);
2.518 + }
2.519 +}
2.520 +
2.521 +/**
2.522 + * Gives a primary weapon to a client.
2.523 + * If the list_index is > the count, we choose one randomly.
2.524 + * This is a hack so we can append "Random" to the choice list.
2.525 + */
2.526 +GivePrimary(client, list_index)
2.527 +{
2.528 + if (list_index < 0)
2.529 + {
2.530 + return;
2.531 + }
2.532 +
2.533 + new weapon_index;
2.534 + if (list_index >= g_PrimaryCount)
2.535 + {
2.536 + if (g_PrimaryCount > 1)
2.537 + {
2.538 + weapon_index = GetRandomInt(0, g_PrimaryCount-1);
2.539 + weapon_index = g_PrimaryList[weapon_index];
2.540 + } else {
2.541 + weapon_index = g_PrimaryList[0];
2.542 + }
2.543 + } else {
2.544 + weapon_index = g_PrimaryList[list_index];
2.545 + }
2.546 +
2.547 + g_PrimaryChoices[client] = list_index;
2.548 +
2.549 + GiveWeapon(client, weapon_index);
2.550 +}
2.551 +
2.552 +/**
2.553 + * Gives a secondary weapon to a client.
2.554 + * If the list_index is > the count, we choose one randomly.
2.555 + * This is a hack so we can append "Random" to the choice list.
2.556 + */
2.557 +GiveSecondary(client, list_index)
2.558 +{
2.559 + if (list_index < 0)
2.560 + {
2.561 + return;
2.562 + }
2.563 +
2.564 + new weapon_index;
2.565 + if (list_index >= g_SecondaryCount)
2.566 + {
2.567 + if (g_SecondaryCount > 1)
2.568 + {
2.569 + weapon_index = GetRandomInt(0, g_SecondaryCount-1);
2.570 + weapon_index = g_SecondaryList[weapon_index];
2.571 + } else {
2.572 + weapon_index = g_SecondaryList[0];
2.573 + }
2.574 + } else {
2.575 + weapon_index = g_SecondaryList[list_index];
2.576 + }
2.577 +
2.578 + g_SecondaryChoices[client] = list_index;
2.579 +
2.580 + GiveWeapon(client, weapon_index);
2.581 +}
2.582 +
2.583 +bool:ShouldRun()
2.584 +{
2.585 + return (DM_IsRunning() && g_IsEnabled);
2.586 +}
2.587 +
2.588 +bool:KvGetYesOrNo(Handle:kv, const String:key[], bool:curdefault)
2.589 +{
2.590 + decl String:value[12];
2.591 + KvGetString(kv, key, value, sizeof(value), curdefault ? "yes" : "no");
2.592 + return (strcmp(value, "yes") == 0);
2.593 +}
2.594 +
2.595 +KvGetGunMenu(Handle:kv, const String:key[], def)
2.596 +{
2.597 + decl String:sdef[12];
2.598 + if (def == CSSDM_GUNMENU_YES)
2.599 + {
2.600 + strcopy(sdef, sizeof(sdef), "yes");
2.601 + } else if (def == CSSDM_GUNMENU_RANDOM) {
2.602 + strcopy(sdef, sizeof(sdef), "random");
2.603 + } else {
2.604 + strcopy(sdef, sizeof(sdef), "no");
2.605 + }
2.606 +
2.607 + decl String:value[12];
2.608 + KvGetString(kv, key, value, sizeof(value), sdef);
2.609 +
2.610 + if (strcmp(value, "yes") == 0)
2.611 + {
2.612 + return CSSDM_GUNMENU_YES;
2.613 + } else if (strcmp(value, "random") == 0) {
2.614 + return CSSDM_GUNMENU_RANDOM;
2.615 + }
2.616 +
2.617 + return CSSDM_GUNMENU_NO;
2.618 +}
2.619 +
2.620 +LoadDefaults()
2.621 +{
2.622 + g_PrimaryMenu = CSSDM_GUNMENU_YES;
2.623 + g_SecondaryMenu = CSSDM_GUNMENU_YES;
2.624 + g_AllowBuy = false;
2.625 + g_ArmorAmount = 100;
2.626 + g_Helmets = true;
2.627 + g_Flashes = 0;
2.628 + g_Smokes = false;
2.629 + g_HEs = false;
2.630 + g_NightVision = false;
2.631 + g_DefuseKits = true;
2.632 + g_HealthAmount = 100;
2.633 + g_AllowGunCommand = true;
2.634 +}
2.635 +
2.636 +bool:LoadConfigFile(const String:path[])
2.637 +{
2.638 + new Handle:kv = CreateKeyValues("Equipment");
2.639 + if (!FileToKeyValues(kv, path))
2.640 + {
2.641 + return false;
2.642 + }
2.643 +
2.644 + decl String:value[255];
2.645 +
2.646 + /* Load settings */
2.647 + if (KvJumpToKey(kv, "Settings"))
2.648 + {
2.649 + g_AllowGunCommand = KvGetYesOrNo(kv, "guns_command", g_AllowGunCommand);
2.650 + KvGoBack(kv);
2.651 + }
2.652 +
2.653 + /* Load menu options */
2.654 + if (KvJumpToKey(kv, "Menus"))
2.655 + {
2.656 + g_PrimaryMenu = KvGetGunMenu(kv, "primary", g_PrimaryMenu);
2.657 + g_SecondaryMenu = KvGetGunMenu(kv, "secondary", g_SecondaryMenu);
2.658 + g_AllowBuy = KvGetYesOrNo(kv, "buy", g_AllowBuy);
2.659 + KvGoBack(kv);
2.660 + }
2.661 +
2.662 + /* Load automatic stuff */
2.663 + if (KvJumpToKey(kv, "AutoItems"))
2.664 + {
2.665 + g_ArmorAmount = KvGetNum(kv, "armor", g_ArmorAmount);
2.666 + g_Flashes = KvGetNum(kv, "flashbangs", g_Flashes);
2.667 + g_Helmets = KvGetYesOrNo(kv, "helmet", g_Helmets);
2.668 + g_Smokes = KvGetYesOrNo(kv, "smokegrenade", g_Smokes);
2.669 + g_HEs = KvGetYesOrNo(kv, "hegrenade", g_HEs);
2.670 + g_NightVision = KvGetYesOrNo(kv, "nightvision", g_NightVision);
2.671 + g_DefuseKits = KvGetYesOrNo(kv, "defusekits", g_DefuseKits);
2.672 + g_HealthAmount = KvGetNum(kv, "health", g_HealthAmount);
2.673 + KvGoBack(kv);
2.674 + }
2.675 +
2.676 + /* Load bot items */
2.677 + if (KvJumpToKey(kv, "BotItems"))
2.678 + {
2.679 + /* Clear out old lists first */
2.680 + g_BotPrimaryCount = 0;
2.681 + g_BotSecondaryCount = 0;
2.682 +
2.683 + if (KvGotoFirstSubKey(kv, false))
2.684 + {
2.685 + do
2.686 + {
2.687 + KvGetSectionName(kv, value, sizeof(value));
2.688 + if (strcmp(value, "weapon") == 0)
2.689 + {
2.690 + KvGetString(kv, NULL_STRING, value, sizeof(value));
2.691 + new index = DM_GetWeaponID(value);
2.692 + if (index != -1)
2.693 + {
2.694 + new DmWeaponType:type = DM_GetWeaponType(index);
2.695 + if (type == DmWeapon_Primary && g_BotPrimaryCount < CSSDM_MAX_WEAPONS)
2.696 + {
2.697 + g_BotPrimaryList[g_BotPrimaryCount++] = index;
2.698 + } else if (type == DmWeapon_Secondary && g_BotSecondaryCount < CSSDM_MAX_WEAPONS) {
2.699 + g_BotSecondaryList[g_BotSecondaryCount++] = index;
2.700 + }
2.701 + }
2.702 + } else if (strcmp(value, "armor") == 0) {
2.703 + g_BotArmor = KvGetNum(kv, NULL_STRING, 100);
2.704 + } else if (strcmp(value, "helmet") == 0) {
2.705 + g_BotHelmets = KvGetYesOrNo(kv, NULL_STRING, true);
2.706 + } else if (strcmp(value, "flashbangs") == 0) {
2.707 + g_BotFlashes = KvGetNum(kv, NULL_STRING);
2.708 + } else if (strcmp(value, "smokegrenade") == 0) {
2.709 + g_BotSmokes = KvGetYesOrNo(kv, NULL_STRING, false);
2.710 + } else if (strcmp(value, "hegrenade") == 0) {
2.711 + g_BotHEs = KvGetYesOrNo(kv, NULL_STRING, false);
2.712 + } else if (strcmp(value, "defusekits") == 0) {
2.713 + g_DefuseKits = KvGetYesOrNo(kv, NULL_STRING, true);
2.714 + } else if (strcmp(value, "health") == 0) {
2.715 + g_BotHealthAmount = KvGetNum(kv, NULL_STRING, 100);
2.716 + }
2.717 + } while (KvGotoNextKey(kv, false));
2.718 + KvGoBack(kv);
2.719 + }
2.720 + KvGoBack(kv);
2.721 + }
2.722 +
2.723 + /* Load secondary weapons */
2.724 + if (KvJumpToKey(kv, "SecondaryMenu"))
2.725 + {
2.726 + /* Clear out old list first */
2.727 + g_SecondaryCount = 0;
2.728 +
2.729 + if (KvGotoFirstSubKey(kv, false))
2.730 + {
2.731 + do
2.732 + {
2.733 + KvGetSectionName(kv, value, sizeof(value));
2.734 + if (strcmp(value, "weapon") == 0)
2.735 + {
2.736 + KvGetString(kv, NULL_STRING, value, sizeof(value));
2.737 + new index = DM_GetWeaponID(value);
2.738 + if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Secondary)
2.739 + {
2.740 + g_SecondaryList[g_SecondaryCount++] = index;
2.741 + }
2.742 + }
2.743 + } while (KvGotoNextKey(kv, false) && g_SecondaryCount < CSSDM_MAX_WEAPONS);
2.744 + KvGoBack(kv);
2.745 + }
2.746 + KvGoBack(kv);
2.747 + }
2.748 +
2.749 + /* Load primary weapons */
2.750 + if (KvJumpToKey(kv, "PrimaryMenu"))
2.751 + {
2.752 + /* Clear out old list first */
2.753 + g_PrimaryCount = 0;
2.754 +
2.755 + if (KvGotoFirstSubKey(kv, false))
2.756 + {
2.757 + do
2.758 + {
2.759 + KvGetSectionName(kv, value, sizeof(value));
2.760 + if (strcmp(value, "weapon") == 0)
2.761 + {
2.762 + KvGetString(kv, NULL_STRING, value, sizeof(value));
2.763 + new index = DM_GetWeaponID(value);
2.764 + if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Primary)
2.765 + {
2.766 + g_PrimaryList[g_PrimaryCount++] = index;
2.767 + }
2.768 + }
2.769 + } while (KvGotoNextKey(kv, false) && g_PrimaryCount < CSSDM_MAX_WEAPONS);
2.770 + KvGoBack(kv);
2.771 + }
2.772 + KvGoBack(kv);
2.773 + }
2.774 +
2.775 + CloseHandle(kv);
2.776 +
2.777 + /* Build the primary menu */
2.778 + if (g_hPrimaryMenu != INVALID_HANDLE)
2.779 + {
2.780 + CloseHandle(g_hPrimaryMenu);
2.781 + }
2.782 + g_hPrimaryMenu = CreateMenu(Menu_PrimaryHandler, MenuAction_DrawItem);
2.783 + SetMenuTitle(g_hPrimaryMenu, "Primary weapon:");
2.784 + for (new i=0; i<g_PrimaryCount; i++)
2.785 + {
2.786 + new index = g_PrimaryList[i];
2.787 + DM_GetWeaponName(index, value, sizeof(value));
2.788 + AddMenuItem(g_hPrimaryMenu, "", value);
2.789 + }
2.790 + AddMenuItem(g_hPrimaryMenu, "", "Random");
2.791 +
2.792 + /* Build the secondary menu */
2.793 + if (g_hSecondaryMenu != INVALID_HANDLE)
2.794 + {
2.795 + CloseHandle(g_hSecondaryMenu);
2.796 + }
2.797 + g_hSecondaryMenu = CreateMenu(Menu_SecondaryHandler, MenuAction_DrawItem);
2.798 + SetMenuTitle(g_hSecondaryMenu, "Secondary weapon:");
2.799 + for (new i=0; i<g_SecondaryCount; i++)
2.800 + {
2.801 + new index = g_SecondaryList[i];
2.802 + DM_GetWeaponName(index, value, sizeof(value));
2.803 + AddMenuItem(g_hSecondaryMenu, "", value);
2.804 + }
2.805 + AddMenuItem(g_hSecondaryMenu, "", "Random");
2.806 +
2.807 + return true;
2.808 +}
2.809 +
2.810 +SetClientArmor(client, armor)
2.811 +{
2.812 + if (g_ArmorOffset == -1)
2.813 + {
2.814 + return;
2.815 + }
2.816 +
2.817 + SetEntData(client, g_ArmorOffset, armor, 4, true);
2.818 +}
2.819 +
2.820 +SetClientHealth(client, health)
2.821 +{
2.822 + if (g_HealthOffset == -1)
2.823 + {
2.824 + return;
2.825 + }
2.826 +
2.827 + SetEntData(client, g_HealthOffset, health, 4, true);
2.828 +}
2.829 +
2.830 +GiveGrenades(client, flashnum, bool:he, bool:smoke)
2.831 +{
2.832 + if (he)
2.833 + {
2.834 + GivePlayerItem(client, "weapon_hegrenade");
2.835 + }
2.836 + for (new i=0; i<flashnum; i++)
2.837 + {
2.838 + GivePlayerItem(client, "weapon_flashbang");
2.839 + }
2.840 + if (smoke)
2.841 + {
2.842 + GivePlayerItem(client, "weapon_smokegrenade");
2.843 + }
2.844 +}
2.845 +
2.846 +GiveNightVision(client)
2.847 +{
2.848 + if (g_NVOffset == -1)
2.849 + {
2.850 + return;
2.851 + }
2.852 +
2.853 + SetEntData(client, g_NVOffset, true, 1, true);
2.854 +}
2.855 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/scripting/dm_spawn_protection.sp Sun Jun 24 21:59:51 2007 +0000
3.3 @@ -0,0 +1,150 @@
3.4 +/**
3.5 + * dm_spawn_protection.sp
3.6 + * Adds spawn protection to CS:S DM.
3.7 + * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
3.8 + *
3.9 + * This program is free software; you can redistribute it and/or
3.10 + * modify it under the terms of the GNU General Public License
3.11 + * as published by the Free Software Foundation; either version 2
3.12 + * of the License, or (at your option) any later version.
3.13 + *
3.14 + * This program is distributed in the hope that it will be useful,
3.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.17 + * GNU General Public License for more details.
3.18 + *
3.19 + * You should have received a copy of the GNU General Public License
3.20 + * along with this program; if not, write to the Free Software
3.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3.22 + *
3.23 + * Version: $Id$
3.24 + */
3.25 +
3.26 +#pragma semicolon 1
3.27 +#include <sourcemod>
3.28 +#include <sdktools>
3.29 +#include <cssdm>
3.30 +
3.31 +#define K_RENDER_NORMAL 0
3.32 +#define K_RENDER_TRANS_COLOR 1
3.33 +
3.34 +/* Plugin stuff */
3.35 +new Handle:g_ProtVar;
3.36 +new Handle:g_TColorVar;
3.37 +new Handle:g_CTColorVar;
3.38 +new Handle:g_ProtTimeVar;
3.39 +new g_NormColor[4] = {255, 255, 255, 255};
3.40 +new g_TColor[4] = {255, 0, 0, 128};
3.41 +new g_CTColor[4] = {0, 0, 255, 128};
3.42 +new g_HealthOffset;
3.43 +new g_RenderModeOffset;
3.44 +new g_RenderClrOffset;
3.45 +
3.46 +/* Player stuff */
3.47 +new Handle:g_PlayerTimers[MAXPLAYERS+1];
3.48 +new g_PlayerHealth[MAXPLAYERS+1];
3.49 +
3.50 +/** PUBLIC INFO */
3.51 +public Plugin:myinfo =
3.52 +{
3.53 + name = "CS:S DM Spawn Protection",
3.54 + author = "AlliedModders LLC",
3.55 + description = "Spawn protection for CS:S DM",
3.56 + version = CSSDM_VERSION,
3.57 + url = "http://www.bailopan.net/cssdm/"
3.58 +};
3.59 +
3.60 +public OnPluginStart()
3.61 +{
3.62 + g_ProtVar = CreateConVar("cssdm_spawn_protection", "1", "Sets whether spawn protection is enabled");
3.63 + g_CTColorVar = CreateConVar("cssdm_prot_ctcolor", "0 0 255 128", "Sets the spawn color of CTs");
3.64 + g_TColorVar = CreateConVar("cssdm_prot_tcolor", "255 0 0 128", "Sets the spawn color of Ts");
3.65 + g_ProtTimeVar = CreateConVar("cssdm_prot_time", "2", "Sets time in seconds players are protected for");
3.66 +
3.67 + HookConVarChange(g_CTColorVar, OnColorChange);
3.68 + HookConVarChange(g_TColorVar, OnColorChange);
3.69 +
3.70 + g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
3.71 + g_RenderModeOffset = FindSendPropOffs("CCSPlayer", "m_nRenderMode");
3.72 + g_RenderClrOffset = FindSendPropOffs("CCSPlayer", "m_clrRender");
3.73 +}
3.74 +
3.75 +public OnColorChange(Handle:convar, const String:oldValue[], const String:newValue[])
3.76 +{
3.77 + decl String:colors[4][12];
3.78 + decl clr[4];
3.79 + new num_strings = ExplodeString(newValue, " ", colors, 4, 12);
3.80 +
3.81 + for (new i=0; i<num_strings; i++)
3.82 + {
3.83 + clr[i] = StringToInt(colors[i]);
3.84 + }
3.85 +
3.86 + if (convar == g_CTColorVar)
3.87 + {
3.88 + g_CTColor = clr;
3.89 + } else if (convar == g_TColorVar) {
3.90 + g_TColor = clr;
3.91 + }
3.92 +}
3.93 +
3.94 +public OnClientDisconnect(client)
3.95 +{
3.96 + if (g_PlayerTimers[client] != INVALID_HANDLE)
3.97 + {
3.98 + CloseHandle(g_PlayerTimers[client]);
3.99 + g_PlayerTimers[client] = INVALID_HANDLE;
3.100 + }
3.101 +}
3.102 +
3.103 +public Action:DM_OnClientDeath(client)
3.104 +{
3.105 + if (g_PlayerTimers[client] != INVALID_HANDLE)
3.106 + {
3.107 + CloseHandle(g_PlayerTimers[client]);
3.108 + g_PlayerTimers[client] = INVALID_HANDLE;
3.109 + }
3.110 +
3.111 + return Plugin_Continue;
3.112 +}
3.113 +
3.114 +public Action:StopProtection(Handle:timer, any:client)
3.115 +{
3.116 + g_PlayerTimers[client] = INVALID_HANDLE;
3.117 +
3.118 + SetEntData(client, g_HealthOffset, g_PlayerHealth[client]);
3.119 + UTIL_Render(client, g_NormColor);
3.120 +
3.121 + return Plugin_Stop;
3.122 +}
3.123 +
3.124 +public DM_OnClientPostSpawned(client)
3.125 +{
3.126 + if (!GetConVarInt(g_ProtVar) || !IsClientInGame(client))
3.127 + {
3.128 + return;
3.129 + }
3.130 +
3.131 + g_PlayerTimers[client] = CreateTimer(GetConVarFloat(g_ProtTimeVar), StopProtection, client);
3.132 +
3.133 + /* Start protection */
3.134 + g_PlayerHealth[client] = GetEntData(client, g_HealthOffset);
3.135 + SetEntData(client, g_HealthOffset, 1012); /* This overflows to show "500" */
3.136 +
3.137 + new team = GetClientTeam(client);
3.138 + if (team == CSSDM_TEAM_T)
3.139 + {
3.140 + UTIL_Render(client, g_TColor);
3.141 + } else if (team == CSSDM_TEAM_CT) {
3.142 + UTIL_Render(client, g_CTColor);
3.143 + }
3.144 +}
3.145 +
3.146 +UTIL_Render(client, const color[4])
3.147 +{
3.148 + new mode = (color[3] == 255) ? K_RENDER_NORMAL : K_RENDER_TRANS_COLOR;
3.149 +
3.150 + SetEntData(client, g_RenderModeOffset, mode, 1);
3.151 + SetEntDataArray(client, g_RenderClrOffset, color, 4, 1);
3.152 + ChangeEdictState(client);
3.153 +}
4.1 --- a/scripting/equipment.sp Sun Jun 24 21:58:09 2007 +0000
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,800 +0,0 @@
4.4 -/**
4.5 - * equip_menu.sp
4.6 - * Adds preset spawning to CS:S DM.
4.7 - * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
4.8 - *
4.9 - * This program is free software; you can redistribute it and/or
4.10 - * modify it under the terms of the GNU General Public License
4.11 - * as published by the Free Software Foundation; either version 2
4.12 - * of the License, or (at your option) any later version.
4.13 - *
4.14 - * This program is distributed in the hope that it will be useful,
4.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 - * GNU General Public License for more details.
4.18 - *
4.19 - * You should have received a copy of the GNU General Public License
4.20 - * along with this program; if not, write to the Free Software
4.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4.22 - *
4.23 - * Version: $Id$
4.24 - */
4.25 -
4.26 -#pragma semicolon 1
4.27 -#include <sourcemod>
4.28 -#include <sdktools>
4.29 -#include <cssdm>
4.30 -
4.31 -#define CSSDM_GUNMENU_NO 0
4.32 -#define CSSDM_GUNMENU_YES 1
4.33 -#define CSSDM_GUNMENU_RANDOM 2
4.34 -
4.35 -/** Plugin Stuff */
4.36 -new Handle:g_hEquipCfg = INVALID_HANDLE; /* cssdm_equip_cfg cvar */
4.37 -new g_ArmorOffset = -1; /* m_ArmorValue offset */
4.38 -new g_NVOffset = -1; /* m_bHasNightVision offset */
4.39 -new Handle:g_SpawnTimers[MAXPLAYERS+1]; /* Post-spawn timers */
4.40 -new Handle:g_hPrimaryMenu = INVALID_HANDLE; /* Priamry menu Handle */
4.41 -new Handle:g_hSecondaryMenu = INVALID_HANDLE; /* Secondary menu Handle */
4.42 -new Handle:g_hEquipMenu = INVALID_HANDLE; /* Main equipment menu */
4.43 -new bool:g_IsEnabled = false; /* Whether the plugin should work */
4.44 -new g_PrimaryChoices[MAXPLAYERS+1]; /* Primary weapon selections */
4.45 -new g_SecondaryChoices[MAXPLAYERS+1]; /* Secondary weapon selections */
4.46 -new bool:g_GunMenuEnabled[MAXPLAYERS+1]; /* Whether the gun menu is enabled */
4.47 -new bool:g_GunMenuAvailable[MAXPLAYERS+1]; /* Whether the gun menu is available */
4.48 -new bool:g_AllowGunCommand = true; /* Whether the gun menu command is enabled */
4.49 -
4.50 -/** HUMAN CONFIGS */
4.51 -new g_PrimaryList[CSSDM_MAX_WEAPONS];
4.52 -new g_SecondaryList[CSSDM_MAX_WEAPONS];
4.53 -new g_PrimaryCount = 0;
4.54 -new g_SecondaryCount = 0;
4.55 -new g_PrimaryMenu = CSSDM_GUNMENU_YES;
4.56 -new g_SecondaryMenu = CSSDM_GUNMENU_YES;
4.57 -new bool:g_AllowBuy = false;
4.58 -new g_ArmorAmount = 100;
4.59 -new bool:g_Helmets = true;
4.60 -new g_Flashes = 0;
4.61 -new bool:g_Smokes = false;
4.62 -new bool:g_HEs = false;
4.63 -new bool:g_NightVision = false;
4.64 -new bool:g_DefuseKits = true;
4.65 -
4.66 -/** BOT CONFIGS */
4.67 -new g_BotPrimaryList[CSSDM_MAX_WEAPONS];
4.68 -new g_BotSecondaryList[CSSDM_MAX_WEAPONS];
4.69 -new g_BotPrimaryCount = 0;
4.70 -new g_BotSecondaryCount = 0;
4.71 -new g_BotArmor = 100;
4.72 -new bool:g_BotHelmets = false;
4.73 -new g_BotFlashes = 0;
4.74 -new bool:g_BotSmokes = false;
4.75 -new bool:g_BotHEs = false;
4.76 -new bool:g_BotDefuseKits = true;
4.77 -
4.78 -/** PUBLIC INFO */
4.79 -public Plugin:myinfo =
4.80 -{
4.81 - name = "CS:S DM Equipment",
4.82 - author = "AlliedModders LLC",
4.83 - description = "Adds gun menu/equipment to CS:S DM",
4.84 - version = CSSDM_VERSION,
4.85 - url = "http://www.bailopan.net/cssdm/"
4.86 -};
4.87 -
4.88 -/******************
4.89 - * IMPLEMENTATION *
4.90 - ******************/
4.91 -
4.92 -public OnPluginStart()
4.93 -{
4.94 - RegConsoleCmd("say", Command_Say);
4.95 - RegConsoleCmd("say_team", Command_Say);
4.96 -
4.97 - g_hEquipCfg = CreateConVar("cssdm_equip_cfg", "cssdm.equip.txt", "CS:S DM Equipment Config File");
4.98 - g_ArmorOffset = FindSendPropOffs("CCSPlayer", "m_ArmorValue");
4.99 - g_NVOffset = FindSendPropOffs("CCSPlayer", "m_bHasNightVision");
4.100 -
4.101 - g_hEquipMenu = CreateMenu(Menu_EquipHandler, MenuAction_DrawItem);
4.102 - SetMenuTitle(g_hEquipMenu, "Weapon Options:");
4.103 - SetMenuExitButton(g_hEquipMenu, false);
4.104 - AddMenuItem(g_hEquipMenu, "", "New weapons");
4.105 - AddMenuItem(g_hEquipMenu, "", "Same weapons");
4.106 - AddMenuItem(g_hEquipMenu, "", "Same weapons every time");
4.107 - AddMenuItem(g_hEquipMenu, "", "Random weapons");
4.108 - AddMenuItem(g_hEquipMenu, "", "Random weapons every time");
4.109 -}
4.110 -
4.111 -public OnConfigsExecuted()
4.112 -{
4.113 - decl String:cvar[64];
4.114 - GetConVarString(g_hEquipCfg, cvar, sizeof(cvar));
4.115 -
4.116 - if (cvar[0] == '\0')
4.117 - {
4.118 - return;
4.119 - }
4.120 -
4.121 - decl String:path[255];
4.122 - Format(path, sizeof(path), "cfg/cssdm/%s", cvar);
4.123 -
4.124 - if ((g_IsEnabled = LoadConfigFile(path)) == false)
4.125 - {
4.126 - LogError("[CSSDM] Could not find equipment file \"%s\"", path);
4.127 - return;
4.128 - }
4.129 -
4.130 - if (strcmp(cvar, "cssdm.equip.txt") == 0)
4.131 - {
4.132 - /** See if there is a map version */
4.133 - decl String:map[64];
4.134 - GetCurrentMap(map, sizeof(map));
4.135 - Format(path, sizeof(path), "cfg/cssdm/%s/cssdm.equip.txt", map);
4.136 -
4.137 - if (FileExists(path))
4.138 - {
4.139 - LoadConfigFile(path);
4.140 - }
4.141 - }
4.142 -}
4.143 -
4.144 -public Action:DM_OnClientDeath(client)
4.145 -{
4.146 - if (g_SpawnTimers[client] != INVALID_HANDLE)
4.147 - {
4.148 - KillTimer(g_SpawnTimers[client]);
4.149 - g_SpawnTimers[client] = INVALID_HANDLE;
4.150 - }
4.151 - g_GunMenuAvailable[client] = true;
4.152 -}
4.153 -
4.154 -public OnClientPutInServer(client)
4.155 -{
4.156 - g_GunMenuEnabled[client] = true;
4.157 - g_GunMenuAvailable[client] = true;
4.158 - g_PrimaryChoices[client] = -1;
4.159 - g_SecondaryChoices[client] = -1;
4.160 -}
4.161 -
4.162 -public OnClientDisconnect(client)
4.163 -{
4.164 - if (g_SpawnTimers[client] != INVALID_HANDLE)
4.165 - {
4.166 - KillTimer(g_SpawnTimers[client]);
4.167 - g_SpawnTimers[client] = INVALID_HANDLE;
4.168 - }
4.169 -}
4.170 -
4.171 -public DM_OnClientSpawned(client)
4.172 -{
4.173 - if (!IsFakeClient(client))
4.174 - {
4.175 - if (g_ArmorAmount > 0)
4.176 - {
4.177 - GivePlayerItem(client, "item_assaultsuit");
4.178 - GivePlayerItem(client, "item_assaultsuit");
4.179 - SetClientArmor(client, g_ArmorAmount);
4.180 - }
4.181 - if (g_Helmets)
4.182 - {
4.183 - GivePlayerItem(client, "item_kevlar");
4.184 - GivePlayerItem(client, "item_kevlar");
4.185 - }
4.186 - GiveGrenades(client, g_Flashes, g_HEs, g_Smokes);
4.187 - if (g_NightVision)
4.188 - {
4.189 - GiveNightVision(client);
4.190 - }
4.191 - } else {
4.192 - /* See if we'll need to strip this bot */
4.193 - if (g_BotSecondaryCount || g_BotPrimaryCount)
4.194 - {
4.195 - DM_StripBotItems(client);
4.196 - }
4.197 - if (g_BotArmor > 0)
4.198 - {
4.199 - GivePlayerItem(client, "item_assaultsuit");
4.200 - GivePlayerItem(client, "item_assaultsuit");
4.201 - SetClientArmor(client, g_BotArmor);
4.202 - } else {
4.203 - /* Make sure bot didn't buy armor */
4.204 - SetClientArmor(client, 0);
4.205 - }
4.206 - if (g_BotHelmets)
4.207 - {
4.208 - GivePlayerItem(client, "item_kevlar");
4.209 - GivePlayerItem(client, "item_kevlar");
4.210 - }
4.211 - GiveGrenades(client, g_BotFlashes, g_BotHEs, g_BotSmokes);
4.212 - }
4.213 - if (g_SpawnTimers[client] == INVALID_HANDLE)
4.214 - {
4.215 - /* Small delay - we want to avoid ResetHUD */
4.216 - g_SpawnTimers[client] = CreateTimer(0.1, PlayerPostSpawn, client);
4.217 - }
4.218 -}
4.219 -
4.220 -public Action:PlayerPostSpawn(Handle:timer, any:client)
4.221 -{
4.222 - g_SpawnTimers[client] = INVALID_HANDLE;
4.223 -
4.224 - if (!ShouldRun())
4.225 - {
4.226 - return Plugin_Stop;
4.227 - }
4.228 -
4.229 - if (IsFakeClient(client))
4.230 - {
4.231 - if (g_BotSecondaryCount > 0)
4.232 - {
4.233 - new index;
4.234 - if (g_BotSecondaryCount == 1)
4.235 - {
4.236 - index = g_BotSecondaryList[0];
4.237 - } else {
4.238 - index = GetRandomInt(0, g_BotSecondaryCount-1);
4.239 - index = g_BotSecondaryList[index];
4.240 - }
4.241 - decl String:classname[64];
4.242 - DM_GetWeaponClassname(index, classname, sizeof(classname));
4.243 - GivePlayerItem(client, classname);
4.244 - }
4.245 - if (g_BotPrimaryCount > 0)
4.246 - {
4.247 - new index;
4.248 - if (g_BotPrimaryCount == 1)
4.249 - {
4.250 - index = g_BotPrimaryList[0];
4.251 - } else {
4.252 - index = GetRandomInt(0, g_BotPrimaryCount-1);
4.253 - index = g_BotPrimaryList[index];
4.254 - }
4.255 - decl String:classname[64];
4.256 - DM_GetWeaponClassname(index, classname, sizeof(classname));
4.257 - GivePlayerItem(client, classname);
4.258 - }
4.259 - if (g_BotDefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
4.260 - {
4.261 - GivePlayerItem(client, "item_defuser");
4.262 - }
4.263 - } else {
4.264 - if (g_DefuseKits && GetClientTeam(client) == CSSDM_TEAM_CT)
4.265 - {
4.266 - GivePlayerItem(client, "item_defuser");
4.267 - PrintToChat(client, "Oh my god, you have a defuse kit");
4.268 - }
4.269 -
4.270 - new numGiven = 0;
4.271 - /* First, check if we should only be giving one of something automatically */
4.272 - if ((g_SecondaryMenu == CSSDM_GUNMENU_RANDOM || g_SecondaryMenu == CSSDM_GUNMENU_YES)
4.273 - && g_SecondaryCount == 1)
4.274 - {
4.275 - GiveSecondary(client, 0);
4.276 - numGiven++;
4.277 - } else if (g_PrimaryMenu == CSSDM_GUNMENU_RANDOM && g_PrimaryCount > 1) {
4.278 - GivePrimary(client, g_PrimaryCount);
4.279 - numGiven++;
4.280 - }
4.281 -
4.282 - if ((g_PrimaryMenu == CSSDM_GUNMENU_RANDOM || g_PrimaryMenu == CSSDM_GUNMENU_YES)
4.283 - && g_PrimaryCount == 1)
4.284 - {
4.285 - GivePrimary(client, 0);
4.286 - numGiven++;
4.287 - } else if (g_SecondaryMenu == CSSDM_GUNMENU_RANDOM && g_SecondaryCount > 1) {
4.288 - GiveSecondary(client, g_SecondaryCount);
4.289 - numGiven++;
4.290 - }
4.291 -
4.292 - /* If we've already given two weapons, there is no need for a menu. */
4.293 - if (numGiven == 2)
4.294 - {
4.295 - return Plugin_Stop;
4.296 - }
4.297 -
4.298 - if (g_GunMenuEnabled[client])
4.299 - {
4.300 - DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
4.301 - } else {
4.302 - GiveBothFromChoices(client);
4.303 - }
4.304 - }
4.305 -
4.306 - return Plugin_Stop;
4.307 -}
4.308 -
4.309 -public Action:Command_Say(client, args)
4.310 -{
4.311 - if (!ShouldRun())
4.312 - {
4.313 - return Plugin_Continue;
4.314 - }
4.315 -
4.316 - new String:text[192];
4.317 - GetCmdArg(1, text, sizeof(text));
4.318 -
4.319 - if (strcmp(text, "guns") == 0)
4.320 - {
4.321 - if (!g_AllowGunCommand)
4.322 - {
4.323 - PrintToChat(client, "[CSSDM] The guns menu command is disabled.");
4.324 - return Plugin_Handled;
4.325 - }
4.326 -
4.327 - if (!ChooseFromSecondary() && !ChooseFromPrimary())
4.328 - {
4.329 - PrintToChat(client, "[CSSDM] The guns menu is not available.");
4.330 - return Plugin_Handled;
4.331 - }
4.332 -
4.333 - if (g_GunMenuEnabled[client])
4.334 - {
4.335 - PrintToChat(client, "[CSSDM] Your guns menu is already enabled.");
4.336 - return Plugin_Handled;
4.337 - }
4.338 -
4.339 - g_GunMenuEnabled[client] = true;
4.340 - if (!g_GunMenuAvailable[client])
4.341 - {
4.342 - PrintToChat(client, "[CSSDM] Your guns menu has been enabled for your next respawn.");
4.343 - } else {
4.344 - DisplayMenu(g_hEquipMenu, client, MENU_TIME_FOREVER);
4.345 - }
4.346 -
4.347 - return Plugin_Handled;
4.348 - }
4.349 -
4.350 - return Plugin_Continue;
4.351 -}
4.352 -
4.353 -public Action:OnClientCommand(client, args)
4.354 -{
4.355 - if (!ShouldRun() || g_AllowBuy)
4.356 - {
4.357 - return Plugin_Continue;
4.358 - }
4.359 -
4.360 - decl String:cmd[32];
4.361 - GetCmdArg(0, cmd, sizeof(cmd));
4.362 -
4.363 - if (StrEqual(cmd, "buy")
4.364 - || StrEqual(cmd, "autobuy")
4.365 - || StrEqual(cmd, "rebuy")
4.366 - || StrEqual(cmd, "buyequip")
4.367 - || StrEqual(cmd, "buymenu"))
4.368 - {
4.369 - return Plugin_Handled;
4.370 - }
4.371 -
4.372 - return Plugin_Continue;
4.373 -}
4.374 -
4.375 -public Menu_EquipHandler(Handle:menu, MenuAction:action, param1, param2)
4.376 -{
4.377 - if (!ShouldRun())
4.378 - {
4.379 - return 0;
4.380 - }
4.381 -
4.382 - if (action == MenuAction_DrawItem)
4.383 - {
4.384 - if (param2 == 1 || param2 == 2)
4.385 - {
4.386 - if (g_PrimaryChoices[param1] == -1 && g_PrimaryChoices[param1] == -1)
4.387 - {
4.388 - return ITEMDRAW_DISABLED;
4.389 - }
4.390 - }
4.391 - return ITEMDRAW_DEFAULT;
4.392 - }
4.393 - else if (action == MenuAction_Select)
4.394 - {
4.395 - if (param2 == 0)
4.396 - {
4.397 - if (ChooseFromSecondary())
4.398 - {
4.399 - DisplayMenu(g_hSecondaryMenu, param1, MENU_TIME_FOREVER);
4.400 - } else if (ChooseFromPrimary()) {
4.401 - DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
4.402 - }
4.403 - } else if (param2 == 1) {
4.404 - GiveBothFromChoices(param1);
4.405 - } else if (param2 == 2) {
4.406 - GiveBothFromChoices(param1);
4.407 - g_GunMenuEnabled[param1] = false;
4.408 - PrintToChat(param1, "[CSSDM] Say \"guns\" in chat to re-enable your menu.");
4.409 - } else if (param2 == 3) {
4.410 - GivePrimary(param1, g_PrimaryCount);
4.411 - GiveSecondary(param1, g_SecondaryCount);
4.412 - } else if (param2 == 4) {
4.413 - GivePrimary(param1, g_PrimaryCount);
4.414 - GiveSecondary(param1, g_SecondaryCount);
4.415 - GiveBothFromChoices(param1);
4.416 - g_GunMenuEnabled[param1] = false;
4.417 - PrintToChat(param1, "[CSSDM] Say \"guns\" in chat to re-enable your menu.");
4.418 - }
4.419 - g_GunMenuAvailable[param1] = false;
4.420 - }
4.421 -
4.422 - return 0;
4.423 -}
4.424 -
4.425 -public Menu_PrimaryHandler(Handle:menu, MenuAction:action, param1, param2)
4.426 -{
4.427 - if (!ShouldRun())
4.428 - {
4.429 - return 0;
4.430 - }
4.431 -
4.432 - if (action == MenuAction_DrawItem)
4.433 - {
4.434 - return ITEMDRAW_DEFAULT;
4.435 - }
4.436 - else if (action == MenuAction_Select)
4.437 - {
4.438 - GivePrimary(param1, param2);
4.439 - }
4.440 -
4.441 - return 0;
4.442 -}
4.443 -
4.444 -public Menu_SecondaryHandler(Handle:menu, MenuAction:action, param1, param2)
4.445 -{
4.446 - if (!ShouldRun())
4.447 - {
4.448 - return 0;
4.449 - }
4.450 -
4.451 - if (action == MenuAction_DrawItem)
4.452 - {
4.453 - return ITEMDRAW_DEFAULT;
4.454 - }
4.455 - else if (action == MenuAction_Select)
4.456 - {
4.457 - GiveSecondary(param1, param2);
4.458 - if (ChooseFromPrimary())
4.459 - {
4.460 - DisplayMenu(g_hPrimaryMenu, param1, MENU_TIME_FOREVER);
4.461 - }
4.462 - }
4.463 -
4.464 - return 0;
4.465 -}
4.466 -
4.467 -bool:ChooseFromPrimary()
4.468 -{
4.469 - return (g_PrimaryMenu == CSSDM_GUNMENU_YES
4.470 - && g_PrimaryCount > 1);
4.471 -}
4.472 -
4.473 -bool:ChooseFromSecondary()
4.474 -{
4.475 - return (g_SecondaryMenu == CSSDM_GUNMENU_YES
4.476 - && g_SecondaryCount > 1);
4.477 -}
4.478 -
4.479 -GiveWeapon(client, index)
4.480 -{
4.481 - new DmWeaponType:type = DM_GetWeaponType(index);
4.482 -
4.483 - new entity = DM_GetClientWeapon(client, type);
4.484 - if (entity != -1)
4.485 - {
4.486 - DM_DropWeapon(client, entity);
4.487 - }
4.488 -
4.489 - new String:cls[64];
4.490 - DM_GetWeaponClassname(index, cls, sizeof(cls));
4.491 -
4.492 - return GivePlayerItem(client, cls);
4.493 -}
4.494 -
4.495 -GiveBothFromChoices(client)
4.496 -{
4.497 - if (ChooseFromPrimary())
4.498 - {
4.499 - GivePrimary(client, g_PrimaryChoices[client]);
4.500 - }
4.501 -
4.502 - if (ChooseFromSecondary())
4.503 - {
4.504 - GiveSecondary(client, g_SecondaryChoices[client]);
4.505 - }
4.506 -}
4.507 -
4.508 -/**
4.509 - * Gives a primary weapon to a client.
4.510 - * If the list_index is > the count, we choose one randomly.
4.511 - * This is a hack so we can append "Random" to the choice list.
4.512 - */
4.513 -GivePrimary(client, list_index)
4.514 -{
4.515 - if (list_index < 0)
4.516 - {
4.517 - return;
4.518 - }
4.519 -
4.520 - new weapon_index;
4.521 - if (list_index >= g_PrimaryCount)
4.522 - {
4.523 - if (g_PrimaryCount > 1)
4.524 - {
4.525 - weapon_index = GetRandomInt(0, g_PrimaryCount-1);
4.526 - weapon_index = g_PrimaryList[weapon_index];
4.527 - } else {
4.528 - weapon_index = g_PrimaryList[0];
4.529 - }
4.530 - } else {
4.531 - weapon_index = g_PrimaryList[list_index];
4.532 - }
4.533 -
4.534 - g_PrimaryChoices[client] = list_index;
4.535 -
4.536 - GiveWeapon(client, weapon_index);
4.537 -}
4.538 -
4.539 -/**
4.540 - * Gives a secondary weapon to a client.
4.541 - * If the list_index is > the count, we choose one randomly.
4.542 - * This is a hack so we can append "Random" to the choice list.
4.543 - */
4.544 -GiveSecondary(client, list_index)
4.545 -{
4.546 - if (list_index < 0)
4.547 - {
4.548 - return;
4.549 - }
4.550 -
4.551 - new weapon_index;
4.552 - if (list_index >= g_SecondaryCount)
4.553 - {
4.554 - if (g_SecondaryCount > 1)
4.555 - {
4.556 - weapon_index = GetRandomInt(0, g_SecondaryCount-1);
4.557 - weapon_index = g_SecondaryList[weapon_index];
4.558 - } else {
4.559 - weapon_index = g_SecondaryList[0];
4.560 - }
4.561 - } else {
4.562 - weapon_index = g_SecondaryList[list_index];
4.563 - }
4.564 -
4.565 - g_SecondaryChoices[client] = list_index;
4.566 -
4.567 - GiveWeapon(client, weapon_index);
4.568 -}
4.569 -
4.570 -bool:ShouldRun()
4.571 -{
4.572 - return (DM_IsRunning() && g_IsEnabled);
4.573 -}
4.574 -
4.575 -bool:KvGetYesOrNo(Handle:kv, const String:key[], const String:def[])
4.576 -{
4.577 - decl String:value[12];
4.578 - KvGetString(kv, key, value, sizeof(value), def);
4.579 - return (strcmp(value, "yes") == 0);
4.580 -}
4.581 -
4.582 -KvGetGunMenu(Handle:kv, const String:key[], const String:def[])
4.583 -{
4.584 - decl String:value[12];
4.585 - KvGetString(kv, key, value, sizeof(value), def);
4.586 -
4.587 - if (strcmp(value, "yes") == 0)
4.588 - {
4.589 - return CSSDM_GUNMENU_YES;
4.590 - } else if (strcmp(value, "random") == 0) {
4.591 - return CSSDM_GUNMENU_RANDOM;
4.592 - }
4.593 -
4.594 - return CSSDM_GUNMENU_NO;
4.595 -}
4.596 -
4.597 -bool:LoadConfigFile(const String:path[])
4.598 -{
4.599 - new Handle:kv = CreateKeyValues("Equipment");
4.600 - if (!FileToKeyValues(kv, path))
4.601 - {
4.602 - return false;
4.603 - }
4.604 -
4.605 - decl String:value[255];
4.606 -
4.607 - /* Load settings */
4.608 - if (KvJumpToKey(kv, "Settings"))
4.609 - {
4.610 - g_AllowGunCommand = KvGetYesOrNo(kv, "guns_command", "yes");
4.611 - KvGoBack(kv);
4.612 - }
4.613 -
4.614 - /* Load menu options */
4.615 - if (KvJumpToKey(kv, "Menus"))
4.616 - {
4.617 - g_PrimaryMenu = KvGetGunMenu(kv, "primary", "yes");
4.618 - g_SecondaryMenu = KvGetGunMenu(kv, "secondary", "yes");
4.619 - g_AllowBuy = KvGetYesOrNo(kv, "buy", "no");
4.620 - KvGoBack(kv);
4.621 - }
4.622 -
4.623 - /* Load automatic stuff */
4.624 - if (KvJumpToKey(kv, "AutoItems"))
4.625 - {
4.626 - g_ArmorAmount = KvGetNum(kv, "armor", 100);
4.627 - g_Flashes = KvGetNum(kv, "flashbangs");
4.628 - g_Helmets = KvGetYesOrNo(kv, "helmet", "yes");
4.629 - g_Smokes = KvGetYesOrNo(kv, "smokegrenade", "no");
4.630 - g_HEs = KvGetYesOrNo(kv, "hegrenade", "no");
4.631 - g_NightVision = KvGetYesOrNo(kv, "nightvision", "no");
4.632 - g_DefuseKits = KvGetYesOrNo(kv, "defusekits", "yes");
4.633 - KvGoBack(kv);
4.634 - }
4.635 -
4.636 - /* Load bot items */
4.637 - if (KvJumpToKey(kv, "BotItems"))
4.638 - {
4.639 - /* Clear out old lists first */
4.640 - g_BotPrimaryCount = 0;
4.641 - g_BotSecondaryCount = 0;
4.642 -
4.643 - if (KvGotoFirstSubKey(kv, false))
4.644 - {
4.645 - do
4.646 - {
4.647 - KvGetSectionName(kv, value, sizeof(value));
4.648 - if (strcmp(value, "weapon") == 0)
4.649 - {
4.650 - KvGetString(kv, NULL_STRING, value, sizeof(value));
4.651 - new index = DM_GetWeaponID(value);
4.652 - if (index != -1)
4.653 - {
4.654 - new DmWeaponType:type = DM_GetWeaponType(index);
4.655 - if (type == DmWeapon_Primary && g_BotPrimaryCount < CSSDM_MAX_WEAPONS)
4.656 - {
4.657 - g_BotPrimaryList[g_BotPrimaryCount++] = index;
4.658 - } else if (type == DmWeapon_Secondary && g_BotSecondaryCount < CSSDM_MAX_WEAPONS) {
4.659 - g_BotSecondaryList[g_BotSecondaryCount++] = index;
4.660 - }
4.661 - }
4.662 - } else if (strcmp(value, "armor") == 0) {
4.663 - g_BotArmor = KvGetNum(kv, NULL_STRING, 100);
4.664 - } else if (strcmp(value, "helmet") == 0) {
4.665 - g_BotHelmets = KvGetYesOrNo(kv, NULL_STRING, "yes");
4.666 - } else if (strcmp(value, "flashbangs") == 0) {
4.667 - g_BotFlashes = KvGetNum(kv, NULL_STRING);
4.668 - } else if (strcmp(value, "smokegrenade") == 0) {
4.669 - g_BotSmokes = KvGetYesOrNo(kv, NULL_STRING, "no");
4.670 - } else if (strcmp(value, "hegrenade") == 0) {
4.671 - g_BotHEs = KvGetYesOrNo(kv, NULL_STRING, "no");
4.672 - } else if (strcmp(value, "defusekits") == 0) {
4.673 - g_DefuseKits = KvGetYesOrNo(kv, NULL_STRING, "yes");
4.674 - }
4.675 - } while (KvGotoNextKey(kv, false));
4.676 - KvGoBack(kv);
4.677 - }
4.678 - KvGoBack(kv);
4.679 - }
4.680 -
4.681 - /* Load secondary weapons */
4.682 - if (KvJumpToKey(kv, "SecondaryMenu"))
4.683 - {
4.684 - /* Clear out old list first */
4.685 - g_SecondaryCount = 0;
4.686 -
4.687 - if (KvGotoFirstSubKey(kv, false))
4.688 - {
4.689 - do
4.690 - {
4.691 - KvGetSectionName(kv, value, sizeof(value));
4.692 - if (strcmp(value, "weapon") == 0)
4.693 - {
4.694 - KvGetString(kv, NULL_STRING, value, sizeof(value));
4.695 - new index = DM_GetWeaponID(value);
4.696 - if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Secondary)
4.697 - {
4.698 - g_SecondaryList[g_SecondaryCount++] = index;
4.699 - }
4.700 - }
4.701 - } while (KvGotoNextKey(kv, false) && g_SecondaryCount < CSSDM_MAX_WEAPONS);
4.702 - KvGoBack(kv);
4.703 - }
4.704 - KvGoBack(kv);
4.705 - }
4.706 -
4.707 - /* Load primary weapons */
4.708 - if (KvJumpToKey(kv, "PrimaryMenu"))
4.709 - {
4.710 - /* Clear out old list first */
4.711 - g_PrimaryCount = 0;
4.712 -
4.713 - if (KvGotoFirstSubKey(kv, false))
4.714 - {
4.715 - do
4.716 - {
4.717 - KvGetSectionName(kv, value, sizeof(value));
4.718 - if (strcmp(value, "weapon") == 0)
4.719 - {
4.720 - KvGetString(kv, NULL_STRING, value, sizeof(value));
4.721 - new index = DM_GetWeaponID(value);
4.722 - if (index != -1 && DM_GetWeaponType(index) == DmWeapon_Primary)
4.723 - {
4.724 - g_PrimaryList[g_PrimaryCount++] = index;
4.725 - }
4.726 - }
4.727 - } while (KvGotoNextKey(kv, false) && g_PrimaryCount < CSSDM_MAX_WEAPONS);
4.728 - KvGoBack(kv);
4.729 - }
4.730 - KvGoBack(kv);
4.731 - }
4.732 -
4.733 - CloseHandle(kv);
4.734 -
4.735 - /* Build the primary menu */
4.736 - if (g_hPrimaryMenu != INVALID_HANDLE)
4.737 - {
4.738 - CloseHandle(g_hPrimaryMenu);
4.739 - }
4.740 - g_hPrimaryMenu = CreateMenu(Menu_PrimaryHandler, MenuAction_DrawItem);
4.741 - SetMenuTitle(g_hPrimaryMenu, "Primary weapon:");
4.742 - for (new i=0; i<g_PrimaryCount; i++)
4.743 - {
4.744 - new index = g_PrimaryList[i];
4.745 - DM_GetWeaponName(index, value, sizeof(value));
4.746 - AddMenuItem(g_hPrimaryMenu, "", value);
4.747 - }
4.748 - AddMenuItem(g_hPrimaryMenu, "", "Random");
4.749 -
4.750 - /* Build the secondary menu */
4.751 - if (g_hSecondaryMenu != INVALID_HANDLE)
4.752 - {
4.753 - CloseHandle(g_hSecondaryMenu);
4.754 - }
4.755 - g_hSecondaryMenu = CreateMenu(Menu_SecondaryHandler, MenuAction_DrawItem);
4.756 - SetMenuTitle(g_hSecondaryMenu, "Secondary weapon:");
4.757 - for (new i=0; i<g_SecondaryCount; i++)
4.758 - {
4.759 - new index = g_SecondaryList[i];
4.760 - DM_GetWeaponName(index, value, sizeof(value));
4.761 - AddMenuItem(g_hSecondaryMenu, "", value);
4.762 - }
4.763 - AddMenuItem(g_hSecondaryMenu, "", "Random");
4.764 -
4.765 - return true;
4.766 -}
4.767 -
4.768 -SetClientArmor(client, armor)
4.769 -{
4.770 - if (g_ArmorOffset == -1)
4.771 - {
4.772 - return;
4.773 - }
4.774 -
4.775 - SetEntData(client, g_ArmorOffset, armor, 4, true);
4.776 -}
4.777 -
4.778 -GiveGrenades(client, flashnum, bool:he, bool:smoke)
4.779 -{
4.780 - if (he)
4.781 - {
4.782 - GivePlayerItem(client, "weapon_hegrenade");
4.783 - }
4.784 - for (new i=0; i<flashnum; i++)
4.785 - {
4.786 - GivePlayerItem(client, "weapon_flashbang");
4.787 - }
4.788 - if (smoke)
4.789 - {
4.790 - GivePlayerItem(client, "weapon_smokegrenade");
4.791 - }
4.792 -}
4.793 -
4.794 -GiveNightVision(client)
4.795 -{
4.796 - if (g_NVOffset == -1)
4.797 - {
4.798 - return;
4.799 - }
4.800 -
4.801 - SetEntData(client, g_NVOffset, true, 1, true);
4.802 -}
4.803 -
5.1 --- a/scripting/include/cssdm.inc Sun Jun 24 21:58:09 2007 +0000
5.2 +++ b/scripting/include/cssdm.inc Sun Jun 24 21:59:51 2007 +0000
5.3 @@ -166,6 +166,45 @@
5.4 */
5.5 native DM_StripBotItems(client);
5.6
5.7 +/**
5.8 + * Returns the spawn waiting time.
5.9 + *
5.10 + * @return Spawn wait time, in seconds.
5.11 + */
5.12 +native Float:DM_GetSpawnWaitTime();
5.13 +
5.14 +/**
5.15 + * Respawns a player using CS:S's low level respawning function. This can be
5.16 + * called even if the player is not dead.
5.17 + *
5.18 + * @param client Client index.
5.19 + * @param fullRespawn If true, client will be forwarded through player_spawn
5.20 + * callbacks.
5.21 + * @noreturn
5.22 + * @error Invalid client index or client not in game.
5.23 + */
5.24 +native DM_RespawnClient(client, bool:fullRespawn=true);
5.25 +
5.26 +/**
5.27 + * Returns whether or not a client is alive.
5.28 + *
5.29 + * @param client Client index.
5.30 + * @return True if alive, false if dead.
5.31 + * @error Invalid client index or client not in game.
5.32 + */
5.33 +native DM_IsClientAlive(client);
5.34 +
5.35 +/**
5.36 + * Gives ammo to a player.
5.37 + *
5.38 + * @param client Client index.
5.39 + * @param type Ammo type (>=0).
5.40 + * @param count Ammo amount to give.
5.41 + * @param noSound If true, the ammo sound will be suppressed.
5.42 + * @return Actual ammo amount given.
5.43 + * @error Invalid client index or client not in game.
5.44 + */
5.45 +native DM_GiveClientAmmo(client, type, count, bool:noSound=false);
5.46
5.47 /**
5.48 * Do not edit below this line!
6.1 --- a/scripting/presetspawns.sp Sun Jun 24 21:58:09 2007 +0000
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,476 +0,0 @@
6.4 -/**
6.5 - * spawn_preset.sp
6.6 - * Adds preset spawning to CS:S DM.
6.7 - * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
6.8 - *
6.9 - * This program is free software; you can redistribute it and/or
6.10 - * modify it under the terms of the GNU General Public License
6.11 - * as published by the Free Software Foundation; either version 2
6.12 - * of the License, or (at your option) any later version.
6.13 - *
6.14 - * This program is distributed in the hope that it will be useful,
6.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 - * GNU General Public License for more details.
6.18 - *
6.19 - * You should have received a copy of the GNU General Public License
6.20 - * along with this program; if not, write to the Free Software
6.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
6.22 - *
6.23 - * Version: $Id$
6.24 - */
6.25 -
6.26 -#pragma semicolon 1
6.27 -#pragma dynamic 16384
6.28 -#include <sourcemod>
6.29 -#include <sdktools>
6.30 -#include <cssdm>
6.31 -
6.32 -public Plugin:myinfo =
6.33 -{
6.34 - name = "CS:S DM Preset Spawns",
6.35 - author = "AlliedModders LLC",
6.36 - description = "Adds preset spawning to CS:S DM",
6.37 - version = CSSDM_VERSION,
6.38 - url = "http://www.bailopan.net/cssdm/"
6.39 -};
6.40 -
6.41 -#define MAX_SPAWNS 256
6.42 -
6.43 -
6.44 -new bool:g_AreWeSpawning = false;
6.45 -new g_SpawnCount = 0;
6.46 -new Float:g_SpawnOrigins[MAX_SPAWNS][3];
6.47 -new Float:g_SpawnAngles[MAX_SPAWNS][3];
6.48 -new Handle:g_hSpawnMenu = INVALID_HANDLE;
6.49 -new g_LastLocation[MAXPLAYERS+1];
6.50 -
6.51 -public OnPluginStart()
6.52 -{
6.53 - RegAdminCmd("cssdm_spawn_menu", Command_SpawnMenu, ADMFLAG_CHANGEMAP, "Edits CS:S DM spawn points");
6.54 -
6.55 - g_hSpawnMenu = CreateMenu(Menu_EditSpawns);
6.56 - SetMenuTitle(g_hSpawnMenu, "Spawn Point Editor");
6.57 - AddMenuItem(g_hSpawnMenu, "nearest", "Teleport to nearest");
6.58 - AddMenuItem(g_hSpawnMenu, "previous", "Teleport to previous");
6.59 - AddMenuItem(g_hSpawnMenu, "next", "Teleport to next");
6.60 - AddMenuItem(g_hSpawnMenu, "add", "Add position");
6.61 - AddMenuItem(g_hSpawnMenu, "preinsert", "Insert position here");
6.62 - AddMenuItem(g_hSpawnMenu, "delete", "Delete nearest");
6.63 - AddMenuItem(g_hSpawnMenu, "clear", "Delete all");
6.64 -}
6.65 -
6.66 -public OnClientPutInServer(client)
6.67 -{
6.68 - g_LastLocation[client] = -1;
6.69 -}
6.70 -
6.71 -/* :TODO: we need this in core */
6.72 -Float:GetDistance(const Float:vec1[3], const Float:vec2[3])
6.73 -{
6.74 - decl Float:x, Float:y, Float:z;
6.75 -
6.76 - x = vec1[0] - vec2[0];
6.77 - y = vec1[1] - vec2[1];
6.78 - z = vec1[2] - vec2[2];
6.79 -
6.80 - return SquareRoot(x*x + y*y + z*z);
6.81 -}
6.82 -
6.83 -GetNearestSpawn(client)
6.84 -{
6.85 - if (!g_SpawnCount)
6.86 - {
6.87 - return -1;
6.88 - }
6.89 -
6.90 - new Float:clorigin[3];
6.91 - GetClientAbsOrigin(client, clorigin);
6.92 -
6.93 - new Float:low_diff = GetDistance(g_SpawnOrigins[0], clorigin);
6.94 - new low_index = 0;
6.95 - for (new i=1; i<g_SpawnCount; i++)
6.96 - {
6.97 - new Float:diff = GetDistance(g_SpawnOrigins[i], clorigin);
6.98 - if (diff < low_diff)
6.99 - {
6.100 - low_diff = diff;
6.101 - low_index = i;
6.102 - }
6.103 - }
6.104 -
6.105 - return low_index;
6.106 -}
6.107 -
6.108 -bool:LoadMapConfig()
6.109 -{
6.110 - new String:map[64];
6.111 - GetCurrentMap(map, sizeof(map));
6.112 -
6.113 - new String:path[255];
6.114 - Format(path, sizeof(path), "cfg/cssdm/spawns/%s.txt", map);
6.115 -
6.116 - g_SpawnCount = 0;
6.117 -
6.118 - new Handle:file = OpenFile(path, "rt");
6.119 - if (file == INVALID_HANDLE)
6.120 - {
6.121 - LogError("Could not find spawn point file \"%s\"", path);
6.122 - LogError("Defaulting to map-based spawns!");
6.123 - return false;
6.124 - }
6.125 -
6.126 - new String:buffer[255];
6.127 - new String:parts[6][16];
6.128 - new partCount;
6.129 - while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
6.130 - {
6.131 - TrimString(buffer);
6.132 - partCount = ExplodeString(buffer, " ", parts, 6, 16);
6.133 - if (partCount < 6)
6.134 - {
6.135 - continue;
6.136 - }
6.137 - g_SpawnOrigins[g_SpawnCount][0] = StringToFloat(parts[0]);
6.138 - g_SpawnOrigins[g_SpawnCount][1] = StringToFloat(parts[1]);
6.139 - g_SpawnOrigins[g_SpawnCount][2] = StringToFloat(parts[2]);
6.140 - g_SpawnAngles[g_SpawnCount][0] = StringToFloat(parts[3]);
6.141 - g_SpawnAngles[g_SpawnCount][1] = StringToFloat(parts[4]);
6.142 - g_SpawnAngles[g_SpawnCount][2] = StringToFloat(parts[5]);
6.143 - g_SpawnCount++;
6.144 - }
6.145 -
6.146 - CloseHandle(file);
6.147 -
6.148 - LogMessage("Preset spawn points loaded (number %d) (map %s)", g_SpawnCount, map);
6.149 -
6.150 - return true;
6.151 -}
6.152 -
6.153 -bool:WriteMapConfig()
6.154 -{
6.155 - new String:map[64];
6.156 - GetCurrentMap(map, sizeof(map));
6.157 -
6.158 - new String:path[255];
6.159 - Format(path, sizeof(path), "cfg/cssdm/spawns/%s.txt", map);
6.160 -
6.161 - new Handle:file = OpenFile(path, "wt");
6.162 - if (file == INVALID_HANDLE)
6.163 - {
6.164 - LogError("Could not open spawn point file \"%s\" for writing.", path);
6.165 - return false;
6.166 - }
6.167 -
6.168 - for (new i=0; i<g_SpawnCount; i++)
6.169 - {
6.170 - WriteFileLine(file, "%f %f %f %f %f %f",
6.171 - g_SpawnOrigins[i][0],
6.172 - g_SpawnOrigins[i][1],
6.173 - g_SpawnOrigins[i][2],
6.174 - g_SpawnAngles[i][0],
6.175 - g_SpawnAngles[i][1],
6.176 - g_SpawnAngles[i][2]);
6.177 - }
6.178 -
6.179 - CloseHandle(file);
6.180 -
6.181 - return true;
6.182 -}
6.183 -
6.184 -AddSpawnFromClient(client)
6.185 -{
6.186 - if (g_SpawnCount >= MAX_SPAWNS)
6.187 - {
6.188 - return -1;
6.189 - }
6.190 -
6.191 - GetClientAbsOrigin(client, g_SpawnOrigins[g_SpawnCount]);
6.192 - GetClientAbsAngles(client, g_SpawnAngles[g_SpawnCount]);
6.193 -
6.194 - new old = g_SpawnCount++;
6.195 -
6.196 - return old;
6.197 -}
6.198 -
6.199 -InsertSpawnFromClient(client, bool:pre, index)
6.200 -{
6.201 - if (index == g_SpawnCount - 1 && !pre)
6.202 - {
6.203 - return AddSpawnFromClient(client);
6.204 - }
6.205 -
6.206 - if (g_SpawnCount >= MAX_SPAWNS)
6.207 - {
6.208 - return -1;
6.209 - }
6.210 -
6.211 - /* If this is a post-insertion, unmark the index for moving */
6.212 - if (!pre)
6.213 - {
6.214 - index++;
6.215 - }
6.216 -
6.217 - /* Move all of the slots down */
6.218 - for (new i=g_SpawnCount-1; i>=index; i--)
6.219 - {
6.220 - g_SpawnOrigins[i+1] = g_SpawnOrigins[i];
6.221 - g_SpawnAngles[i+1] = g_SpawnAngles[i];
6.222 - }
6.223 -
6.224 - GetClientAbsOrigin(client, g_SpawnOrigins[index]);
6.225 - GetClientAbsAngles(client, g_SpawnAngles[index]);
6.226 -
6.227 - g_SpawnCount++;
6.228 -
6.229 - return index;
6.230 -}
6.231 -
6.232 -bool:DeleteSpawn(index)
6.233 -{
6.234 - if (index < 0 || index >= g_SpawnCount)
6.235 - {
6.236 - return false;
6.237 - }
6.238 -
6.239 - for (new i=index; i<g_SpawnCount-1; i++)
6.240 - {
6.241 - g_SpawnAngles[i] = g_SpawnAngles[i+1];
6.242 - g_SpawnOrigins[i] = g_SpawnOrigins[i+1];
6.243 - }
6.244 -
6.245 - g_SpawnCount--;
6.246 -
6.247 - return true;
6.248 -}
6.249 -
6.250 -public Action:Command_SpawnMenu(client, args)
6.251 -{
6.252 - if (client == 0)
6.253 - {
6.254 - ReplyToCommand(client, "[CSSDM] This command is not available from the server console.");
6.255 - return Plugin_Handled;
6.256 - }
6.257 -
6.258 - DisplayMenu(g_hSpawnMenu, client, MENU_TIME_FOREVER);
6.259 -
6.260 - return Plugin_Handled;
6.261 -}
6.262 -
6.263 -public Panel_VerifyDeleteSpawns(Handle:menu, MenuAction:action, param1, param2)
6.264 -{
6.265 - if (action == MenuAction_Select)
6.266 - {
6.267 - if (param2 == 1)
6.268 - {
6.269 - g_SpawnCount = 0;
6.270 - if (!WriteMapConfig())
6.271 - {
6.272 - PrintToChat(param1, "[CSSDM] Could not write to spawn config file.");
6.273 - } else {
6.274 - PrintToChat(param1, "[CSSDM] All spawn points have been deleted.");
6.275 - }
6.276 - }
6.277 - DisplayMenu(g_hSpawnMenu, param1, MENU_TIME_FOREVER);
6.278 - }
6.279 -}
6.280 -
6.281 -public Menu_EditSpawns(Handle:menu, MenuAction:action, param1, param2)
6.282 -{
6.283 - if (action == MenuAction_Select)
6.284 - {
6.285 - if (param2 == 0)
6.286 - {
6.287 - new index = GetNearestSpawn(param1);
6.288 - if (index == -1)
6.289 - {
6.290 - PrintToChat(param1, "[CSSDM] There are no spawn points.");
6.291 - } else {
6.292 - TeleportEntity(param1, g_SpawnOrigins[index], g_SpawnAngles[index], NULL_VECTOR);
6.293 - PrintToChat(param1, "[CSSDM] Teleported to spawn #%d (%d total).", index, g_SpawnCount);
6.294 - g_LastLocation[param1] = index;
6.295 - }
6.296 - } else if (param2 == 2) {
6.297 - if (g_SpawnCount == 0)
6.298 - {
6.299 - PrintToChat(param1, "[CSSDM] There are no spawn points.");
6.300 - } else {
6.301 - new index = g_LastLocation[param1] + 1;
6.302 - if (index >= g_SpawnCount)
6.303 - {
6.304 - index = 0;
6.305 - }
6.306 - TeleportEntity(param1, g_SpawnOrigins[index], g_SpawnAngles[index], NULL_VECTOR);
6.307 - PrintToChat(param1, "[CSSDM] Teleported to spawn #%d (%d total).", index, g_SpawnCount);
6.308 - g_LastLocation[param1] = index;
6.309 - }
6.310 - } else if (param2 == 1) {
6.311 - if (g_SpawnCount == 0)
6.312 - {
6.313 - PrintToChat(param1, "[CSSDM] There are no spawn points.");
6.314 - } else {
6.315 - new index = g_LastLocation[param1] - 1;
6.316 - if (index < 0)
6.317 - {
6.318 - index = g_SpawnCount - 1;
6.319 - }
6.320 - TeleportEntity(param1, g_SpawnOrigins[index], g_SpawnAngles[index], NULL_VECTOR);
6.321 - PrintToChat(param1, "[CSSDM] Teleported to spawn #%d (%d total).", index, g_SpawnCount);
6.322 - g_LastLocation[param1] = index;
6.323 - }
6.324 - } else if (param2 == 5) {
6.325 - new index = GetNearestSpawn(param1);
6.326 - if (index == -1)
6.327 - {
6.328 - PrintToChat(param1, "[CSSDM] There are no spawn points.");
6.329 - } else {
6.330 - if (!DeleteSpawn(index))
6.331 - {
6.332 - PrintToChat(param1, "[CSSDM] Could not delete spawn #%d.", index);
6.333 - } else {
6.334 - if (!WriteMapConfig())
6.335 - {
6.336 - PrintToChat(param1, "[CSSDM] Could not write to spawn config file!");
6.337 - } else {
6.338 - PrintToChat(param1, "[CSSDM] Deleted spawn #%d (%d total).", index, g_SpawnCount);
6.339 - }
6.340 - }
6.341 - }
6.342 - } else if (param2 == 3) {
6.343 - new index;
6.344 - if ((index = AddSpawnFromClient(param1)) == -1)
6.345 - {
6.346 - PrintToChat(param1, "[CSSDM] Could not add spawn (max limit reached).");
6.347 - } else {
6.348 - if (!WriteMapConfig())
6.349 - {
6.350 - PrintToChat(param1, "[CSSDM] Could not write to spawn config file!");
6.351 - } else {
6.352 - PrintToChat(param1, "[CSSDM] Added spawn #%d (%d total).", index, g_SpawnCount);
6.353 - }
6.354 - }
6.355 - } else if (param2 == 4) {
6.356 - new index = g_LastLocation[param1];
6.357 - new bool:pre = true;
6.358 - if (index == -1 || index >= g_SpawnCount)
6.359 - {
6.360 - index = g_SpawnCount - 1;
6.361 - pre = false;
6.362 - }
6.363 - if ((index = InsertSpawnFromClient(param1, pre, index)) == -1)
6.364 - {
6.365 - PrintToChat(param1, "[CSSDM] Could not add spawn (max limit reached).");
6.366 - } else {
6.367 - if (!WriteMapConfig())
6.368 - {
6.369 - PrintToChat(param1, "[CSSDM] Could not write to spawn config file!");
6.370 - } else {
6.371 - PrintToChat(param1, "[CSSDM] Inserted spawn at #%d (%d total).", index, g_SpawnCount);
6.372 - }
6.373 - }
6.374 - } else if (param2 == 6) {
6.375 - /* Of course, we ask the user first. */
6.376 - new Handle:panel = CreatePanel();
6.377 - SetPanelTitle(panel, "Delete all spawn points?");
6.378 - DrawPanelItem(panel, "Yes");
6.379 - DrawPanelItem(panel, "No");
6.380 - SendPanelToClient(panel, param1, Panel_VerifyDeleteSpawns, MENU_TIME_FOREVER);
6.381 - CloseHandle(panel);
6.382 - return;
6.383 - }
6.384 - /* Redraw the menu */
6.385 - DisplayMenu(g_hSpawnMenu, param1, MENU_TIME_FOREVER);
6.386 - }
6.387 -}
6.388 -
6.389 -public DM_OnStartup()
6.390 -{
6.391 - new String:method[32];
6.392 - DM_GetSpawnMethod(method, sizeof(method));
6.393 -
6.394 - if (strcmp(method, "preset") != 0)
6.395 - {
6.396 - return;
6.397 - }
6.398 -
6.399 - g_AreWeSpawning = LoadMapConfig();
6.400 -}
6.401 -
6.402 -public Action:DM_OnSetSpawnMethod(const String:method[])
6.403 -{
6.404 - g_AreWeSpawning = (strcmp(method, "preset") == 0);
6.405 -
6.406 - if (!g_AreWeSpawning)
6.407 - {
6.408 - return Plugin_Continue;
6.409 - }
6.410 -
6.411 - if (!LoadMapConfig())
6.412 - {
6.413 - g_AreWeSpawning = false;
6.414 - return Plugin_Continue;
6.415 - }
6.416 -
6.417 - return Plugin_Stop;
6.418 -}
6.419 -
6.420 -public DM_OnClientSpawned(client)
6.421 -{
6.422 - if (!g_AreWeSpawning || !g_SpawnCount)
6.423 - {
6.424 - return;
6.425 - }
6.426 -
6.427 - new maxClients = GetMaxClients();
6.428 - new startPoint = GetRandomInt(0, g_SpawnCount-1);
6.429 -
6.430 - /* Prefetch player origins */
6.431 - decl Float:origins[65][3];
6.432 - new numToCheck = 0;
6.433 -
6.434 - for (new i=1; i<=maxClients; i++)
6.435 - {
6.436 - if (i == client || !IsClientInGame(i))
6.437 - {
6.438 - continue;
6.439 - }
6.440 - GetClientAbsOrigin(i, origins[numToCheck]);
6.441 - numToCheck++;
6.442 - }
6.443 -
6.444 - /* Cycle through until we get a spawn point */
6.445 - new bool:use_this_point;
6.446 - new checked = 0;
6.447 - while (checked < g_SpawnCount)
6.448 - {
6.449 - if (startPoint >= g_SpawnCount)
6.450 - {
6.451 - startPoint = 0;
6.452 - }
6.453 -
6.454 - use_this_point = true;
6.455 - for (new i=0; i<numToCheck; i++)
6.456 - {
6.457 - if (GetDistance(g_SpawnOrigins[startPoint], origins[i]) < 600.0)
6.458 - {
6.459 - use_this_point = false;
6.460 - break;
6.461 - }
6.462 - }
6.463 -
6.464 - if (use_this_point)
6.465 - {
6.466 - break;
6.467 - }
6.468 -
6.469 - checked++;
6.470 - startPoint++;
6.471 - }
6.472 -
6.473 - if (startPoint >= g_SpawnCount)
6.474 - {
6.475 - startPoint = 0;
6.476 - }
6.477 -
6.478 - TeleportEntity(client, g_SpawnOrigins[startPoint], g_SpawnAngles[startPoint], NULL_VECTOR);
6.479 -}
7.1 --- a/scripting/spawnprotection.sp Sun Jun 24 21:58:09 2007 +0000
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,150 +0,0 @@
7.4 -/**
7.5 - * spawnprotection.sp
7.6 - * Adds spawn protection to CS:S DM.
7.7 - * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
7.8 - *
7.9 - * This program is free software; you can redistribute it and/or
7.10 - * modify it under the terms of the GNU General Public License
7.11 - * as published by the Free Software Foundation; either version 2
7.12 - * of the License, or (at your option) any later version.
7.13 - *
7.14 - * This program is distributed in the hope that it will be useful,
7.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 - * GNU General Public License for more details.
7.18 - *
7.19 - * You should have received a copy of the GNU General Public License
7.20 - * along with this program; if not, write to the Free Software
7.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
7.22 - *
7.23 - * Version: $Id$
7.24 - */
7.25 -
7.26 -#pragma semicolon 1
7.27 -#include <sourcemod>
7.28 -#include <sdktools>
7.29 -#include <cssdm>
7.30 -
7.31 -#define K_RENDER_NORMAL 0
7.32 -#define K_RENDER_TRANS_COLOR 1
7.33 -
7.34 -/* Plugin stuff */
7.35 -new Handle:g_ProtVar;
7.36 -new Handle:g_TColorVar;
7.37 -new Handle:g_CTColorVar;
7.38 -new Handle:g_ProtTimeVar;
7.39 -new g_NormColor[4] = {255, 255, 255, 255};
7.40 -new g_TColor[4] = {255, 0, 0, 128};
7.41 -new g_CTColor[4] = {0, 0, 255, 128};
7.42 -new g_HealthOffset;
7.43 -new g_RenderModeOffset;
7.44 -new g_RenderClrOffset;
7.45 -
7.46 -/* Player stuff */
7.47 -new Handle:g_PlayerTimers[MAXPLAYERS+1];
7.48 -new g_PlayerHealth[MAXPLAYERS+1];
7.49 -
7.50 -/** PUBLIC INFO */
7.51 -public Plugin:myinfo =
7.52 -{
7.53 - name = "CS:S DM Spawn Protection",
7.54 - author = "AlliedModders LLC",
7.55 - description = "Spawn protection for CS:S DM",
7.56 - version = CSSDM_VERSION,
7.57 - url = "http://www.bailopan.net/cssdm/"
7.58 -};
7.59 -
7.60 -public OnPluginStart()
7.61 -{
7.62 - g_ProtVar = CreateConVar("cssdm_spawn_protection", "1", "Sets whether spawn protection is enabled");
7.63 - g_CTColorVar = CreateConVar("cssdm_prot_ctcolor", "0 0 255 128", "Sets the spawn color of CTs");
7.64 - g_TColorVar = CreateConVar("cssdm_prot_tcolor", "255 0 0 128", "Sets the spawn color of Ts");
7.65 - g_ProtTimeVar = CreateConVar("cssdm_prot_time", "2", "Sets time in seconds players are protected for");
7.66 -
7.67 - HookConVarChange(g_CTColorVar, OnColorChange);
7.68 - HookConVarChange(g_TColorVar, OnColorChange);
7.69 -
7.70 - g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
7.71 - g_RenderModeOffset = FindSendPropOffs("CCSPlayer", "m_nRenderMode");
7.72 - g_RenderClrOffset = FindSendPropOffs("CCSPlayer", "m_clrRender");
7.73 -}
7.74 -
7.75 -public OnColorChange(Handle:convar, const String:oldValue[], const String:newValue[])
7.76 -{
7.77 - decl String:colors[4][12];
7.78 - decl clr[4];
7.79 - new num_strings = ExplodeString(newValue, " ", colors, 4, 12);
7.80 -
7.81 - for (new i=0; i<num_strings; i++)
7.82 - {
7.83 - clr[i] = StringToInt(colors[i]);
7.84 - }
7.85 -
7.86 - if (convar == g_CTColorVar)
7.87 - {
7.88 - g_CTColor = clr;
7.89 - } else if (convar == g_TColorVar) {
7.90 - g_TColor = clr;
7.91 - }
7.92 -}
7.93 -
7.94 -public OnClientDisconnect(client)
7.95 -{
7.96 - if (g_PlayerTimers[client] != INVALID_HANDLE)
7.97 - {
7.98 - CloseHandle(g_PlayerTimers[client]);
7.99 - g_PlayerTimers[client] = INVALID_HANDLE;
7.100 - }
7.101 -}
7.102 -
7.103 -public Action:DM_OnClientDeath(client)
7.104 -{
7.105 - if (g_PlayerTimers[client] != INVALID_HANDLE)
7.106 - {
7.107 - CloseHandle(g_PlayerTimers[client]);
7.108 - g_PlayerTimers[client] = INVALID_HANDLE;
7.109 - }
7.110 -
7.111 - return Plugin_Continue;
7.112 -}
7.113 -
7.114 -public Action:StopProtection(Handle:timer, any:client)
7.115 -{
7.116 - g_PlayerTimers[client] = INVALID_HANDLE;
7.117 -
7.118 - SetEntData(client, g_HealthOffset, g_PlayerHealth[client]);
7.119 - UTIL_Render(client, g_NormColor);
7.120 -
7.121 - return Plugin_Stop;
7.122 -}
7.123 -
7.124 -public DM_OnClientPostSpawned(client)
7.125 -{
7.126 - if (!GetConVarInt(g_ProtVar) || !IsClientInGame(client))
7.127 - {
7.128 - return;
7.129 - }
7.130 -
7.131 - g_PlayerTimers[client] = CreateTimer(GetConVarFloat(g_ProtTimeVar), StopProtection, client);
7.132 -
7.133 - /* Start protection */
7.134 - g_PlayerHealth[client] = GetEntData(client, g_HealthOffset);
7.135 - SetEntData(client, g_HealthOffset, 1012); /* This overflows to show "500" */
7.136 -
7.137 - new team = GetClientTeam(client);
7.138 - if (team == CSSDM_TEAM_T)
7.139 - {
7.140 - UTIL_Render(client, g_TColor);
7.141 - } else if (team == CSSDM_TEAM_CT) {
7.142 - UTIL_Render(client, g_CTColor);
7.143 - }
7.144 -}
7.145 -
7.146 -UTIL_Render(client, const color[4])
7.147 -{
7.148 - new mode = (color[3] == 255) ? K_RENDER_NORMAL : K_RENDER_TRANS_COLOR;
7.149 -
7.150 - SetEntData(client, g_RenderModeOffset, mode, 1);
7.151 - SetEntDataArray(client, g_RenderClrOffset, color, 4, 1);
7.152 - ChangeEdictState(client);
7.153 -}