csmit195

Namar Reactor: PDA

Jun 11th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local bedrockPath='Build/' 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 baseRestAPI = 'http://45.76.117.50:8080/datastore/'
  4.  
  5. local program, currentState
  6.  
  7. function init()
  8.     program = Bedrock:Initialise()
  9.     program:Run(function()
  10.         program:LoadView('main')
  11.        
  12.         -- Make sure the button is up to date with current reactor state
  13.         currentState = getReactorState()
  14.         local newText = currentState and 'Reactor State: ON' or 'Reactor State: OFF'
  15.         local newColour = currentState and colors.green or colors.red
  16.         program:GetObject('labelState').Text = newText
  17.         program:GetObject('labelState').TextColour = newColour
  18.        
  19.         program:GetObject('reactorState').OnClick = function(self, event, side, x, y)
  20.             currentState = not currentState
  21.             local newText = currentState and 'Reactor State: ON' or 'Reactor State: OFF'
  22.             local newColour = currentState and colors.green or colors.red
  23.             program:GetObject('labelState').Text = 'OFF'
  24.             program:GetObject('labelState').TextColour = newColour
  25.             program:StartTimer(function()setReactorState(currentState)end, 0.1)
  26.         end
  27.     end)
  28. end
  29.  
  30. function getReactorState()
  31.     local reactorRequest = http.get(baseRestAPI..'get/namar_reactor/state')
  32.     local requestContent = reactorRequest.readAll()
  33.     local reactorState = requestContent == 'error:nostore' or requestContent == 'true' or false
  34.     reactorRequest.close()
  35.     return reactorState
  36. end
  37.  
  38. function setReactorState(bool)
  39.     http.request(baseRestAPI..'set/namar_reactor/state/'..tostring(bool))
  40. end
  41.  
  42. -- Start Init Function
  43. init()
Advertisement
Add Comment
Please, Sign In to add comment