Skip to content

Commit

Permalink
1.0.1.
Browse files Browse the repository at this point in the history
-Steam IDs are now saved upon successful team join; steam IDs were getting lost when people crash so it was impossible to save their score
  • Loading branch information
rowedahelicon committed Dec 17, 2023
1 parent fca2374 commit 0b126bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Binary file modified plugins/scoresaver.smx
Binary file not shown.
23 changes: 18 additions & 5 deletions scripting/scoresaver.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#define PL_NAME "ScoreSaver"
#define PL_DESC "Saves scores when players disconnect"
#define PL_VERSION "1.0.0"
#define PL_VERSION "1.0.1"

public Plugin myinfo =
{
Expand All @@ -22,6 +22,8 @@ Handle g_Cvar_Teamplay = INVALID_HANDLE;
static Address CTFGameStats;
static Handle SDKIncrementStat;

int steamAddresses[MAXPLAYERS +1] = {0};

StringMap sm_SavedScores;

enum Game
Expand Down Expand Up @@ -91,11 +93,16 @@ public void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
return;
}

steamAddresses[client] = GetSteamAccountID(client);

if (steamAddresses[client] == 0) return;

char steamId[16];
Format(steamId, sizeof(steamId), "%d", GetSteamAccountID(client));
Format(steamId, sizeof(steamId), "%d", steamAddresses[client]);

char strScore[5];
bool found = sm_SavedScores.GetString(steamId, strScore, sizeof(strScore));

if (!found)
{
return;
Expand All @@ -109,24 +116,30 @@ public void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)

public void OnClientDisconnect(int client)
{
if (IsFakeClient(client))
if (IsFakeClient(client) || steamAddresses[client] == 0)
{
return;
}

char steamId[16];
Format(steamId, sizeof(steamId), "%d", GetSteamAccountID(client));
Format(steamId, sizeof(steamId), "%d", steamAddresses[client]);

int score = GetScore(client);

char strScore[5];
Format(strScore, sizeof(strScore), "%d", score);

sm_SavedScores.SetString(steamId, strScore, true);
steamAddresses[client] = 0;
}

public void OnMapEnd()
{
for (int client=1;client<=MAXPLAYERS; client++)
{
steamAddresses[client] = 0;
}

sm_SavedScores.Clear();
}

Expand Down Expand Up @@ -236,4 +249,4 @@ public MRESReturn DHook_ResetRoundStats(Address address)
CTFGameStats = address;
sm_SavedScores.Clear();
return MRES_Ignored;
}
}

0 comments on commit 0b126bc

Please sign in to comment.