readded the ingame commands dogan previously had
This commit is contained in:
parent
0270ffc1e3
commit
7bdfb1b288
@ -4,6 +4,7 @@
|
||||
#include <sourcemod>
|
||||
|
||||
Database g_hDatabase;
|
||||
Handle g_h_time_activity = null;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@ -14,13 +15,13 @@ public Plugin myinfo =
|
||||
url = "www.unloze.com"
|
||||
};
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
CreateTimer(10.0, time_query_activity, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
public Action time_query_activity(Handle timer, any data)
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||
return Plugin_Continue;
|
||||
}
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
if (IsValidClient(client) && !IsFakeClient(client) && IsPlayerAlive(client))
|
||||
{
|
||||
@ -67,6 +68,16 @@ public Action time_query_activity(Handle timer, any data)
|
||||
public void OnPluginStart()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||
RegConsoleCmd("sm_playtime", Command_Time, "retreives total connection time on all connected servers");
|
||||
RegConsoleCmd("sm_topplaytime", Command_TopTime, "retreives top 12 playtime highscores on all connected servers");
|
||||
|
||||
g_h_time_activity = CreateTimer(10.0, time_query_activity, INVALID_HANDLE, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
public void OnPluginEnd()
|
||||
{
|
||||
if (g_h_time_activity != null)
|
||||
delete g_h_time_activity;
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
@ -109,13 +120,13 @@ public void insert_client(int client)
|
||||
g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
|
||||
}
|
||||
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
delete data;
|
||||
delete results;
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
@ -124,3 +135,190 @@ stock bool IsValidClient(int client)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Action Command_TopTime(int client, int args)
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
char sQuery[512];
|
||||
char sServer[32];
|
||||
|
||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
||||
if (i_port == 27015 || i_port == 27019)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "ze_time");
|
||||
}
|
||||
else if (i_port == 27016)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "zr_time");
|
||||
}
|
||||
else if (i_port == 27017)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "mg_time");
|
||||
}
|
||||
else if (i_port == 27023)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "jb_time");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
Format(sQuery, sizeof(sQuery), "select steam_id, player_name, sum(%s) as %s_total from unloze_playtimestats.player_time GROUP BY steam_id order by %s_total desc limit 10", sServer, sServer, sServer);
|
||||
g_hDatabase.Query(SQL_OnQueryCompletedTopTime, sQuery, GetClientSerial(client));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_Time(int client, int args)
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
char sQuery[512];
|
||||
char sAuthID[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
|
||||
Format(sQuery, sizeof(sQuery), "select ze_time, mg_time, zr_time, jb_time from unloze_playtimestats.player_time pt where pt.steam_id = '%s'", sAuthID);
|
||||
g_hDatabase.Query(SQL_OnQueryCompletedTime, sQuery, GetClientSerial(client));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompletedTopTime(Database db, DBResultSet results, const char[] error, int iSerial)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(iSerial)) == 0)
|
||||
return;
|
||||
char sServer[32];
|
||||
|
||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
||||
if (i_port == 27015 || i_port == 27019)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "ze_time");
|
||||
}
|
||||
else if (i_port == 27016)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "zr_time");
|
||||
}
|
||||
else if (i_port == 27017)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "mg_time");
|
||||
}
|
||||
else if (i_port == 27023)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "jb_time");
|
||||
}
|
||||
|
||||
int iTime;
|
||||
char sName[MAX_NAME_LENGTH];
|
||||
char sAuthID[32];
|
||||
Panel mSayPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio));
|
||||
char sTitle[64];
|
||||
Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime] Record Holders for %s:", sServer);
|
||||
mSayPanel.SetTitle(sTitle);
|
||||
int counter = 1;
|
||||
while (results.RowCount && results.FetchRow())
|
||||
{
|
||||
char sBuffer[256];
|
||||
results.FetchString(0, sAuthID, sizeof(sAuthID));
|
||||
results.FetchString(1, sName, sizeof(sName));
|
||||
iTime = results.FetchInt(2);
|
||||
|
||||
int iHours = (iTime / 60) / 60;
|
||||
Format(sBuffer, sizeof(sBuffer), "%i %s %d Hours", counter, sName, iHours);
|
||||
counter++;
|
||||
mSayPanel.DrawText(sBuffer);
|
||||
}
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawItem("1. Got it!", ITEMDRAW_RAWLINE);
|
||||
|
||||
mSayPanel.SetKeys(1023);
|
||||
mSayPanel.Send(client, Handler_Menu, 0);
|
||||
delete mSayPanel;
|
||||
delete results;
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompletedTime(Database db, DBResultSet results, const char[] error, int iSerial)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(iSerial)) == 0)
|
||||
return;
|
||||
|
||||
int iTime_ze;
|
||||
int iTime_mg;
|
||||
int iTime_zr;
|
||||
int iTime_jb;
|
||||
|
||||
while (results.RowCount && results.FetchRow())
|
||||
{
|
||||
iTime_ze += results.FetchInt(0);
|
||||
iTime_mg += results.FetchInt(1);
|
||||
iTime_zr += results.FetchInt(2);
|
||||
iTime_jb += results.FetchInt(3);
|
||||
}
|
||||
delete results;
|
||||
int iHours_ze = (iTime_ze / 60) / 60;
|
||||
int iMinutes_ze = (iTime_ze / 60) % 60;
|
||||
int iSeconds_ze = (iTime_ze % 60);
|
||||
|
||||
int iHours_mg = (iTime_mg / 60) / 60;
|
||||
int iMinutes_mg = (iTime_mg / 60) % 60;
|
||||
int iSeconds_mg = (iTime_mg % 60);
|
||||
|
||||
int iHours_zr = (iTime_zr / 60) / 60;
|
||||
int iMinutes_zr = (iTime_zr / 60) % 60;
|
||||
int iSeconds_zr = (iTime_zr % 60);
|
||||
|
||||
int iHours_jb = (iTime_jb / 60) / 60;
|
||||
int iMinutes_jb = (iTime_jb / 60) % 60;
|
||||
int iSeconds_jb = (iTime_jb % 60);
|
||||
|
||||
char sTime_ze[64];
|
||||
char sTime_mg[64];
|
||||
char sTime_zr[64];
|
||||
char sTime_jb[64];
|
||||
char sTitle[64];
|
||||
Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime] Player %N:", client);
|
||||
Format(sTime_ze, sizeof(sTime_ze), "Zombie Escape: %d Hours %d Minutes %d Seconds", iHours_ze, iMinutes_ze, iSeconds_ze);
|
||||
Format(sTime_mg, sizeof(sTime_mg), "MiniGame: %d Hours %d Minutes %d Seconds", iHours_mg, iMinutes_mg, iSeconds_mg);
|
||||
Format(sTime_zr, sizeof(sTime_zr), "Zombie Riot: %d Hours %d Minutes %d Seconds", iHours_zr, iMinutes_zr, iSeconds_zr);
|
||||
Format(sTime_jb, sizeof(sTime_jb), "Jail Break: %d Hours %d Minutes %d Seconds", iHours_jb, iMinutes_jb, iSeconds_jb);
|
||||
|
||||
Panel mSayPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio));
|
||||
|
||||
mSayPanel.SetTitle(sTitle);
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawText(sTime_ze);
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawText(sTime_mg);
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawText(sTime_zr);
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawText(sTime_jb);
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawItem("1. Got it!", ITEMDRAW_RAWLINE);
|
||||
mSayPanel.SetKeys(1023);
|
||||
|
||||
mSayPanel.Send(client, Handler_Menu, 0);
|
||||
delete mSayPanel;
|
||||
}
|
||||
|
||||
public int Handler_Menu(Menu menu, MenuAction action, int param1, int param2)
|
||||
{
|
||||
switch(action)
|
||||
{
|
||||
case MenuAction_Select, MenuAction_Cancel:
|
||||
delete menu;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user