Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions addons/sourcemod/scripting/caster_assister.sp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@

#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <caster_system>
#define MAX_SPEED 2

bool readyUpIsAvailable;
bool casterSystemAvailable;

public Plugin myinfo =
{
name = "Caster Assister",
author = "CanadaRox, Sir, Forgetest",
description = "Allows spectators to control their own specspeed and move vertically",
version = "2.3.1",
version = "2.4.0",
url = ""
};

Expand All @@ -35,46 +33,41 @@ public void OnPluginStart()

public void OnAllPluginsLoaded()
{
readyUpIsAvailable = LibraryExists("caster_system");
casterSystemAvailable = LibraryExists("caster_system");
}

public void OnLibraryRemoved(const char[] name)
{
if (StrEqual(name, "caster_system"))
{
readyUpIsAvailable = false;
casterSystemAvailable = false;
}
}

public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "caster_system"))
{
readyUpIsAvailable = true;
}
}

public void OnClientPutInServer(int client)
{
if (readyUpIsAvailable && IsClientCaster(client))
{
FakeClientCommand(client, "sm_spechud");
casterSystemAvailable = true;
}
}

void PlayerTeam_Event(Event event, const char[] name, bool dontBroadcast)
{
int team = event.GetInt("team");
if (team == 1)
{
int client = GetClientOfUserId(event.GetInt("userid"));
SetEntPropFloat(client, Prop_Send, "m_flLaggedMovementValue", currentMulti[client]);
}
if (!casterSystemAvailable || event.GetInt("team") != 1)
return;

int client = GetClientOfUserId(event.GetInt("userid"));

if (!IsValidClient(client))
return;

SetEntPropFloat(client, Prop_Send, "m_flLaggedMovementValue", currentMulti[client]);
}

Action SetSpecspeed_Cmd(int client, int args)
{
if (!IsValidClient(client) || GetClientTeam(client) != 1)
if (!casterSystemAvailable || !IsValidClient(client) || GetClientTeam(client) != 1)
{
return Plugin_Handled;
}
Expand All @@ -96,7 +89,7 @@ Action SetSpecspeed_Cmd(int client, int args)

Action SetSpecspeedIncrement_Cmd(int client, int args)
{
if (!IsValidClient(client) || GetClientTeam(client) != 1)
if (!casterSystemAvailable || !IsValidClient(client) || GetClientTeam(client) != 1)
{
return Plugin_Handled;
}
Expand All @@ -114,7 +107,7 @@ Action SetSpecspeedIncrement_Cmd(int client, int args)

Action IncreaseSpecspeed_Cmd(int client, int args)
{
if (!IsValidClient(client) || GetClientTeam(client) != 1)
if (!casterSystemAvailable || !IsValidClient(client) || GetClientTeam(client) != 1)
{
return Plugin_Handled;
}
Expand All @@ -125,7 +118,7 @@ Action IncreaseSpecspeed_Cmd(int client, int args)

Action DecreaseSpecspeed_Cmd(int client, int args)
{
if (!IsValidClient(client) || GetClientTeam(client) != 1)
if (!casterSystemAvailable || !IsValidClient(client) || GetClientTeam(client) != 1)
{
return Plugin_Handled;
}
Expand All @@ -145,7 +138,7 @@ stock void IncreaseSpecspeed(int client, float difference)

Action SetVerticalIncrement_Cmd(int client, int args)
{
if (!IsValidClient(client) || GetClientTeam(client) != 1)
if (!casterSystemAvailable || !IsValidClient(client) || GetClientTeam(client) != 1)
{
return Plugin_Handled;
}
Expand All @@ -163,7 +156,7 @@ Action SetVerticalIncrement_Cmd(int client, int args)

public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if (IsValidClient(client) && GetClientTeam(client) == 1)
if (casterSystemAvailable && IsValidClient(client) && GetClientTeam(client) == 1)
{
if (buttons & IN_USE)
{
Expand All @@ -187,5 +180,5 @@ bool IsSpeedValid(float speed)

bool IsValidClient(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client));
return (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client));
}
70 changes: 62 additions & 8 deletions addons/sourcemod/scripting/spechud.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include <l4d_tank_control_eq>
#include <lerpmonitor>
#include <witch_and_tankifier>
#include <caster_system>

#define PLUGIN_VERSION "3.9.1"
#define PLUGIN_VERSION "3.11.0"

public Plugin myinfo =
{
Expand All @@ -33,7 +34,8 @@ public Plugin myinfo =
// ======================================================================
// Macros
// ======================================================================
#define SPECHUD_DRAW_INTERVAL 1.0
#define SPECHUD_DRAW_INTERVAL 0.5
#define PING_REFRESH_INTERVAL 2.0
#define TRANSLATION_FILE "spechud.phrases"

// ======================================================================
Expand Down Expand Up @@ -77,10 +79,16 @@ bool bTankSelection;
bool bTankifier;
bool bStaticTank, bStaticWitch;

// Caster System
bool bCasterSystem;

// Hud Toggle & Hint Message
bool bSpecHudActive[MAXPLAYERS+1], bTankHudActive[MAXPLAYERS+1];
bool bSpecHudHintShown[MAXPLAYERS+1], bTankHudHintShown[MAXPLAYERS+1];

// Ping Cache
int iPingCache[MAXPLAYERS+1] = { -1, ... };

/**********************************************************************************************/

// ======================================================================
Expand Down Expand Up @@ -121,6 +129,7 @@ public void OnPluginStart()
}

CreateTimer(SPECHUD_DRAW_INTERVAL, HudDrawTimer, _, TIMER_REPEAT);
CreateTimer(PING_REFRESH_INTERVAL, PingRefreshTimer, _, TIMER_REPEAT);
}

/**********************************************************************************************/
Expand Down Expand Up @@ -203,6 +212,11 @@ void FindTankifier()
bTankifier = LibraryExists("witch_and_tankifier");
}

void FindCasterSystem()
{
bCasterSystem = LibraryExists("caster_system");
}

void LoadPluginTranslations()
{
char sPath[PLATFORM_MAX_PATH];
Expand Down Expand Up @@ -237,20 +251,23 @@ public void OnAllPluginsLoaded()

FindTankSelection();
FindTankifier();
FindCasterSystem();
}

public void OnLibraryAdded(const char[] name)
{
FindScoreMod();
FillBossPercents();
FindTankifier();
FindCasterSystem();
}

public void OnLibraryRemoved(const char[] name)
{
FindScoreMod();
FillBossPercents();
FindTankifier();
FindCasterSystem();
}

public void L4D_OnGameModeChange(int gamemode)
Expand Down Expand Up @@ -311,12 +328,24 @@ Action SetFinaleExceptionMap(int args)
// ======================================================================
// Forwards
// ======================================================================
public void OnClientPutInServer(int client)
{
if (bCasterSystem && !IsFakeClient(client) && IsClientCaster(client))
bSpecHudActive[client] = true;
}

public void OnClientDisconnect(int client)
{
iPingCache[client] = -1;
bSpecHudHintShown[client] = false;
bTankHudHintShown[client] = false;
}

public void OnCasterRegistered(int client)
{
bSpecHudActive[client] = true;
}

Action Timer_RespectateSpecs(Handle hTimer)
{
for (int i = 1; i <= MaxClients; i++)
Expand Down Expand Up @@ -689,6 +718,32 @@ int SortSurvByCharacter(int elem1, int elem2, const int[] array, Handle hndl)
else { return 0; }
}

void RefreshClientPing(int client)
{
iPingCache[client] = RoundToNearest(GetClientAvgLatency(client, NetFlow_Both) * 1000.0);
}

Action PingRefreshTimer(Handle hTimer)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
continue;

RefreshClientPing(i);
}

return Plugin_Continue;
}

int GetCachedPing(int client)
{
if (iPingCache[client] == -1)
RefreshClientPing(client);

return iPingCache[client];
}

void GetClientPing(int client, char[] buffer, int bufferSize)
{
if (IsFakeClient(client))
Expand All @@ -697,8 +752,7 @@ void GetClientPing(int client, char[] buffer, int bufferSize)
}
else
{
int latency = RoundToNearest(GetClientAvgLatency(client, NetFlow_Both) * 1000.0);
FormatEx(buffer, bufferSize, "%ims", latency);
FormatEx(buffer, bufferSize, "%ims", GetCachedPing(client));
}
}

Expand Down Expand Up @@ -839,16 +893,16 @@ void FillScoreInfo(Panel hSpecHud)

DrawPanelText(hSpecHud, " ");

// > HB: 860 <86%> | DB: 420 <84%> | Pills: 60 <60%>
// > HB: 860 <86%> | DB: 420 <84%> | Pills: 60
// > Bonus: 1340 <83.8%>
// > Dist: 400

FormatEx( info,
sizeof(info),
"> HB: %i <%.0f%%> | DB: %i <%.0f%%> | Pills: %i <%.0f%%>",
"> HB: %i <%.0f%%> | DB: %i <%.0f%%> | Pills: %i",
healthBonus, L4D2Util_IntToPercentFloat(healthBonus, maxHealthBonus),
damageBonus, L4D2Util_IntToPercentFloat(damageBonus, maxDamageBonus),
pillsBonus, L4D2Util_IntToPercentFloat(pillsBonus, maxPillsBonus));
pillsBonus);
DrawPanelText(hSpecHud, info);

FormatEx(info, sizeof(info), "> Bonus: %i <%.1f%%>", totalBonus, L4D2Util_IntToPercentFloat(totalBonus, maxTotalBonus));
Expand Down Expand Up @@ -1118,7 +1172,7 @@ bool FillTankInfo(Panel hSpecHud, bool bTankHUD = false)
// Draw network
if (!IsFakeClient(tank))
{
FormatEx(info, sizeof(info), "Net: %ims / %.1f", RoundToNearest(GetClientAvgLatency(tank, NetFlow_Both) * 1000.0), LM_GetLerpTime(tank) * 1000.0);
FormatEx(info, sizeof(info), "Net: %ims / %.1f", GetCachedPing(tank), LM_GetLerpTime(tank) * 1000.0);
}
else
{
Expand Down
Loading