Advertisement
BombBloke

ladder_swerve_jump.1

Jul 10th, 2015
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. -- ladder_swerve_jump.1
  2. -- For use with this: http://www.computercraft.info/forums2/index.php?/topic/23785-virtual-parkour/
  3.  
  4. --Get what the main program is telling us to do
  5. local args={...};
  6.  
  7. local trans = {{["x+"]=5, ["x-"]=4, ["z+"]=3, ["z-"]=2},
  8.         {["x+"]=3, ["x-"]=2, ["z+"]=4, ["z-"]=5},
  9.         {["x+"]=2, ["x-"]=3, ["z+"]=5, ["z-"]=4},
  10.         {["x+"]=4, ["x-"]=5, ["z+"]=2, ["z-"]=3}}
  11.  
  12. --If it wants to know how much probability we have to be chosen when selecting the next structure
  13. if args[1]=="weight" then
  14.     return 0.3;
  15.    
  16. --If it wants us to build the structure,
  17. elseif args[1]=="build" then
  18.     --Get the angle the last structure had
  19.     local lastAngle=args[2];
  20.    
  21.     --Get a random height difference for the block we are going to place in relation to the last block, from -2 to 1
  22.     local hdif;
  23.     local r=math.random();
  24.     if r>0.66666 then   hdif=1;
  25.     elseif  r<0.22222 then  hdif=-1;
  26.     elseif  r<0.33333 then  hdif=-2;
  27.     else                    hdif=0;
  28.     end
  29.    
  30.     --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)
  31.     local dist;
  32.     if hdif==1 then dist=4.9;
  33.     elseif hdif==-1 then dist=5.9;
  34.     elseif hdif==-2 then dist=6.5;
  35.     elseif hdif==0 then dist=5.7;
  36.     end
  37.    
  38.     --Get the new angle, which is (+-)0.3PI from the previous angle (lastAngle)
  39.     local ang=lastAngle-math.pi*0.3+math.random()*math.pi*0.6;
  40.    
  41.     --Get the radius of our areaCheck sphere depending on the height difference
  42.     local sphere;
  43.     if hdif==-2 then sphere=7;
  44.     elseif hdif==-1 then sphere=6;
  45.     else sphere=5; end
  46.    
  47.     --Create our setblock parameters and place them in a table
  48.     local b1={
  49.         math.floor(0.5+math.cos(ang)*dist),
  50.         hdif,
  51.         math.floor(0.5+math.sin(ang)*dist),
  52.         "minecraft:stone",
  53.     };
  54.     local b1lad1={
  55.         b1[1]-1;
  56.         b1[2],
  57.         b1[3],
  58.         "minecraft:ladder",
  59.     };
  60.     local ladderOffset=numberToDir(dirToNumber(final().next)+2);
  61.     b1lad1[5]=trans[1][ladderOffset];
  62.    
  63.     local b1lad2={
  64.         b1[1],
  65.         b1[2],
  66.         b1[3],
  67.         "minecraft:ladder",
  68.     };
  69.    
  70.     if b1[3]>0 then --To the right, ladder on left
  71.         b1lad2[3]=b1lad2[3]-1;
  72.         b1lad2[5]=trans[2][ladderOffset];
  73.     else            --To the left, ladder on right
  74.         b1lad2[3]=b1lad2[3]+1;
  75.         b1lad2[5]=trans[3][ladderOffset];
  76.     end
  77.    
  78.     local b2 = {
  79.         b1[1],
  80.         b1[2] + 1,
  81.         b1[3],
  82.         "minecraft:stone",
  83.     };
  84.  
  85.     local b2lad1={
  86.         b2[1]+1;
  87.         b2[2],
  88.         b2[3],
  89.         "minecraft:ladder",
  90.     };
  91.     local ladderOffset=numberToDir(dirToNumber(final().next)-2);
  92.     b2lad1[5]=trans[4][ladderOffset];
  93.    
  94.     local b2lad2={
  95.         b2[1],
  96.         b2[2],
  97.         b2[3],
  98.         "minecraft:ladder",
  99.     };
  100.    
  101.     if b1[3]<0 then --To the right, ladder on left
  102.         b2lad2[3]=b2lad2[3]-1;
  103.         b2lad2[5]=trans[2][ladderOffset];
  104.     else            --To the left, ladder on right
  105.         b2lad2[3]=b2lad2[3]+1;
  106.         b2lad2[5]=trans[3][ladderOffset];
  107.     end
  108.    
  109.     local b3 = {
  110.         b2[1],
  111.         b2[2] + 1,
  112.         b2[3],
  113.         "minecraft:stone",
  114.     };
  115.    
  116.     --Return the StructureTable, with everything it needs to have
  117.     return {
  118.         blocks={b1,b1lad1,b1lad2,b2,b2lad1,b2lad2,b3},      --The blocks table contains 1 element: the floating block
  119.         areaCheck={{b2[1],b2[2],b2[3],sphere}}, --The areaCheck table also only contains 1 element, our floating block area check.
  120.         exit={b3[1],b3[2],b3[3]},                   --The exit of this structure is this same block
  121.         next=ang,                               --Tell the next structure our angle was this
  122.         length=15,                              --This structure is 15% a total checkpoint-to-checkpoint parkour section in normal difficulty
  123.     };
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement