Newbie Spellweaver
- Joined
- Jun 3, 2008
- Messages
- 84
- Reaction score
- 13
Well I programmed this today after implementing player npc from Remixes.
I used a clean MoopleDEV source.
In netbeans if you get red squiggly lines underneither sub, change it to splitted.
Change Player NPC Name
*note* the npc's name will not look like it changed unless you CC or re-enter the map.
Add to Commands.java
Add to MapleCharacter.java
Delete Player NPC
*note* the npc will not disappear until the server is restarted.
Add to Commands.java
Add to MapleCharacter.java
I used a clean MoopleDEV source.
In netbeans if you get red squiggly lines underneither sub, change it to splitted.
Change Player NPC Name
*note* the npc's name will not look like it changed unless you CC or re-enter the map.
Add to Commands.java
Code:
else if (sub[0].equals("cplayernpc")){ //change player npc name
if(player.cPlayerNPC(sub[1],sub[2],player.getMapId())){
player.yellowMessage("Command works after a server restart.");
} else {
player.yellowMessage("The NPC "+sub[1]+" does not exist or you are not in the same map as the NPC.");
}
}
Add to MapleCharacter.java
Code:
public boolean cPlayerNPC(String originalName,String newName, int mapId){
boolean doesNPCExist = false;
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("update playernpcs set name = ? where name = ? and map = ?");
ps.setString(1, newName);
ps.setString(2, originalName);
ps.setInt(3, mapId);
if(ps.executeUpdate() > 0){
doesNPCExist = true;
} else {
doesNPCExist = false;
}
con.close();
} catch (SQLException e){
}
return doesNPCExist;
}
Delete Player NPC
*note* the npc will not disappear until the server is restarted.
Add to Commands.java
Code:
else if (sub[0].equals("dplayernpc")){ //delete player npc
if(player.dPlayerNPC(sub[1],player.getMapId())){
player.yellowMessage("Command works after a server restart.");
} else {
player.yellowMessage("The NPC "+sub[1]+" does not exist or you are not in the same map as the NPC.");
}
}
Add to MapleCharacter.java
Code:
public boolean dPlayerNPC(String name, int mapId){
boolean doesNPCExist = false;
try {
PreparedStatement ps2 = DatabaseConnection.getConnection().prepareStatement("SELECT id FROM playernpcs WHERE name = ?");
ps2.setString(1, name);
ResultSet rs = ps2.executeQuery();
if (!rs.next()) {
rs.close();
ps2.close();
}
int id = rs.getInt("id");
rs.close();
ps2.close();
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("delete from playernpcs where (name = ? and map = ?)");
ps.setString(1, name);
ps.setInt(2, mapId);
if(ps.executeUpdate() > 0){
doesNPCExist = true;
ps.close();
PreparedStatement pse = DatabaseConnection.getConnection().prepareStatement("delete from playernpcs_equip where NpcId = ?");
pse.setInt(1, id);
pse.executeUpdate();
pse.close();
}
ps.close();
} catch (SQLException e) {
}
return doesNPCExist;
}
Last edited: