[Request] Select Region & Replace Block

Discussion in 'CraftScripts' started by MorroZ, Feb 26, 2015.

  1. MorroZ

    MorroZ New Member

    Hello guys,

    i was watching out for a method for my mods that they can make spleef without any new plugins or giving them too much permissions, but it seems like there is no permission like "worldedit.region.set.snow_block" or something like this.

    but then i saw the permissions for CraftScripts, but actually i dont know anything about javascript.

    So could craftscript replace the blocks from multiple regions(3) to different blocks.
    like //set 60%80,20%18,20%46

    if yes, could someone help me out here and make me a script that replaces the blocks of 3 regions to the named ids above? :3
  2. inHaze

    inHaze New Member

    I put something together real quick that should help you. The only thing you should have to change is the regions location and size, which are in the array setRgs. If you want more areas to be filled, just add in another line using the same format.

    Code (Text):
    importPackage(Packages.com.sk89q.worldedit);
    importPackage(Packages.com.sk89q.worldedit.blocks);

    var es = context.remember();

    var setRgs = [
        [767,67,547,15,3,15], // format is base coord x,y,z then size x,y,z
        [767,87,547,15,3,15],
    ];

    function rngBlock() {
        var rng = Math.random();
        if (rng <= .2) return new BaseBlock(18);
        else if (rng > .2 && rng < .4) return new BaseBlock(46);
        else return new BaseBlock(80);
    }

    var r,x,y,z;
    for (r = 0; r < setRgs.length; r++) {
        for (x = 0; x < setRgs[r][3]; x++) {
            for (y = 0; y < setRgs[r][4]; y++) {
                for (z = 0; z < setRgs[r][5]; z++) {
                    es.setBlock(new Vector(setRgs[r][0]+x, setRgs[r][1]+y, setRgs[r][2]+z), rngBlock());
                }
            }
        }
    }
     
    MorroZ likes this.
  3. MorroZ

    MorroZ New Member


    Thank u Sir, thats very nice and exactly what i needed.