In AdminCommand.java or w/e:
!pmob
!pnpcPHP Code:} else if (splitted[0].equals("pmob")) {
int npcId = Integer.parseInt(splitted[1]);
int mobTime = Integer.parseInt(splitted[2]);
if (splitted[2] == null) {
mobTime = 0;
}
int xpos = player.getPosition().x;
int ypos = player.getPosition().y;
int fh = player.getMap().getFootholds().findBelow(player.getPosition()).getId();
MapleMonster mob = MapleLifeFactory.getMonster(npcId);
if (mob != null && !mob.getName().equals("MISSINGNO")) {
mob.setPosition(player.getPosition());
mob.setCy(ypos);
mob.setRx0(xpos + 50);
mob.setRx1(xpos - 50);
mob.setFh(fh);
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO spawns ( idd, f, fh, cy, rx0, rx1, type, x, y, mid, mobtime ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
ps.setInt(1, npcId);
ps.setInt(2, 0);
ps.setInt(3, fh);
ps.setInt(4, ypos);
ps.setInt(5, xpos + 50);
ps.setInt(6, xpos - 50);
ps.setString(7, "m");
ps.setInt(8, xpos);
ps.setInt(9, ypos);
ps.setInt(10, player.getMapId());
ps.setInt(11, mobTime);
ps.executeUpdate();
} catch (SQLException e) {
player.dropMessage("Failed to save MOB to the database");
}
final Point position = mob.getPosition();
final boolean mobile = mob.isMobile();
player.getMap().addMonsterSpawn(mob.getId(), mobTime, position, mobile);
} else {
player.dropMessage("You have entered an invalid Npc-Id");
}
In MapleMapFactory.javaPHP Code:} else if (splitted[0].equals("pnpc")) {
int npcId = Integer.parseInt(splitted[1]);
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
int xpos = player.getPosition().x;
int ypos = player.getPosition().y;
int fh = player.getMap().getFootholds().findBelow(player.getPosition()).getId();
if (npc != null && !npc.getName().equals("MISSINGNO")) {
npc.setPosition(player.getPosition());
npc.setCy(ypos);
npc.setRx0(xpos + 50);
npc.setRx1(xpos - 50);
npc.setFh(fh);
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO spawns ( idd, f, fh, cy, rx0, rx1, type, x, y, mid ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
ps.setInt(1, npcId);
ps.setInt(2, 0);
ps.setInt(3, fh);
ps.setInt(4, ypos);
ps.setInt(4, ypos);
ps.setInt(5, xpos + 50);
ps.setInt(6, xpos - 50);
ps.setString(7, "n");
ps.setInt(8, xpos);
ps.setInt(9, ypos);
ps.setInt(10, player.getMapId());
ps.executeUpdate();
} catch (SQLException e) {
player.dropMessage("Failed to save NPC to the database");
}
player.getMap().addMapObject(npc);
player.getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
} else {
player.dropMessage("You have entered an invalid Npc-Id");
}
Add:
AfterPHP Code:try
{
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM spawns WHERE mid = ?");
ps.setInt(1, omapid);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
int id = rs.getInt("idd");
int f = rs.getInt("f");
boolean hide = false;
String type = rs.getString("type");
int fh = rs.getInt("fh");
int cy = rs.getInt("cy");
int rx0 = rs.getInt("rx0");
int rx1 = rs.getInt("rx1");
int x = rs.getInt("x");
int y = rs.getInt("y");
int mobTime = rs.getInt("mobtime");
AbstractLoadedMapleLife myLife = loadLife(id, f, hide, fh, cy, rx0, rx1, x, y, type);
if(type.equals("n"))
{
map.addMapObject(myLife);
}
else if (type.equals("m")) {
MapleMonster monster = (MapleMonster) myLife;
final Point position = monster.getPosition();
final boolean mobile = monster.isMobile();
map.addMonsterSpawn(monster.getId(), mobTime, position, mobile);
}
}
} catch(SQLException e) {
}
Then addPHP Code:if (mapData.getChildByPath("area") != null) {
for (MapleData area : mapData.getChildByPath("area")) {
int x1 = MapleDataTool.getInt(area.getChildByPath("x1"));
int y1 = MapleDataTool.getInt(area.getChildByPath("y1"));
int x2 = MapleDataTool.getInt(area.getChildByPath("x2"));
int y2 = MapleDataTool.getInt(area.getChildByPath("y2"));
map.addMapleArea(new Rectangle(x1, y1, (x2 - x1), (y2 - y1)));
}
}
AfterPHP Code:private AbstractLoadedMapleLife giveLife(int id, int f, boolean hide, int fh, int cy, int rx0, int rx1, int x, int y, String type) {
AbstractLoadedMapleLife myLife = MapleLifeFactory.getLife(id, type);
myLife.setCy(cy);
myLife.setF(f);
myLife.setFh(fh);
myLife.setRx0(rx0);
myLife.setRx1(rx1);
myLife.setPosition(new Point(x, y));
myLife.setHide(hide);
return myLife;
}
And here is the SQL file:PHP Code:public boolean isMapLoaded(int mapId) {
return maps.containsKey(mapId);
}
Enjoy!~PHP Code:SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for spawns
-- ----------------------------
DROP TABLE IF EXISTS `spawns`;
CREATE TABLE `spawns` (
`id` int(11) NOT NULL auto_increment,
`idd` int(11) NOT NULL,
`f` int(11) NOT NULL,
`fh` int(11) NOT NULL,
`type` varchar(1) NOT NULL,
`cy` int(11) NOT NULL,
`rx0` int(11) NOT NULL,
`rx1` int(11) NOT NULL,
`x` int(11) NOT NULL,
`y` int(11) NOT NULL,
`mobtime` int(11) default '1000',
`mid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records
-- ----------------------------



Reply With Quote

