This is the original player npc code from MapleGenesis, the first server to have player npc's working.
Advantages: Cleaner, Less Code, Run's Smoother, No stupid new classes needed.
In MaplePacketCreator.java , Make sure you have this function:
In MapleNPC.java, make sure your function looks like this:
How to use: Edit the player npc data in the database. The id is the npc id you want your player npc to use. What ever you use for the id, that is the npc id you use for your npc script. This id must be an id of a player npc. Edit the location of the player noc in the xml files. Just go to the map xml that you want, and add the npc id like you would when you edit npc's in a map normally.
Enjoy!
Advantages: Cleaner, Less Code, Run's Smoother, No stupid new classes needed.
In MaplePacketCreator.java , Make sure you have this function:
- Code:
public static MaplePacket getPlayerNPC(int id) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendPacketOpcode.PLAYER_NPC.getValue());
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
mplew.write(1);
mplew.writeInt(id);
mplew.writeMapleAsciiString(rs.getString("name"));
mplew.write(0);
mplew.write(rs.getByte("skin"));
mplew.writeInt(rs.getInt("face"));
mplew.write(0);
mplew.writeInt(rs.getInt("hair"));
}
rs.close();
ps.close();
} catch (SQLException se) {
log.info("Error loading player npc from database", se);
}
try {
PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs_equip WHERE npcid = ? AND type = 0");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
mplew.write(rs.getByte("equippos"));
mplew.writeInt(rs.getInt("equipid"));
}
rs.close();
ps.close();
} catch (SQLException se) {
log.info("Error loading player npc equips from database", se);
}
mplew.writeShort(-1);
int count = 0;
try {
PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs_equip WHERE npcid = ? AND type = 1");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
mplew.writeInt(rs.getInt("equipid"));
count += 1;
}
rs.close();
ps.close();
} catch (SQLException se) {
log.info("Error loading player npc nx equips from database", se);
}
while (count < 4) {
mplew.writeInt(0);
count += 1;
}
return mplew.getPacket();
}
In MapleNPC.java, make sure your function looks like this:
- Code:
public void sendSpawnData(MapleClient client) {
if (this.getId() >= 9010011 && this.getId() <= 9010013) {
client.getSession().write(MaplePacketCreator.spawnNPCRequestController(this, false));
} else if (this.getId() >= 9901000 && this.getId() <= 9901319) {
Connection con = (Connection) DatabaseConnection.getConnection();
try {
PreparedStatement ps = (PreparedStatement) con.prepareStatement("SELECT * FROM playernpcs WHERE id = ?");
ps.setInt(1, this.getId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
client.getSession().write(MaplePacketCreator.spawnNPCRequestController(this, true));
client.getSession().write(MaplePacketCreator.getPlayerNPC(rs.getInt("id")));
}
rs.close();
ps.close();
} catch (SQLException se) {
}
} else {
client.getSession().write(MaplePacketCreator.spawnNPC(this));
client.getSession().write(MaplePacketCreator.spawnNPCRequestController(this, true));
}
}
How to use: Edit the player npc data in the database. The id is the npc id you want your player npc to use. What ever you use for the id, that is the npc id you use for your npc script. This id must be an id of a player npc. Edit the location of the player noc in the xml files. Just go to the map xml that you want, and add the npc id like you would when you edit npc's in a map normally.
Enjoy!