[Request/Help] Refill dispenser

Discussion in 'CraftScripts' started by BlueII, Jul 13, 2012.

  1. BlueII

    BlueII New Member

    I found this "Examplescript" on the sk89q wikipage.

    my question is now: Is there a way to fill the dispenser with speedII potions (ID: 373:16418) instead? I already tried to replace the itemID from the arrows but when I write the ID like I did above I get an error.

    Can anyone help me please?

    BlueII
  2. blockhead

    blockhead New Member

    In the ID 373:16418, the 16418 part is the "damage value" (even though it has nothing to do with damage in this case. If the item was a tool or weapon, then that number would specify how damaged it is). To specify an item stack with a damage value, you simply use the optional third argument of BaseItemStack like so:
    new BaseItemStack(373,64,16418)

    However for me, trying to set the contents of a dispenser doesn't work. I even tried copying and pasting that code straight from the wiki, but it always just sets an empty dispenser (erasing the previous contents if any). I'm using Single Player Commands, so if you're using WorldEdit through another interface, such as Bukkit, it might work for you.
  3. BlueII

    BlueII New Member

    I'm using craftbukkit but thanks for the tip! I'll try this :)

    EDIT: It works perfectly for me! Thanks a lot!
  4. bunny365

    bunny365 New Member

    I've already made something like this. I've created three versions, one for chests, one for dispensers and one for both (at once), but I'll share the one for just refilling dispensers:
    Code (Text):
    importPackage(Packages.com.sk89q.worldedit);
    importPackage(Packages.com.sk89q.worldedit.blocks);
    context.checkArgs(2,3,"<radius> <block> [data]");
    var session=context.remember();
    var radius=Math.floor(Math.abs(parseInt(argv[1])-1));
    var origin=player.getPosition();
    if (isNaN(Number(argv[2]))){
    var item=new BaseItemStack(Math.floor(Math.abs(context.getBlock(argv[2]).getType())),64);
    }else{
    var item=new BaseItemStack(Math.floor(Math.abs(argv[2])),64);
    }
    if(argv.length>3){item.setData(parseInt(argv[3]))};
    var items=[item,item,item,item,item,item,item,item,item];
    var count=0;
    for(var x=radius*-1;x<=radius;x++){
        for(var y=radius*-1;y<=radius;y++){
            for(var z=radius*-1;z<=radius;z++){
                var pt=origin.add(x,y,z)
                var id=session.getBlockType(pt);
                if (id==BlockID.DISPENSER){
                    session.setBlock(pt,new DispenserBlock(session.getBlockData(pt),items));
                    count=count+1;
                }
            }
        }
    }
    player.print(count+" "+(count==1?"dispenser":"dispensers")+" filled with "+item.getType()+(argv.length>3?":"+item.getData():""));
    For blocks, it currently supports block names, block IDs, item IDs, but not item names. And also, it replaces all the items in the dispensers, so if you have anything important in the dispenser and accidentally replace it, I would suggest typing //undo before the server crashes. :p
  5. Kimb

    Kimb New Member

    I tried it .... and dispensers are EMPTY. I copied the code in total from here and ran it as is; but EMPTY DISPENSERS. What gives?
    Also tried the code at top (as copied from the sk89 wiki) and tried to run it, and got error message that setItems function was not found in Block.
  6. Kimb

    Kimb New Member

    UPDATE: it seems that BaseBlock, Container, Dispenser and Chest methods have ALL BEEN SUPPLANTED (replaced!) by the BLOCK class, which LACKS ANY WAY TO HANDLE ITEMS. THIS IS WHY the 'arrow dispenser' example is now out of date and is non-working -- due to this change in WorldEdit. Obviously the WE website needs to update their craftscripts.
  7. wizjany

    wizjany Administrator Developer

    the craftscript on the wiki was written by some random person. if you'd like to update it on the wiki go ahead.
    beside from that, the BaseBlock specific block classes should still work and are still used at least as of 5.6.2, which is the latest release.
  8. Kimb

    Kimb New Member

    Update the example on wiki? Perhaps after I get more proficient in craftscripting...........