Source Used: Shard
This is pissing me off because its so simple but only works some times.
Basicily it only works if I log on really quick If I don't the npcs don't turn to where their supposed to.
I'm trying to load which direction the npcs face from the autospawns.
I should have set everything up right.
In NPC.java I've changed it to
Code:
public NPC(int npcId, NPCDefinition definition, int absX, int absY,
int heightLevel, int faceX, int faceY) {
this.npcId = npcId;
this.definition = definition;
this.maxHP = definition.getHealth();
this.hp = definition.getHealth();
this.setAbsX(absX);
this.setAbsY(absY);
this.spawnAbsX = absX;
this.spawnAbsY = absY;
this.setHeightLevel(heightLevel);
this.faceX = faceX; // new
this.faceY = faceY; // new
this.turnNpc(); // new
}
I also added this to NPC.java along with the update flags
Code:
/**
* Turns NPC Direction
*
*/
public int focusPointX, focusPointY, faceX, faceY;
public boolean turnUpdateRequired;
public int getFaceX() {
return faceX;
}
public int getFaceY() {
return faceY;
}
public void turnNpc() {
if(faceX != -1 && faceY != -1) {
focusPointX = 2 * faceX + 1;
focusPointY = 2 * faceY + 1;
updateRequired = true;
turnUpdateRequired = true;
}
}
private void appendSetFocusDestination(Stream str) {
str.writeWordBigEndian(focusPointX);
str.writeWordBigEndian(focusPointY);
}
Npc Manager I changed it to.
Code:
private void loadSpawns(String name) throws IOException {
BufferedReader file = null;
try {
file = new BufferedReader(new FileReader(name));
while (true) {
String line = file.readLine();
if (line == null)
break;
int spot = line.indexOf('=');
if (spot > -1) {
String values = line.substring(spot + 1);
values = values.replace("\t\t", "\t");
values = values.replace("\t\t", "\t");
values = values.trim();
String[] valuesArray = values.split("\t");
int id = Integer.valueOf(valuesArray[0]);
int slot = freeSlot();
NPCDefinition def = npcDefinitions.get(id);
if (def == null)
continue;
NPC npc = new NPC(slot, def, Integer
.valueOf(valuesArray[1]), Integer
.valueOf(valuesArray[2]), Integer
.valueOf(valuesArray[3]), Integer
.valueOf(valuesArray[9]), Integer // new
.valueOf(valuesArray[10])); // new
npc.setX1(Integer.valueOf(valuesArray[4]));
npc.setY1(Integer.valueOf(valuesArray[5]));
npc.setX2(Integer.valueOf(valuesArray[6]));
npc.setY2(Integer.valueOf(valuesArray[7]));
int walkType = Integer.valueOf(valuesArray[8]);
if (walkType == 1 || walkType == 2) {
npc.setWalking(true);
}
npcMap.put(npc.getNpcId(), npc);
}
}
System.out.println("Loaded " + npcMap.size() + " npc spawns.");
} finally {
if (file != null)
file.close();
}
}
So now my spawn cfg is 2 tabs longer which should make it like this because the face cords is at the end
Code:
spawn = 1062 2511 3372 0 0 0 0 0 0 2511 3373 Soldier at home
So whats the problem and why aren't they turning properly when the server starts?