How to add "Best buy items" to XP statistics?

Want to talk about war3ft or make suggestions? Post them here

Moderator: Forum Moderator

Post Reply
User avatar
YamiKaitou
Forum Moderator
Forum Moderator
Posts: 1925
Joined: Wed Feb 01, 2006 4:33 pm
Contact:

Re: How to add "Best buy items" to XP statistics?

Post by YamiKaitou » Wed Dec 17, 2008 8:50 am

This will involve adding a bit to the code. What do you mean by "best buy items"
Image

No support via PM or Email

whosyourdaddy
Spell Breaker
Posts: 398
Joined: Sun Apr 27, 2008 10:11 pm

Re: How to add "Best buy items" to XP statistics?

Post by whosyourdaddy » Wed Dec 17, 2008 11:54 am

create a new table with values of items and how many times baught. everytime some1 buy's an item add 1 to that value. are you using mysql or sqlite?
Image

whosyourdaddy
Spell Breaker
Posts: 398
Joined: Sun Apr 27, 2008 10:11 pm

Re: How to add "Best buy items" to XP statistics?

Post by whosyourdaddy » Sat Jan 17, 2009 1:32 am

only cause u said please ill make something up are u using mysql or sqlite?
Image

whosyourdaddy
Spell Breaker
Posts: 398
Joined: Sun Apr 27, 2008 10:11 pm

Re: How to add "Best buy items" to XP statistics?

Post by whosyourdaddy » Thu Jan 22, 2009 1:15 pm

run this in ur mysql query to make the table for ur items

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;
that will create ur table

this will get the top 5 items

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)
}
this will input top 5 items in a motd

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 );

}
add this into constants.inl

Code: Select all

new UpdateBoughtItems[MAX_PLAYER_ITEM]
in items.inl do this

Code: Select all

ITEM_GiveItem( id, iItem )
{
	UpdateBoughtItems[iItem]++
in clientcommands.inl add

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)
	}
this will save the new purchased amounts into the mysql server

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;
			}
		}

}
in war3ft.sma in plugin_end() add

Code: Select all

SAVETOPITEMS()
at the bottum of

Code: Select all

DB_Close();
this should be all u need let me know how it works out
Image

User avatar
YamiKaitou
Forum Moderator
Forum Moderator
Posts: 1925
Joined: Wed Feb 01, 2006 4:33 pm
Contact:

Re: How to add "Best buy items" to XP statistics?

Post by YamiKaitou » Wed Feb 04, 2009 6:27 pm

fjollerik 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 ?
Mon Dec 03, 2007 :D

whosyourdaddy
Spell Breaker
Posts: 398
Joined: Sun Apr 27, 2008 10:11 pm

Re: How to add "Best buy items" to XP statistics?

Post by whosyourdaddy » Wed Feb 04, 2009 10:57 pm

funny thing is that im not sure if this works 100% did any1 test it out yet?
Image

Post Reply