Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 11-26-2011, 06:38 PM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

I would do something like this:

Code:
int retval = 0;
if(database.RunQuery(query, MakeAnyLenString(&query,"select `id` from `items` WHERE `classes`= '%i'", class_id), errbuf, &result))
{
	int selected_row = MakeRandomInt(0, mysql_num_rows(result) - 1);
	mysql_data_seek(result, selected_row);
	if(row = mysql_fetch_row(result))
	{
		retval = atoi(row[0]);
	}
	mysql_free_result(result);
}
return retval;
You don't want to return the result where you did, or you will leak memory because the mysql_free_result() call will be skipped.

This will return 0 if there aren't any items that match the query. You will want to check for that in whatever code you use that calls this as an error.

The query you're using is also a bit suspect. I'm not sure what the value of class_id is, but in the best case, assuming the value is (1 << (client->GetClass() - 1)) you will only select items where the class can exclusively equip them. If the value is just what GetClass() returns then it will only return valid items for a warrior or a cleric.

You probably want something like:
Code:
if(database.RunQuery(query, MakeAnyLenString(&query,"select `id` from `items` WHERE `classes` & (1 << %i)", class_id), errbuf, &result))
Where class_id = client->GetClass() - 1.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 01:08 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3