[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]:
[TELE]:
[MENU]:
Code:
MenuName(from menu tutorial)
[MESSAGE]:
Credits: 100% Me
[size=15pt]A whole bunch of commands attatched to thread[/size]