sm-plugins/Hitmarker/scripting/Hitmarker.sp

377 lines
13 KiB
SourcePawn
Raw Normal View History

2019-09-01 17:22:03 +02:00
#include <sourcemod>
#include <sdktools>
#include <BossHP>
#include <zombiereloaded>
#include <clientprefs>
#include <multicolors>
#define SPECMODE_NONE 0
#define SPECMODE_FIRSTPERSON 4
#define SPECMODE_THIRDPERSON 5
#define SPECMODE_FREELOOK 6
#pragma newdecls required
#pragma semicolon 1
bool g_bShowBossHitmarker[MAXPLAYERS+1];
bool g_bShowZombieHitmarker[MAXPLAYERS+1];
2019-09-07 14:17:16 +02:00
bool g_bHitmarkerSound[MAXPLAYERS+1];
2019-09-01 17:22:03 +02:00
Handle g_hTimer[MAXPLAYERS+1] = {null,...};
Handle g_hCookie_ShowBossHitmarker;
Handle g_hCookie_ShowZombieHitmarker;
2019-09-07 14:17:16 +02:00
Handle g_hCookie_HitmarkerSound;
//Handle g_hHudText;
2019-09-01 17:22:03 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "Htimarker",
author = "Neon & Nano",
description = "Players can enable or disable their hitmarkers while shooting zombies or bosses",
version = "1.0.0",
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
g_hCookie_ShowBossHitmarker = RegClientCookie("hitmarker_boss", "", CookieAccess_Private);
g_hCookie_ShowZombieHitmarker = RegClientCookie("hitmarker_zombie", "", CookieAccess_Private);
2019-09-07 14:17:16 +02:00
g_hCookie_HitmarkerSound = RegClientCookie("hitmarker_sound", "", CookieAccess_Private);
//g_hHudText = CreateHudSynchronizer();
2019-09-01 17:22:03 +02:00
2019-09-07 14:17:16 +02:00
RegConsoleCmd("sm_hm", OnHitmarkerSettings);
RegConsoleCmd("sm_hitmarker", OnHitmarkerSettings);
2019-09-01 17:22:03 +02:00
RegConsoleCmd("sm_bhm", OnToggleBossHitmarker);
RegConsoleCmd("sm_zhm", OnToggleZombieHitmarker);
2019-09-07 14:17:16 +02:00
RegConsoleCmd("sm_hmsound", OnToggleHitmarkerSound);
2019-09-01 17:22:03 +02:00
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hitmarker");
HookEvent("player_hurt", OnClientHurt);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
PrecacheGeneric("overlays/nano/hitmarker.vtf", true);
PrecacheGeneric("overlays/nano/hitmarker.vmt", true);
AddFileToDownloadsTable("materials/overlays/nano/hitmarker.vtf");
AddFileToDownloadsTable("materials/overlays/nano/hitmarker.vmt");
2019-09-07 14:17:16 +02:00
PrecacheSound("unloze/hm.mp3");
AddFileToDownloadsTable("sound/unloze/hm.mp3");
2019-09-01 17:22:03 +02:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientCookiesCached(int client)
{
char sBuffer[4];
GetClientCookie(client, g_hCookie_ShowBossHitmarker, sBuffer, sizeof(sBuffer));
if (sBuffer[0])
g_bShowBossHitmarker[client] = true;
else
g_bShowBossHitmarker[client] = false;
GetClientCookie(client, g_hCookie_ShowZombieHitmarker, sBuffer, sizeof(sBuffer));
if (sBuffer[0])
g_bShowZombieHitmarker[client] = true;
else
g_bShowZombieHitmarker[client] = false;
2019-09-07 14:17:16 +02:00
GetClientCookie(client, g_hCookie_HitmarkerSound, sBuffer, sizeof(sBuffer));
if (sBuffer[0])
g_bHitmarkerSound[client] = true;
else
g_bHitmarkerSound[client] = false;
2019-09-01 17:22:03 +02:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client)
{
g_bShowBossHitmarker[client] = false;
g_bShowZombieHitmarker[client] = false;
2019-09-07 14:17:16 +02:00
g_bHitmarkerSound[client] = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnHitmarkerSettings(int client, int args)
{
ShowSettingsMenu(client);
return Plugin_Handled;
2019-09-01 17:22:03 +02:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnToggleBossHitmarker(int client, int args)
{
ToggleBossHitmarker(client);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ToggleBossHitmarker(int client)
{
g_bShowBossHitmarker[client] = !g_bShowBossHitmarker[client];
SetClientCookie(client, g_hCookie_ShowBossHitmarker, g_bShowBossHitmarker[client] ? "1" : "");
CPrintToChat(client, "{cyan}[Hitmarker] {white}%s", g_bShowBossHitmarker[client] ? "Boss Hitmarker Enabled" : "Boss Hitmarker Disabled");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnToggleZombieHitmarker(int client, int args)
{
ToggleZombieHitmarker(client);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ToggleZombieHitmarker(int client)
{
g_bShowZombieHitmarker[client] = !g_bShowZombieHitmarker[client];
SetClientCookie(client, g_hCookie_ShowZombieHitmarker, g_bShowZombieHitmarker[client] ? "1" : "");
CPrintToChat(client, "{cyan}[Hitmarker] {white}%s", g_bShowZombieHitmarker[client] ? "Zombie Hitmarker Enabled" : "Zombie Hitmarker Disabled");
}
2019-09-07 14:17:16 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnToggleHitmarkerSound(int client, int args)
{
ToggleHitmarkerSound(client);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ToggleHitmarkerSound(int client)
{
g_bHitmarkerSound[client] = !g_bHitmarkerSound[client];
SetClientCookie(client, g_hCookie_HitmarkerSound, g_bHitmarkerSound[client] ? "1" : "");
CPrintToChat(client, "{cyan}[Hitmarker] {white}%s", g_bHitmarkerSound[client] ? "Hitmarker Sound Enabled" : "Hitmarker Sound Disabled");
}
2019-09-01 17:22:03 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu(int client)
{
Menu menu = new Menu(MenuHandler_MainMenu);
menu.SetTitle("Hitmarker Settings", client);
char sBuffer[128];
Format(sBuffer, sizeof(sBuffer), "Boss Hitmarker: %s", g_bShowBossHitmarker[client] ? "Enabled" : "Disabled");
menu.AddItem("0", sBuffer);
Format(sBuffer, sizeof(sBuffer), "Zombie Hitmarker: %s", g_bShowZombieHitmarker[client] ? "Enabled" : "Disabled");
menu.AddItem("1", sBuffer);
2019-09-07 14:17:16 +02:00
Format(sBuffer, sizeof(sBuffer), "Hitmarker Sound: %s", g_bHitmarkerSound[client] ? "Enabled" : "Disabled");
menu.AddItem("2", sBuffer);
2019-09-01 17:22:03 +02:00
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
{
switch(action)
{
case(CookieMenuAction_DisplayOption):
{
Format(buffer, maxlen, "Hitmarker", client);
}
case(CookieMenuAction_SelectOption):
{
ShowSettingsMenu(client);
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case(MenuAction_Select):
{
switch(selection)
{
case(0): ToggleBossHitmarker(client);
case(1): ToggleZombieHitmarker(client);
2019-09-07 14:17:16 +02:00
case(2): ToggleHitmarkerSound(client);
2019-09-01 17:22:03 +02:00
}
ShowSettingsMenu(client);
}
case(MenuAction_Cancel):
{
ShowCookieMenu(client);
}
case(MenuAction_End):
{
delete menu;
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnBossDamaged(any Boss, any Config, int client, float damage)
{
if (!IsValidClient(client))
return;
if (g_bShowBossHitmarker[client])
2019-09-07 14:17:16 +02:00
{
//SetHudTextParams(-1.0, -1.0, 0.3, 255, 0, 0, 255, 0, 0.0, 0.0, 0.0);
//ShowSyncHudText(client, g_hHudText, "∷");
2019-09-01 17:22:03 +02:00
ShowOverlay(client);
2019-09-07 14:17:16 +02:00
}
2019-09-01 17:22:03 +02:00
for (int spec = 1; spec <= MaxClients; spec++)
{
if (!IsClientInGame(spec) || !IsClientObserver(spec) || !g_bShowBossHitmarker[spec])
continue;
int specMode = GetClientSpectatorMode(spec);
int specTarget = GetClientSpectatorTarget(spec);
if ((specMode == SPECMODE_FIRSTPERSON) && specTarget == client)
2019-09-07 14:17:16 +02:00
{
//SetHudTextParams(-1.0, -1.0, 0.3, 255, 0, 0, 255, 0, 0.0, 0.0, 0.0);
//ShowSyncHudText(spec, g_hHudText, "∷");
2019-09-01 17:22:03 +02:00
ShowOverlay(spec);
2019-09-07 14:17:16 +02:00
}
2019-09-01 17:22:03 +02:00
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
int client = GetClientOfUserId(hEvent.GetInt("attacker"));
int victim = GetClientOfUserId(hEvent.GetInt("userid"));
if (client < 1 || client > MaxClients || victim < 1 || victim > MaxClients)
return;
if (client == victim || (IsPlayerAlive(client) && ZR_IsClientZombie(client)))
return;
if (g_bShowZombieHitmarker[client])
2019-09-07 14:17:16 +02:00
{
//SetHudTextParams(-1.0, -1.0, 0.3, 255, 0, 0, 255, 0, 0.0, 0.0, 0.0);
//ShowSyncHudText(client, g_hHudText, "∷");
2019-09-01 17:22:03 +02:00
ShowOverlay(client);
2019-09-07 14:17:16 +02:00
}
2019-09-01 17:22:03 +02:00
for (int spec = 1; spec <= MaxClients; spec++)
{
if (!IsClientInGame(spec) || !IsClientObserver(spec) || !g_bShowZombieHitmarker[spec])
continue;
int specMode = GetClientSpectatorMode(spec);
int specTarget = GetClientSpectatorTarget(spec);
if (specMode == SPECMODE_FIRSTPERSON && specTarget == client)
2019-09-07 14:17:16 +02:00
{
//SetHudTextParams(-1.0, -1.0, 0.3, 255, 0, 0, 255, 0, 0.0, 0.0, 0.0);
//ShowSyncHudText(spec, g_hHudText, "∷");
2019-09-01 17:22:03 +02:00
ShowOverlay(spec);
2019-09-07 14:17:16 +02:00
}
2019-09-01 17:22:03 +02:00
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ShowOverlay(int client)
{
2019-09-07 14:17:16 +02:00
if (g_bHitmarkerSound[client])
EmitSoundToClient(client, "unloze/hm.mp3", .volume=1.0);
2019-09-01 17:22:03 +02:00
if (g_hTimer[client] != null)
{
delete g_hTimer[client];
g_hTimer[client] = null;
}
ClientCommand(client, "r_screenoverlay \"%s\"", "overlays/nano/hitmarker");
g_hTimer[client] = CreateTimer(0.3, ClearOverlay, client, TIMER_FLAG_NO_MAPCHANGE);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action ClearOverlay(Handle timer, int client)
{
g_hTimer[client] = null;
ClientCommand(client, "r_screenoverlay \"\"");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock int IsValidClient(int client, bool nobots = true)
{
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
return false;
return IsClientInGame(client);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
int GetClientSpectatorMode(int client)
{
return GetEntProp(client, Prop_Send, "m_iObserverMode");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
int GetClientSpectatorTarget(int client)
{
return GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
}