Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OBJ_NAME = "Powerup Printer"
- PRINT_OBJECT_GUID = "cbbdeb"
- PRINT_TIME = 600
- TIMER_IDENTIFIER = nil
- timeToNextPrint = PRINT_TIME
- printedObject = false
- active = false
- printBtn={
- label="PRINT", click_function="printPowerUp", function_owner=self,
- position={2.5,1,5}, rotation={0,0,0}, scale={3,3,3}, width=500, height=300, font_size=120
- }
- itemsInsideLbl="Items inside: "
- timeLeftLbl="Next print in: "
- timerBtn={
- label=timeLeftLbl, click_function="none", function_owner=self,
- 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
- }
- count=12
- timerBtn.label= "Items inside: 12\nNext print in: 34"
- function onLoad()
- count=0
- for i, item in ipairs(self.getObjects()) do
- count=count+1
- end
- self.createButton(printBtn)
- self.createButton(timerBtn)
- if OBJ_NAME == nil then
- OBJ_NAME = self.getName()
- else
- self.setName(OBJ_NAME)
- end
- end
- function printPowerUp(obj, player_clicker_color, alt_click)
- if not active and player_clicker_color ~= "Black" then
- activateTimer()
- active = true
- end
- end
- function activateTimer()
- local timerIdentifier = "Timer." .. math.random(1,10000)
- local timerFunction = "timerFire"
- local timerPassParams = {""}
- local timerDelay = 1
- local timerReps = 0
- local timerParams = {}
- timerParams.identifier = timerIdentifier
- timerParams.function_name = timerFunction
- timerParams.parameters = timerPassParams
- timerParams.delay = timerDelay
- timerParams.repetitions = timerReps
- Timer.create(timerParams)
- TIMER_IDENTIFIER = timerIdentifier
- end
- function onDestroy()
- if TIMER_IDENTIFIER then
- Timer.destroy(TIMER_IDENTIFIER)
- end
- end
- function printObject(objGUID)
- activateTimer()
- local objToClone = getObjectFromGUID(objGUID)
- local pos = self.getPosition()
- local yOffset = 1
- local cloneParams = {}
- cloneParams.position = {pos.x, pos.y + yOffset, pos.z}
- local clonedObj = objToClone.clone(cloneParams)
- clonedObj.unlock()
- end
- function timerFire()
- timeToNextPrint = timeToNextPrint - 1
- if timeToNextPrint <= 0 then
- printObject(PRINT_OBJECT_GUID)
- timeToNextPrint = PRINT_TIME
- end
- local timeLeft = string.format("%02d:%02d", timeToNextPrint / 60 % 60, timeToNextPrint % 60)
- self.clearButtons()
- self.createButton(printBtn)
- timerBtn.label= itemsInsideLbl..string(count).."\n".. timeLeftLbl..timeLeft
- self.createButton(timerBtn)
- --self.setName(OBJ_NAME .. " (Next Print: " .. timeLeft .. ")")
- end
- function onObjectEnterContainer(bag, obj)
- if bag==self then
- count=count+1
- end
- end
- function onObjectLeaveContainer(bag, obj)
- if bag==self then
- count=count-1
- if count < 0 then
- count=0
- end
- end
- end
- function none()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement