Lion4ever

booby_trap.1.1

Aug 18th, 2015
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1. --Floating Blocks by negamartin
  2. --Modified to Booby Trap by Lion4ever
  3.  
  4. --You can use it for whatever you want, copy, modify, distribute it or use it as a base for your own structures
  5.  
  6. --Get what the main program is telling us to do
  7. local args={...};
  8. function waitForExplosion(x,y,z)
  9.     while commands.getBlockInfo(x,y,z).name == "minecraft:air" and
  10.           commands.getBlockInfo(x,y-1,z).name == "minecraft:stone" do
  11.         sleep(1)
  12.     end
  13. end
  14.  
  15. --If it wants to know how much probability we have to be chosen when selecting the next structure
  16. if args[1]=="weight" then
  17.     return 1;   --We have a normal structure's probability to be chosen
  18.    
  19. --If it wants us to build the structure,
  20. elseif args[1]=="death" then
  21.     local s = args[2]
  22.     waitForExplosion(unpack(s.blocks[3]))
  23.     for i,b in ipairs(s.blocks) do
  24.         commands.async.setblock(unpack(b))
  25.     end
  26. elseif args[1]=="remove_structure" then
  27.     local s = args[2]
  28.     waitForExplosion(unpack(s.blocks[3]))
  29.     return false -- so that the remaining blocks are still removed
  30. elseif args[1]=="place_marker" then
  31.     local fence=args[2].blocks[1];
  32.     fence[4]="minecraft:obsidian";
  33.     commands.async.setblock(unpack(fence));
  34.     return true;
  35. elseif args[1]=="build" then
  36.     --Get the angle the last structure had
  37.     local lastAngle=args[2];
  38.    
  39.     --Get a random height difference for the block we are going to place in relation to the last block, from -2 to 1
  40.     local hdif;
  41.     local r=math.random();
  42.     if      r>0.66666 then  hdif=1;
  43.     elseif  r<0.22222 then  hdif=-1;
  44.     elseif  r<0.33333 then  hdif=-2;
  45.     else                    hdif=0;
  46.     end
  47.    
  48.     --Get the distance between the last block and the one we are gonna place, depending on the height difference (if the block is lower you can jump farther)
  49.     local dist;
  50.     if hdif==1 then dist=3.2;
  51.     elseif hdif==-1 then dist=5;
  52.     elseif hdif==-2 then dist=5.3;
  53.     elseif hdif==0 then dist=4.6;
  54.     end
  55.    
  56.     --Get the new angle, which is (+-)0.3PI from the previous angle (lastAngle)
  57.     local ang=lastAngle-math.pi*0.3+math.random()*math.pi*0.6;
  58.    
  59.     --Get the radius of our areaCheck sphere depending on the height difference
  60.     local sphere;
  61.     if hdif==-2 then sphere=7;
  62.     elseif hdif==-1 then sphere=6;
  63.     else sphere=5; end
  64.    
  65.     --Create our setblock parameters and place them in a table
  66.     local b={
  67.         math.floor(0.5+math.cos(ang)*dist),
  68.         hdif,
  69.         math.floor(0.5+math.sin(ang)*dist),
  70.         "minecraft:stone",
  71.     };
  72.     local bAll = {
  73.         b,
  74.         {b[1],b[2]+1,b[3],"minecraft:wooden_pressure_plate"},
  75.         {b[1],b[2]-1,b[3],"minecraft:tnt"},
  76.         {b[1],b[2]-2,b[3],b[4]},
  77.     }
  78.     for c=-1,1 do
  79.         for d=-1,1 do
  80.             if c ~= 0 or d ~= 0 then
  81.                 for e=-2,0 do
  82.                     table.insert(bAll,{b[1]+c,b[2]+e,b[3]+d,"minecraft:web"})
  83.                 end
  84.             end
  85.         end
  86.     end
  87. --Return the StructureTable, with everything it needs to have
  88.     return {
  89.         blocks= bAll,                           --The blocks table contains 1 element: the floating block
  90.         areaCheck={{b[1],b[2],b[3],sphere}},    --The areaCheck table also only contains 1 element, our floating block area check.
  91.         exit={b[1],b[2],b[3]},                  --The exit of this structure is this same block
  92.         next=ang,                               --Tell the next structure our angle was this
  93.         length=15,                              --This structure is 15% a total checkpoint-to-checkpoint parkour section in normal difficulty
  94.     };
  95. end
Advertisement
Add Comment
Please, Sign In to add comment