antonsavov

Untitled

Dec 17th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 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 = -111
  10. }
  11. ROW = 1 --the number of the row for the wanted vocab. First is 1, not 0
  12. COL = 1 --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-4
  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)*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. return result
  96. end
  97.  
  98. --vocab constructor. Enforces some data structure
  99. function newVocabZone(x,y,z,w )--,reward,name)
  100. local nvz = {}
  101. nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
  102.  
  103. nvz.cx = nvz.x - nvz.w - 2
  104. nvz.cy = nvz.y
  105. nvz.cz = nvz.z
  106. --nvz.name = name
  107. --nvz.reward = reward
  108.  
  109. return nvz
  110.  
  111. end
  112.  
  113.  
  114.  
  115.  
  116.  
  117. --buildzone and vocabzone creation
  118. vocabSet = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  119.  
  120. -- this function does the cloning to a position
  121. function cloneVocab(position,row,col)
  122. local index = (col-1)*4 + row-1
  123. local vocab = vocabSet[index]
  124. if vocab then
  125. 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")
  126. else
  127. print("something wrong with vocab")
  128. end
  129.  
  130. end
  131.  
  132. function main()
  133. cloneVocab(POSITION,ROW,COL)
  134. end
  135.  
  136. main()
Advertisement
Add Comment
Please, Sign In to add comment