PlayerRankings: Update rotating code, less prone to errors?

Less global ints is gud yes?
This commit is contained in:
zaCade 2019-07-17 15:47:38 +02:00
parent ce3804b3d5
commit c604047688

View File

@ -1,9 +1,9 @@
#include <hlstatsx_loghelper>
#include <zombiereloaded> #include <zombiereloaded>
#include <clientprefs> #include <clientprefs>
#include <multicolors> #include <multicolors>
#include <sourcemod> #include <sourcemod>
#include <sdktools> #include <sdktools>
#include <hlstatsx_loghelper>
#define SPECMODE_NONE 0 #define SPECMODE_NONE 0
#define SPECMODE_FIRSTPERSON 4 #define SPECMODE_FIRSTPERSON 4
@ -28,10 +28,6 @@ ConVar g_hCVar_ProtectionMinimal2;
ConVar g_hCVar_ProtectionMinimal3; ConVar g_hCVar_ProtectionMinimal3;
/* INTERGERS */ /* INTERGERS */
int g_iCrownEntity = INVALID_ENT_REFERENCE;
int g_iCrownParent = INVALID_ENT_REFERENCE;
int g_iSkullEntity = INVALID_ENT_REFERENCE;
int g_iSkullParent = INVALID_ENT_REFERENCE;
int g_iDialogLevel = 100000; int g_iDialogLevel = 100000;
int g_iPlayerWinner[6]; int g_iPlayerWinner[6];
@ -82,7 +78,6 @@ public void OnPluginStart()
CreateTimer(0.1, UpdateScoreboard, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(0.1, UpdateScoreboard, INVALID_HANDLE, TIMER_REPEAT);
CreateTimer(0.1, UpdateDialog, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(0.1, UpdateDialog, INVALID_HANDLE, TIMER_REPEAT);
CreateTimer(0.1, UpdateCrowns, INVALID_HANDLE, TIMER_REPEAT);
RegConsoleCmd("sm_togglecrown", OnToggleCrown); RegConsoleCmd("sm_togglecrown", OnToggleCrown);
RegConsoleCmd("sm_toggleskull", OnToggleCrown); RegConsoleCmd("sm_toggleskull", OnToggleCrown);
@ -93,7 +88,6 @@ public void OnPluginStart()
HookEvent("round_end", OnRoundEnding); HookEvent("round_end", OnRoundEnding);
HookEvent("player_hurt", OnClientHurt); HookEvent("player_hurt", OnClientHurt);
HookEvent("player_spawn", OnClientSpawn); HookEvent("player_spawn", OnClientSpawn);
HookEvent("player_death", OnClientDeath);
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings"); SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings");
} }
@ -383,34 +377,6 @@ public Action UpdateDialog(Handle timer)
g_iDialogLevel--; g_iDialogLevel--;
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action UpdateCrowns(Handle timer)
{
if (g_bEngineCSGO)
return;
if (IsValidEntity(g_iCrownEntity) && IsValidEntity(g_iCrownParent) && IsClientInGame(g_iCrownParent))
{
float fAngles[3];
GetClientAbsAngles(g_iCrownParent, fAngles);
fAngles[0] += 8.0;
fAngles[2] += 5.5;
TeleportEntity(g_iCrownEntity, NULL_VECTOR, fAngles, NULL_VECTOR);
}
if (IsValidEntity(g_iSkullEntity) && IsValidEntity(g_iSkullParent) && IsClientInGame(g_iSkullParent))
{
float fAngles[3];
GetClientAbsAngles(g_iSkullParent, fAngles);
TeleportEntity(g_iSkullEntity, NULL_VECTOR, fAngles, NULL_VECTOR);
}
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -623,15 +589,10 @@ public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast
int steamAccountID = GetSteamAccountID(client); int steamAccountID = GetSteamAccountID(client);
if (g_iPlayerWinner[0] == steamAccountID) if (g_iPlayerWinner[0] == steamAccountID)
{
CreateTimer(7.0, OnClientSpawnPostCrown, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE); CreateTimer(7.0, OnClientSpawnPostCrown, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
KillCrown();
}
else if (g_iPlayerWinner[3] == steamAccountID) else if (g_iPlayerWinner[3] == steamAccountID)
{
CreateTimer(7.0, OnClientSpawnPostSkull, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE); CreateTimer(7.0, OnClientSpawnPostSkull, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
KillSkull();
}
} }
} }
@ -644,10 +605,9 @@ public Action OnClientSpawnPostCrown(Handle timer, int serial)
if((client = GetClientFromSerial(serial)) == -1) if((client = GetClientFromSerial(serial)) == -1)
return; return;
if (!IsClientInGame(client) || IsFakeClient(client) || !IsPlayerAlive(client)) if (!IsClientInGame(client) || !IsPlayerAlive(client))
return; return;
KillCrown();
SpawnCrown(client); SpawnCrown(client);
} }
@ -660,30 +620,12 @@ public Action OnClientSpawnPostSkull(Handle timer, int serial)
if((client = GetClientFromSerial(serial)) == -1) if((client = GetClientFromSerial(serial)) == -1)
return; return;
if (!IsClientInGame(client) || IsFakeClient(client) || !IsPlayerAlive(client)) if (!IsClientInGame(client) || !IsPlayerAlive(client))
return; return;
KillSkull();
SpawnSkull(client); SpawnSkull(client);
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
int client = GetClientOfUserId(hEvent.GetInt("userid"));
if (!IsPlayerAlive(client))
{
if (g_iCrownParent == client)
KillCrown();
if (g_iSkullParent == client)
KillSkull();
}
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -723,8 +665,12 @@ void SpawnCrown(int client)
SetVariantString("!activator"); SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", client); AcceptEntityInput(entity, "SetParent", client);
g_iCrownEntity = entity; DataPack data = new DataPack();
g_iCrownParent = client; data.WriteCell(entity);
data.WriteCell(client);
data.Reset();
CreateTimer(0.1, OnCrownUpdate, data, TIMER_REPEAT);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -753,6 +699,8 @@ void SpawnSkull(int client)
TeleportEntity(entity, fVector, fAngles, NULL_VECTOR); TeleportEntity(entity, fVector, fAngles, NULL_VECTOR);
fVector[2] += 110.0;
float fDirection[3]; float fDirection[3];
fDirection[0] = 0.0; fDirection[0] = 0.0;
fDirection[1] = 0.0; fDirection[1] = 0.0;
@ -764,31 +712,62 @@ void SpawnSkull(int client)
SetVariantString("!activator"); SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", client); AcceptEntityInput(entity, "SetParent", client);
g_iSkullEntity = entity; DataPack data = new DataPack();
g_iSkullParent = client; data.WriteCell(entity);
data.WriteCell(client);
data.Reset();
CreateTimer(0.1, OnSkullUpdate, data, TIMER_REPEAT);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void KillCrown() public Action OnCrownUpdate(Handle timer, DataPack data)
{ {
if ((IsValidEntity(g_iCrownEntity) && AcceptEntityInput(g_iCrownEntity, "Kill")) || g_iCrownEntity != INVALID_ENT_REFERENCE) int entity = data.ReadCell();
int client = data.ReadCell();
data.Reset();
if (!IsValidEntity(entity) || !IsClientInGame(client) || !IsPlayerAlive(client))
{ {
g_iCrownEntity = INVALID_ENT_REFERENCE; AcceptEntityInput(entity, "Kill");
g_iCrownParent = INVALID_ENT_REFERENCE; return Plugin_Stop;
}
else
{
float fAngles[3];
GetClientAbsAngles(client, fAngles);
fAngles[0] += 8.0;
fAngles[2] += 5.5;
TeleportEntity(entity, NULL_VECTOR, fAngles, NULL_VECTOR);
return Plugin_Continue;
} }
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void KillSkull() public Action OnSkullUpdate(Handle timer, DataPack data)
{ {
if ((IsValidEntity(g_iSkullEntity) && AcceptEntityInput(g_iSkullEntity, "Kill")) || g_iSkullEntity != INVALID_ENT_REFERENCE) int entity = data.ReadCell();
int client = data.ReadCell();
data.Reset();
if (!IsValidEntity(entity) || !IsClientInGame(client) || !IsPlayerAlive(client))
{ {
g_iSkullEntity = INVALID_ENT_REFERENCE; AcceptEntityInput(entity, "Kill");
g_iSkullParent = INVALID_ENT_REFERENCE; return Plugin_Stop;
}
else
{
float fAngles[3];
GetClientAbsAngles(client, fAngles);
TeleportEntity(entity, NULL_VECTOR, fAngles, NULL_VECTOR);
return Plugin_Continue;
} }
} }