csmit195

code

Sep 29th, 2018
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. local bedrockPath='/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end
  2.  
  3. local monitor = peripheral.wrap('monitor_299')
  4. term.redirect(monitor)
  5. monitor.setTextScale(1)
  6.  
  7. -- Variables
  8. local dragonRunning = false
  9. local dragonRunTimes = 1
  10.  
  11. function init()
  12.     program = Bedrock:Initialise()
  13.  
  14.     program:Run(function()
  15.         program:LoadView("main")
  16.  
  17.         dragonDelay = program:GetObject('dragonDelay')
  18.         dragonCount = program:GetObject('dragonCount')
  19.         submitBtn = program:GetObject('Submit')
  20.  
  21.         program:GetObject('dragonDelay_add1m').OnClick = function(self, event, side, x, y)
  22.             dragonDelay.Value = dragonDelay.Value + 60
  23.         end
  24.         program:GetObject('dragonDelay_add1h').OnClick = function(self, event, side, x, y)
  25.             dragonDelay.Value = dragonDelay.Value + 3600
  26.         end
  27.         program:GetObject('dragonDelay_subtract1m').OnClick = function(self, event, side, x, y)
  28.             dragonDelay.Value = dragonDelay.Value - 60
  29.         end
  30.         program:GetObject('dragonDelay_subtract1h').OnClick = function(self, event, side, x, y)
  31.             dragonDelay.Value = dragonDelay.Value - 3600
  32.         end
  33.         submitBtn.OnClick = function(self, event, side, x, y)
  34.             if ( not dragonRunning ) then
  35.                 program:DisplayAlertWindow('Are you sure?', 'This could cause lag...', {'Yes', 'No'}, function(value)
  36.                     if value == 'Yes' then
  37.                         setFarmingState(true)
  38.                     end
  39.                 end)
  40.             else
  41.                 setFarmingState(false)
  42.             end
  43.         end
  44.     end)
  45. end
  46.  
  47. function setFarmingState(active)
  48.     if ( not dragonRunning and active ) then
  49.         dragonRunTimes = 1
  50.         dragonRunning = true
  51.         submitBtn.Text = 'STOP'
  52.         submitBtn.BackgroundColour = 'red'
  53.         dragonDelay.Enabled = false
  54.         dragonCount.Enabled = false
  55.         dragonTimer = program:StartRepeatingTimer(doFarm, dragonDelay.Value)
  56.     elseif ( not active and dragonRunning and dragonTimer ) then
  57.         program.Timers[dragonTimer] = nil
  58.         submitBtn.Text = 'Start'
  59.         submitBtn.BackgroundColour = 'green'
  60.         dragonDelay.Enabled = true
  61.         dragonCount.Enabled = true
  62.         dragonRunTimes = 1
  63.         dragonRunning = false
  64.     end
  65. end
  66.  
  67. function doFarm()
  68.     if ( dragonRunning ) then
  69.         rs.setOutput('back', true)
  70.         sleep(0.5)
  71.        
  72.         rs.setOutput('back', false)
  73.        
  74.         if ( dragonCount.Value == 1 ) then
  75.             setFarmingState(false)
  76.             return false
  77.         end
  78.         dragonCount.Value = dragonCount.Value - 1
  79.         dragonRunTimes = dragonRunTimes + 1
  80.     end
  81. end
  82.  
  83. init()
Advertisement
Add Comment
Please, Sign In to add comment