Advertisement
antonsavov

Untitled

Dec 17th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. -- clones a vocab by number (row and column) to the position of a provided player name
  2. --
  3. --
  4.  
  5. PLAYER = "quantx"
  6. POSITION = {
  7. x = 18,
  8. y = 57,
  9. z = -30
  10. }
  11. ROW = 1 --the number of the row for the wanted vocab. First is 1, not 0
  12. COL = 7 --the number of the column for the wanted vocab. First is 1, not 0
  13.  
  14. VOCAB_WIDTH = 27
  15. VOCAB_HEIGHT = 19
  16. NUMBER_OF_VOCAB = 10
  17.  
  18. FIRSTVOCAB= { --this is at ~-4 ~ ~-4 from the corner of the shape zone of the vocab that is closest to zero
  19. x=-60,
  20. y=57,
  21. z=-107
  22. }
  23.  
  24. --DEFAULT_REWARD = 'minecraft:emerald 2 0 {display:{Name:"Emerald",Lore:[Trade this to the villager for wool]}}'
  25. --DEFAULT_NAME = 'default-vocab'
  26.  
  27. --local ox,oy,oz = commands.getBlockPosition()
  28.  
  29. --return a list of all players in the game world as player objects
  30. local function getPlayePos(name)
  31. local result, message = commands.tp("@a[name="..name.."]","~ ~ ~")
  32. local names = {}
  33.  
  34. if result == true then
  35. for i,result in ipairs(message) do
  36. local wordpattern = "[^, ]+"
  37. local numberpattern = "[%-% ]%d+[%.]%d+"
  38. local words,numbers = {},{}
  39.  
  40. for word in string.gmatch(result, wordpattern) do
  41. table.insert(words,word)
  42. end
  43.  
  44. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  45.  
  46. local coords = {
  47. x = math.floor(numbers[1]),
  48. y = math.floor(numbers[2]),
  49. z = math.floor(numbers[3])
  50. }
  51. local name = words[2]
  52. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  53. --print("Player Found - getAllPos")
  54. end
  55. end
  56. local position = {
  57. x = names[0].x,
  58. y = names[0].y,
  59. z = names[0].z
  60. }
  61. return position
  62. end
  63.  
  64. --constructor for player object so that data structure is consistant
  65. function newPlayerData(name,x,y,z)
  66. local p = {
  67. name = name,
  68. x=x,
  69. y=y,
  70. z=z
  71. }
  72. return p
  73. end
  74.  
  75. --a multi builder which uses the vocab constructor to create sets of vocab
  76. function makeVocabZones(quant,w)
  77. local x,y,z = FIRSTVOCAB.x, FIRSTVOCAB.y, FIRSTVOCAB.z
  78. local result = {}
  79. local namecount = 1
  80. for i=0,quant-1 do
  81. for k=0,3 do
  82. local zpos = i
  83. local ypos = k
  84. if i == -1 then
  85. print("vocab at X")
  86. print(x)
  87. print("and Z")
  88. print(z)
  89. end
  90. local nextVocab = newVocabZone(x,y+(ypos*(VOCAB_HEIGHT+3)),z+((w+1)*zpos),w ) --,REWARDS[namecount] or DEFAULT_REWARD,VOCAB_NAMES[namecount] or DEFAULT_NAME)
  91. table.insert(result,nextVocab)
  92. namecount = namecount +1
  93. end
  94. end
  95. --print(result[1].cx)
  96. return result
  97. end
  98.  
  99. --vocab constructor. Enforces some data structure
  100. function newVocabZone(x,y,z,w )--,reward,name)
  101. local nvz = {}
  102. nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
  103.  
  104. nvz.cx = nvz.x - nvz.w - 2
  105. nvz.cy = nvz.y
  106. nvz.cz = nvz.z
  107. --nvz.name = name
  108. --nvz.reward = reward
  109.  
  110. return nvz
  111.  
  112. end
  113.  
  114.  
  115.  
  116.  
  117.  
  118. --buildzone and vocabzone creation
  119. vocabSet = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  120.  
  121. -- this function does the cloning to a position
  122. function cloneVocab(position,row,col)
  123. local index = (col-1)*4 + row
  124. local vocab = vocabSet[index]
  125. if vocab then
  126. commands.clone(vocab.cx,vocab.cy,vocab.cz,vocab.cx+vocab.w,vocab.cy+VOCAB_HEIGHT,vocab.cz+vocab.w,position.x-math.floor(vocab.w/2),position.y-1,position.z-math.floor(vocab.w/2),"masked")
  127. print("cloned vocab at col:"..col.." and row:"..row.." to x:"..position.x..", y:"..position.y..", z:"..position.z..". done!")
  128. print("the vocab is from x:"..vocab.cx..", y"..vocab.cy..", z:"..vocab.cz)
  129. else
  130. print("something wrong with vocab")
  131. end
  132.  
  133. end
  134.  
  135. function main()
  136. cloneVocab(POSITION,ROW,COL)
  137. end
  138.  
  139. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement