Kitsunay

Untitled

Feb 22nd, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. function onLoad()
  2.     Wait.time(countItems, 2.0, -1)
  3. end
  4.  
  5. function countItems()
  6.     local bounds = self.getBounds()
  7.     local vertical_bound = 1
  8.  
  9.     local hits = Physics.cast({
  10.         origin = {
  11.             x = bounds.center.x,
  12.             y = bounds.center.y + bounds.size.y + vertical_bound / 2,
  13.             z = bounds.center.z,
  14.         },
  15.         direction = {0, 0.001, 0},
  16.         type = 3,
  17.         size = {
  18.             x = bounds.size.x,
  19.             y = vertical_bound,
  20.             z = bounds.size.z,
  21.         },
  22.         orientation = self.getRotation(),
  23.         max_distance = 1,
  24.         --debug = true
  25.     })
  26.  
  27.     -- tally token totals
  28.     -- A table that defaults to 0, and each object's name is matched for "amount label"
  29.     total = {}
  30.  
  31.     for i, v in pairs(hits) do
  32.         name = v.hit_object.getName()
  33.         if name != nil then
  34.             amount, label = string.match(name, '(%d+) (%a+)s?')
  35.             total[label] = (total[label] or 0) + amount
  36.         end
  37.         -- v.hit_object.highlightOn({0, 1, 0}, 10)
  38.     end
  39.  
  40.     for k, v in pairs(total) do
  41.         print(v, ' ', k)
  42.     end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment