Thread: Topic: In-Game Item ID Finder / Item Search [EPIC]

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 44
  1. #1 Topic: In-Game Item ID Finder / Item Search [EPIC] 
    MopTop
    Guest
    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.
     

  2. #2  
    Thecowman
    Guest
    Wohw thats 100% awesome, I suggest everyone adds this to there server ,

    >TCM
     

  3. #3  
    Icy Realm Owner
    Icy Whip's Avatar
    Join Date
    May 2007
    Posts
    1,419
    Thanks given
    30
    Thanks received
    35
    Rep Power
    213
    wow rep for that very nice
    [Only registered and activated users can see links. ]

    Signature made by Mr. Ervis

    Any questions, MSN me; [Only registered and activated users can see links. ]
     

  4. #4  
    Registered Member
    Eternal Darknes's Avatar
    Join Date
    Jul 2007
    Age
    27
    Posts
    384
    Thanks given
    0
    Thanks received
    0
    Rep Power
    95
    Very awesome.
    [Only registered and activated users can see links. ]

    Not allowed
     

  5. #5  
    jags 4
    Guest
    Incredible, stuff like this is taking private servers to a higher standard...REP
     

  6. #6  
    Registered Member m0nkeymadd's Avatar
    Join Date
    Oct 2007
    Age
    26
    Posts
    295
    Thanks given
    0
    Thanks received
    0
    Rep Power
    57
    Lol wow great job, people on my server are like "What is code for" good job !
    [Only registered and activated users can see links. ]
     

  7. #7  
    Z
    Z is offline
    Registered Member
    Z's Avatar
    Join Date
    Jun 2007
    Age
    26
    Posts
    1,391
    Thanks given
    6
    Thanks received
    30
    Rep Power
    853
    Holy crap, that's awsome! Great work
     

  8. #8  
    MopTop
    Guest
    Thanks everyone
     

  9. #9  
    Donator

    tj007razor's Avatar
    Join Date
    Feb 2007
    Posts
    895
    Thanks given
    2
    Thanks received
    9
    Rep Power
    210
    That is actually pretty amazing....maybe a similar concept could be applied to a G.E. if anyone decides to make it.

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ]
     

  10. #10  
    Registered Member
    Rune Arc's Avatar
    Join Date
    Nov 2007
    Age
    26
    Posts
    788
    Thanks given
    30
    Thanks received
    12
    Rep Power
    215
    sweet, i can use for npcs and objects to, ur a genius! =p
    "There is no such thing as a bad drug. Or a good drug. They don't have moral qualities. Human beings have moral qualities. There are plenty of opportunities to misuse a drug or use a drug in a bad way, that's not the drugs fault. It simply has the pharmacological chemical properties it has." - Dennis Mckenna
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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