View Single Post
Author Message
Wooky_
Junior Member
Join Date: Aug 2017
Old 10-11-2017 , 12:52   Edit menu ITEMDRAW_RAWLINE
Reply With Quote #1

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<= MaxClientsi++)
    {
        if (
IsValidClient(i))
        {
            
OnClientPutInServer(i);
        }
    }
}

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint 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(clientgB_PlayerNameMAX_NAME_LENGTH);
    
    
char gB_SteamID64[32];
    if (!
GetClientAuthId(clientAuthId_SteamID64gB_SteamID6432))
    {
        
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_PlayerNamegB_EscapedNameiLength);
    
    
char gB_ClientIP[64];
    
GetClientIP(clientgB_ClientIP64);
    
    
char gB_Query[512];
    
FormatEx(gB_Query512"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_SteamID64gB_EscapedNamegB_ClientIPgB_EscapedNamegB_ClientIP);
    
gB_DBSQL.Query(SQL_InsertPlayer_CallbackgB_QueryGetClientSerial(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 menuMenuAction actionint clientint item)
{
    if (
action == MenuAction_End)
    {
        
delete menu;
    }
    
    return 
0;
}

public 
int AreYouSureHandler(Menu menuMenuAction actionint clientint item)
{
    if (
action == MenuAction_Select)
    {
        
char info[32];
        
menu.GetItem(iteminfo32);
        
        if (
StrEqual(info"yes"))
        {
            
int target GetClientFromSerial(gB_RemoveClient[client]);
            
            
char gB_SteamID64[32];
            if (!
GetClientAuthId(targetAuthId_SteamID64gB_SteamID6432))
            {
                return 
0;
            }
            
char gB_Query[512];
            
FormatEx(gB_Query512"DELETE FROM `players` WHERE `steamid` = '%s'"gB_SteamID64);
            
gB_DBSQL.Query(SQL_RemovePlayer_CallbackgB_QueryGetClientSerial(client), DBPrio_Normal);
        }
    }
    if (
action == MenuAction_End)
    {
        
delete menu;
    }
    return 
0;
}

public 
void SQL_RemovePlayer_Callback(Database dbDBResultSet results, const char[] errorany 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."PREFIXGetClientFromSerial(gB_RemoveClient[client]));
    
OnClientPutInServer(GetClientFromSerial(gB_RemoveClient[client]));
    
gB_RemoveClient[client] = 0;
}

public 
Action Cmd_Top(int clientint args)
{
    if (!
gB_EnabledTop.BoolValue)
    {
        return 
Plugin_Handled;
    }
    
    
char gB_Query[512];
    
    
FormatEx(gB_Query512"SELECT steamid, name, kills FROM `players` WHERE kills != 0 ORDER BY kills DESC LIMIT %d;"gB_TopLimit.IntValue);
    
gB_DBSQL.Query(SQL_SelectTop_CallbackgB_QueryGetClientSerial(client), DBPrio_Normal);
    
    
    return 
Plugin_Handled;
}

public 
void SQL_SelectTop_Callback(Database dbDBResultSet results, const char[] errorany 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_Title128"★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(0gS_SteamID32);
        
        
        
//Player Name
        
char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
        
results.FetchString(1gS_PlayerNameMAX_NAME_LENGTH);
        
        
//Kills
        
int gS_Kills results.FetchInt(2);
        
        
char gS_MenuContent[128];
        
Format(gS_MenuContent128"%d - %s (%d kill%s)"gS_CountgS_PlayerNamegS_KillsgS_Kills "s":"");
        
menu.AddItem(gS_SteamIDgS_MenuContentITEMDRAW_DISABLED);
    }
    
    if (!
gS_Count)
    {
        
menu.AddItem("-1""No results.");
    }
    
    
menu.ExitButton true;
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int TopHandler(Menu menuMenuAction actionint clientint item)
{
    if (
action == MenuAction_End)
    {
        
delete menu;
    }
    
    return 
0;

i re-write plugin . I want menu without number. But ITEMDRAW_RAWLINE not work..
Wooky_ is offline