Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- conn = new ActiveXObject("ADODB.Connection");
- rs = new ActiveXObject("ADODB.Recordset");
- function loadTbl(table_name) {
- var ret = {};
- rs.Open("SELECT * FROM " + table_name, conn);
- if (!rs.bof) {
- rs.MoveFirst();
- while (!rs.eof) {
- var row = {};
- for (var i = 0; i < rs.fields.count; i++)
- row[rs.fields(i).name] = rs.fields(i).value;
- ret[rs.fields(0).value] = row;
- rs.MoveNext();
- }
- }
- rs.Close();
- return ret;
- }
- function sign(x) {
- return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
- }
- function loadZMap(filepath) {
- conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath);
- var zones = loadTbl("ZoneTbl");
- var rooms = loadTbl("ObjectTbl");
- var dirs = loadTbl("DirTbl");
- var exits = loadTbl("ExitTbl");
- var total_rooms = 0;
- jmc.parse(jmc.CommandChar + "mapper clear");
- for (var id in dirs) {
- var dir = dirs[id];
- var rev = dirs[dir.RevId];
- jmc.parse(jmc.CommandChar + "mapper add direction {" + dirs[id].DirName + "} " + sign(dir.Dx) + " " + sign(-dir.Dy) + " " + sign(dir.Dz) + " {" + rev.DirName + "}");
- }
- jmc.showme("Loading rooms");
- for (var rid in rooms) {
- var room = rooms[rid];
- if (room.KindID != 0) //'Room'
- continue;
- room.Desc = "";
- jmc.parse(jmc.CommandChar + "mapper autoid {" + room.Name + "} {" + room.Desc + "} {} PrimaryId");
- var secondary = room.ObjId;
- var primary = jmc.GetVar("PrimaryId");
- if (primary.indexOf('.') >= 0)
- primary = primary.substr(0, primary.indexOf('.'));
- var id = primary + "." + secondary;
- rooms[rid]['jmcId'] = id;
- jmc.parse(jmc.CommandChar + "mapper add room " + id + " {" + room.Name + "} {" + room.Desc + "} {} {} {}");
- total_rooms += 1;
- }
- jmc.showme("Total rooms: " + total_rooms + ", loading exits");
- for (var eid in exits) {
- var exit = exits[eid];
- var fromid = rooms[exit.FromID].jmcId;
- var toid = rooms[exit.ToID].jmcId;
- var dir = dirs[exit.DirType + 1];
- if (!fromid) {
- jmc.showme("Can't find from-room: <" + exit.FromID + "> (" + dir.DirName + ")");
- continue;
- }
- if (!toid) {
- jmc.showme("Can't find to-room: <" + exit.ToID + "> (" + dir.DirName + ")");
- continue;
- }
- jmc.parse(jmc.CommandChar + "mapper add exit " + fromid + " {" + dir.DirName + "} " + toid);
- }
- jmc.showme("Done.");
- conn.Close();
- }
- /* usage:
- - copy importZMap.js to ./settings
- - copy <worldname>.mdb from zMUD to ./zmap.mdb
- - execute in jmc:
- #use importZMap.js
- #scri loadZMap("zmap.mdb")
- #mapper write z.map
- */
Add Comment
Please, Sign In to add comment