Advertisement
VirtualParkourStore

Archery Test

Jul 9th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.67 KB | None | 0 0
  1. --Get what the main program is telling us to do
  2. local args={...};
  3.  
  4. --If it wants to know how much probability we have to be chosen when selecting the next structure
  5. if args[1]=="place_marker" then
  6.     local s=args[2];
  7.     s.placeMarker=true;
  8.     return true;
  9. elseif args[1]=="check_exit" then
  10.     local s=args[2];
  11.     return commands.getBlockInfo(s.blocks[2][1],s.blocks[2][2],s.blocks[2][3]).name~="minecraft:web" and
  12.     commands.testfor(s.playerData.incompleteSelector.."x="..s.exit[1]..",y="..(s.exit[2]+1)..",z="..s.exit[3]..",r=1]");
  13. elseif args[1]=="death" then
  14.     local s=args[2];
  15.     if s.bowGiven then
  16.         if s.complete then
  17.             s.blocks[4][5]=0;
  18.             for i=2,13 do
  19.                 if i~=3 then commands.async.setblock(unpack(s.blocks[i])); end
  20.             end
  21.         else
  22.             commands.async.clear(s.playerData.selector.." minecraft:bow");
  23.             commands.async.clear(s.playerData.selector.." minecraft:arrow");
  24.             s.blocks[4][5]=0;
  25.             commands.async.setblock(unpack(s.blocks[4]));
  26.             commands.async.setblock(s.blocks[3][1],s.blocks[3][2],s.blocks[3][3],"minecraft:air 0 replace");
  27.         end
  28.         s.complete=false;
  29.         s.bowGiven=false;
  30.     end
  31. elseif args[1]=="build" then
  32.     local b={};
  33.     local ac={};
  34.     --Get the angle the last structure had
  35.     local lastAngle=args[2];
  36.    
  37.     --Get a random height difference for the block we are going to place in relation to the last block, from -2 to 1
  38.     local hdif;
  39.     local r=math.random();
  40.     if      r>0.66666 then  hdif=1;
  41.     elseif  r<0.22222 then  hdif=-1;
  42.     elseif  r<0.33333 then  hdif=-2;
  43.     else                    hdif=0;
  44.     end
  45.    
  46.     --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)
  47.     local dist;
  48.     if hdif==1 then dist=3.7;
  49.     elseif hdif==-1 then dist=5;
  50.     elseif hdif==-2 then dist=5.3;
  51.     elseif hdif==0 then dist=4.6;
  52.     end
  53.    
  54.     --Get the new angle, which is (+-)0.3PI from the previous angle (lastAngle)
  55.     local ang=lastAngle-math.pi*0.3+math.random()*math.pi*0.6;
  56.    
  57.     --Get the radius of our areaCheck sphere depending on the height difference
  58.     local sphere;
  59.     if hdif==-2 then sphere=7;
  60.     elseif hdif==-1 then sphere=6;
  61.     else sphere=5; end
  62.    
  63.     --Create our setblock parameters and place them in a table
  64.     b[1]={
  65.         math.floor(0.5+math.cos(ang)*dist),
  66.         hdif,
  67.         math.floor(0.5+math.sin(ang)*dist),
  68.         "minecraft:stone",
  69.     };
  70.     ac[#ac+1]={b[1][1],b[1][2],b[1][3],sphere};
  71.     b[2]={
  72.         math.floor(b[1][1]+0.5+math.cos(ang)*4),
  73.         hdif,
  74.         math.floor(b[1][3]+0.5+math.sin(ang)*4),
  75.         "minecraft:web",
  76.     };
  77.     ac[#ac+1]={b[2][1],b[2][2],b[2][3],5};
  78.    
  79.     local targetSide=math.random(0,1);
  80.     if targetSide==0 then targetSide=-1; end
  81.    
  82.     local distance=((checkpointStride()-100)*0.2+30)*targetSide;
  83.     b[4]={
  84.         b[1][1],
  85.         hdif+2,
  86.         b[1][3]+distance,
  87.         "minecraft:wool",
  88.         0,
  89.     };
  90.     b[3]={
  91.         b[4][1],
  92.         b[4][2],
  93.         b[4][3]-targetSide,
  94.         "minecraft:wooden_button",
  95.         disableAutobuild=true,
  96.         autoMeta=true,
  97.     };
  98.     if targetSide==1 then b[3][5]="z-";
  99.     elseif targetSide==-1 then b[3][5]="z+";
  100.     else error("Invalid targetSide "..tostring(targetSide)); end
  101.     b[5]={
  102.         b[4][1],
  103.         b[4][2]+1,
  104.         b[4][3],
  105.         "minecraft:wool",
  106.     };
  107.     b[6]={
  108.         b[4][1]+1,
  109.         b[4][2],
  110.         b[4][3],
  111.         "minecraft:wool",
  112.     };
  113.     b[7]={
  114.         b[4][1]-1,
  115.         b[4][2],
  116.         b[4][3],
  117.         "minecraft:wool",
  118.     };
  119.     b[8]={
  120.         b[4][1],
  121.         b[4][2]-1,
  122.         b[4][3],
  123.         "minecraft:wool",
  124.     };
  125.     b[9]={
  126.         b[4][1]-1,
  127.         b[4][2]+1,
  128.         b[4][3],
  129.         "minecraft:wool",
  130.     };
  131.     b[10]={
  132.         b[4][1]+1,
  133.         b[4][2]+1,
  134.         b[4][3],
  135.         "minecraft:wool",
  136.     };
  137.     b[11]={
  138.         b[4][1]-1,
  139.         b[4][2]-1,
  140.         b[4][3],
  141.         "minecraft:wool",
  142.     };
  143.     b[12]={
  144.         b[4][1]+1,
  145.         b[4][2]-1,
  146.         b[4][3],
  147.         "minecraft:wool",
  148.     };
  149.     b[13]={
  150.         b[4][1],
  151.         b[4][2],
  152.         b[4][3]+targetSide,
  153.         "minecraft:command_block",
  154.         0,
  155.         "replace",
  156.         --"{Command:\"setblock "..tb13[1].." "..tb13[2].." "..tb13[3].." minecraft:stone\"}",
  157.     };
  158.    
  159.     function doStuff(struct)
  160.         local pd=struct.playerData;
  161.         if not struct.bowGiven then
  162.             struct.bowGiven=true;
  163.             commands.async.clear(pd.selector.." minecraft:bow");
  164.             commands.async.clear(pd.selector.." minecraft:arrow");
  165.             commands.async.give(pd.selector.." minecraft:bow");
  166.             commands.async.give(pd.selector.." minecraft:arrow 4");
  167.             struct.blocks[4][5]=14;
  168.             commands.async.setblock(unpack(struct.blocks[4]));
  169.             commands.setblock(unpack(struct.blocks[3]));
  170.             commands.async.tellraw(pd.selector,"{text:\"Shoot the red target. You'll only be given more arrows if you suicide.\",color:gold}");
  171.         end
  172.         if commands.getBlockInfo(unpack(struct.blocks[13])).name=="minecraft:stone" then
  173.             for i=3,13 do
  174.                 commands.async.setblock(struct.blocks[i][1],struct.blocks[i][2],struct.blocks[i][3],"minecraft:air");
  175.             end
  176.             commands.async.clear(pd.selector.." minecraft:bow");
  177.             commands.async.clear(pd.selector.." minecraft:arrow");
  178.             local tb2=struct.blocks[2];
  179.             if struct.placeMarker then commands.async.setblock(tb2[1],tb2[2],tb2[3],"minecraft:obsidian");
  180.             else commands.async.setblock(tb2[1],tb2[2],tb2[3],"minecraft:stone"); end
  181.             struct.complete=true;
  182.         end
  183.     end
  184.     ac[#ac+1]={b[1][1],b[1][2]+1,b[1][3],1,doStuff};
  185.    
  186.     --Return the StructureTable, with everything it needs to have
  187.     return {
  188.         blocks=b,                               --The blocks table contains 1 element: the floating block
  189.         areaCheck=ac,   --The areaCheck table also only contains 1 element, our floating block area check.
  190.         exit={b[2][1],b[2][2],b[2][3]},                 --The exit of this structure is this same block
  191.         next=ang,                               --Tell the next structure our angle was this
  192.         length=20,                              --This structure is 15% a total checkpoint-to-checkpoint parkour section in normal difficulty
  193.     };
  194. elseif args[1]=="post_transform" then
  195.     local tb13=args[2].blocks[13];
  196.     tb13[7]="{Command:\"setblock "..tb13[1].." "..tb13[2].." "..tb13[3].." minecraft:stone\"}";
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement