Advertisement
Guest User

startup

a guest
Jan 26th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. -- Config
  2.  
  3. isDiselGen = true
  4. genPos = "right"
  5. redstoneControl = false
  6. redstoneOutputSide = "left"
  7. requiredPowerGenLevel = 5
  8.  
  9. modemPos = "top"
  10. xOffsett = -1
  11.  
  12.  
  13. -- end of config
  14.  
  15. term.clear()
  16. status = "disabled"
  17. powerGenLevel = 0
  18.  
  19. gen = peripheral.wrap(genPos)
  20. rednet.open(modemPos)
  21.  
  22. function cText(text, yPos, xOff)
  23. x,y = term.getSize()
  24. xPos = (x - string.len(text))/2 - xOffsett - xOff
  25. term.setCursorPos(xPos,yPos)
  26. print(text)
  27. end
  28.  
  29. function screen()
  30. term.clear()
  31. cText("PowerController by _TheSettler_", 2, 0)
  32. cText("Recived power gen level:" .. powerGenLevel, 4, 0)
  33. cText("Status: " .. status, 5, 0)
  34. cText("Inncoming brodcasts:", 16, 0)
  35. cText(message .. " / " .. protocol, 17, 0)
  36. end
  37.  
  38. function checkMessage()
  39.   if protocol == "powerGenLevel" then
  40.   if message == 1 then
  41.         powerGenLevel = 1
  42.         elseif message == 2 then
  43.         powerGenLevel = 2
  44.         elseif message == 3 then
  45.         powerGenLevel = 3
  46.         elseif message == 4 then
  47.         powerGenLevel = 4      
  48.         else
  49.         status = "Error: No PowerLevel"
  50.         end
  51.     end
  52.     if requiredPowerGenLevel <= powerGenLevel then
  53.         status = "Activated"
  54.     else
  55.         status = "Deactivated"
  56.     end
  57.     controlPower()
  58. end
  59.  
  60. function isNumeric(value)
  61.   if tonumber(value) ~= nil then    
  62.     return true
  63.   else
  64.     return false
  65.   end
  66. end
  67.  
  68.  
  69. function controlPower()
  70.     if isDiselGen == true then
  71.         if status == "Activated" then
  72.             gen.setEnabled(true)
  73.         else
  74.             gen.setEnabled(false)  
  75.         end
  76.     end
  77.     if redstoneControl == true then
  78.         if status == "Activated" then
  79.             redstone.setOutput(redstoneOutputSide, false)
  80.         else
  81.             redstone.setOutput(redstoneOutputSide, false)
  82.         end
  83.     end
  84. end
  85.  
  86.  
  87. while true do
  88. senderID, message, protocol = rednet.receive()
  89.   checkMessage()
  90.   screen()
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement