mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 18:38:26 +00:00
add Shavit_GetRankedPlayers
This commit is contained in:
parent
495f9fb171
commit
ff187069df
@ -85,7 +85,7 @@ Core
|
||||
- [x] Add unranked styles.
|
||||
- [x] Add a setting to not start timer if Z axis velocity is a thing (non-prespeed styles).
|
||||
- [ ] Add native that will execute threaded MySQL queries and allow callbacks - including safety checks, to prevent error spams. (Migrate DBI to new syntax first!)
|
||||
- [ ] Measure strafe sync, also have it in the Shavit_OnFinish forward.
|
||||
- [ ] Measure strafe count/sync, also have it in the Shavit_OnFinish forward.
|
||||
- [ ] Add bonus timer.
|
||||
|
||||
HUD
|
||||
@ -160,9 +160,9 @@ Rankings **(NEW!)**
|
||||
- [x] Calculate points per scored time once it's added to the database.
|
||||
- [x] Recalculate points for every record on the current map when a ROOT admin changes the point value for it. (retroactive!)
|
||||
- [x] Add natives. `float Shavit_GetPoints(int client)` `int Shavit_GetRank(int client)` `void Shavit_GetMapValues(float &points, float &idealtime)`
|
||||
- [ ] Add native that checks the total amount of players with over 0 points.
|
||||
- [ ] Remove deleted records from `playerpoints`.
|
||||
- [x] Add native that checks the total amount of players with over 0 points.
|
||||
- [ ] Find a way to update newly calculated points for all records on a map with the least amount of queries possible.
|
||||
- [ ] Remove deleted records from `playerpoints`.
|
||||
|
||||
Web Interface
|
||||
--
|
||||
|
||||
@ -626,7 +626,6 @@ native bool Shavit_IsReplayDataLoaded(BhopStyle style);
|
||||
*/
|
||||
native float Shavit_GetPoints(int client);
|
||||
|
||||
|
||||
/**
|
||||
* Gets player rank.
|
||||
*
|
||||
@ -645,6 +644,14 @@ native int Shavit_GetRank(int client);
|
||||
*/
|
||||
native void Shavit_GetMapValues(float &points, float &idealtime);
|
||||
|
||||
/**
|
||||
* Gets the amount of players with over 0 points.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @return Amount of ranked players.
|
||||
*/
|
||||
native int Shavit_GetRankedPlayers(int client);
|
||||
|
||||
/**
|
||||
* Force an HUD update for a player. Requires shavit-hud.
|
||||
*
|
||||
|
||||
@ -38,6 +38,7 @@ float gF_IdealTime = 0.0;
|
||||
float gF_MapPoints = -1.0;
|
||||
int gI_NeededRecordsAmount = 0;
|
||||
int gI_CachedRecordsAmount = 0;
|
||||
int gI_RankedPlayers = 0;
|
||||
|
||||
float gF_PlayerPoints[MAXPLAYERS+1];
|
||||
int gI_PlayerRank[MAXPLAYERS+1];
|
||||
@ -63,17 +64,19 @@ public Plugin myinfo =
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
{
|
||||
CreateNative("Shavit_GetPoints", Native_GetPoints);
|
||||
CreateNative("Shavit_GetRank", Native_GetRank);
|
||||
CreateNative("Shavit_GetMapValues", Native_GetMapValues);
|
||||
CreateNative("Shavit_GetPoints", Native_GetPoints);
|
||||
CreateNative("Shavit_GetRank", Native_GetRank);
|
||||
CreateNative("Shavit_GetMapValues", Native_GetMapValues);
|
||||
CreateNative("Shavit_GetRankedPlayers", Native_GetRankedPlayers);
|
||||
|
||||
MarkNativeAsOptional("Shavit_GetPoints");
|
||||
MarkNativeAsOptional("Shavit_GetRank");
|
||||
MarkNativeAsOptional("Shavit_GetMapValues");
|
||||
MarkNativeAsOptional("Shavit_GetPoints");
|
||||
MarkNativeAsOptional("Shavit_GetRank");
|
||||
MarkNativeAsOptional("Shavit_GetMapValues");
|
||||
MarkNativeAsOptional("Shavit_GetRankedPlayers");
|
||||
|
||||
RegPluginLibrary("shavit-rankings");
|
||||
RegPluginLibrary("shavit-rankings");
|
||||
|
||||
return APLRes_Success;
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public void OnAllPluginsLoaded()
|
||||
@ -142,39 +145,41 @@ public void OnClientPutInServer(int client)
|
||||
|
||||
public void SQL_GetUserPoints_Callback(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer error on GetUserPoints. Reason: %s", error);
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer error on GetUserPoints. Reason: %s", error);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int client = GetClientFromSerial(data);
|
||||
int client = GetClientFromSerial(data);
|
||||
|
||||
if(client == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(client == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(results.FetchRow())
|
||||
{
|
||||
gF_PlayerPoints[client] = results.FetchFloat(0);
|
||||
if(results.FetchRow())
|
||||
{
|
||||
gF_PlayerPoints[client] = results.FetchFloat(0);
|
||||
|
||||
UpdatePlayerPoints(client, false);
|
||||
}
|
||||
UpdatePlayerPoints(client, false);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
char[] sAuthID3 = new char[32];
|
||||
else
|
||||
{
|
||||
char[] sAuthID3 = new char[32];
|
||||
|
||||
if(GetClientAuthId(client, AuthId_Steam3, sAuthID3, 32))
|
||||
{
|
||||
char[] sQuery = new char[128];
|
||||
FormatEx(sQuery, 128, "REPLACE INTO %suserpoints (auth, points) VALUES ('%s', 0.0);", gS_MySQLPrefix, sAuthID3);
|
||||
if(GetClientAuthId(client, AuthId_Steam3, sAuthID3, 32))
|
||||
{
|
||||
char[] sQuery = new char[128];
|
||||
FormatEx(sQuery, 128, "REPLACE INTO %suserpoints (auth, points) VALUES ('%s', 0.0);", gS_MySQLPrefix, sAuthID3);
|
||||
|
||||
gH_SQL.Query(SQL_InsertUser_Callback, sQuery, 0, DBPrio_Low);
|
||||
}
|
||||
}
|
||||
gH_SQL.Query(SQL_InsertUser_Callback, sQuery, 0, DBPrio_Low);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateRankedPlayers();
|
||||
}
|
||||
|
||||
public void SQL_InsertUser_Callback(Database db, DBResultSet results, const char[] error, any data)
|
||||
@ -285,7 +290,7 @@ public Action Command_Rank(int client, int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
Shavit_PrintToChat(client, "\x03%N\x01 is ranked \x03#%d\x01 with \x05%.02f points\x01.", target, gI_PlayerRank[target], gF_PlayerPoints[target]);
|
||||
Shavit_PrintToChat(client, "\x03%N\x01 is ranked \x03%d\x01 out of \x03%d\x01 with \x05%.02f points\x01.", target, gI_PlayerRank[target], gI_RankedPlayers, gF_PlayerPoints[target]);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@ -462,26 +467,28 @@ public void SQL_RetroactivePoints_Callback(Database db, DBResultSet results, con
|
||||
|
||||
public void SQL_RetroactivePoints_Callback2(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer (rankings module) error! RetroactivePoints2 failed. Reason: %s", error);
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer (rankings module) error! RetroactivePoints2 failed. Reason: %s", error);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(gI_CachedRecordsAmount == gI_NeededRecordsAmount)
|
||||
{
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(IsValidClient(i))
|
||||
{
|
||||
OnClientPutInServer(i);
|
||||
}
|
||||
}
|
||||
if(gI_CachedRecordsAmount == gI_NeededRecordsAmount)
|
||||
{
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(IsValidClient(i))
|
||||
{
|
||||
OnClientPutInServer(i);
|
||||
}
|
||||
}
|
||||
|
||||
gI_NeededRecordsAmount = 0;
|
||||
gI_CachedRecordsAmount = 0;
|
||||
}
|
||||
gI_NeededRecordsAmount = 0;
|
||||
gI_CachedRecordsAmount = 0;
|
||||
}
|
||||
|
||||
UpdateRankedPlayers();
|
||||
}
|
||||
|
||||
public void UpdatePointsCache(const char[] map)
|
||||
@ -633,19 +640,21 @@ public void SQL_FindRecordID_Callback(Database db, DBResultSet results, const ch
|
||||
|
||||
public void SQL_InsertPoints_Callback(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer (rankings module) error! Insertion of %d (serial) points to table failed. Reason: %s", data, error);
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer (rankings module) error! Insertion of %d (serial) points to table failed. Reason: %s", data, error);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int client = GetClientFromSerial(data);
|
||||
int client = GetClientFromSerial(data);
|
||||
|
||||
if(client != 0)
|
||||
{
|
||||
UpdatePlayerPoints(client, true);
|
||||
}
|
||||
if(client != 0)
|
||||
{
|
||||
UpdatePlayerPoints(client, true);
|
||||
}
|
||||
|
||||
UpdateRankedPlayers();
|
||||
}
|
||||
|
||||
public void UpdatePlayerPoints(int client, bool chat)
|
||||
@ -761,6 +770,29 @@ public void SQL_UpdatePlayerRank_Callback(Database db, DBResultSet results, cons
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRankedPlayers()
|
||||
{
|
||||
char[] sQuery = new char[128];
|
||||
FormatEx(sQuery, 128, "SELECT COUNT(*) FROM %suserpoints WHERE points > 0 LIMIT 1;", gS_MySQLPrefix);
|
||||
|
||||
gH_SQL.Query(SQL_UpdateRankedPlayers_Callback, sQuery);
|
||||
}
|
||||
|
||||
public void SQL_UpdateRankedPlayers_Callback(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(results == null)
|
||||
{
|
||||
LogError("Timer (rankings module) error! UpdateRankedPlayers failed. Reason: %s", error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(results.FetchRow())
|
||||
{
|
||||
gI_RankedPlayers = results.FetchInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public int Native_GetPoints(Handle handler, int numParams)
|
||||
{
|
||||
return view_as<int>(gF_PlayerPoints[GetNativeCell(1)]);
|
||||
@ -777,6 +809,11 @@ public int Native_GetMapValues(Handle handler, int numParams)
|
||||
SetNativeCellRef(2, gF_IdealTime);
|
||||
}
|
||||
|
||||
public int Native_GetRankedPlayers(Handle handler, int numParams)
|
||||
{
|
||||
return gI_RankedPlayers;
|
||||
}
|
||||
|
||||
public Action CheckForSQLInfo(Handle Timer)
|
||||
{
|
||||
return SetSQLInfo();
|
||||
|
||||
@ -205,12 +205,12 @@ public void UpdateMVPs(int client)
|
||||
|
||||
if(gCV_MVPRankOnes.IntValue == 2)
|
||||
{
|
||||
FormatEx(sQuery, 256, "SELECT COUNT(*) FROM (SELECT s.auth FROM (SELECT style, auth, MIN(time) FROM %splayertimes GROUP BY map, style) s WHERE style = 0) ss WHERE ss.auth = '%s';", gS_MySQLPrefix, sAuthID);
|
||||
FormatEx(sQuery, 256, "SELECT COUNT(*) FROM (SELECT s.auth FROM (SELECT style, auth, MIN(time) FROM %splayertimes GROUP BY map, style) s WHERE style = 0) ss WHERE ss.auth = '%s' LIMIT 1;", gS_MySQLPrefix, sAuthID);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
FormatEx(sQuery, 256, "SELECT COUNT(*) FROM (SELECT s.auth FROM (SELECT auth, MIN(time) FROM %splayertimes GROUP BY map, style) s) ss WHERE ss.auth = '%s';", gS_MySQLPrefix, sAuthID);
|
||||
FormatEx(sQuery, 256, "SELECT COUNT(*) FROM (SELECT s.auth FROM (SELECT auth, MIN(time) FROM %splayertimes GROUP BY map, style) s) ss WHERE ss.auth = '%s' LIMIT 1;", gS_MySQLPrefix, sAuthID);
|
||||
}
|
||||
|
||||
gH_SQL.Query(SQL_GetWRs_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user