Description: Adding autospawn npc's
Difficulty: 0/10
Assumed Knowledge: none
Tested Server: cellkyborg's 474 server
Files/Classes Modified: I don't feel like listing them
Procedure
Step 1: Replace your whole npchandler with this.
Code:
package net.cellkyborg.server;
import net.cellkyborg.RSInstances.RSNPC;
import java.io.*;
public class NPCHandler {
public static int maxNPC = 10000;
public static int maxListedNPCs = 10000;
public RSNPC[] npcs = new RSNPC[maxNPC];
public NPCHandler() {
for (int i = 0; i < maxNPC; i++)
npcs[i] = null;
loadAutoSpawn("/autospawn.cfg");
}
private int getFreeSlot() {
for (int i = 1; i < maxNPC; i++)
if (npcs[i] == null)
return i;
return -1;
}
public boolean addNPC(RSNPC npc) {
int slot = getFreeSlot();
if (slot < 1)
return false;
npc.slot = slot;
npcs[slot] = npc;
return true;
}
public int GetNpcListHP(int NpcID) {
return 0;
}
public boolean loadAutoSpawn(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./"+FileName));
} catch(FileNotFoundException fileex) {
misc.println(FileName+": file not found.");
return false;
}
try {
line = characterfile.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) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token3 = token2_2.split("\t");
if (token.equals("spawn")) {
newNPC(Integer.parseInt(token3[0]), Integer.parseInt(token3[1]), Integer.parseInt(token3[2]), Integer.parseInt(token3[3]), Integer.parseInt(token3[4]), Integer.parseInt(token3[5]), Integer.parseInt(token3[6]), Integer.parseInt(token3[7]), Integer.parseInt(token3[8]), GetNpcListHP(Integer.parseInt(token3[0])));
}
} else {
if (line.equals("[ENDOFSPAWNLIST]")) {
try { characterfile.close(); } catch(IOException ioexception) { }
return true;
}
}
try {
line = characterfile.readLine();
} catch(IOException ioexception1) { EndOfFile = true; }
}
try { characterfile.close(); } catch(IOException ioexception) { }
return false;
}
boolean invul;
public boolean newNPC(int npcID, int x, int y, int heightLevel, int rangex1, int rangey1, int rangex2, int rangey2, int WalkingType, int HP) {
int slot = getFreeSlot();
if (slot < 1)
return false;
RSNPC npc = new RSNPC();
npc.npcID = npcID;
npc.location[0] = x;
npc.location[1] = y;
npc.location[2] = heightLevel;
npc.invulnerable = invul;
npc.slot = slot;
npc.mapRegion[0] = x >> 3;
npc.mapRegion[1] = y >> 3;
npc.currentLocation[0] = x - (npc.mapRegion[0] - 6) * 8;
npc.currentLocation[1] = y - (npc.mapRegion[1] - 6) * 8;
npcs[slot] = npc;
return true;
}
public boolean addNewNPC(int npcID, int x, int y, int h, boolean invul) {
int slot = getFreeSlot();
if (slot < 1)
return false;
RSNPC npc = new RSNPC();
npc.npcID = npcID;
npc.location[0] = x;
npc.location[1] = y;
npc.location[2] = h;
npc.invulnerable = invul;
npc.slot = slot;
npc.mapRegion[0] = x >> 3;
npc.mapRegion[1] = y >> 3;
npc.currentLocation[0] = x - (npc.mapRegion[0] - 6) * 8;
npc.currentLocation[1] = y - (npc.mapRegion[1] - 6) * 8;
npcs[slot] = npc;
return true;
}
public void process() {
for (int i = 1; i < maxNPC; i++) {
if (npcs[i] != null) {
npcs[i].process();
if (npcs[i].destroy) {
npcs[i] = null;
}
}
}
}
public void shutdown() {
}
}
Step 2: Make a new file called NPCList.java then paste this into it
Code:
public class NPCList {
public int npcId;
public String npcName;
public int npcCombat;
public int npcHealth;
public NPCList(int _npcId) {
npcId = _npcId;
}
}
Step 3: Go to your main server folder and create a new file called autospawn.cfg.
Step 4. Paste this into it
Code:
//------NpcID---CoordX--CoordY--Height--RangeX1-RangeY1-RangeX2-RangeY2-WalkType-Descrption
[ENDOFSPAWNLIST]
You know the drill on adding npc's ;)
Credits: Me
Comment you dirty leechers!