Ok, I've noticed that in servers with pickup enabled, people are CONSTANTLY asking "what's the Id for this, what's the ID for that", etc. It's annoying right?
So I've created this - it's a command that searches your item.cfg for item's who's name matches their search query!
Screenshots!

Note that this works on Moparscape AND Silabsoft servers!
So first, we need to load the item list!
Code:
public String[] ItemSearchArray = new String[20000];
public String[] ItemIdArray = new String[20000];
public boolean loaditemsearch(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String itemname = "";
String[] token3 = new String[10];
int sitemd = 0;
boolean EndOfFile = false;
int ReadMode = 0;
BufferedReader itemsearchfile = null;
try {
itemsearchfile = new BufferedReader(new FileReader("./" + FileName));
} catch (FileNotFoundException fileex) {
misc.println(FileName + ": file not found.");
return false;
}
try {
line = itemsearchfile.readLine();
} catch (IOException ioexception) {
misc.println(FileName + ": error loading file.");
return false;
}
while (EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token3 = line.split("\t");
itemname = token3[1].replaceAll("_", " ");
//The item name is now in itemname
//get it's id....
token3=line.split(" = ");
token3=token3[1].split("\t");
sitemd=Integer.parseInt(token3[0]);
ItemSearchArray[sitemd]=itemname;
//misc.println("Item ID: " + sitemd + ", Name: " + itemname);
} else {
if (line.equals("[ENDOFITEMLIST]")) {
try {
itemsearchfile.close();
} catch (IOException ioexception) {}
return true;
}
}
try {
line = itemsearchfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
try {
itemsearchfile.close();
} catch (IOException ioexception) {}
return false;
}
What does that do!? It loads the item list, from your specified file path, and puts the item names & ids in an array, for later searching!
So now you need to put it in a place that will load it on a connection. I put it at the end of the public client function (what's the proper name from this? I don't know.) Anyways, it starts with the code
Code:
public client(java.net.Socket s, int _playerId) {
And and the end of it, add
Code:
loaditemsearch("item.cfg");
and be sure to replace item.cfg with the name or path of your item.cfg!
So now, the actual command.
Somewhere in your commands area of code, you need to add
Code:
if(command.startsWith("itemsearch")) {
try {
String searchquery = command.substring(11);
sendQuest("Search Query - \"" + searchquery + "\"", 8144); // Title
clearQuestInterface();
int idstart=8145;
int searchhits=0;
String prefix="";
int moparmode=0; /* *************** 0 for silab servers, 1 for mopar server! *************** */
for (int i = 0; i < ItemSearchArray.length; i++) {
try {
if(countOccurrences(ItemSearchArray[i].toLowerCase(), searchquery.toLowerCase())>0) {
if(moparmode==0) {
if (i<10) { prefix="0000"; }
else if(i<100) { prefix="000"; }
else if(i<1000) { prefix="00"; }
else if(i<=10000) { prefix="0"; }
else { prefix=""; }
} else {
if (i<10) { prefix="000"; }
else if(i<100) { prefix="00"; }
else if(i<1000) { prefix="0"; }
else { prefix=""; }
}
sendQuest("ID #" + prefix + String.valueOf(i) + " - " + ItemSearchArray[i], idstart);
idstart++;
searchhits++;
if(idstart>=8194) {
break;
}
}
} catch (Exception e) {}
}
if(searchhits==0) {
prefix="None";
} else {
prefix=String.valueOf(searchhits);
}
sendQuest("@[email protected] Results: " + prefix, idstart);
sendQuestSomething(8143);
showInterface(8134);
flushOutStream();
} catch (Exception e) { sendMessage("Usage: ::itemsearch godsword"); }
}
Make sure you edit int moparmode=0; ! If your server uses the "Mopar items", set it to 1, if your server uses "Silab items", set it to 0. This changes how many digits the ID's are shown as, so they are the proper length for the pickup command.
Lastly, you need to add this static int somewhere!
Code:
static int countOccurrences(String sBig, String sSub) {
int nMainIndex = 0;
int nMatches = 0;
do {
if (sBig.substring(nMainIndex, nMainIndex + sSub.length()).equals(sSub)) {
nMatches++;
}
} while (nMainIndex++ < (sBig.length() - sSub.length()));
return nMatches;
}
That function counts the occurrences of a substring in a string. It's used to count results.
Credits
Coding: 100% Me, except:
countOccurrences Function: Joeldi
Enjoy! I hope this helps you all.