Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. OBJ_NAME = "Powerup Printer"
  2. PRINT_OBJECT_GUID = "cbbdeb"
  3.  
  4. PRINT_TIME = 600
  5. TIMER_IDENTIFIER = nil
  6.  
  7. timeToNextPrint = PRINT_TIME
  8. printedObject = false
  9.  
  10. active = false
  11.  
  12. printBtn={
  13. label="PRINT", click_function="printPowerUp", function_owner=self,
  14. position={2.5,1,5}, rotation={0,0,0}, scale={3,3,3}, width=500, height=300, font_size=120
  15. }
  16.  
  17. itemsInsideLbl="Items inside: "
  18. timeLeftLbl="Next print in: "
  19.  
  20. timerBtn={
  21. label=timeLeftLbl, click_function="none", function_owner=self,
  22. position={-3,1,5}, rotation={0,0,0}, color={0,0,0}, font_color={1,1,1}, scale={3,3,3}, width=1000, height=300, font_size=100
  23. }
  24. count=12
  25. timerBtn.label= "Items inside: 12\nNext print in: 34"
  26.  
  27. function onLoad()
  28. count=0
  29. for i, item in ipairs(self.getObjects()) do
  30. count=count+1
  31. end
  32. self.createButton(printBtn)
  33. self.createButton(timerBtn)
  34. if OBJ_NAME == nil then
  35. OBJ_NAME = self.getName()
  36. else
  37. self.setName(OBJ_NAME)
  38. end
  39. end
  40.  
  41. function printPowerUp(obj, player_clicker_color, alt_click)
  42. if not active and player_clicker_color ~= "Black" then
  43.  
  44. activateTimer()
  45. active = true
  46.  
  47. end
  48.  
  49. end
  50.  
  51. function activateTimer()
  52.  
  53. local timerIdentifier = "Timer." .. math.random(1,10000)
  54. local timerFunction = "timerFire"
  55. local timerPassParams = {""}
  56. local timerDelay = 1
  57. local timerReps = 0
  58.  
  59. local timerParams = {}
  60. timerParams.identifier = timerIdentifier
  61. timerParams.function_name = timerFunction
  62. timerParams.parameters = timerPassParams
  63. timerParams.delay = timerDelay
  64. timerParams.repetitions = timerReps
  65. Timer.create(timerParams)
  66.  
  67. TIMER_IDENTIFIER = timerIdentifier
  68.  
  69. end
  70.  
  71. function onDestroy()
  72.  
  73. if TIMER_IDENTIFIER then
  74. Timer.destroy(TIMER_IDENTIFIER)
  75. end
  76.  
  77. end
  78.  
  79. function printObject(objGUID)
  80. activateTimer()
  81. local objToClone = getObjectFromGUID(objGUID)
  82.  
  83. local pos = self.getPosition()
  84. local yOffset = 1
  85.  
  86. local cloneParams = {}
  87. cloneParams.position = {pos.x, pos.y + yOffset, pos.z}
  88.  
  89. local clonedObj = objToClone.clone(cloneParams)
  90. clonedObj.unlock()
  91.  
  92. end
  93.  
  94. function timerFire()
  95.  
  96. timeToNextPrint = timeToNextPrint - 1
  97.  
  98. if timeToNextPrint <= 0 then
  99.  
  100. printObject(PRINT_OBJECT_GUID)
  101. timeToNextPrint = PRINT_TIME
  102.  
  103. end
  104.  
  105. local timeLeft = string.format("%02d:%02d", timeToNextPrint / 60 % 60, timeToNextPrint % 60)
  106. self.clearButtons()
  107. self.createButton(printBtn)
  108. timerBtn.label= itemsInsideLbl..string(count).."\n".. timeLeftLbl..timeLeft
  109. self.createButton(timerBtn)
  110. --self.setName(OBJ_NAME .. " (Next Print: " .. timeLeft .. ")")
  111. end
  112.  
  113. function onObjectEnterContainer(bag, obj)
  114. if bag==self then
  115. count=count+1
  116. end
  117. end
  118.  
  119. function onObjectLeaveContainer(bag, obj)
  120. if bag==self then
  121. count=count-1
  122. if count < 0 then
  123. count=0
  124. end
  125. end
  126. end
  127.  
  128. function none()
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement