Page 1 of 1

[HELP] item check issue

Posted: Mon Jun 28, 2010 8:56 pm
by rychoo84
L2J Revision n/a:
L2JDP Revision n/a:
Hi again,
Let's say I have such part of code, where I'm checking for an item DEFINED in config file:

Code: Select all

 if(player.getInventory().getItemByItemId(Config.NEEDED_ITEM) == null) {player.sendMessage("You run out of " + //and bump... );	return;} 
Is it possible to check for player's item names without "looking" into his inventory? (I won't even try -> an obvious nullpointer will appear IMHO)

I can get that item name from DB, but the questions are:
1. Is it effective?
2. How to pull out a single string from DB, let's say I have a custom method like this:

Code: Select all

 public final String GetItemNameFromDB(){	String itemName = new String();	try	{		Connection conn = L2DatabaseFactory.getInstance().getConnection();		PreparedStatement statement =  conn.prepareStatement("SELECT name FROM etcitem WHERE item_id = " + Config.NEEDED_ITEM);		ResultSet rset = statement.executeQuery(); 		itemName = //... now, how to get that string? 		conn.close();		statement.close();	}	catch(SQLException e)	{		e.printStackTrace();	}	return itemName;} 
If I'm doing it completely wrong please give me a hint how to catch up with it.
Thx in advance
Tom
P.S. If my topic doesn't fit into this venue, pls move it (I need to earn the rights to post in Custom Section) Sorry and Thank You!

Re: [HELP] item check issue

Posted: Mon Jun 28, 2010 9:07 pm
by JIV
check com.l2jserver.gameserver.datatables.ItemTable.getTemplate(int id) method.

Re: [HELP] item check issue

Posted: Thu Jul 08, 2010 11:30 am
by rychoo84
thx JIV,
I had some probs with that method you mentioned about, but now everything is clear to me (eureka step by step) - since getTemplate(int id) method is non-static I needed to create a new instance of ItemTable class and refer through it to that non-static method getTemplate(int id) - something like this:

Code: Select all

 ItemTable xxx = new ItemTable();  //needed to change also the ItemTable constructor to publicxxx.getTemplate(Config.SCHEME_BUFF_CURRENCY).getName(); 
Instead of this I did it as follow:

Code: Select all

 ItemTable.getInstance().createDummyItem(Config.SCHEME_BUFF_CURRENCY).getName(); 
But here I'm doing the same thing as above + an extra usage of memory for dummy item w/o changing the visibility of class constructor...

Concluding I finally got it (i guess):

Code: Select all

 ItemTable.getInstance().getTemplate(Config.SCHEME_BUFF_CURRENCY).getName() 
Correct me if I'm wrong, sorry for this bunch of "personal thoughts" and thx again JIV

Re: [HELP] item check issue

Posted: Thu Jul 08, 2010 11:35 am
by JIV

Code: Select all

ItemTable.getInstance().getTemplate(Config.SCHEME_BUFF_CURRENCY).getName()
is correct and do not create new instance of itemtable.