Diarreamental
Well-Known Member
- Joined
- Jul 6, 2015
- Messages
- 453
- Solutions
- 1
- Reaction score
- 80
Hello
I'm trying to re convert a map that is using some ids from 7.4 version and i want to convert these old ids to the newer ones i found this OpenTibia - Convert any map to 7.6 (https://otland.net/threads/convert-any-map-to-7-6.259410/page-2#post-2708866)
and edited the script but it's not working. it gives me errors
if you wonder why im trying to add mutiple ids is because if i convert for example 567 to 4644 the new border stays unfilled.
error
solved case word was wrong added at the end
the script is working but is not adding the id 102 in this case, please help the same thing happens with RME
@Peonso Hello sorry to tag you but you would mind helping me, please?
I'm trying to re convert a map that is using some ids from 7.4 version and i want to convert these old ids to the newer ones i found this OpenTibia - Convert any map to 7.6 (https://otland.net/threads/convert-any-map-to-7-6.259410/page-2#post-2708866)
and edited the script but it's not working. it gives me errors
if you wonder why im trying to add mutiple ids is because if i convert for example 567 to 4644 the new border stays unfilled.
Lua:
// A tool to convert OpenTibia maps to https://github.com/peonso/opentibia_sprite_pack
// by Peonso
// dependencies https://github.com/Inconcessus/OTBM2JSON
// node --max-old-space-size=4096 convert.js
var start = Date.now();
const otbm2json = require("./OTBM2JSON/otbm2json");
// Read the map data using the otbm2json library
const mapData = otbm2json.read("map.otbm");
// converting to 7.6
mapData.data.itemsMinorVersion = 3;
// iterating through tiles converting items
mapData.data.nodes.forEach(function(x) {
x.features.forEach(function(x) {
if(x.type !== otbm2json.HEADERS.OTBM_TILE_AREA) return;
if(x.tiles == undefined) return;
x.tiles.forEach(function(x) {
if((x.type !== otbm2json.HEADERS.OTBM_TILE) && (x.type !== otbm2json.HEADERS.OTBM_HOUSETILE)) return;
if(x.tileid) {
x.tileid = convertId(x.tileid);
//removing invalid ids
if (x.tileid == 6666) {
delete x.tileid;
}
}
if(x.items) {
x.items.forEach(function(x) {
if(x.id) {
// TO DO: if mud wall, remove border items
x.id = convertId(x.id);
//removing invalid ids
if (x.id == 6666) {
delete x.id;
}
}
if(x.content) {
x.content.forEach(function(x) {
x.id = convertId(x.id);
if(x.content) {
x.content.forEach(function(x) {
x.id = convertId(x.id);
});
}
});
}
});
}
});
});
});
// Write the output to OTBM using the library
console.log("Finished conversion in " + (Date.now() - start) + "ms. Writing output to converted_map.otbm");
otbm2json.write("converted_map.otbm", mapData);
console.log("Total process took less than " + Math.ceil((Date.now() - start)/1000) + "s.");
// Returns an integer between min, max (inclusive)
function getRandomBetween(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
// Return a random element based on a weight
function getWeightedRandom(weights) {
// Draw a random sample
var value = Math.random();
var sum = 0;
for(var i = 0; i < weights.length; i++) {
sum += weights[i].weight;
if(value < sum) {
return weights[i].id;
}
}
return weights[1].id;
}
function convertId(id) {
switch(id) {
case 567:
return 4644;
return 102;
break;
case 566:
return 4646;
return 102;
break;
case 568:
return 4645;
return 102;
break;
case 569:
return 4647;
return 102;
break;
case 570:
return 4655;
return 102;
break;
case 572:
return 4652;
return 102;
break;
case 573:
return 4653;
return 102;
break;
case 571:
return 4654;
return 102;
break;
case 574:
return 4651;
return 102;
break;
case 575:
return 4650;
return 102;
break;
case 576:
return 4648;
return 102;
break;
case 4649:
return 577;
return 102;
break;
case
default:
return id;
}
return id;
}
error
Lua:
C:\Users\diap\Desktop\map-conversor>node convert.js
C:\Users\diap\Desktop\map-conversor\convert.js:145
default:
^^^^^^^
SyntaxError: Unexpected token 'default'
←[90m at Object.compileFunction (node:vm:360:18)←[39m
←[90m at wrapSafe (node:internal/modules/cjs/loader:1088:15)←[39m
←[90m at Module._compile (node:internal/modules/cjs/loader:1123:27)←[39m
←[90m at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:1037:32)←[39m
←[90m at Module._load (node:internal/modules/cjs/loader:878:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)←[39m
←[90m at node:internal/main/run_main_module:23:47←[39m
Node.js v19.0.1
C:\Users\diap\Desktop\map-conversor>pause
Presione una tecla para continuar . . .
Post automatically merged:
solved case word was wrong added at the end
the script is working but is not adding the id 102 in this case, please help the same thing happens with RME
@Peonso Hello sorry to tag you but you would mind helping me, please?
Attachments
-
1.png1.2 MB · Views: 11 · VirusTotal
Last edited: