Just a small addition to the server that may be useful to others.
When you go through a portal (like Athean Peirce house originally) the portal on the inside is not coded, so in effect the char can get stuck inside.
This little addition will attempt to automatically create the script to get back to the previous map for you.
If it detects a portal not working, it pops a yes/no NPC up, and asks if you are trying to get back to previous map. If you answer yes it will attempt to create the basic script for you. On the second attempt at the portal you 'should' get warped back to previous map.
It probably should have more checking in it, as it is open to abuse, maybe should be limited to Gm's etc.
(Written for v116 ciphra)
EDIT: just realised I missed adding the boolean to MapleCharacter.java
prvate boolean returningToMap;
PortalScriptManager.java
------------------------
add these lines to executePortalScript(.....)
after
FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, "Unhandled portal script " + portal.getScriptName() + " on map " + c.getPlayer().getMapId());
add this routine
MapleCharacter.java
-------------------
add these fields
add these routines
MaplePortal.java
--------------------
add these lines
after
final MapleMap currentmap = c.getPlayer().getMap();
before
if (!c.getPlayer().hasBlockedInventory() && (portalState || c.getPlayer().isGM())) {
Finally the NPC script:
-----------------------
Enjoy.
When you go through a portal (like Athean Peirce house originally) the portal on the inside is not coded, so in effect the char can get stuck inside.
This little addition will attempt to automatically create the script to get back to the previous map for you.
If it detects a portal not working, it pops a yes/no NPC up, and asks if you are trying to get back to previous map. If you answer yes it will attempt to create the basic script for you. On the second attempt at the portal you 'should' get warped back to previous map.
It probably should have more checking in it, as it is open to abuse, maybe should be limited to Gm's etc.
(Written for v116 ciphra)
EDIT: just realised I missed adding the boolean to MapleCharacter.java
prvate boolean returningToMap;
PortalScriptManager.java
------------------------
add these lines to executePortalScript(.....)
after
FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, "Unhandled portal script " + portal.getScriptName() + " on map " + c.getPlayer().getMapId());
Code:
System.out.print("Attempting to create script for this portal back to map ["+c.getPlayer().getLastMap()+"]\r\n");
try {
createPortalScript(c,portal.getScriptName(), c.getPlayer().getLastMap(), c.getPlayer().getLastPortal());
} catch (IOException ex) {
ex.printStackTrace();
}
add this routine
Code:
private void createPortalScript(MapleClient c,String name,int mapid,MaplePortal portal) throws IOException{
int portalnpc = 9270031;// choose an NPC for this
if (portalnpc==0) return;
NPCScriptManager.getInstance().start( c ,portalnpc);// ask if trying to get back
c.getSession().write(CWvsContext.enableActions());
if (!c.getPlayer().getReturningToMap()) return; // want to get back = true
String fname = "./scripts/portal/"+name+".js";
if (new File(fname).exists()) return; // make sure script does not exist already.
PrintWriter pw = new PrintWriter(fname);
pw.println("function enter(pi) {");
pw.format(" pi.warp(%s,%s);\r\n",mapid,portal.getId());
pw.println("}");
pw.flush();
pw.close();
System.out.print("Script created back to map [" + mapid + "]\r\n");
}
MapleCharacter.java
-------------------
add these fields
Code:
private int lastMap,lastMap1;
private MaplePortal lastPortal;
[COLOR=#ff0000]private boolean returningToMap = false;[/COLOR]
add these routines
Code:
public void setLastMap(int map, MaplePortal portal){
if (map != lastMap){
lastMap1 = lastMap;
lastMap = map;
lastPortal = portal;
}
}
public MaplePortal getLastPortal(){
return lastPortal;
}
public int getLastMap(){
return lastMap1;
}
public void setReturningToMap(boolean flag){
returningToMap = flag;
}
public boolean getReturningToMap(){
return returningToMap;
}
MaplePortal.java
--------------------
add these lines
after
final MapleMap currentmap = c.getPlayer().getMap();
Code:
c.getPlayer().setLastMap(currentmap.getId(),this);
System.out.print("Saving current map [" + currentmap.getMapName()+"]\r\n");
if (!c.getPlayer().hasBlockedInventory() && (portalState || c.getPlayer().isGM())) {
Finally the NPC script:
-----------------------
Code:
var status = -1;
function start() {
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == 0 || mode==-1) { // cancel or no - not inetrested
cm.getPlayer().setReturningToMap(false);
cm.dispose();
}
status++;
if (status == 0) {
cm.sendYesNo("Are you trying to get back to previous map?");
} else if (status == 1){
cm.getPlayer().setReturningToMap(true);
cm.dispose();
}
}
Enjoy.
Last edited: