Re: How to add "Best buy items" to XP statistics?
Posted: Wed Dec 17, 2008 8:50 am
This will involve adding a bit to the code. What do you mean by "best buy items"
Home to war3, war3ft, war3x and uwc3
https://wc3mods.net/forums/
Code: Select all
CREATE TABLE IF NOT EXISTS `wc3_best_item` ( `item_id` int(8) unsigned NOT NULL default '0', `times_bought` int(8) unsigned NOT NULL default '0',PRIMARY KEY (`item_id`) ) TYPE=MyISAM;
Code: Select all
TOP_5(id)
{
// Make sure our connection is working
if ( !MYSQLX_Connection_Available() )
{
return;
}
new TopItemsName[6]; i = 0
new szQuery[256],Handle:query;
format(szQuery, 255, "SELECT * FROM `wc3_best_item` ORDER BY times_bought DESC LIMIT 5; ");
query = SQL_PrepareQuery( g_DBConn, szQuery );
if ( !SQL_Execute( query ) )
{
client_print( id, print_chat, "Sql error");
MYSQLX_Error( query, szQuery, 6 );
return;
}
// Loop through all of the records to find the items data
while ( SQL_MoreResults( query ) )
{
TopItemsName[i] = SQL_ReadResult( query, 0 );
i++
SQL_NextRow( query );
}
SQL_FreeHandle( query );
MOTD_TOPITEMS(id,TopItemsName)
}
Code: Select all
MOTD_TOPITEMS(id,Topitem[6])
{
static szTmp[256], szTmp2[256], pos, i;
pos = 0;
// Add header
pos += formatex( szTmpMsg[pos], 2047-pos, "%s", MOTD_header );
// Add the item information
for ( i = 0; i < 6; i++ )
{
LANG_GetItemInfo( Topitem[i], id, szTmp, 127 );
LANG_GetItemName( Topitem[i], id, szTmp2, 127 );
pos += formatex( szTmpMsg[pos], 2047-pos, "<li>%s</li><div id='s'>%s</div><br>", szTmp, szTmp2 );
}
formatex( szTmp, 127, "Top 5 Items Bought", id);
show_motd( id, szTmpMsg, szTmp );
}
Code: Select all
new UpdateBoughtItems[MAX_PLAYER_ITEM]
Code: Select all
ITEM_GiveItem( id, iItem )
{
UpdateBoughtItems[iItem]++
Code: Select all
CMD_Handle( id, szCmd[], bool:bThroughSay )
{
// Change the user's race
if ( CMD_Equal( id, szCmd, "changerace" ) )
{
WC3_ChangeRaceStart( id );
}
// Change the user's race
else if ( CMD_Equal( id, szCmd, "top5items" ) )
{
TOP_5(id)
}
Code: Select all
SAVETOPITEMS()
{
// Make sure our connection is working
if ( !MYSQLX_Connection_Available() )
{
return;
}
new TimesBought[MAX_PLAYER_ITEM]; i = 0
new szQuery[256],Handle:query;
format(szQuery, 255, "SELECT * FROM `wc3_best_item`; ");
query = SQL_PrepareQuery( g_DBConn, szQuery );
if ( !SQL_Execute( query ) )
{
client_print( id, print_chat, "Sql error");
MYSQLX_Error( query, szQuery, 6 );
return;
}
// Loop through all of the records to find the items data
while ( SQL_MoreResults( query ) )
{
TimesBought[i] = SQL_ReadResult( query, 1 );
i++
SQL_NextRow( query );
}
SQL_FreeHandle( query );
for( new w= 0; w < MAX_PLAYER_ITEM; w++ )
if( UpdateBoughtItems[w] != 0 )
{
TimesBought[w] += UpdateBoughtItems[w]
format( szQuery, 511, "REPLACE INTO `wc3_best_item` ( `item_id` , `times_bought` ) VALUES ( '%d', '%d', '%d' );", w, TimesBought[w] );
query = SQL_PrepareQuery( g_DBConn, szQuery );
if ( !SQL_Execute( query ) )
{
WC3_Log( false, "Unable to update bought items" );
MYSQLX_Error( query, szQuery, 5 );
return;
}
}
}
Code: Select all
SAVETOPITEMS()
Code: Select all
DB_Close();
Mon Dec 03, 2007fjollerik wrote:just another question.. im using XP statistics too (MySQL)
And i was thinking.. when did you guys last made an update for that one ?