SHARE
TWEET

Untitled

a guest Jun 28th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ Lua code. See documentation: http://berserk-games.com/knowledgebase/scripting/ --]]
  2.  
  3. --[[ The OnLoad function. This is called after everything in the game save finishes loading.
  4. Most of your script code goes here. --]]
  5. function onload()
  6.     self.createButton({
  7.         label="---", click_function="none", function_owner=Global,
  8.         position={0,0.1,0}, rotation={0,90,0}, height=0, width=0, font_size=25,
  9.         font_color={0.9, 0.9, 0.9}
  10.     })
  11.    
  12.     -- Get the text tool
  13.     --textObject = getObjectFromGUID('006bdc')
  14.     --[[
  15.     if textObject == nil then
  16.         -- The GUID is invalid
  17.         errorGuidInvalid()
  18.         textTool = nil
  19.     else
  20.         textTool = textObject.TextTool
  21.     end
  22.     ]]
  23.    
  24.     emptyText = ' '
  25.  
  26.     --[[
  27.     if textTool == nil then
  28.         -- The GUID is invalid
  29.         errorGuidInvalid()
  30.     else
  31.         -- Initialize the text options
  32.         local textColor = {}
  33.         textColor['r'] = 200
  34.         textColor['g'] = 200
  35.         textColor['b'] = 200
  36.         textTool.setFontColor(textColor)
  37.         textTool.setFontSize(40)
  38.         textTool.setValue(emptyText)
  39.     end
  40.     ]]
  41.    
  42. end
  43.  
  44. --[[ The Update function. This is called once per frame. --]]
  45. function update ()
  46.    
  47.     -- Validate text object
  48.     --[[if textTool == nil then
  49.         -- The GUID is invalid
  50.         errorGuidInvalid()
  51.         return
  52.     end]]
  53.     --[[
  54.     -- Get and validate cardboard object
  55.     if cardboard == nil then
  56.         cardboard = getObjectFromGUID('11df74')
  57.         if cardboard == nil then
  58.             -- The GUID is invalid
  59.             errorGuidInvalid()
  60.             return
  61.         end
  62.     end
  63. --]]
  64.     -- If the zone is moving, wait
  65.     if not self.resting then
  66.         --textTool.setValue(emptyText)
  67.         --cardboard.setDescription(emptyText)
  68.         return
  69.     end
  70.  
  71.     local ownPos = self.getPosition()
  72.     local ownRotation = self.getRotation()['x']
  73.     local ownScale = self.getScale()['x']
  74.  
  75.     -- Move the display with the box
  76.    
  77.     local displayOffsetX = -0.96 * ownScale
  78.     local displayOffsetY = 0 * ownScale
  79.     local displayOffsetZ = 0.18 * ownScale
  80.    
  81.     --local displayOffsetX = -1 * ownScale
  82.     --local displayOffsetY = 0.05 * ownScale
  83.     --local displayOffsetZ = 1.8 * ownScale
  84.     --local displayOffsetX = 0
  85.     --local displayOffsetY = 0
  86.     --local displayOffsetZ = 0
  87.     --textObject.setPosition({ownPos['x'] + displayOffsetX, ownPos['y'] + displayOffsetY, ownPos['z'] + displayOffsetZ})
  88.     --cardboard.setPosition({ownPos['x'] + displayOffsetX, ownPos['y'] + displayOffsetY, ownPos['z'] + displayOffsetZ})
  89.  
  90.     -- Compute the bounds of the box
  91.     local xboundOffset = 1.0
  92.     local yboundOffset = 1
  93.     local zboundOffset = 0.2
  94.     local leftBound = ownPos['x'] - xboundOffset * ownScale
  95.     local rightBound = ownPos['x'] + xboundOffset * ownScale
  96.     local upperBound = ownPos['z'] + zboundOffset * ownScale
  97.     local lowerBound = ownPos['z'] - zboundOffset * ownScale
  98.     local yupperBound = ownPos['y'] + yboundOffset --* ownScale
  99.     local ylowerBound = ownPos['y'] - yboundOffset --* ownScale
  100.  
  101.     local valueToCounter = {}
  102.     local valuesToSort = {}
  103.  
  104.     -- Iterate all objects in the zone
  105.     for _, obj in pairs(getAllObjects()) do
  106.         -- Fetch resting dices
  107.         if obj != nil and obj.tag == 'Dice' and obj.resting then
  108.             -- Only use objects inside the zone
  109.             local objPos = obj.getPosition()
  110.             if objPos['x'] > leftBound and objPos['x'] < rightBound and objPos['z'] > lowerBound and objPos['z'] < upperBound and objPos['y'] < yupperBound and objPos['y'] > ylowerBound then
  111.                 local value = obj.getValue()
  112.                 local counter = valueToCounter[value]
  113.                 -- First occurrence of this value
  114.                 if counter == nil then
  115.                     counter = 0
  116.                     valuesToSort[#valuesToSort + 1] = value
  117.                 end
  118.                 -- Increase the occurrence of this value
  119.                 counter = counter + 1
  120.                 valueToCounter[value] = counter
  121.             end
  122.         end
  123.     end
  124.  
  125.     -- Process the tracked values, sorted and build the lines to display
  126.     local textLines = {}
  127.     table.sort(valuesToSort)
  128.     for index, value in ipairs(valuesToSort) do
  129.         local counter = valueToCounter[value]
  130.         local line = '#' .. value .. ': ' .. counter
  131.         textLines[#textLines + 1] = line
  132.     end
  133.  
  134.     -- Display the text
  135.     local text = table.concat(textLines, '\n')
  136.     if text == '' then
  137.         -- Suppress the default text 'Type Here'
  138.         text = emptyText
  139.     end
  140.     self.editButton({index=0, label=text})
  141.     --textTool.setValue(text)
  142.     --cardboard.setDescription(text)
  143. end
  144.  
  145. function errorGuidInvalid()
  146.     print('Error: GUID invalid')
  147. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top