2009-04-06 03:20:13 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-06 03:20:13 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: clientoverlays.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Handles overlays on clients, as a part of class attributes.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-06 03:20:13 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-05-14 02:28:26 +02:00
|
|
|
* @section Suicide intercept defines.
|
2009-04-06 03:20:13 +02:00
|
|
|
*/
|
2009-05-14 02:28:26 +02:00
|
|
|
#define CLASSOVERLAY_TOGGLE_MAX_CMDS 5
|
|
|
|
#define CLASSOVERLAY_TOGGLE_MAX_LENGTH 16
|
2009-04-06 03:20:13 +02:00
|
|
|
/**
|
2009-05-14 02:28:26 +02:00
|
|
|
* @endsection
|
2009-04-06 03:20:13 +02:00
|
|
|
*/
|
2009-06-21 21:24:24 +02:00
|
|
|
|
2009-04-06 03:20:13 +02:00
|
|
|
/**
|
2009-06-21 21:24:24 +02:00
|
|
|
* Name of the cookie for toggle state the class overlay.
|
2009-04-06 03:20:13 +02:00
|
|
|
*/
|
2009-06-21 21:24:24 +02:00
|
|
|
#define CLASSOVERLAY_COOKIE_ENABLED "zr_overlay"
|
2009-04-06 03:20:13 +02:00
|
|
|
|
|
|
|
/**
|
2009-06-21 21:24:24 +02:00
|
|
|
* Cookie handle for the toggle state of an overlay.
|
2009-04-06 03:20:13 +02:00
|
|
|
*/
|
2009-06-21 21:24:24 +02:00
|
|
|
new Handle:g_hOverlayEnabledCookie = INVALID_HANDLE;
|
2009-04-25 14:19:14 +02:00
|
|
|
|
|
|
|
/**
|
2009-05-14 02:28:26 +02:00
|
|
|
* Hook commands related to overlay here.
|
2009-04-25 14:19:14 +02:00
|
|
|
*/
|
2009-05-14 02:28:26 +02:00
|
|
|
ClassOverlayOnCommandsHook()
|
2009-04-06 03:20:13 +02:00
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
// Create command callbacks (intercepts) for listed suicide commands.
|
|
|
|
decl String:togglecmds[CLASSOVERLAY_TOGGLE_MAX_CMDS * CLASSOVERLAY_TOGGLE_MAX_LENGTH];
|
|
|
|
GetConVarString(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLECMDS], togglecmds, sizeof(togglecmds));
|
|
|
|
|
|
|
|
// Create array to store cmds
|
|
|
|
new String:arrayCmds[CLASSOVERLAY_TOGGLE_MAX_CMDS][CLASSOVERLAY_TOGGLE_MAX_LENGTH];
|
|
|
|
|
|
|
|
// Explode string into array indexes.
|
2009-07-24 00:05:14 +02:00
|
|
|
new cmdcount = ExplodeString(togglecmds, ",", arrayCmds, sizeof(arrayCmds), sizeof(arrayCmds[]));
|
2009-05-14 02:28:26 +02:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// x = Array index.
|
2009-05-14 02:28:26 +02:00
|
|
|
// arrayCmds[x] = suicide command.
|
|
|
|
for (new x = 0; x <= cmdcount - 1; x++)
|
|
|
|
{
|
2009-07-24 00:05:14 +02:00
|
|
|
// Trim whitespace.
|
|
|
|
TrimString(arrayCmds[x]);
|
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
// Prepare intercept for this command.
|
|
|
|
RegConsoleCmd(arrayCmds[x], ClassOverlayEnableCommand);
|
|
|
|
}
|
2009-04-06 03:20:13 +02:00
|
|
|
}
|
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
/**
|
|
|
|
* Create class overlay-related cookies here.
|
|
|
|
*/
|
|
|
|
ClassOverlayOnCookiesCreate()
|
|
|
|
{
|
2009-10-10 18:26:27 +02:00
|
|
|
// Create cookie handle only if it don't exist.
|
|
|
|
if (g_hOverlayEnabledCookie == INVALID_HANDLE)
|
2009-10-08 19:47:23 +02:00
|
|
|
{
|
2009-10-10 18:26:27 +02:00
|
|
|
g_hOverlayEnabledCookie = RegClientCookie(CLASSOVERLAY_COOKIE_ENABLED, "The toggle state of the class overlay.", CookieAccess_Protected);
|
2009-10-08 19:47:23 +02:00
|
|
|
}
|
2009-06-21 21:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is joining the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ClassOverlayClientInit(client)
|
|
|
|
{
|
|
|
|
// Get overlay toggle cvar values.
|
|
|
|
new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]);
|
|
|
|
new bool:overlaydefault = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_DEFAULT]);
|
|
|
|
|
|
|
|
// Get ZHP enabled cookie value.
|
|
|
|
decl String:overlayenabled[8];
|
|
|
|
GetClientCookie(client, g_hOverlayEnabledCookie, overlayenabled, sizeof(overlayenabled));
|
|
|
|
|
|
|
|
// If the cookie is empty, then set the default value.
|
|
|
|
if (!overlayenabled[0])
|
|
|
|
{
|
|
|
|
// Set cookie to default value from cvar.
|
|
|
|
new bool:overlayvalue = overlaytoggle ? overlaydefault : true;
|
|
|
|
CookiesSetClientCookieBool(client, g_hOverlayEnabledCookie, overlayvalue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-21 07:13:51 +02:00
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ClassOverlayOnClientDeath(client)
|
|
|
|
{
|
|
|
|
// Disable overlay.
|
|
|
|
OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, false, false, true);
|
2009-04-25 14:19:14 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
ClassOverlayInitialize(client, const String:overlay[])
|
2009-04-06 03:20:13 +02:00
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
if (IsFakeClient(client))
|
2009-04-06 03:20:13 +02:00
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
return;
|
2009-04-06 03:20:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
// If overlay path is empty, then disable channel, then stop.
|
|
|
|
if (!overlay[0])
|
2009-04-06 03:20:13 +02:00
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, false, false, true);
|
|
|
|
return;
|
2009-04-06 03:20:13 +02:00
|
|
|
}
|
|
|
|
|
2009-06-21 23:59:18 +02:00
|
|
|
// If overlay toggle is enabled and class has an overlay, then send center text.
|
|
|
|
new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]);
|
|
|
|
|
|
|
|
decl String:overlaypath[PLATFORM_MAX_PATH];
|
|
|
|
ClassGetOverlayPath(client, overlaypath, sizeof(overlaypath));
|
|
|
|
|
|
|
|
if (overlaytoggle && overlaypath[0])
|
|
|
|
{
|
|
|
|
decl String:togglecmds[CLASSOVERLAY_TOGGLE_MAX_CMDS * CLASSOVERLAY_TOGGLE_MAX_LENGTH];
|
|
|
|
GetConVarString(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLECMDS], togglecmds, sizeof(togglecmds));
|
|
|
|
|
2009-07-08 00:53:18 +02:00
|
|
|
TranslationPrintHintText(client, "Classes overlay toggle", togglecmds);
|
2009-06-21 23:59:18 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
// Display class overlays.
|
|
|
|
OverlaysClientSetChannelPath(client, OVERLAYS_CHANNEL_CLASSES, overlay);
|
2009-06-21 21:24:24 +02:00
|
|
|
OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, false, CookiesGetClientCookieBool(client, g_hOverlayEnabledCookie));
|
2009-04-06 03:20:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
/**
|
2009-05-21 07:13:51 +02:00
|
|
|
* Command callback. (See zr_classes_overlay_togglecmds)
|
2009-05-14 02:28:26 +02:00
|
|
|
* Toggles nightvision of a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param argc Argument count.
|
|
|
|
*/
|
|
|
|
public Action:ClassOverlayEnableCommand(client, argc)
|
2009-04-06 03:20:13 +02:00
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
// If overlay toggle is disabled, then stop.
|
|
|
|
new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]);
|
|
|
|
if (!overlaytoggle)
|
2009-04-06 03:20:13 +02:00
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
return;
|
2009-04-06 03:20:13 +02:00
|
|
|
}
|
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
// Toggle current overlay channel, retrieve new value, and update cookie.
|
|
|
|
new bool:overlayenabled = OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, true);
|
|
|
|
CookiesSetClientCookieBool(client, g_hOverlayEnabledCookie, overlayenabled);
|
2009-04-06 03:20:13 +02:00
|
|
|
}
|