Hey this was told to me by [Only registered and activated users can see links. ]
Simply it is just so u can make new npcs spawn somewhere u want them to spawn every time the server loads up,
ok first go to
src\com\rs\utils
in there ur going to add a new file called NPCSpawning.java
in there add
Code:
package com.rs.utils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.npc.NPC;
public class NPCSpawning {
/**
* Contains the custom npc spawning
*/
public static void spawnNPCS() {
/**
* NPCS
*/;
World.spawnNPC(554, new WorldTile(3091, 3502, 0), -1, true, true);
/**
* Object custom add
*/
World.spawnObject(new WorldObject(17010, 10, 0, 3154, 3484, 0), true);
}
/**
* The NPC classes.
*/
private static final Map<Integer, Class<?>> CUSTOM_NPCS = new HashMap<Integer, Class<?>>();
public static void npcSpawn() {
int size = 0;
boolean ignore = false;
try {
for (String string : FileUtilities
.readFile("data/npcs/npcspawns.txt")) {
if (string.startsWith("//") || string.equals("")) {
continue;
}
if (string.contains("/*")) {
ignore = true;
continue;
}
if (ignore) {
if (string.contains("*/")) {
ignore = false;
}
continue;
}
String[] spawn = string.split(" ");
@SuppressWarnings("unused")
int id = Integer.parseInt(spawn[0]), x = Integer
.parseInt(spawn[1]), y = Integer.parseInt(spawn[2]), z = Integer
.parseInt(spawn[3]), faceDir = Integer
.parseInt(spawn[4]);
NPC npc = null;
Class<?> npcHandler = CUSTOM_NPCS.get(id);
if (npcHandler == null) {
npc = new NPC(id, new WorldTile(x, y, z), -1, true, false);
} else {
npc = (NPC) npcHandler.getConstructor(int.class)
.newInstance(id);
}
if (npc != null) {
WorldTile spawnLoc = new WorldTile(x, y, z);
npc.setLocation(spawnLoc);
World.spawnNPC(npc.getId(), spawnLoc, -1, true, false);
size++;
}
}
} catch (NumberFormatException e1) {
e1.printStackTrace();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
}
System.err.println("Loaded " + size + " custom npc spawns!");
}
}
then your going to add another file called FileUtilities.java
in it add this
Code:
package com.rs.utils;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.LinkedList;
/**
* @author 'Mystic Flow
*/
public class FileUtilities {
public static final int BUFFER = 1024;
public static boolean exists(String name) {
File file = new File(name);
return file.exists();
}
public static ByteBuffer fileBuffer(String name) throws IOException {
File file = new File(name);
if(!file.exists())
return null;
FileInputStream in = new FileInputStream(name);
byte[] data = new byte[BUFFER];
int read;
try {
ByteBuffer buffer = ByteBuffer.allocate(in.available() + 1);
while ((read = in.read(data, 0, BUFFER)) != -1) {
buffer.put(data, 0, read);
}
buffer.flip();
return buffer;
} finally {
if (in != null)
in.close();
in = null;
}
}
public static void writeBufferToFile(String name, ByteBuffer buffer) throws IOException {
File file = new File(name);
if(!file.exists())
file.createNewFile();
FileOutputStream out = new FileOutputStream(name);
out.write(buffer.array(), 0, buffer.remaining());
out.flush();
out.close();
}
public static LinkedList<String> readFile(String directory) throws IOException {
LinkedList<String> fileLines = new LinkedList<String>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(directory));
String string;
while ((string = reader.readLine()) != null) {
fileLines.add(string);
}
} finally {
if (reader != null) {
reader.close();
reader = null;
}
}
return fileLines;
}
}
then open Launcher.java and look for
Code:
ServerChannelHandler.init();
under that add
Code:
NPCSpawning.spawnNPCS();
and in launcher add this
Code:
import com.rs.utils.NPCSpawning;
then go back to NPCSpawning and where it says
Code:
public static void spawnNPCS() {
/**
* NPCS
*/
under it is
Code:
World.spawnNPC(554, new WorldTile(3091, 3502, 0), -1, true, true);
now thats ur npc so the 554 is the npc id and (3091, 3502, 0) is coords and true is if it walks or stays still so true walks false stays still!