mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 10:28:26 +00:00
misc changes & stockify GetSpectatorTarget
This commit is contained in:
parent
dc9f39bdf3
commit
65f58219bd
@ -473,6 +473,28 @@ stock void GetTrackName(int client, int track, char[] output, int size)
|
||||
}
|
||||
}
|
||||
|
||||
stock int GetSpectatorTarget(int client, int fallback = -1)
|
||||
{
|
||||
int target = fallback;
|
||||
|
||||
if(IsClientObserver(client))
|
||||
{
|
||||
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
|
||||
|
||||
if(iObserverMode >= 3 && iObserverMode <= 5)
|
||||
{
|
||||
int iTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
|
||||
|
||||
if(IsValidClient(iTarget, true))
|
||||
{
|
||||
target = iTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before shavit-core processes the client's usercmd.
|
||||
* Before this is called, safety checks (fake/dead clients) happen.
|
||||
|
||||
@ -530,7 +530,7 @@ void Frame_SendText(DataPack pack)
|
||||
}
|
||||
|
||||
int team = GetClientTeam(client);
|
||||
int[] clients = new int[MaxClients];
|
||||
int clients[MAXPLAYERS+1];
|
||||
int count = 0;
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
|
||||
@ -388,7 +388,7 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(i == client || (IsValidClient(i) && GetHUDTarget(i) == client))
|
||||
if(i == client || (IsValidClient(i) && GetSpectatorTarget(i, i) == client))
|
||||
{
|
||||
TriggerHUDUpdate(i, true);
|
||||
}
|
||||
@ -429,7 +429,7 @@ public void PostThinkPost(int client)
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(i != client && (IsValidClient(i) && GetHUDTarget(i) == client))
|
||||
if(i != client && (IsValidClient(i) && GetSpectatorTarget(i, i) == client))
|
||||
{
|
||||
TriggerHUDUpdate(i, true);
|
||||
}
|
||||
@ -914,7 +914,7 @@ void Cron()
|
||||
if((gI_Cycle % 50) == 0)
|
||||
{
|
||||
float fSpeed[3];
|
||||
GetEntPropVector(GetHUDTarget(i), Prop_Data, "m_vecVelocity", fSpeed);
|
||||
GetEntPropVector(GetSpectatorTarget(i, i), Prop_Data, "m_vecVelocity", fSpeed);
|
||||
gI_PreviousSpeed[i] = RoundToNearest(((gI_HUDSettings[i] & HUD_2DVEL) == 0)? GetVectorLength(fSpeed):(SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0))));
|
||||
}
|
||||
|
||||
@ -1426,7 +1426,7 @@ int AddHUDToBuffer_CSGO(int client, huddata_t data, char[] buffer, int maxlen)
|
||||
|
||||
void UpdateMainHUD(int client)
|
||||
{
|
||||
int target = GetHUDTarget(client);
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
|
||||
if((gI_HUDSettings[client] & HUD_CENTER) == 0 ||
|
||||
((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target) ||
|
||||
@ -1533,9 +1533,9 @@ void UpdateKeyOverlay(int client, Panel panel, bool &draw)
|
||||
return;
|
||||
}
|
||||
|
||||
int target = GetHUDTarget(client);
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
|
||||
if(((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target) || !IsValidClient(target) || IsClientObserver(target))
|
||||
if(((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target) || IsClientObserver(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1586,9 +1586,9 @@ void UpdateCenterKeys(int client)
|
||||
return;
|
||||
}
|
||||
|
||||
int target = GetHUDTarget(client);
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
|
||||
if(((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target) || !IsValidClient(target) || IsClientObserver(target))
|
||||
if(((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target) || IsClientObserver(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1627,20 +1627,20 @@ void UpdateSpectatorList(int client, Panel panel, bool &draw)
|
||||
return;
|
||||
}
|
||||
|
||||
int target = GetHUDTarget(client);
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
|
||||
if(((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target) || !IsValidClient(target))
|
||||
if(((gI_HUDSettings[client] & HUD_OBSERVE) == 0 && client != target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] iSpectatorClients = new int[MaxClients];
|
||||
int iSpectatorClients[MAXPLAYERS+1];
|
||||
int iSpectators = 0;
|
||||
bool bIsAdmin = CheckCommandAccess(client, "admin_speclisthide", ADMFLAG_KICK);
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(i == client || !IsValidClient(i) || IsFakeClient(i) || !IsClientObserver(i) || GetClientTeam(i) < 1 || GetHUDTarget(i) != target)
|
||||
if(i == client || !IsValidClient(i) || IsFakeClient(i) || !IsClientObserver(i) || GetClientTeam(i) < 1 || GetSpectatorTarget(i, i) != target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1689,7 +1689,7 @@ void UpdateTopLeftHUD(int client, bool wait)
|
||||
{
|
||||
if((!wait || gI_Cycle % 25 == 0) && (gI_HUDSettings[client] & HUD_TOPLEFT) > 0)
|
||||
{
|
||||
int target = GetHUDTarget(client);
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
|
||||
int track = 0;
|
||||
int style = 0;
|
||||
@ -1805,9 +1805,9 @@ void UpdateKeyHint(int client)
|
||||
FormatEx(sMessage, 256, (iTimeLeft > 60)? "%T: %d minutes":"%T: <1 minute", "HudTimeLeft", client, (iTimeLeft / 60), "HudTimeLeft", client);
|
||||
}
|
||||
|
||||
int target = GetHUDTarget(client);
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
|
||||
if(IsValidClient(target) && (target == client || (gI_HUDSettings[client] & HUD_OBSERVE) > 0))
|
||||
if(target == client || (gI_HUDSettings[client] & HUD_OBSERVE) > 0)
|
||||
{
|
||||
int style = Shavit_GetBhopStyle(target);
|
||||
|
||||
@ -1829,13 +1829,13 @@ void UpdateKeyHint(int client)
|
||||
|
||||
if((gI_HUDSettings[client] & HUD_SPECTATORS) > 0)
|
||||
{
|
||||
int[] iSpectatorClients = new int[MaxClients];
|
||||
int iSpectatorClients[MAXPLAYERS+1];
|
||||
int iSpectators = 0;
|
||||
bool bIsAdmin = CheckCommandAccess(client, "admin_speclisthide", ADMFLAG_KICK);
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(i == client || !IsValidClient(i) || IsFakeClient(i) || !IsClientObserver(i) || GetClientTeam(i) < 1 || GetHUDTarget(i) != target)
|
||||
if(i == client || !IsValidClient(i) || IsFakeClient(i) || !IsClientObserver(i) || GetClientTeam(i) < 1 || GetSpectatorTarget(i, i) != target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1882,28 +1882,6 @@ void UpdateKeyHint(int client)
|
||||
}
|
||||
}
|
||||
|
||||
int GetHUDTarget(int client)
|
||||
{
|
||||
int target = client;
|
||||
|
||||
if(IsClientObserver(client))
|
||||
{
|
||||
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
|
||||
|
||||
if(iObserverMode >= 3 && iObserverMode <= 5)
|
||||
{
|
||||
int iTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
|
||||
|
||||
if(IsValidClient(iTarget, true))
|
||||
{
|
||||
target = iTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
public int PanelHandler_Nothing(Menu m, MenuAction action, int param1, int param2)
|
||||
{
|
||||
// i don't need anything here
|
||||
@ -1920,12 +1898,12 @@ public void Shavit_OnStyleChanged(int client, int oldstyle, int newstyle, int tr
|
||||
|
||||
public int Native_ForceHUDUpdate(Handle handler, int numParams)
|
||||
{
|
||||
int[] clients = new int[MaxClients];
|
||||
int clients[MAXPLAYERS+1];
|
||||
int count = 0;
|
||||
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
if(client < 0 || client > MaxClients || !IsClientInGame(client))
|
||||
if(!IsValidClient(client))
|
||||
{
|
||||
ThrowNativeError(200, "Invalid client index %d", client);
|
||||
|
||||
@ -1938,7 +1916,7 @@ public int Native_ForceHUDUpdate(Handle handler, int numParams)
|
||||
{
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(i == client || !IsValidClient(i) || GetHUDTarget(i) != client)
|
||||
if(i == client || !IsValidClient(i) || GetSpectatorTarget(i, i) != client)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1959,7 +1937,7 @@ public int Native_GetHUDSettings(Handle handler, int numParams)
|
||||
{
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
if(client < 0 || client > MaxClients)
|
||||
if(!IsValidClient(client))
|
||||
{
|
||||
ThrowNativeError(200, "Invalid client index %d", client);
|
||||
|
||||
|
||||
@ -1458,7 +1458,7 @@ public Action OnTakeDamage(int victim, int attacker)
|
||||
|
||||
case 2:
|
||||
{
|
||||
if(IsValidClient(attacker, true))
|
||||
if(IsValidClient(attacker))
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@ -2276,18 +2276,10 @@ bool SaveCheckpoint(int client, int index, bool overflow = false)
|
||||
return false;
|
||||
}
|
||||
|
||||
int target = client;
|
||||
|
||||
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
|
||||
int iObserverTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
|
||||
int target = GetSpectatorTarget(client, client);
|
||||
int iFlags = GetEntityFlags(client);
|
||||
|
||||
if(IsClientObserver(client) && IsValidClient(iObserverTarget) && 3 <= iObserverMode <= 5)
|
||||
{
|
||||
target = iObserverTarget;
|
||||
}
|
||||
|
||||
else if(!IsPlayerAlive(client))
|
||||
if(target == client && !IsPlayerAlive(client))
|
||||
{
|
||||
Shavit_PrintToChat(client, "%T", "CommandAliveSpectate", client, gS_ChatStrings.sVariable, gS_ChatStrings.sText, gS_ChatStrings.sVariable, gS_ChatStrings.sText);
|
||||
|
||||
@ -2818,19 +2810,7 @@ public Action Command_Specs(int client, int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if(!IsPlayerAlive(client) && !IsClientObserver(client))
|
||||
{
|
||||
Shavit_PrintToChat(client, "%T", "SpectatorInvalid", client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
int iObserverTarget = client;
|
||||
|
||||
if(IsClientObserver(client))
|
||||
{
|
||||
iObserverTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
|
||||
}
|
||||
int iObserverTarget = GetSpectatorTarget(client, client);
|
||||
|
||||
if(args > 0)
|
||||
{
|
||||
@ -3213,7 +3193,7 @@ public Action Shotgun_Shot(const char[] te_name, const int[] Players, int numCli
|
||||
|
||||
gI_LastShot[client] = ticks;
|
||||
|
||||
int[] clients = new int[MaxClients];
|
||||
int clients[MAXPLAYERS+1];
|
||||
int count = 0;
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
@ -3223,8 +3203,7 @@ public Action Shotgun_Shot(const char[] te_name, const int[] Players, int numCli
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!gB_Hide[i] ||
|
||||
(IsClientObserver(i) && GetEntPropEnt(i, Prop_Send, "m_hObserverTarget") == client && 3 <= GetEntProp(i, Prop_Send, "m_iObserverMode") <= 5))
|
||||
if(!gB_Hide[i] || GetSpectatorTarget(i) == client)
|
||||
{
|
||||
clients[count++] = i;
|
||||
}
|
||||
|
||||
@ -2542,8 +2542,6 @@ public Action Command_Replay(int client, int args)
|
||||
}
|
||||
}
|
||||
|
||||
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", gA_CentralCache.iClient);
|
||||
|
||||
if(CanStopCentral(client))
|
||||
{
|
||||
char arg[8];
|
||||
@ -2557,6 +2555,8 @@ public Action Command_Replay(int client, int args)
|
||||
}
|
||||
}
|
||||
|
||||
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", gA_CentralCache.iClient);
|
||||
|
||||
return OpenReplayMenu(client);
|
||||
}
|
||||
|
||||
@ -2835,28 +2835,6 @@ int GetReplayTrack(int client)
|
||||
return (gCV_CentralBot.BoolValue)? gA_CentralCache.iTrack:Track_Main;
|
||||
}
|
||||
|
||||
int GetSpectatorTarget(int client)
|
||||
{
|
||||
int target = -1;
|
||||
|
||||
if(IsClientObserver(client))
|
||||
{
|
||||
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
|
||||
|
||||
if(iObserverMode >= 3 && iObserverMode <= 5)
|
||||
{
|
||||
int iTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
|
||||
|
||||
if(IsValidClient(iTarget, true))
|
||||
{
|
||||
target = iTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
float GetReplayLength(int style, int track)
|
||||
{
|
||||
if(gA_FrameCache[style][track].iFrameCount == 0)
|
||||
|
||||
@ -270,7 +270,7 @@ public void Shavit_OnWorstRecord(int client, int style, float time, int jumps, i
|
||||
|
||||
void PlayEventSound(int client, bool everyone, char sound[PLATFORM_MAX_PATH])
|
||||
{
|
||||
int[] clients = new int[MaxClients];
|
||||
int clients[MAXPLAYERS+1];
|
||||
int count = 0;
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
@ -296,7 +296,6 @@ void PlayEventSound(int client, bool everyone, char sound[PLATFORM_MAX_PATH])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Action result = Plugin_Continue;
|
||||
Call_StartForward(gH_OnPlaySound);
|
||||
Call_PushCell(client);
|
||||
|
||||
@ -2648,7 +2648,7 @@ void DrawZone(float points[8][3], int color[4], float life, float width, bool fl
|
||||
{ 7, 5 }
|
||||
};
|
||||
|
||||
int[] clients = new int[MaxClients];
|
||||
int clients[MAXPLAYERS+1];
|
||||
int count = 0;
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user