adding top activity display ingame
This commit is contained in:
parent
9ff0faf337
commit
8b6f2e0d96
141
topactivity/scripting/top_activitiy.sp
Normal file
141
topactivity/scripting/top_activitiy.sp
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#pragma semicolon 1
|
||||||
|
#define PLUGIN_AUTHOR "jenz"
|
||||||
|
#define PLUGIN_VERSION "1.0"
|
||||||
|
#include <sourcemod>
|
||||||
|
|
||||||
|
Database g_hDatabase;
|
||||||
|
char g_cTimeRecords[18][256];
|
||||||
|
|
||||||
|
public Plugin myinfo =
|
||||||
|
{
|
||||||
|
name = "unloze top activity",
|
||||||
|
author = PLUGIN_AUTHOR,
|
||||||
|
description = "listing top activity on ze",
|
||||||
|
version = PLUGIN_VERSION,
|
||||||
|
url = "www.unloze.com"
|
||||||
|
};
|
||||||
|
|
||||||
|
public void OnPluginStart()
|
||||||
|
{
|
||||||
|
if (!g_hDatabase)
|
||||||
|
{
|
||||||
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||||
|
}
|
||||||
|
RegConsoleCmd("sm_activity", Command_topactivity, "retrieve top activity on ze for the week");
|
||||||
|
CreateTimer(1800.0, update_top_activity, _, TIMER_REPEAT);
|
||||||
|
update_top_activity_ze();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action update_top_activity(Handle timer)
|
||||||
|
{
|
||||||
|
update_top_activity_ze();
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update_top_activity_ze()
|
||||||
|
{
|
||||||
|
if (!g_hDatabase)
|
||||||
|
{
|
||||||
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char sQuery[1024];
|
||||||
|
Format(sQuery, sizeof(sQuery), "select pt.steam_id, pt.player_name, SUM(pt.ze_time) - pa.ze_time_start_week AS time_this_week from unloze_playtimestats.player_activity_ze pa inner join unloze_playtimestats.player_time pt on pa.steamid = pt.steam_id where pa.steamid not in ('STEAM_0:0:518094602', 'STEAM_0:0:204398871', 'STEAM_0:1:60189040', 'STEAM_0:0:610560766') GROUP BY pt.steam_id ORDER BY time_this_week DESC limit 15");
|
||||||
|
g_hDatabase.Query(SQL_top_activity, sQuery, DBPrio_Low);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SQL_top_activity(Database db, DBResultSet results, const char[] error, int iSerial)
|
||||||
|
{
|
||||||
|
if (!db || strlen(error))
|
||||||
|
{
|
||||||
|
delete results;
|
||||||
|
LogError("Query error: %s", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int counter = 0;
|
||||||
|
int counter_menu = 1;
|
||||||
|
Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), "Top activity: 5 days VIP");
|
||||||
|
counter++;
|
||||||
|
while (results.RowCount && results.FetchRow())
|
||||||
|
{
|
||||||
|
char sBuffer[528];
|
||||||
|
char sName[MAX_NAME_LENGTH];
|
||||||
|
results.FetchString(1, sName, sizeof(sName));
|
||||||
|
float time_this_week = results.FetchFloat(2);
|
||||||
|
|
||||||
|
int hours_server = RoundToFloor((time_this_week / 60) / 60);
|
||||||
|
int minutes_server = RoundToFloor((time_this_week / 60) % 60);
|
||||||
|
|
||||||
|
Format(sBuffer, sizeof(sBuffer), "%i %s %d Hours %d Minutes", counter_menu, sName, hours_server, minutes_server);
|
||||||
|
Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), sBuffer);
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
counter_menu++;
|
||||||
|
if (counter == 6)
|
||||||
|
{
|
||||||
|
Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), "Top activity: 3 days VIP");
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (counter == 11)
|
||||||
|
{
|
||||||
|
Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), "Top activity: 1 day VIP");
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||||
|
{
|
||||||
|
if(!db || strlen(error))
|
||||||
|
{
|
||||||
|
LogError("Database error: %s", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_hDatabase = db;
|
||||||
|
|
||||||
|
char sQuery[1024];
|
||||||
|
Format(sQuery, sizeof(sQuery), "select pt.steam_id, pt.player_name, SUM(pt.ze_time) - pa.ze_time_start_week AS time_this_week from unloze_playtimestats.player_activity_ze pa inner join unloze_playtimestats.player_time pt on pa.steamid = pt.steam_id where pa.steamid not in ('STEAM_0:0:518094602', 'STEAM_0:0:204398871', 'STEAM_0:1:60189040', 'STEAM_0:0:610560766') GROUP BY pt.steam_id ORDER BY time_this_week DESC limit 15");
|
||||||
|
g_hDatabase.Query(SQL_top_activity, sQuery, DBPrio_Low);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Command_topactivity(int client, int args)
|
||||||
|
{
|
||||||
|
if (!g_hDatabase)
|
||||||
|
{
|
||||||
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
char sTitle[64];
|
||||||
|
Format(sTitle, sizeof(sTitle), "[UNLOZE weekly activity ZE]");
|
||||||
|
Menu menu = new Menu(MenuHandler1);
|
||||||
|
menu.SetTitle(sTitle);
|
||||||
|
for (int i = 0; i < sizeof(g_cTimeRecords); i++)
|
||||||
|
{
|
||||||
|
menu.AddItem("-1", g_cTimeRecords[i], ITEMDRAW_DISABLED);
|
||||||
|
}
|
||||||
|
menu.ExitButton = true;
|
||||||
|
menu.Display(client, 0);
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
|
||||||
|
{
|
||||||
|
switch(action)
|
||||||
|
{
|
||||||
|
case MenuAction_End:
|
||||||
|
{
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClientPostAdminCheck(int client)
|
||||||
|
{
|
||||||
|
if (StrEqual(g_cTimeRecords[0], ""))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Command_topactivity(client, 0);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user