Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. function onload()
  2.   live = 0
  3.   live2 = 0
  4.   track = 1
  5.   self.createButton({
  6.    label="", click_function="queueAnimation", function_owner=self,
  7.    position={0.8,0.3,1.15}, height=100, width=90, font_size=240, rotation={0,0,0}
  8.  })
  9.  -- previous btn
  10.  self.createButton({
  11.    label="", click_function="previousTrack", function_owner=self,
  12.    position={0.84,0.3,-0.98}, height=100, width=40, font_size=240, rotation={0,0,0}
  13.  })
  14.  -- next btn
  15.   self.createButton({
  16.    label="", click_function="nextTrack", function_owner=self,
  17.    position={0.84,0.3,-1.175}, height=100, width=40, font_size=240, rotation={0,0,0}
  18.  })
  19. end
  20.  
  21. function queueAnimation()
  22.   self.AssetBundle.playTriggerEffect(2)
  23.   Timer.destroy("waitforanimation")
  24.   Timer.create({identifier="waitforanimation", function_name='armIn', delay=0.6})
  25. end
  26.  
  27. function armIn()
  28.   if live == 0 then
  29.     self.AssetBundle.playTriggerEffect(0)
  30.     live = 1
  31.     track = 1
  32.     queueMusic()
  33.     print("Playing track: " .. track)
  34.   elseif live == 1 then
  35.     self.AssetBundle.playTriggerEffect(1)
  36.     live = 0
  37.     live2 = 0
  38.     stopMusic()
  39.   end
  40. end
  41.  
  42. function queueMusic()
  43.   Timer.destroy("waitforanimation")
  44.   Timer.create({identifier="waitforanimation", function_name='musicOn', delay=2})
  45. end
  46.  
  47. function musicOn()
  48.     live2 = 1
  49.     findMusic()
  50.     findObject()
  51. end
  52.  
  53. function nextTrack()
  54.   self.AssetBundle.playTriggerEffect(4)
  55.   if live == 0 then
  56.     -- don't play!
  57.     print("Invalid input - No music is currently playing.")
  58.   elseif live == 1 then
  59.     track = track + 1
  60.     print("Playing track: " .. track)
  61.     findMusic()
  62.   end
  63. end
  64.  
  65. function findMusic()
  66.     local allObjects = getAllObjects()
  67.     local toolPos = self.getPosition()
  68.     local toolPosX = toolPos.x
  69.     local toolPosZ = toolPos.z
  70.     for i, v in pairs(allObjects) do
  71.         if v.tag == "Generic" then
  72.             local vPos = v.getPosition()
  73.             local vPosX = vPos.x
  74.             local vPosZ = vPos.z
  75.             local dX = toolPosX - vPosX
  76.             local dZ = toolPosZ - vPosZ
  77.             if dX<3 and dX>-3 and dZ<2 and dZ>-2 then
  78.               v.AssetBundle.playTriggerEffect(track)
  79.             end
  80.         end
  81.     end
  82. end
  83.  
  84. function previousTrack()
  85.   self.AssetBundle.playTriggerEffect(3)
  86.   if live == 0 then
  87.     -- don't play!
  88.     print("Invalid input - No music is currently playing.")
  89.   elseif live == 1 then
  90.     if track <= 1 then
  91.       track = 1
  92.     else
  93.       track = track - 1
  94.       print("Playing track: " .. track)
  95.       findMusic()
  96.     end
  97.   end
  98. end
  99.  
  100. function stopMusic()
  101.   track = 0
  102.   findMusic()
  103. end
  104.  
  105. function findObject()
  106.     local allObjects = getAllObjects()
  107.     local toolPos = self.getPosition()
  108.     local toolPosX = toolPos.x
  109.     local toolPosZ = toolPos.z
  110.     local found
  111.     for i, v in pairs(allObjects) do
  112.         if v.tag == "Generic" then
  113.             local vPos = v.getPosition()
  114.             local vPosX = vPos.x
  115.             local vPosZ = vPos.z
  116.             local dX = toolPosX - vPosX
  117.             local dZ = toolPosZ - vPosZ
  118.             if dX<3 and dX>-3 and dZ<2 and dZ>-2 then
  119.               rotateMe(v)
  120.               found = true
  121.               foundObjectGUID = v.guid
  122.             end
  123.         end
  124.     end
  125.     if not found then
  126.         if foundObjectGUID then
  127.             local foundObject = getObjectFromGUID(foundObjectGUID)
  128.             if foundObject then
  129.                 foundObject.AssetBundle.playTriggerEffect(0)           
  130.             end
  131.         end
  132.         if live2 == 1 then
  133.             armIn()
  134.         end
  135.     end
  136. end
  137.  
  138. function rotateMe(v)
  139.   rot = v.getRotation()
  140.      v.setRotation({0,rot['y']+5,0})
  141. end
  142.  
  143. function update()
  144.   if live == 1 then
  145.     findObject()
  146.   elseif live == 0 then
  147.     -- don't!
  148.   end
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement