PHP Code:
#pragma semicolon 1
#define DEBUG
#include <sourcemod>
#include <sdktools>
#include <colors>
#include <simplestats>
#define PREFIX "[\x0B\x02NexusGaming\x01]"
// === MySQL === //
Database gB_DBSQL = null;
// === Player Stats === //
int gB_PKills[MAXPLAYERS + 1] = 0;
int gB_RemoveClient[MAXPLAYERS + 1];
// === ConVars === //
ConVar gB_PluginEnabled;
ConVar gB_MinimumPlayers;
ConVar gB_WarmUP;
ConVar gB_CountKnife;
ConVar gB_EnabledTop;
ConVar gB_TopLimit;
public Plugin myinfo =
{
name = "NexusGaming Stats",
author = "Wooky",
description = "Realy simple stats plugin.",
version = "1.0",
url = "http://steamcommunity.com/id/wooky01"
};
public void OnPluginStart()
{
RegConsoleCmd("sm_top", Cmd_Top, "Command for client to open menu with top kills x players.");
// === Events === //
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("weapon_fire", Event_WeaponFire);
HookEvent("player_hurt", Event_PlayerHurt);
// === ConVars && More === //
gB_PluginEnabled = CreateConVar("sm_ss_enabled", "1", "Sets whether or not to record stats");
gB_MinimumPlayers = CreateConVar("sm_ss_minplayers", "1", "Minimum players to start record stats");
gB_WarmUP = CreateConVar("sm_ss_warmup", "1", "Record stats while we are in warmup ?");
gB_CountKnife = CreateConVar("sm_ss_countknife", "1", "Record knife as shot when client slash ?");
gB_EnabledTop = CreateConVar("sm_ss_topenabled", "1", "Enable the menu with top players?");
gB_TopLimit = CreateConVar("sm_ss_toplimit", "10", "Amount of people to display on sm_top");
SQL_StartConnection();
AutoExecConfig(true, "stats");
for (int i = 0; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
OnClientPutInServer(i);
}
}
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("SS_GetKillsAmount", Native_GetKillsAmount);
RegPluginLibrary("stats");
return APLRes_Success;
}
public void OnClientPutInServer(int client)
{
if (!IsValidClient(client))
{
return;
}
if (!gB_PluginEnabled.BoolValue)
{
return;
}
if (gB_DBSQL == null)
{
return;
}
// Player Stuff
gB_PKills[client] = 0;
char gB_PlayerName[MAX_NAME_LENGTH];
GetClientName(client, gB_PlayerName, MAX_NAME_LENGTH);
char gB_SteamID64[32];
if (!GetClientAuthId(client, AuthId_SteamID64, gB_SteamID64, 32))
{
KickClient(client, "Verification problem , please reconnect.");
return;
}
//escaping name , dynamic array;
int iLength = ((strlen(gB_PlayerName) * 2) + 1);
char[] gB_EscapedName = new char[iLength];
gB_DBSQL.Escape(gB_PlayerName, gB_EscapedName, iLength);
char gB_ClientIP[64];
GetClientIP(client, gB_ClientIP, 64);
char gB_Query[512];
FormatEx(gB_Query, 512, "INSERT INTO `players` (`steamid`, `name`, `ip`, `lastconn`) VALUES ('%s', '%s', '%s', UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE `name` = '%s', `ip` = '%s', `lastconn` = CURRENT_TIMESTAMP();", gB_SteamID64, gB_EscapedName, gB_ClientIP, gB_EscapedName, gB_ClientIP);
gB_DBSQL.Query(SQL_InsertPlayer_Callback, gB_Query, GetClientSerial(client), DBPrio_Normal);
}
public void OnClientDisconnect(int client)
{
if (!IsValidClient(client))
{
return;
}
if (!gB_PluginEnabled.BoolValue)
{
return;
}
if (gB_DBSQL == null)
{
return;
}
}
public int Stats_MenuHandler(Menu menu, MenuAction action, int client, int item)
{
if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
public int AreYouSureHandler(Menu menu, MenuAction action, int client, int item)
{
if (action == MenuAction_Select)
{
char info[32];
menu.GetItem(item, info, 32);
if (StrEqual(info, "yes"))
{
int target = GetClientFromSerial(gB_RemoveClient[client]);
char gB_SteamID64[32];
if (!GetClientAuthId(target, AuthId_SteamID64, gB_SteamID64, 32))
{
return 0;
}
char gB_Query[512];
FormatEx(gB_Query, 512, "DELETE FROM `players` WHERE `steamid` = '%s'", gB_SteamID64);
gB_DBSQL.Query(SQL_RemovePlayer_Callback, gB_Query, GetClientSerial(client), DBPrio_Normal);
}
}
if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
public void SQL_RemovePlayer_Callback(Database db, DBResultSet results, const char[] error, any data)
{
int client = GetClientFromSerial(data);
if (results == null)
{
if (client == 0)
{
LogError("[SS] Client is not valid. Reason: %s", error);
}
else
{
LogError("[SS] Cant use client data. Reason: %s", GetClientFromSerial(gB_RemoveClient[client]), error);
}
return;
}
CPrintToChat(client, "%s You have been restarted \x07%N's\x01 stats.", PREFIX, GetClientFromSerial(gB_RemoveClient[client]));
OnClientPutInServer(GetClientFromSerial(gB_RemoveClient[client]));
gB_RemoveClient[client] = 0;
}
public Action Cmd_Top(int client, int args)
{
if (!gB_EnabledTop.BoolValue)
{
return Plugin_Handled;
}
char gB_Query[512];
FormatEx(gB_Query, 512, "SELECT steamid, name, kills FROM `players` WHERE kills != 0 ORDER BY kills DESC LIMIT %d;", gB_TopLimit.IntValue);
gB_DBSQL.Query(SQL_SelectTop_Callback, gB_Query, GetClientSerial(client), DBPrio_Normal);
return Plugin_Handled;
}
public void SQL_SelectTop_Callback(Database db, DBResultSet results, const char[] error, any data)
{
if (results == null)
{
LogError("[SS] Selecting players error. Reason: %s", error);
return;
}
int client = GetClientFromSerial(data);
if (client == 0)
{
LogError("[SS] Client is not valid. Reason: %s", error);
return;
}
Menu menu = new Menu(TopHandler);
char gS_Title[128];
Format(gS_Title, 128, "★Top %d Hráčů★", gB_TopLimit.IntValue);
menu.SetTitle(gS_Title);
int gS_Count = 0;
while (results.FetchRow())
{
gS_Count++;
//SteamID
char[] gS_SteamID = new char[32];
results.FetchString(0, gS_SteamID, 32);
//Player Name
char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
results.FetchString(1, gS_PlayerName, MAX_NAME_LENGTH);
//Kills
int gS_Kills = results.FetchInt(2);
char gS_MenuContent[128];
Format(gS_MenuContent, 128, "%d - %s (%d kill%s)", gS_Count, gS_PlayerName, gS_Kills, gS_Kills > 1 ? "s":"");
menu.AddItem(gS_SteamID, gS_MenuContent, ITEMDRAW_DISABLED);
}
if (!gS_Count)
{
menu.AddItem("-1", "No results.");
}
menu.ExitButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int TopHandler(Menu menu, MenuAction action, int client, int item)
{
if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
i re-write plugin . I want menu without number. But ITEMDRAW_RAWLINE not work..