diff --git a/addons/sourcemod/scripting/caster_assister.sp b/addons/sourcemod/scripting/caster_assister.sp index 08455b51f..335a7c3fa 100644 --- a/addons/sourcemod/scripting/caster_assister.sp +++ b/addons/sourcemod/scripting/caster_assister.sp @@ -3,18 +3,16 @@ #include #include -#undef REQUIRE_PLUGIN -#include #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 = "" }; @@ -35,14 +33,14 @@ 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; } } @@ -50,31 +48,26 @@ 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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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) { @@ -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)); } diff --git a/addons/sourcemod/scripting/spechud.sp b/addons/sourcemod/scripting/spechud.sp index 18f94d7bd..27d48f077 100644 --- a/addons/sourcemod/scripting/spechud.sp +++ b/addons/sourcemod/scripting/spechud.sp @@ -18,8 +18,9 @@ #include #include #include +#include -#define PLUGIN_VERSION "3.9.1" +#define PLUGIN_VERSION "3.11.0" public Plugin myinfo = { @@ -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" // ====================================================================== @@ -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, ... }; + /**********************************************************************************************/ // ====================================================================== @@ -121,6 +129,7 @@ public void OnPluginStart() } CreateTimer(SPECHUD_DRAW_INTERVAL, HudDrawTimer, _, TIMER_REPEAT); + CreateTimer(PING_REFRESH_INTERVAL, PingRefreshTimer, _, TIMER_REPEAT); } /**********************************************************************************************/ @@ -203,6 +212,11 @@ void FindTankifier() bTankifier = LibraryExists("witch_and_tankifier"); } +void FindCasterSystem() +{ + bCasterSystem = LibraryExists("caster_system"); +} + void LoadPluginTranslations() { char sPath[PLATFORM_MAX_PATH]; @@ -237,6 +251,7 @@ public void OnAllPluginsLoaded() FindTankSelection(); FindTankifier(); + FindCasterSystem(); } public void OnLibraryAdded(const char[] name) @@ -244,6 +259,7 @@ public void OnLibraryAdded(const char[] name) FindScoreMod(); FillBossPercents(); FindTankifier(); + FindCasterSystem(); } public void OnLibraryRemoved(const char[] name) @@ -251,6 +267,7 @@ public void OnLibraryRemoved(const char[] name) FindScoreMod(); FillBossPercents(); FindTankifier(); + FindCasterSystem(); } public void L4D_OnGameModeChange(int gamemode) @@ -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++) @@ -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)) @@ -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)); } } @@ -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)); @@ -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 {