Thread: Loading Commands From Text File

Results 1 to 3 of 3
  1. #1 Loading Commands From Text File 
    ThatOneServer
    Guest
    [size=13pt]If you use this tutorial, please post at least a 'thank you'. It is appreciated. [/size]
    Purpose: Well, Now you can add Menu commands, Item commands, and Tele commands without restarting server. A message feature is also included

    Difficulty: 3/10

    Assumed Knowledge: C+P, how to create a folder, and

    You must add this tut: http://www.moparscape.org/smf/index....,129004.0.html


    Server Base: Cheezscape (Works On All)

    Classes Modified: Client.java

    Procedure
    Step 1: Adding the folder, and the code
    The first thing you have to do, is create the Menus folder. I believe that it is case sensitive, but please correct me.
    Create a folder called "config" in your server directory. Then add a "Commands" folder in "config".

    Now open up Client.java and add this void
    DO NOT REMOVE COPYRIGHT
    Code:
    	public void loadCommand(String command) {
    		String line = "";
    		String token = "";
    		String token2 = "";
    		String[] token3 = new String[3];
    		boolean EndOfFile = false;
    		int ReadMode = 0;
    		BufferedReader characterfile = null;
    		BufferedReader characterfile2 = null;
    		boolean File1 = false;
    		boolean File2 = false;
                    
    		try {
    			characterfile = new BufferedReader(new FileReader("./config/Commands/"+command+".txt"));
    			File1 = true;
    		} catch(FileNotFoundException fileex1) {
    		}
    File myfile1 = null;
    File myfile2 = null;
    if (File1 == true && File2 == true) {
    			myfile1 = new File ("./config/Commands/"+command+".txt");
    			myfile2 = new File ("./config/Commands/"+command+".txt");
    			if (myfile1.lastModified() < myfile2.lastModified()) {
    				characterfile = characterfile2;
    			}
    		} else if (File1 == false && File2 == true) {
    			characterfile = characterfile2;
    		} else if (File1 == false && File2 == false) {
    		}
        boolean exists = (new File("./config/Commands/"+command+".txt")).exists();
        if (exists) {
    
    	
    		try {
    			line = characterfile.readLine();
    		} catch(IOException ioexception) {
    		}
    		while(EndOfFile == false && line != null) {
    			try{
    				token = line;
    				token = token.trim();
    				token2 = line;
    				token2 = token2.trim();
    				token3 = token2.split("\t");
    				if (line.equals("[ITEMS]")) {		
    								ReadMode = 1;
    				}  else if (line.equals("[MESSAGES]")) {
                                    ReadMode = 2;
    				} else if (line.equals("[TELE]")) {
                                    ReadMode = 3;
    				} else if (line.equals("[MENU]")) {
                                    ReadMode = 4;
    				}
    								switch (ReadMode) {
    					case 1:
    						try {
    							int itemId = Integer.parseInt(token3[0]);
    							int itemAmount = Integer.parseInt(token3[1]);
    addItem(itemId, itemAmount);
    						} catch (Exception e) {
    						}
    						break;
    					case 2: 
    						try {
    							if(line.equals("[MESSAGES]")) {
    							} else {
    sendMessage(line);
    							}
    						} catch (Exception e) {
    						}
                                                    break;
    					case 3:
    						try {
    							teleportToX = Integer.parseInt(token3[0]);
    							teleportToY = Integer.parseInt(token3[1]);
    						} catch (Exception e) {
    						}
    						break;
    					case 4: 
    						try {
    							if(line.equals("[MENU]")) {
    							} else {
    loadMenu(line);
    							}
    						} catch (Exception e) {
    						}
                                                    break;
    				}
    				 if (line.equals("[END]")) {		
    					try { characterfile.close(); } catch(IOException ioexception) { } 
    				}
    			
    			try {
    				line = characterfile.readLine();
    			} catch(IOException ioexception1) { EndOfFile = true; }
    						} catch (Exception e){
    		}
    		}
    	
    		try { characterfile.close(); } catch(IOException ioexception) { }
        } else {
        }
    	}
    Step 2: Using the void and creating a menu
    You must have the Menu TXT file by me, here is the link:
    http://www.moparscape.org/smf/index....,102064.0.html

    IN the customCommand void, add
    Code:
     loadCommand(command);
    Here is an example of the file. The [MESSAGES] part must be last!

    Code:
    [ITEMS]
    995	1
    [TELE]
    3000	3000
    [MENU]
    startup
    [MESSAGES]
    Test

    [ITEMS]:
    Code:
    ItemId	ItemAmount

    [TELE]:
    Code:
    TeleX	TeleY

    [MENU]:
    Code:
    MenuName(from menu tutorial)

    [MESSAGE]:
    Code:
    sendMessage
    Credits: 100% Me

    [size=15pt]A whole bunch of commands attatched to thread[/size]
     

  2. #2  
    Real pmgz
    Guest
    Awsome tut man
     

  3. #3  
    Nathanmarck
    Guest
    wow i needed this and it gave no errors yay now to test in the game

    lol works but then well oh well
    Last edited by Nathanmarck; 05-05-2007 at 12:49 PM. Reason: Double posting is not allowed!
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Loading News/Text for a Text file to server
    By inFamous in forum Tutorials
    Replies: 36
    Last Post: 02-23-2011, 09:15 PM
  2. Some Class file that popped up when loading rsbot 574 jar file
    By Streax in forum Application Development
    Replies: 2
    Last Post: 12-15-2009, 03:05 PM
  3. Loading News/Text from file to Server
    By inFamous in forum Tutorials
    Replies: 13
    Last Post: 03-14-2009, 06:08 PM
  4. Loading Menus From Text File
    By ThatOneServer in forum Tutorials
    Replies: 3
    Last Post: 06-19-2007, 11:01 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •