Raised This Month: $ Target: $400
 0% 

Counting and showing in MOTD


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 09-19-2011 , 06:41   Counting and showing in MOTD
Reply With Quote #1

Hey, how to count like how many times player wrote a command (would like to save it in SQL) and then show it in motd like (Should be descending order):

Name1 Count
Name2 Count
Name3 Count

like:
Reinert 9
someone 4
mememe 2


PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#define PLUGIN "Plugin name"
#define VERSION "1.0"
#define AUTHOR "reinert"

new Host[]     = "hostname"
new User[]    = "username"
new Pass[]     = "password"
new Db[]     = "database"

new Handle:g_SqlTuple
new g_Error[512]

new 
iMenuUsed[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /amenu""CmdAdminMenu")
    
    
set_task(1.0"MySql_Init")
}

public 
MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
   
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS tutorial (steamid varchar(32),exp INT(11))")

    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
       
    }
    
    
SQL_FreeHandle(Queries)
   
    
SQL_FreeHandle(SqlConnection)   
}

public 
Load_MySql(id)
{
    new 
szName[32], szTemp[512]
    
get_user_name(idszNamecharsmax(szName))
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `count` WHERE (`count`.`name` = '%s')"szName)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        new 
szName[32]
        
get_user_name(idszNamecharsmax(szName))
                    
        new 
szTemp[512]
        
        
format(szTemp,charsmax(szTemp),"INSERT INTO `count` ( `name` , `count`)VALUES ('%s','0');",szName)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
iMenuUsed[id]         = SQL_ReadResult(Query1)
    }
    return 
PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    new 
szName[32], szTemp[512]
    
get_user_name(idszNamecharsmax(szName))
    
    
format(szTemp,charsmax(szTemp),"UPDATE `count` SET `count` = '%i' WHERE `count`.`name` = '%s';",iMenuUsed[id], szName)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    return 
PLUGIN_HANDLED
}


public 
CmdAdminMenu(id)
{
    if(
get_user_flags(id) & ADMIN_MENU)
    {
        
iMenuUsed[id]+=1;
    }
}

public 
client_disconnect(id)
{
    if(
get_user_flags(id) & ADMIN_MENU)
    {
        
Save_MySql(id)
        
iMenuUsed[id] = 0;
    }
}

public 
client_putinserver(id)
{
    if(
get_user_flags(id) & ADMIN_MENU)
    {
        
Load_MySql(id)
    }
}

public 
plugin_end()
{
    
SQL_FreeHandle(g_SqlTuple)

How to get all names from SQLx and show them on MOTD.

PHP Code:
public PrintCountMotd(id)
{
    new 
MotdMAX_BUFFER_LENGTH ], NameMAX_NAME_LENGTH ], PlayerLen;

    while( ++
Player <= gMaxPlayers )
    if( 
is_user_connectedPlayer ) && get_user_flagsPlayer ) & ADMIN_KICK )
    {
        
get_user_namePlayerName32 );
        
Len += formatexMotdLen ], MAX_BUFFER_LENGTH Len 1"%d.%s/* - %d*/"PlayerName/*, iCount*/ );
    }
    
show_motdIdMotd"Admin Countings" );


Last edited by reinert; 09-19-2011 at 06:54.
reinert is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode