AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Solved Print online players (https://forums.alliedmods.net/showthread.php?t=307664)

4ever16 05-20-2018 14:20

Print online players
 
Remove this thread

karimoo97 05-20-2018 17:27

Re: Scoreboard to MYSQL
 
GOOD NEWS: It is possible
I have already seen this 3-5 year ago in forum that hosted a tournament,
BAD NEWS: I do not remember the name of the forum and i cannot make it.

GOOD LUCK

Airkish 05-21-2018 01:57

Re: Scoreboard to MYSQL
 
Here's one I have for a long time, may not be the perfect code but it works. There's /rs because I used resetscore plugin, if u don't then just simply comment that line //.
Tell me if it works and if you need help with PHP/MySQL part.

PHP Code:

#include < amxmodx >
#include < sqlx >
#include < cstrike >
#include < hamsandwich >

/* Database */
new Host[ ] = ""
new User[ ] =  ""
new Pass[ ] =  ""
new Db[ ] =  ""

new MySQL_Query512 ]
new 
Handle:MySQL_Tuple
new Handle:MySQL_Connection
new bool:g_Loaded33 ] = false
new Kills[33], Deaths[33];
new 
Team[33]

new 
g_logfile[64];

new const 
VERSION[ ] = "0.0.1"

public plugin_init( ) {
    
register_plugin"Scoreboard to MySQL"VERSION"Airkish" )
    
register_event("HLTV""RoundStart""a""1=0""2=0");
    
register_clcmd("say /rs""ResetScore")
}

public 
client_putinserverid )
{
    
set_task(5.0"Presql_Load"id)
    
g_Loadedid ] = false
}

public 
Presql_Load(id) {
    if ( 
cs_get_user_team(id) == CS_TEAM_T) {
        
Team[id] = 1;
    }
    else if ( 
cs_get_user_team(id) == CS_TEAM_CT ) {
        
Team[id] = 2;
    }
    else {
        
Team[id] = 3;
    }
    
MySQL_Load(id)
}

public 
client_death(KillerVictimwpnindexhitplaceTK)
{
    if(
Killer == Victim) { 
        
Deaths[Killer]++; 
        
MySQL_Update(Killer);
        return 
PLUGIN_HANDLED;
    }
    
Kills[Killer]++;
    
Deaths[Victim]++;
    
MySQL_Update(Killer)
    
MySQL_Update(Victim)

    return 
PLUGIN_CONTINUE;
}

public 
ResetScore(id) {
    
Kills[id] = 0;
    
Deaths[id] = 0;
    
MySQL_Update(id);
}

public 
RoundStart() {

    new 
iPlayers[32],iNum,Players;
    
get_players(iPlayers,iNum,"ch");
    
    for(new 
iiNumi++) {
        
Players iPlayers[i];
        if(
cs_get_user_team(Players) == CS_TEAM_T) {
            
Team[Players] = 1
            MySQL_Update
(Players)
        }
        else if(
cs_get_user_team(Players) == CS_TEAM_CT) {
            
Team[Players] = 2
            MySQL_Update
(Players)
        }
        else if (
cs_get_user_team(Players) == CS_TEAM_SPECTATOR || cs_get_user_team(Players) == CS_TEAM_UNASSIGNED) {
            
Team[Players] = 3
            MySQL_Update
(Players)
        }
    }
}

public 
client_disconnectedid )
{
    if( 
g_Loadedid ] )
        
MySQL_Deleteid )
}

public 
plugin_precache( )
{
    
get_time("online_players_%Y%m%d.log"g_logfilecharsmax(g_logfile));
    
log_errors("-------------------- == --------------------");

    
MySQL_Tuple SQL_MakeDbTupleHostUserPassDb )
    
#if AMXX_VERSION_NUM >= 183
        
SQL_SetCharset(MySQL_Tuple,"utf8");
    
#endif
    
    
new ErrorCode
    MySQL_Connection 
SQL_ConnectMySQL_TupleErrorCodeMySQL_QuerycharsmaxMySQL_Query ) )
    
    if( 
MySQL_Connection == Empty_Handle )
        
set_fail_stateMySQL_Query )
    
    
SQL_ThreadQueryMySQL_Tuple"SQL_TrashHandler""CREATE TABLE IF NOT EXISTS online_players (username VARCHAR(128) COLLATE utf8_lithuanian_ci NOT NULL, kills INT(11), deaths INT(11), team INT(1) )" )  

    
SQL_ThreadQueryMySQL_Tuple"SQL_TrashHandler""DELETE FROM online_players" )  
}

public 
MySQL_Loadid 
{
    new 
Temp]
    
Temp] = id
    
    formatex
MySQL_QuerycharsmaxMySQL_Query ), "SELECT * FROM `online_players` WHERE `username` = '%s'"get_user_name_ex(id) )
    
SQL_ThreadQueryMySQL_Tuple"Load_PlayerInfo"MySQL_QueryTempsizeofTemp ) )
}
                                                                                
public 
Load_PlayerInfoFailStateHandle:QueryError[ ], ErrcodeData[ ], DataSize 
{
    if( 
FailState == TQUERY_CONNECT_FAILED 
    {
        new 
Players32 ], PlayersNum
        get_players
PlayersPlayersNum"ch" )
        
        for( new 
iPlayersNumi++ )
            
log_errors"Load - Could not connect to SQL database.  [%d] %s"ErrcodeError )
    }
            
    else if( 
FailState == TQUERY_QUERY_FAILED )
    {
        new 
Players32 ], PlayersNum
        get_players
PlayersPlayersNum"ch" )
        
        for( new 
iPlayersNumi++ )
        {
            
log_errors"Load Query failed. [%d] %s"ErrcodeError )
        }
    }
    new 
id Data]
    
    if( !
is_user_connectedid ) )
        return
        
    if( 
SQL_NumResultsQuery ) < 
    {
        
formatexMySQL_QuerycharsmaxMySQL_Query ), "INSERT INTO `online_players` (`username`, `kills`, `deaths`, `team`) VALUES ('%s', '%d', '%d', '%d')"get_user_name_ex(id), Kills[id], Deaths[id], Team[id])
        
SQL_ThreadQueryMySQL_Tuple"SQL_TrashHandler"MySQL_Query )
        
log_errors("%s"MySQL_Query)
        
g_Loadedid ] = true
    
}
}

public 
MySQL_Updateid ) {
    
formatexMySQL_QuerycharsmaxMySQL_Query ), "UPDATE `online_players` SET `kills` = '%d', `deaths` = '%d', `team` = '%d' WHERE `username` = '%s'"Kills[id], Deaths[id], Team[id], get_user_name_ex(id) )
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query);    
}

public 
MySQL_Delete( const id 
{
    
formatexMySQL_QuerycharsmaxMySQL_Query ), "DELETE from `online_players` WHERE `username` = '%s'"get_user_name_ex(id) )
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query);
}

public 
SQL_TrashHandlerFailState,Handle:QueryError[ ], Errcode,Data[ ], DataSize )  

    if( 
FailState == TQUERY_CONNECT_FAILED )
        
log_errors"Load - Could not connect to SQL database.  [%d] %s"ErrcodeError 
        
    else if( 
FailState == TQUERY_QUERY_FAILED )
        
log_errors"Load Query failed. [%d] %s"ErrcodeError )
    
    
SQL_FreeHandleQuery )
}

public 
plugin_end( ) 
{   
    
SQL_FreeHandleMySQL_Connection )
}

stock log_errors(const szText[], any:...)
{
    static 
szMessage[256];
    
vformat(szMessage256szText2);
    
    
log_to_file(g_logfileszMessage);
    
    return 
PLUGIN_HANDLED;
}

stock get_user_name_ex(id)
{
    new 
szName[33];
    
get_user_name(idszNamecharsmax(szName));

    
replace_all(szNamecharsmax(szName), "'""\'");
    
replace_all(szNamecharsmax(szName), "^"", "\^"");

    return 
szName;



4ever16 05-21-2018 09:07

Re: Scoreboard to MYSQL
 
Yes i would need html/php/mysql part :)

Can you also make 2 lines.

Terorist score: 16
Counter terrorist score: 10

GunGameR 05-23-2018 19:32

Re: Scoreboard to MYSQL
 
something like this?

http://image.prntscr.com/image/tSWf7...nCuI7jcFQw.png

4ever16 05-25-2018 17:43

Re: Scoreboard to MYSQL
 
Found one bug. When i change nickname the scoreboard doesnt change for that user. It just leaves the old one and doesnt update the user who changed the nick.

karimoo97 05-26-2018 01:00

Re: Scoreboard to MYSQL
 
Quote:

Originally Posted by GunGameR (Post 2593564)

wow,what if we put this web page in a motd and remplace the tab scoreboard with it,Tthis can allow us to have a modern scoreboard and rank icons can be added to it,just like cs go
off topic,sorry

Airkish 05-26-2018 03:10

Re: Scoreboard to MYSQL
 
Quote:

Originally Posted by 4ever16 (Post 2593859)
Found one bug. When i change nickname the scoreboard doesnt change for that user. It just leaves the old one and doesnt update the user who changed the nick.

BTW this i what i got so far. Oldschool style.

https://i.imgur.com/Sl7ZOoG.png

It's aint bug, I just forgot of nick change cuz on my server it was blocked.

Update - player's team on mysql now changes on team change event rather then roundstart.
Try this:

PHP Code:

#include < amxmodx > 
#include < sqlx > 
#include < cstrike > 
#include < hamsandwich > 

/* Database */ 
new Host[ ] = "" 
new User[ ] =  "" 
new Pass[ ] =  "" 
new Db[ ] =  "" 

new MySQL_Query512 
new 
Handle:MySQL_Tuple 
new Handle:MySQL_Connection 
new bool:g_Loaded33 ] = false 
new Kills[33], Deaths[33]; 
new 
Team[33], OldName[33][32]

new 
g_logfile[64]; 

new const 
VERSION[ ] = "0.0.2" 

public plugin_init( ) { 
    
register_plugin"Scoreboard to MySQL"VERSION"Airkish" 
    
register_clcmd("say /rs""ResetScore"
    
register_event"TeamInfo""event_team_info""a" );


public 
client_putinserverid 

    
OldName[id] = "";
    
set_task(5.0"Presql_Load"id
    
g_Loadedid ] = false 


public 
client_infochanged(id

    new 
newname[32],oldname[32
    
get_user_info(id"name"newname,31
    
get_user_name(idoldname31
    
    if(!
equali(newnameoldname))
    {
        
OldName[id] = oldname;
        
MySQL_UpdateName(id);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

public 
Presql_Load(id) { 
    if ( 
cs_get_user_team(id) == CS_TEAM_T) { 
        
Team[id] = 1
    } 
    else if ( 
cs_get_user_team(id) == CS_TEAM_CT ) { 
        
Team[id] = 2
    } 
    else { 
        
Team[id] = 3
    } 
    
MySQL_Load(id


public 
client_death(KillerVictimwpnindexhitplaceTK

    if(
Killer == Victim) {  
        
Deaths[Killer]++;  
        
MySQL_Update(Killer); 
        return 
PLUGIN_HANDLED
    } 
    
Kills[Killer]++; 
    
Deaths[Victim]++; 
    
MySQL_Update(Killer
    
MySQL_Update(Victim

    return 
PLUGIN_CONTINUE


public 
ResetScore(id) { 
    
Kills[id] = 0
    
Deaths[id] = 0
    
MySQL_Update(id); 


public 
event_team_info()
{
    new 
id read_data);
        
    new 
team[12];
    
read_data2teamsizeof team );
    
    switch( 
team[0] )
    {
        case 
'C': {
            
Team[id] = 1;
        }
        case 
'T': {
            
Team[id] = 2;
        }
        case 
'S': {
            
Team[id] = 3;
        }
    }
    
MySQL_Update(id);
}

public 
client_disconnectedid 

    
OldName[id] = "";
    if( 
g_Loadedid ] ) 
        
MySQL_Deleteid 


public 
plugin_precache( ) 

    
get_time("online_players_%Y%m%d.log"g_logfilecharsmax(g_logfile)); 
    
log_errors("-------------------- == --------------------"); 

    
MySQL_Tuple SQL_MakeDbTupleHostUserPassDb 
    
#if AMXX_VERSION_NUM >= 183 
        
SQL_SetCharset(MySQL_Tuple,"utf8"); 
    
#endif 
     
    
new ErrorCode 
    MySQL_Connection 
SQL_ConnectMySQL_TupleErrorCodeMySQL_QuerycharsmaxMySQL_Query ) ) 
     
    if( 
MySQL_Connection == Empty_Handle 
        
set_fail_stateMySQL_Query 
     
    
SQL_ThreadQueryMySQL_Tuple"SQL_TrashHandler""CREATE TABLE IF NOT EXISTS online_players (username VARCHAR(128) COLLATE utf8_lithuanian_ci NOT NULL, kills INT(11), deaths INT(11), team INT(1) )" )   

    
SQL_ThreadQueryMySQL_Tuple"SQL_TrashHandler""DELETE FROM online_players" )   


public 
MySQL_Loadid )  

    new 
Temp
    
Temp] = id 
     
    formatex
MySQL_QuerycharsmaxMySQL_Query ), "SELECT * FROM `online_players` WHERE `username` = '%s'"get_user_name_ex(id) ) 
    
SQL_ThreadQueryMySQL_Tuple"Load_PlayerInfo"MySQL_QueryTempsizeofTemp ) ) 

                                                                                 
public 
Load_PlayerInfoFailStateHandle:QueryError[ ], ErrcodeData[ ], DataSize )  

    if( 
FailState == TQUERY_CONNECT_FAILED )  
    { 
        new 
Players32 ], PlayersNum 
        get_players
PlayersPlayersNum"ch" 
         
        for( new 
iPlayersNumi++ ) 
            
log_errors"Load - Could not connect to SQL database.  [%d] %s"ErrcodeError 
    } 
             
    else if( 
FailState == TQUERY_QUERY_FAILED 
    { 
        new 
Players32 ], PlayersNum 
        get_players
PlayersPlayersNum"ch" 
         
        for( new 
iPlayersNumi++ ) 
        { 
            
log_errors"Load Query failed. [%d] %s"ErrcodeError 
        } 
    } 
    new 
id Data
     
    if( !
is_user_connectedid ) ) 
        return 
         
    if( 
SQL_NumResultsQuery ) < )  
    { 
        
formatexMySQL_QuerycharsmaxMySQL_Query ), "INSERT INTO `online_players` (`username`, `kills`, `deaths`, `team`) VALUES ('%s', '%d', '%d', '%d')"get_user_name_ex(id), Kills[id], Deaths[id], Team[id]) 
        
SQL_ThreadQueryMySQL_Tuple"SQL_TrashHandler"MySQL_Query 
        
log_errors("%s"MySQL_Query
        
g_Loadedid ] = true 
    



public 
MySQL_Updateid ) { 
    
formatexMySQL_QuerycharsmaxMySQL_Query ), "UPDATE `online_players` SET `kills` = '%d', `deaths` = '%d', `team` = '%d' WHERE `username` = '%s'"Kills[id], Deaths[id], Team[id], get_user_name_ex(id) ) 
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query);     


public 
MySQL_UpdateName(id) {
    
replace_all(OldName[id], 32"'""\'"); 
    
replace_all(OldName[id], 32"^"", "\^""); 

    
formatexMySQL_QuerycharsmaxMySQL_Query ), "UPDATE `online_players` SET `username` = '%s' WHERE `username` = '%s'"get_user_name_ex(id), OldName[id] ) 
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query);   
}

public 
MySQL_Delete( const id )  

    
formatexMySQL_QuerycharsmaxMySQL_Query ), "DELETE from `online_players` WHERE `username` = '%s'"get_user_name_ex(id) ) 
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query); 


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


public 
plugin_end( )  
{    
    
SQL_FreeHandleMySQL_Connection 


stock log_errors(const szText[], any:...) 

    static 
szMessage[256]; 
    
vformat(szMessage256szText2); 
     
    
log_to_file(g_logfileszMessage); 
     
    return 
PLUGIN_HANDLED


stock get_user_name_ex(id

    new 
szName[33]; 
    
get_user_name(idszNamecharsmax(szName)); 

    
replace_all(szNamecharsmax(szName), "'""\'"); 
    
replace_all(szNamecharsmax(szName), "^"", "\^""); 

    return 
szName



sekac 05-26-2018 06:10

Re: Scoreboard to MYSQL
 
So is it possible to have live score preview on your website with this? Useful for tournaments and such.

4ever16 05-26-2018 08:17

Re: Scoreboard to MYSQL
 
Quote:

Originally Posted by sekac (Post 2593914)
So is it possible to have live score preview on your website with this? Useful for tournaments and such.

Yes but 1.6 tournaments you ciding right? :)


All times are GMT -4. The time now is 18:00.

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