Leche Loco
Join Date: Mar 2009
Location: Argentina
|
06-10-2012
, 22:52
Re: Miniduels! + Top15 + Stats!
|
#37
|
No problem , but , i dont play tf2 some time ago , but if i'm not wrong ( maybe had more changes / updates ) the duels finish when a player disconnect , is kicked , or map changes.
EDIT: Try this
PHP Code:
/* Copyright © 2012, lucas_7_94
'MiniDuels!' is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 'MiniDuels!'; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
///////////////////////////////////////////////////////////////////////////////////
I want to send a greeting to a friend of this forum
that according to information, he died in an accident, L//, may he rest in peace.
*/
#include < amxmisc >
#include < fakemeta_util >
#include < cstrike >
#include < sqlx >
#include < hamsandwich >
#pragma semicolon 1
#define ROUNDS 10
new bool:bPlayerDueling[ 33 ] , gPlayerTeam[ 33 ] ,CountOfKills[ 2 ], gDuelPlayers[ 33 ];
new gDuelPlayerNames[ 2 ][ 33 ] , gMenuCallBack , gLastMapToSave[ 20 ] , szSteamID[ 2 ][ 33 ];
new bool:gPlayerInTheDatabase[ 33 ] , gWinCount[ 33 ] , gLosesCount[ 33 ] , gLastPlayerPlayed[ 33 ][ 33 ];
new gLastDayPlayed[ 33 ][ 33 ] , gLastMap[ 33 ][ 20 ] , gWinTheLastDuel[ 33 ][ 33 ], Handle:gSqlTuple;
new szBuffer[ 512 ] , bool:WhoWins[ 2 ], gGlowPlayers[ 2 ], ParseColors[ 2 ][ 3 ];
new gMotd[ 2048 ], len , k;
new gTable[] = "duels";
enum
{
DUEL_SENDER,
DUEL_RECEIVER
}
public plugin_init( ) {
static const szAuthor[ ] = "Luqqas";
static const szPluginName[ ] = "MiniDuels!";
static const szVersion[ ] = "1.0";
register_plugin( szPluginName, szVersion, szAuthor );
register_clcmd( "say /duel", "clcmd_duel" );
register_clcmd("amx_kick", "cmd_amx_cvar");
get_mapname( gLastMapToSave, charsmax( gLastMapToSave ) );
gMenuCallBack = menu_makecallback( "DuelPlayerEnabled" );
register_menu("Duel Stats", MENU_KEY_1, "Duel_Stats");
register_clcmd( "say /duelstats", "clcmd_duelstats" );
register_forward( FM_AddToFullPack , "func_AddToFullPack", 1 );
register_event( "DeathMsg" , "OnDeathMsg" , "a" );
register_event("TeamInfo", "join_spect", "a", "2=SPECTATOR" );
register_event( "30" , "event_intermission" , "a" );
RegisterHam(Ham_Spawn, "player", "PlayerSpawn", 1);
gGlowPlayers[ 0 ] = register_cvar( "dl_tt_glow", "255000000" );
gGlowPlayers[ 1 ] = register_cvar( "dl_ct_glow", "000000255" );
/* SQL Data */
static szHost[] = "";
static szUser[] = "";
static szPass[] = "";
static szDB[] = "";
gSqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
/* END SQL Data */
register_cvar("dl_version", szVersion, FCVAR_SERVER|FCVAR_SPONLY);
// Check if the table exists!
set_task(2.0, "CheckTableIfExists");
// Multilang
register_dictionary( "MiniDuelsML.txt" );
}
public cmd_amx_cvar( id )
{
if( access( id, ADMIN_ADMIN ) )
{
new get_kicked[ 32 ], playerindex, szName[ 32 ];
read_argv( 1, get_kicked, 31 );
new player = cmd_target( id, get_kicked ,9 );
if( !player )
return PLUGIN_HANDLED;
get_user_name( player, szName, 31 );
playerindex = get_user_index( szName );
if( bPlayerDueling[ playerindex ] ) // One of the dueler's kicked ... :(
{
client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_PLAYERKICKED", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ]);
bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
CountOfKills[ 0 ] = CountOfKills[ 1 ] = 0;
}
}
return PLUGIN_CONTINUE;
}
public client_putinserver( id )
{
for( k = 0 ; k < 2 ; k++ )
gDuelPlayerNames[ k ][ id ] = EOS;
if( !is_user_bot( id ) )
CheckIfPlayerIsInDb( id );
gLastPlayerPlayed[ id ][ 0 ] = gLastDayPlayed[ id ][ 0 ] = gLastMap[ id ][ 0 ] = gWinTheLastDuel[ id ][ 0 ] = EOS;
}
public PlayerSpawn(id)
{
if ( !is_user_alive( id ) )
return HAM_IGNORED;
if( bPlayerDueling[ id ] && ( cs_get_user_team( gDuelPlayers[ DUEL_SENDER ] ) == cs_get_user_team( gDuelPlayers[ DUEL_RECEIVER ] ) ) ) // possible bug ? ok , duel closed.
{
client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_CANCELLED", gDuelPlayerNames[ 0 ] , gDuelPlayerNames[ 1 ]);
bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
CountOfKills[ 0 ] = CountOfKills[ 1 ] = 0;
}
new color[10];
for( k = 0 ; k < 2 ; k++ )
{
get_pcvar_string( gGlowPlayers[ k ], color, 9);
new strtonum = str_to_num(color);
ParseColors[ k ][ 0 ] = str_to_num(color) / 1000000;
strtonum %= 1000000;
ParseColors[ k ][ 1 ] = strtonum / 1000;
ParseColors[ k ][ 2 ] = strtonum % 1000;
#pragma unused strtonum
}
return HAM_IGNORED;
}
public join_spect( )
{
new id = read_data( 1 );
if( bPlayerDueling[ id ] )
{
client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_CHANGETOSPECT", (gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ] , (gDuelPlayers[ DUEL_RECEIVER ] == id) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ] );
WhoWins[ 0 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? false : true;
WhoWins[ 1 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? true : false;
Save_Db( WhoWins );
bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
}
}
public event_intermission( )
{
if( !bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] && !bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] ) return;
if( CountOfKills[ 0 ] == CountOfKills[ 1 ] )
client_print(0, print_chat, "%L", LANG_PLAYER, "MD_TIE", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ]);
else
{
static result;
result = CountOfKills[ 0 ] > CountOfKills[ 1 ];
client_print(0, print_chat, "%L", LANG_PLAYER, "MD_WIN",
( result ) ? gDuelPlayerNames[ 0 ] : gDuelPlayerNames[ 1 ],
( result ) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ],
( result ) ? CountOfKills[ 0 ] : CountOfKills[ 1 ],
( result ) ? CountOfKills[ 1 ] : CountOfKills[ 0 ]);
WhoWins[ 0 ] = ( result ) ? true : false;
WhoWins[ 1 ] = ( result ) ? false : true;
Save_Db( WhoWins );
}
}
public OnDeathMsg()
{
new killer = read_data( 1 );
new victim = read_data( 2 );
if ( !killer || killer == victim )
return;
if( bPlayerDueling[ killer ] && bPlayerDueling[ victim ] ) // DUEL HERE SIRS!
{
if( CountOfKills[ 0 ] >= ROUNDS || CountOfKills[ 1 ] >= ROUNDS )
{
// BETA NO TESTED
static result;
result = CountOfKills[ 0 ] > CountOfKills[ 1 ];
client_print(0, print_chat, "%L", LANG_PLAYER, "MD_WIN",
( result ) ? gDuelPlayerNames[ 0 ] : gDuelPlayerNames[ 1 ],
( result ) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ],
( result ) ? CountOfKills[ 0 ] : CountOfKills[ 1 ],
( result ) ? CountOfKills[ 1 ] : CountOfKills[ 0 ]);
WhoWins[ 0 ] = ( result ) ? true : false;
WhoWins[ 1 ] = ( result ) ? false : true;
Save_Db( WhoWins );
bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
// NO TESTED
}
else
{
( gDuelPlayers[ DUEL_SENDER ] == killer ) ? CountOfKills[ 0 ]++ : CountOfKills[ 1 ]++;
client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_STATUSDUEL", gDuelPlayerNames[ 0 ], CountOfKills[ 0 ] , gDuelPlayerNames[ 1 ], CountOfKills[ 1 ] );
}
}
}
public client_disconnect( id )
{
if( !bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] && !bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] )
return;
client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_PLAYERLEAVESERVER",
( gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[1] : gDuelPlayerNames[0],
( gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[0] : gDuelPlayerNames[1] );
WhoWins[ 0 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? false : true;
WhoWins[ 1 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? true : false;
Save_Db( WhoWins );
bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
return;
}
public clcmd_duel( id )
{
if( bPlayerDueling[ id ] )
{
client_print( id , print_chat, "%L" , id, "MD_INDUEL");
return PLUGIN_HANDLED;
}
if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR || cs_get_user_team( id ) == CS_TEAM_UNASSIGNED )
return PLUGIN_HANDLED;
static title[250];
formatex( title , charsmax(title) , "%L", id, "MD_MENUTITLE" );
new menu = menu_create( title , "Duel_Handled" );
new players[ 32 ], pnum, tempid;
new szName[ 32 ], szTempid[ 10 ];
get_players( players, pnum );
for( new i ; i < pnum ; i++ )
{
tempid = players[ i ];
if( get_user_team( tempid ) == get_user_team( id ) || cs_get_user_team( tempid ) == CS_TEAM_SPECTATOR )
continue;
get_user_name( tempid, szName, charsmax( szName ) );
num_to_str( tempid, szTempid, charsmax( szTempid ) );
menu_additem( menu, szName, szTempid, 0 , gMenuCallBack );
}
menu_display( id, menu, 0 );
return PLUGIN_HANDLED;
}
public DuelPlayerEnabled(id, menu, item)
{
new data[ 6 ], szName[ 64 ];
new access, callback;
menu_item_getinfo( menu, item, access, data,charsmax(data), szName,charsmax(szName), callback );
new tempid = str_to_num( data );
if( bPlayerDueling[ tempid ] )
return ITEM_DISABLED;
return ITEM_ENABLED;
}
public Duel_Handled(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[ 6 ], szName[ 64 ];
new access, callback;
menu_item_getinfo( menu, item, access, data,charsmax( data ), szName,charsmax( szName ), callback );
new tempid = str_to_num( data );
if( bPlayerDueling[ tempid ] )
{
client_print(id, print_chat, "%L", id , "MD_CANTINVITE");
clcmd_duel( id );
return PLUGIN_HANDLED;
}
gDuelPlayers[ DUEL_SENDER ] = id;
gDuelPlayers[ DUEL_RECEIVER ] = tempid;
get_user_name( gDuelPlayers[ DUEL_RECEIVER ], gDuelPlayerNames[ 1 ], charsmax( gDuelPlayerNames[ ] ) );
get_user_name( gDuelPlayers[ DUEL_SENDER ] , gDuelPlayerNames[ 0 ], charsmax( gDuelPlayerNames[ ] ) );
client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_SENDINVITATION", gDuelPlayerNames[ 0 ] , gDuelPlayerNames[ 1 ]);
receive_menu_duel( gDuelPlayers[ DUEL_RECEIVER ] );
return PLUGIN_HANDLED;
}
receive_menu_duel( const Receiver )
{
static buffer[ 65 ], szOptions[ 2 ][ 100 ];
formatex( buffer, sizeof( buffer ) - 1 , "%L", Receiver, "MD_RECEIVEINVITATION", gDuelPlayerNames[ 0 ] ) ;
new menu = menu_create( buffer , "Receive_Handled");
formatex( szOptions[ 0 ] , charsmax( szOptions[ ] ), "%L", Receiver, "MD_ACCEPTDUEL" );
formatex( szOptions[ 1 ] , charsmax( szOptions[ ] ), "%L", Receiver, "MD_CANCELDUEL" );
menu_additem( menu, szOptions[ 0 ], "1", 0 );
menu_additem( menu, szOptions[ 1 ], "2", 0 );
menu_setprop( menu, MPROP_EXIT, MEXIT_NEVER );
menu_display( Receiver , menu, 0 );
return;
}
public Receive_Handled(id, menu, item)
{
new data[ 6 ], szName[ 64 ];
new access, callback;
menu_item_getinfo( menu, item, access, data,charsmax(data), szName,charsmax(szName), callback );
new key = str_to_num( data );
if( bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] )
{
client_print(id, print_chat, "%L", id , "MD_CANTINVITE" );
return PLUGIN_HANDLED;
}
switch(key)
{
case 1:
{
client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_DUELACCEPTED", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ] );
bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = true;
gPlayerTeam[ gDuelPlayers[ DUEL_SENDER ] ] = _:cs_get_user_team( gDuelPlayers[ DUEL_SENDER ] );
gPlayerTeam[ gDuelPlayers[ DUEL_RECEIVER ] ] = _:cs_get_user_team( gDuelPlayers[ DUEL_RECEIVER ] );
get_user_authid( gDuelPlayers[ DUEL_SENDER ], szSteamID[ 0 ] , 32 );
get_user_authid( gDuelPlayers[ DUEL_RECEIVER ], szSteamID[ 1 ] , 32 );
}
case 2:
{
client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_DUELCANCELLED", gDuelPlayerNames[ 1 ], gDuelPlayerNames[ 0 ] );
gDuelPlayers[DUEL_SENDER] = gDuelPlayers[id] = EOS;
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public func_AddToFullPack(es, e, ent, host, hostflags, player, pSet)
{
if( !player || !pev_valid( ent ) || !get_orig_retval( ) || host == ent )
return FMRES_IGNORED;
if( bPlayerDueling[ host ] && bPlayerDueling[ ent ] )
{
set_es( es , ES_RenderFx, kRenderFxGlowShell );
switch( gPlayerTeam[ ( host ) ? host : ent ] )
{
case CS_TEAM_T:set_es( es , ES_RenderColor, ParseColors[ 0 ][ 0 ], ParseColors[ 0 ][ 1 ] , ParseColors[ 0 ][ 0 ] );
case CS_TEAM_CT:set_es( es , ES_RenderColor, ParseColors[ 1 ][ 0 ], ParseColors[ 1 ][ 1 ] , ParseColors[ 1 ][ 0 ] );
}
switch( gPlayerTeam[ ent ] )
{
case CS_TEAM_T:set_es( es , ES_RenderColor, ParseColors[ 0 ][ 0 ], ParseColors[ 0 ][ 1 ] , ParseColors[ 0 ][ 0 ] );
case CS_TEAM_CT:set_es( es , ES_RenderColor, ParseColors[ 1 ][ 0 ], ParseColors[ 1 ][ 1 ] , ParseColors[ 1 ][ 0 ] );
}
set_es( es , ES_RenderAmt, 25 );
}
return FMRES_IGNORED;
}
CheckIfPlayerIsInDb( id )
{
static iData[ 1 ];
static szSteamid[33];
get_user_authid( id , szSteamid , 32 );
szBuffer[ 0 ] = EOS ;
formatex( szBuffer , 511 , "SELECT * FROM %s WHERE steam = '%s'", gTable, szSteamid );
iData[ 0 ] = id ;
SQL_ThreadQuery( gSqlTuple, "CheckPlayer", szBuffer , iData, 1 );
}
public CheckPlayer( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
{
if( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", Error );
return;
}
else
{
new id = Data[ 0 ];
if( SQL_NumResults( Query ) < 1 )
{
gPlayerInTheDatabase[ id ] = false;
}
else
{
gPlayerInTheDatabase[ id ] = true;
SQL_ReadResult( Query, 2 , gLastPlayerPlayed[ id ] , charsmax( gLastPlayerPlayed[ ] ));
SQL_ReadResult( Query, 3 , gWinTheLastDuel[ id ] , charsmax( gWinTheLastDuel[ ] ) );
SQL_ReadResult( Query, 4 , gLastMap[ id ] , charsmax( gLastMap[ ] ));
SQL_ReadResult( Query, 5 , gLastDayPlayed[ id ] , charsmax( gLastDayPlayed[ ] ));
gWinCount[ id ] = SQL_ReadResult( Query, 6 );
gLosesCount[ id ] = SQL_ReadResult( Query, 7 );
}
}
}
public clcmd_duelstats( id )
{
static szTitle[ 90 ];
formatex( szTitle, charsmax( szTitle ) , "%L", id, "MD_STATSTITLE2" );
new menu = menu_create( szTitle, "DuelStats_Handled" );
new players[ 32 ], pnum, tempid;
new szName[ 32 ], szTempid[ 10 ];
get_players( players, pnum );
for( new i ; i < pnum ; i++ )
{
tempid = players[ i ];
get_user_name( tempid, szName, charsmax( szName ) );
num_to_str( tempid, szTempid, charsmax( szTempid ) );
menu_additem( menu, szName, szTempid );
}
menu_display( id, menu, 0 );
}
public DuelStats_Handled(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[ 6 ], szName[ 64 ];
new access, callback;
menu_item_getinfo( menu, item, access, data,charsmax( data ), szName,charsmax( szName ), callback );
new tempid = str_to_num( data );
get_user_name( tempid, szName, charsmax( szName ) );
look_menu_stats( id , tempid , szName , "Duel Stats" );
return PLUGIN_HANDLED;
}
// my id , idplayer , nameplayer , menutittle
look_menu_stats( id , playertolook, const szPlayerName[] = "" , const MenuTitle[] = "" )
{
static menu[ 512 ], len;
len = 0;
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_STATSTITLE", szPlayerName );
if( !gPlayerInTheDatabase[ playertolook ] )
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_NOSTATSFOUNDED" );
else
{
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTPLAYERPLAYED", gLastPlayerPlayed[ playertolook ] );
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_WINLASTDUEL", id, gWinTheLastDuel[ playertolook ][ 0 ] == 'Y' ? "MD_YES" : "MD_NO");
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTMAPPLAYED", gLastMap[ playertolook ] );
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTDAYPLAYED", gLastDayPlayed[ playertolook ] );
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_WINCOUNT", gWinCount[ playertolook ] );
len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_LOSESCOUNT", gLosesCount[ playertolook ] );
}
len += formatex( menu[ len ], charsmax( menu ) - len, "\r1.%L^n", id, "MD_EXIT");
show_menu( id, MENU_KEY_1, menu, -1, MenuTitle );
}
public Duel_Stats( id, key )
{
return PLUGIN_HANDLED;
}
public CheckTableIfExists()
{
szBuffer[ 0 ] = EOS;
formatex( szBuffer, charsmax( szBuffer ) , "CREATE TABLE IF NOT EXISTS duels (`steam` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `LastPlayerPlayed` VARCHAR(32) NOT NULL, `WinLastGame` VARCHAR(32) NOT NULL, `LastMapPlayedInDuel` VARCHAR(32) NOT NULL, `LastDayPlayedDuel` VARCHAR(32) NOT NULL, `WinCount` INT(10) NOT NULL, `LosesCount` INT(10) NOT NULL, PRIMARY KEY (`steam`))");
SQL_ThreadQuery( gSqlTuple, "CreateTableHandle", szBuffer );
}
public CreateTableHandle( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
{
if( FailState )
{
log_amx( "SQL Error: %s (%d)", Error, Errcode );
return PLUGIN_HANDLED;
}
szBuffer[ 0 ] = EOS;
formatex( szBuffer, charsmax( szBuffer ), "SELECT * FROM `%s` ORDER BY WinCount DESC, LosesCount DESC LIMIT 15;", gTable );
SQL_ThreadQuery( gSqlTuple, "duel_top", szBuffer );
return PLUGIN_CONTINUE;
}
public duel_top( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
{
if( FailState )
{
log_amx( "SQL Error: %s (%d)", Error, Errcode );
return PLUGIN_HANDLED;
}
if( SQL_NumResults( Query ) > 1 )
{
register_clcmd( "say /topduels" , "clcmd_topduels" );
new Name[ 64 ], steam[ 64 ];
k = 0;
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<meta charset=UTF-8><style>body{color:#FFFFFF;background-color:black;margin-top:5;font-family:arial}table{border-collapse:separate;border-spacing:1px;text-align:left;}" );
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "td{font-size:15px;}</style>" );
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<table border=1 width=700>" );
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "%s","<br><tr bgcolor=##ffffff><td> #<td> Name<td> Steam<td>Win Count<td>Loses Count</tr>");
new isteam = SQL_FieldNameToNum( Query, "steam" );
new iname = SQL_FieldNameToNum( Query, "name" );
new iwincount = SQL_FieldNameToNum( Query, "WinCount" );
new ilosescount = SQL_FieldNameToNum( Query, "LosesCount" );
while ( SQL_MoreResults( Query ) )
{
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "%s%d", (++k != 1) ? "<tr><td>" : "<tr bgcolor=#00ff00><td>", k);
SQL_ReadResult(Query, iname, Name, charsmax(Name));
SQL_ReadResult(Query, isteam, steam, charsmax(steam));
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%-22.22s", Name );
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%-22.22s", steam );
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%d", SQL_ReadResult( Query, iwincount ) );
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%d", SQL_ReadResult( Query, ilosescount ) );
SQL_NextRow( Query );
}
len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "</table></font>" );
}
return PLUGIN_HANDLED;
}
public clcmd_topduels( id ) show_motd( id, gMotd , "Duel Stats!" );
Save_Db( const Winner[] )
{
static Player1, Player2;
Player1 = gDuelPlayers[ DUEL_SENDER ];
Player2 = gDuelPlayers[ DUEL_RECEIVER ]; // index of players
static Query[ 2 ][ 1024 ], gTime[18];
get_time( "%c", gTime , 17 );
static k, Question[ 2 ];
for( k = 0 ; k < 2 ; k++ )
{
replace_all( gDuelPlayerNames[ k ], charsmax( gDuelPlayerNames[ ] ), "`", "" );
replace_all( gDuelPlayerNames[ k ], charsmax( gDuelPlayerNames[ ] ), "'", "''" );
Question[ 0 ] = ( !k ) ? 0 : 1;
Question[ 1 ] = ( !k ) ? Player1 : Player2;
formatex( Query[ Question[ 0 ] ] , sizeof( Query[ ] ) , "%s %s SET `steam` = '%s' , `name` = '%s' , `LastPlayerPlayed` = '%s', `LastDayPlayedDuel` = '%s', `WinLastGame` = '%s', `LastmapPlayedInDuel` = '%s', `WinCount` = %s, `LosesCount` = %s",
(gPlayerInTheDatabase[ Question[ 1 ] ]) ? "UPDATE" : "INSERT INTO" ,gTable, szSteamID[ Question[ 0 ] ], gDuelPlayerNames[ Question[ 0 ] ], gDuelPlayerNames[ ( !k ) ? 1 : 0 ], gTime, (Winner[ Question[ 0 ] ] ) ? "Yes" : "No" , gLastMapToSave, (Winner[ Question[ 0 ] ] ) ? "`WinCount` + 1" : "`WinCount`" , (Winner[ Question[ 0 ] ] ) ? "`LosesCount`" : "`LosesCount` + 1");
if( gPlayerInTheDatabase[ Question[ 1 ] ] )
{
static AddBuffer[ 512 ];
formatex( AddBuffer , charsmax( AddBuffer ), " WHERE steam = '%s'", szSteamID[ Question[ 0 ] ] );
add( Query[ Question[ 0 ] ] , charsmax( Query[ ] ), AddBuffer );
}
gPlayerInTheDatabase[ Question[ 1 ] ] = true;
CountOfKills[ k ] = 0;
SQL_ThreadQuery( gSqlTuple, "SaveHandled", Query[ k ] );
}
}
public SaveHandled( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
{
if( FailState )
{
log_amx( "SQL Error: %s (%d)", Error, Errcode );
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public plugin_end()
SQL_FreeHandle( gSqlTuple );
To change max rounds , change:
Sorry , i can't test it , i use a modem 3g with proxy and i can't connect to steam to test it.
__________________
Last edited by lucas_7_94; 06-10-2012 at 23:28.
|
|