AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Counting and showing in MOTD (https://forums.alliedmods.net/showthread.php?t=167722)

reinert 09-19-2011 06:41

Counting and showing in MOTD
 
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" );



joshknifer 11-15-2011 18:30

Re: Counting and showing in MOTD
 
Sorry to revive this, but I was looking into something simular, where you could take the SQL command logger plugin and have admins be able to access the data via MOTD through a command. Any suggestions?


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

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