The Soul
09-01-2009, 03:57 AM
First, we'll need to create this object called 'teleporting' in the server class:
public static teleporting Teleporting;
Now add this class:
import java.io.*;
public class TeleportLoader {
public int numOfTele = 0;
public int x[] = new int[500];
public int y[] = new int[500];
public int ab[] = new int[500];
public void fileLoad(String name) {
FileInputStream fstream = new FileInputStream(name);
DataInputStream in = new DataInputStream(fstream);
teleCount = 0;
while (in.available() != 0) {
String l = in.readLine();
String[] splitInfo = l.split("\t");
if(splitData[0].startsWith("teleport")) {
x[teleCount] = Integer.parseInt(splitInfo[1]);
y[teleCount] = Integer.parseInt(splitInfo[2]);
ab[teleCount] = Integer.parseInt(splitInfo[3]);
teleCount++;
}
}
}
What this does is import the io package in order to use the DataInputStream and FileInputStream classes. It also uses the arrays x, y and ab to store data. The fileLoad() method reads/parses what's being written to the arrays.
Add the method below into the client class (it doesn't matter where, as long as it isn't interfering with another method). It takes the variables 'teleportToX', 'teleportToY', and 'actionButtonId' so that they can be used within the method's parameters when invoked.
public void teleport(int x, int y, int actionButton) {
teleportToX = x;
teleportToY = y;
actionButton = actionButtonId;
}
Below uses the 'new' keyword to use the 'Teleporting' instance from 'teleporting' and loads the configuration file titled 'teleports':
Teleporting = new teleporting();
Teleporting.loadFile("./teleporting");
Under packet 185, add this:
for(int i=0; i<server.Teleporting.teleCount; i++) {
int absx = server.Teleporting.x[teleCount];
int absy = server.Teleporting.y[teleCount];
int abi = server.Teleporting.ab[teleCount];
teleport(absx,absy,abi);
}
This'll enable the teleporting action for whatever you add into the 'teleporting' configuration file. When you add anything to this file, make sure it's not already added under this packet or else you'll be disappointed.
Format of writing the teleports:
teleport=XcoordinateYcoordinateActionButtonID
Make sure you add your teleports.cfg file!
Credits: The Soul and Lin (for creating a tutorial on loading objects via configuration file, which led me to do this)
Post any errors, there probably will be some as I did this all through the initial text box.
public static teleporting Teleporting;
Now add this class:
import java.io.*;
public class TeleportLoader {
public int numOfTele = 0;
public int x[] = new int[500];
public int y[] = new int[500];
public int ab[] = new int[500];
public void fileLoad(String name) {
FileInputStream fstream = new FileInputStream(name);
DataInputStream in = new DataInputStream(fstream);
teleCount = 0;
while (in.available() != 0) {
String l = in.readLine();
String[] splitInfo = l.split("\t");
if(splitData[0].startsWith("teleport")) {
x[teleCount] = Integer.parseInt(splitInfo[1]);
y[teleCount] = Integer.parseInt(splitInfo[2]);
ab[teleCount] = Integer.parseInt(splitInfo[3]);
teleCount++;
}
}
}
What this does is import the io package in order to use the DataInputStream and FileInputStream classes. It also uses the arrays x, y and ab to store data. The fileLoad() method reads/parses what's being written to the arrays.
Add the method below into the client class (it doesn't matter where, as long as it isn't interfering with another method). It takes the variables 'teleportToX', 'teleportToY', and 'actionButtonId' so that they can be used within the method's parameters when invoked.
public void teleport(int x, int y, int actionButton) {
teleportToX = x;
teleportToY = y;
actionButton = actionButtonId;
}
Below uses the 'new' keyword to use the 'Teleporting' instance from 'teleporting' and loads the configuration file titled 'teleports':
Teleporting = new teleporting();
Teleporting.loadFile("./teleporting");
Under packet 185, add this:
for(int i=0; i<server.Teleporting.teleCount; i++) {
int absx = server.Teleporting.x[teleCount];
int absy = server.Teleporting.y[teleCount];
int abi = server.Teleporting.ab[teleCount];
teleport(absx,absy,abi);
}
This'll enable the teleporting action for whatever you add into the 'teleporting' configuration file. When you add anything to this file, make sure it's not already added under this packet or else you'll be disappointed.
Format of writing the teleports:
teleport=XcoordinateYcoordinateActionButtonID
Make sure you add your teleports.cfg file!
Credits: The Soul and Lin (for creating a tutorial on loading objects via configuration file, which led me to do this)
Post any errors, there probably will be some as I did this all through the initial text box.