Advertisement
natie3

Tanks

Oct 29th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. m1 = peripheral.wrap("railcraft:tank_iron_valve_2")
  2. m2 = peripheral.wrap("railcraft:tank_iron_valve_1")
  3. m3 = peripheral.wrap("railcraft:tank_iron_valve_0")
  4.  
  5. os.startTimer(1)
  6. creosote_oil = false
  7. tree_oil = false
  8.  
  9. function set(value1, value2)
  10.   creosote_oil = value1
  11.   tree_oil = value2
  12.   rs.setOutput("left", creosote_oil)
  13.   rs.setOutput("right", tree_oil)
  14. end
  15.  
  16. function getValue(device)
  17.   tanksTable = device.getTanks()
  18.   maintank = tanksTable[1]
  19.   return math.floor(100 * (maintank.amount or 0) / maintank.capacity)
  20. end
  21.  
  22. function sendUpdate(v1, v2, v3, currentState)
  23.   url = "http://gorgony.nl:25586/update?vals="
  24.   url = url .. v1 .. ";"
  25.   url = url .. v2 .. ";"
  26.   url = url .. v3
  27.   url = url .. "&state=" .. currentState
  28.   http.get(url)
  29. end
  30.  
  31. while true do
  32.   e, r1, r2, r3, r4 = os.pullEvent()
  33.   if e == "timer" then
  34.     v1 = getValue(m1)
  35.     v2 = getValue(m2)
  36.     v3 = getValue(m3)
  37.  
  38.     if not creosote_oil and v1 > 95 then
  39.       set(true, false)
  40.     elseif creosote_oil and v1 < 5 then
  41.       set(false, v2 > 30)
  42.     end
  43.  
  44.     if not (creosote_oil or tree_oil) and v2 > 60 then
  45.       set(false, true)
  46.     elseif tree_oil and v2 < 20 then
  47.       set(false, false)
  48.     end
  49.  
  50.     sendUpdate(v1, v2, v3, ((creosote_oil or tree_oil) and "on") or "off")
  51.     os.startTimer(60)
  52.   end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement