kensuaga

HelperBot

Jan 15th, 2021
907
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. function onLoad()
  5.  
  6.     storageBagGUID = '259c8c'
  7.     storageBag = getObjectFromGUID(storageBagGUID)
  8.  
  9.     self.createButton({
  10.         click_function = 'export',
  11.         function_owner = self,
  12.         label          = 'Export',
  13.         position       = {0,0.25,0.7},
  14.         scale          = {0.3,0.3,0.3},
  15.         width          = 1100,
  16.         height         = 400,
  17.         font_size      = 360,
  18.         font_color     = {0.9,0.9,0.9},
  19.         color          = {0.1,0.1,0.1},
  20.         tooltip        = 'Export:\nLeft Click - Print Table\nRight Click = Print and Store table\nTable buttons:\nLeft Click - Deploy Table\nRight Click - Store Table'
  21.     })
  22.  
  23.     buildTables()
  24. end
  25.  
  26.  
  27.  
  28. --This will export the table of the current setup to the notepad tool.
  29. function export(obj, player_clicker_color, alt_click)
  30.  
  31.     hitList = Physics.cast({
  32.         origin       = {0, 4.06, 0},
  33.         direction    = {0,1,0},
  34.         type         = 3,
  35.         size         = {31.24, 5.10, 31.78},
  36.         max_distance = 0,
  37.         debug        = true,
  38.     }) -- returns {{Vector point, Vector normal, float distance, Object hit_object}, ...}
  39.  
  40.  
  41.     --Begins to build the data export
  42.     local note = 'tableName = {\n'
  43.  
  44.  
  45.     for _, entry in ipairs(hitList) do
  46.  
  47.         obj = entry.hit_object
  48.  
  49.         printGUID = obj.getGUID()
  50.         printPos = obj.getPosition()
  51.         printRot = obj.getRotation()
  52.  
  53.         --Adds the guid to note
  54.         note = note .. '\t{guid="'
  55.         note = note .. obj.getGUID()
  56.  
  57.         --Adds the posision to note
  58.         note = note .. '", pos={'
  59.         note = note .. round(printPos.x,2) .. ","
  60.         note = note .. round(printPos.y,2)  .. ","
  61.         note = note .. round(printPos.z,2)  .. "}"
  62.  
  63.         --Adds the rotation to note
  64.         note = note .. ', rot={'
  65.         note = note .. round(printRot.x,2) .. ","
  66.         note = note .. round(printRot.y,2)  .. ","
  67.         note = note .. round(printRot.z,2)  .. "}"
  68.  
  69.         --Adds the lock state to the note
  70.  
  71.         note = note .. ', lock='
  72.         if obj.getLock() == true then
  73.             note = note .. "true},\n"
  74.         else
  75.             note = note .. "false},\n"
  76.         end
  77.  
  78.  
  79.         if alt_click == true then
  80.             Wait.time(|| storageBag.putObject(entry.hit_object), 0.5)
  81.         end
  82.  
  83.     end
  84.  
  85.     --Add the final tag to the end of the table
  86.     note = note ..  "\n},"
  87.     --Sends the final results of note to the notepad tool
  88.     setNotes(note)
  89.  
  90.  
  91.  
  92.  
  93. end
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. function table01(obj, player_clicker_color, alt_click)
  102.  
  103.     selectedTable = dataTables[self.getButtons()[2].tooltip]
  104.  
  105.     if alt_click != true then
  106.         deploy(selectedTable)
  107.     else
  108.         store(selectedTable)
  109.     end
  110. end
  111.  
  112. function table02(obj, player_clicker_color, alt_click)
  113.  
  114.     selectedTable = dataTables[self.getButtons()[3].tooltip]
  115.  
  116.     if alt_click != true then
  117.         deploy(selectedTable)
  118.     else
  119.         store(selectedTable)
  120.     end
  121.  
  122. end
  123.  
  124. function table03(obj, player_clicker_color, alt_click)
  125.  
  126.     selectedTable = dataTables[self.getButtons()[4].tooltip]
  127.  
  128.     if alt_click != true then
  129.         deploy(selectedTable)
  130.     else
  131.         store(selectedTable)
  132.     end
  133.  
  134. end
  135.  
  136.  
  137. function deploy(objTable)
  138.  
  139.  
  140.     for _, entry in pairs(objTable) do
  141.         storageBag.takeObject({
  142.             position          = entry.pos,
  143.             rotation          = entry.rot,
  144.             callback_function = function(obj) obj.setLock(entry.lock) end,
  145.             smooth            = false,
  146.             guid              = entry.guid
  147.         })
  148.     end
  149.  
  150.  
  151. end
  152.  
  153. function store(objTable)
  154.  
  155.     for _, entry in pairs(objTable) do
  156.         storageBag.putObject(getObjectFromGUID(entry.guid))
  157.     end
  158.  
  159. end
  160.  
  161.  
  162. function buildTables()
  163.  
  164.     dataTables = {
  165.  
  166.  
  167.  
  168.         ['comp'] = {
  169.             {guid="a7b0f4", pos={-7.84,3.66,8.05}, rot={0,180,0}, lock=false},
  170.             {guid="8984d3", pos={-6,3.66,12}, rot={0,180,0}, lock=false},
  171.             {guid="4f6282", pos={0,1.49,0.02}, rot={0,0,0}, lock=false},
  172.             {guid="3abc95", pos={8,3.66,8}, rot={0,180,0}, lock=false},
  173.             {guid="fdcc18", pos={6,3.66,12}, rot={0,180,0}, lock=false},
  174.             {guid="c4b11b", pos={0.18,3.66,14.02}, rot={0,180,0}, lock=false},
  175.             {guid="ba04fe", pos={0,1.48,0}, rot={0,180,0}, lock=true},
  176.             {guid="6b3803", pos={8,3.66,-8}, rot={0,180,0}, lock=false},
  177.             {guid="736109", pos={0,3.66,-14}, rot={0,180,0}, lock=false},
  178.             {guid="3c8a64", pos={6,3.66,-12}, rot={0,180,0}, lock=false},
  179.             {guid="589d44", pos={-8.13,3.66,-7.95}, rot={0,180,0}, lock=false},
  180.             {guid="fc398c", pos={-6,3.66,-12}, rot={0,180,0}, lock=false},
  181.  
  182.         },
  183.  
  184.         ['coopGate'] = {
  185.  
  186.         },
  187.  
  188.         ['coopAi'] = {
  189.  
  190.         },
  191.  
  192.     }
  193.  
  194.     local i = 1
  195.     for tableName, table in pairs(dataTables) do
  196.         self.createButton({
  197.             click_function = 'table0' .. i,
  198.             function_owner = self,
  199.             label          = i,
  200.             position       = {0.8 , 0.25, -1.25 + i*0.25},
  201.             scale          = {0.3,0.3,0.3},
  202.             width          = 400,
  203.             height         = 400,
  204.             font_size      = 360,
  205.             font_color     = {0.9,0.9,0.9},
  206.             color          = {0.1,0.1,0.1},
  207.             tooltip        = tableName
  208.         })
  209.         i = i + 1
  210.     end
  211.  
  212. end
  213.  
  214.  
  215.  
  216.  
  217.  
  218. --Round number (num) to the second decimal
  219. function round(num,dec)
  220.   local mult = 10^(dec or 0)
  221.   return math.floor(num * mult + 0.5) / mult
  222. end
RAW Paste Data