Advertisement
Guest User

Untitled

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