Many servers use tiles that are supposed to be used in a block pattern, but often are destroyed by levelers who don't pay attention to such things. This script fixes it.
It turns this:
into this:
I find it most useful on grass. It works on individual levels or GMAPs.
Note that you may have to download and reupload the levels because updateBoard2 doesn't always change the file modification time, which can result in old levels being shown for some players.
Example usage:
PHP Code:
FloodFiller.fill("my_map.gmap", "water");
// or
FloodFiller.fillMultiple("mylevel.nw", {"water", "road", "grass"});
PHP Code:
// DBNPC FloodFiller
function onCreated() {
// pattern to fill; lay it out in rows
this.pattern.grass.pattern = {
{1024, 1025, 1026, 1027, 1028, 1029},
{1040, 1041, 1042, 1043, 1044, 1045},
{1056, 1057, 1058, 1059, 1060, 1061},
{1072, 1073, 1074, 1075, 1076, 1077},
{1088, 1089, 1090, 1091, 1092, 1093},
{1104, 1105, 1106, 1107, 1108, 1109}
};
// tiles to fill even if not in pattern
// (for filling blank levels with grass, etc)
this.pattern.grass.exceptions = {0};
// pattern to fill; lay it out in rows
this.pattern.water.pattern = {
{64, 65},
{80, 81}
};
// tiles to fill even if not in pattern
// (for filling blank levels with grass, etc)
this.pattern.water.exceptions = {};
}
public function floodMultiple(levelName, patternNames) {
for (temp.patternName : patternNames) {
flood(levelName, patternName);
sleep(0.1);
}
}
public function flood(levelName, patternName) {
temp.floodLevel = findLevel(levelName);
if (floodLevel == null) {
return echo("Level Flood: Level '" @ levelName @ "' not found!");
}
temp.pattern = this.pattern.(@ patternName).pattern;
temp.exceptions = this.pattern.(@ patternName).exceptions;
if (pattern == null) {
return echo("Level Flood: Pattern '" @ patternName @ "' has no defined pattern!");
}
this.maxlooplimit = 100000; // 100,000
sleep(0.1); // make the max loop limit take effect
this.loopCount = 0;
temp.possibleTiles = exceptions;
for (temp.row : pattern) {
for (temp.tile : row) {
possibleTiles.add(tile);
this.nextLoop();
}
this.nextLoop();
}
for (temp.x = 0; x < floodLevel.width; x ++) {
for (temp.y = 0; y < floodLevel.height; y ++) {
for (temp.layer : floodLevel.tilelayers) {
temp.tile = layer.tiles[x, y];
if (tile in possibleTiles) {
// replace tile
temp.row = pattern[y % row.size()];
layer.tiles[x, y] = row[x % row.size()];
}
this.nextLoop();
}
this.nextLoop();
}
this.nextLoop();
}
floodLevel.updateBoard2(0, 0, floodLevel.width, floodLevel.height);
echo("Level Flood: Successfully applied pattern '" @ patternName @ "' to level '" @ floodLevel.name @ "'!");
}
// increase number of loops; do I need to wait?
function nextLoop() {
this.loopCount ++;
if (this.loopCount >= this.maxlooplimit - 1) {
this.loopCount = 0;
echo("Level Flood: Working...");
sleep(0.1);
}
}
It should work fine with layers (it checks each layer individually for tiles that need to be replaced), but I haven't tested it.
It might be a good idea to back the levels up first since I haven't tested this in some situations.