[HELP] item check issue

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
rychoo84
Posts: 58
Joined: Fri Jan 01, 2010 11:26 am
Location: Breslau

[HELP] item check issue

Post 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!
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

Re: [HELP] item check issue

Post by JIV »

check com.l2jserver.gameserver.datatables.ItemTable.getTemplate(int id) method.
User avatar
rychoo84
Posts: 58
Joined: Fri Jan 01, 2010 11:26 am
Location: Breslau

Re: [HELP] item check issue

Post 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
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

Re: [HELP] item check issue

Post by JIV »

Code: Select all

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