Advertisement
Corbinhol

energy dummy

Feb 21st, 2022 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 KB | None | 0 0
  1. --Turbine Client System
  2. --Version 0.1
  3.  
  4. local component = require("component");
  5. local sides = require("sides");
  6. local thread = require("thread");
  7. local filesystem = require("filesystem");
  8. local gpu = component.gpu;
  9. local serialization = require("serialization");
  10. local event = require("event");
  11. local modem = component.modem;
  12. --variables
  13. local systemName;
  14. local redstone = {};
  15. local inventory = {};
  16. local serverAddress;
  17. local port = 60;
  18. modem.open(port);
  19.  
  20. --Start Setup
  21. if not filesystem.exists("/home/systemName.dat") then
  22. print("No Current Name Found for System...")
  23. while true do
  24. print("Please Enter the System Name");
  25. io.write("> ");
  26. local tempName = io.read();
  27. io.write("\n");
  28. print("Are you sure you want System Name to be " .. tempName .. "? [y/n]");
  29. io.write("> ");
  30. local ans = io.read();
  31. io.write("\n");
  32. if ans == "y" then
  33. systemName = tempName;
  34. modem.setWakeMessage("Wake Up " .. systemName);
  35. local nameFile = io.open("systemName.dat", "w");
  36. nameFile:write(systemName);
  37. nameFile:close();
  38. break;
  39. end
  40. end
  41. else
  42. local nameFile = io.open("systemName.dat", "r");
  43. systemName = nameFile:read();
  44. nameFile:close();
  45. end
  46.  
  47. local turbineStatus = "Offline";
  48. local fuelCreation1Status = "Offline";
  49. local fuelCreation2Status = "Offline";
  50. local mainPowerStatus = "Disconnected";
  51. local powerOutput = 232313123;
  52. local energyStored = 312312321;
  53. local fuelLoaded = 32312312321312;
  54. local connectionStatus = "Disconnected";
  55. local breakerStatus = "Disconnected";
  56.  
  57. local checkCloche = true;
  58.  
  59. function toggleTurbine(status)
  60. if status == true then
  61. turbineStatus = "Online"
  62. else
  63. turbineStatus = "Offline"
  64. end
  65. end
  66.  
  67. function togglePotatoCloche1(status)
  68. if status == true then
  69. potatoChloche1Status = "Online"
  70. else
  71. potatoCloche1Address.setOutput(sides.left, 15)
  72. togglePotatoCloche1 = "Offline"
  73. end
  74. end
  75.  
  76. function togglePotatoCloche2(status)
  77. if status == true then
  78. potatoChloche1Status = "Online"
  79. else
  80. togglePotatoCloche2 = "Offline"
  81. end
  82.  
  83. end
  84.  
  85. function togglehempCloche1(status)
  86. if status == true then
  87. hempChloche1Status = "Online"
  88. else
  89. togglehempCloche1 = "Offline"
  90. end
  91. end
  92.  
  93. function togglehempCloche2(status)
  94. if status == true then
  95. hempChloche1Status = "Online"
  96. else
  97. togglehempCloche2 = "Offline"
  98. end
  99. end
  100.  
  101. function toggleFuelCreation1(status)
  102. if status == true then
  103. toggleFuelCreation1 = "Online"
  104. else
  105. toggleFuelCreation1 = "Offline"
  106. end
  107. end
  108.  
  109. function toggleFuelCreation2(status)
  110. if status == true then
  111. toggleFuelCreation2 = "Online"
  112. else
  113. toggleFuelCreation2 = "Offline"
  114. end
  115. end
  116.  
  117. function toggleBreaker(status)
  118. if status == true then
  119. breakerStatus = "Connected"
  120. else
  121. toggleBreaker = "Disonnected"
  122. end
  123. end
  124.  
  125. function toggleMainPower(status)
  126. if status == true then
  127. mainPowerStatus = "Connected"
  128. else
  129. toggleMainPower = "Disonnected"
  130. end
  131. end
  132.  
  133. function checkFuel(inv, side)
  134. return false;
  135. end
  136.  
  137.  
  138. function serverUpdater()
  139. local timeout = 6;
  140. run = true;
  141. while true do
  142. local _, _, serverAddress, _, _, input = event.pull(10, "modem_message", nil, nil, nil, nil, "getInfo");
  143. if input == nil then
  144. if timeout == 0 then
  145. connectionStatus = "Disconnected";
  146. timeout = 6;
  147. else
  148. timeout = timeout - 1;
  149. end
  150. else
  151. modem.send(serverAddress, port, "info", turbineStatus, powerOutput, energyStored, mainPowerStatus, fuelLoaded, breakerStatus, checkCloche);
  152. connectionStatus = "Connected";
  153. end
  154. end
  155. end
  156.  
  157. function serverHandler()
  158. while true do
  159. local _, _, serverAddress, _, _, msg1, msg2, msg3 = event.pull(10, "modem_message", nil);
  160. if msg1 == "cmd" then
  161. modem.send(serverAddress, port, "recieved");
  162. local cmdOut = executeCmd(msg2);
  163. os.sleep(1);
  164. modem.send(serverAddress, port, "report", cmdOut);
  165. elseif msg1 == "whois " .. systemName then
  166. modem.send(serverAddress, port, "I AM!!!", systemName);
  167. elseif msg1 == "getData" then
  168. modem.send(serverAddress, port, "heres data", getData(msg2));
  169. end
  170. end
  171. end
  172.  
  173.  
  174. function updateScreen()
  175.  
  176. gpu.set(1, 1, "==================================");
  177. gpu.set(1, 2, "Turbine Control System [Ver 0.1]");
  178. gpu.set(1, 3, "By Yogi And Shaggy");
  179. gpu.set(1, 4, "==================================");
  180.  
  181. gpu.set(1, 6, "System Name: ");
  182. gpu.set(1, 7, "Server Connection: ");
  183. gpu.set(1, 8, "Turbine Status: ");
  184. gpu.set(1, 9, "Fuel Creation 1: ");
  185. gpu.set(1, 10, "Fuel Creation 2: ");
  186. gpu.set(1, 11, "Breaker Status: ")
  187. gpu.set(1, 12, "Main Power: ");
  188. gpu.set(1, 13, "Power Output: ");
  189. gpu.set(1, 14, "Energy Stored: ");
  190. gpu.set(1, 15, "Biodiesel Stored: ");
  191. gpu.set(1, 17, "==================================");
  192.  
  193. while true do
  194. os.sleep(1)
  195. gpu.set(14, 6, systemName .. " ");
  196. gpu.set(20, 7, connectionStatus .. " " );
  197. gpu.set(17, 8, turbineStatus .. " ");
  198. gpu.set(19, 9, fuelCreation1Status .. " ");
  199. gpu.set(19, 10, fuelCreation2Status .. " ");
  200. gpu.set(17, 11, breakerStatus .. " ");
  201. gpu.set(12, 12, mainPowerStatus .. " ");
  202. gpu.set(15, 13, tostring(math.floor(powerOutput)) .. " ");
  203. gpu.set(16, 14, tostring(math.floor(energyStored)) .. " ");
  204. gpu.set(19, 15, tostring(math.floor(fuelLoaded)) .. " ");
  205. end
  206. end
  207.  
  208. function executeCmd(cmd)
  209. if cmd == "turnOnPotatoCloche1" then
  210. togglePotatoCloche1(true);
  211. return true
  212. elseif cmd == "turnOffPotatoCloche1" then
  213. togglePotatoCloche1(false);
  214. return true
  215. elseif cmd == "turnOnPotatoCloche2" then
  216. togglePotatoCloche2(true);
  217. return true
  218. elseif cnd == "turnOffPotatoCloche2" then
  219. togglePotatoCloche2(false);
  220. return true
  221. elseif cmd == "turnOnHempCloche1" then
  222. toggleHempCloche1(true);
  223. return true
  224. elseif cmd == "turnOffHempCloche1" then
  225. toggleHempCloche1(false);
  226. return true
  227. elseif cmd == "turnOnHempCloche2" then
  228. toggleHempCloche2(true);
  229. return true
  230. elseif cmd == "turnOffHempCloche2" then
  231. toggleHempCloche2(false);
  232. return true
  233. elseif cmd == "connectMainPower" then
  234. toggleMainPower(true);
  235. return true
  236. elseif cmd == "disconnectMainPower" then
  237. toggleMainPower(false);
  238. return true
  239. elseif cmd == "disableTurbine" then
  240. toggleTurbine(false);
  241. return true
  242. elseif cmd == "enableTurbine" then
  243. toggleTurbine(true)
  244. return true
  245. elseif cmd == "startSystems" then
  246. startSystems()
  247. return true
  248. elseif cmd == "stopSystems" then
  249. stopSystems()
  250. return true
  251. elseif cmd == "stopClocheCheck" then
  252. checkCloche = false;
  253. return true
  254. elseif cmd == "startClocheCheck" then
  255. checkCloche = true;
  256. return true
  257. else
  258. return false
  259. end
  260. end
  261.  
  262. function startSystems()
  263.  
  264. end
  265.  
  266. function stopSystems()
  267.  
  268. end
  269.  
  270. function getData(data)
  271. if data == "potatoCloche1Status" then
  272. return potatoCloche1Status;
  273. elseif data == "potatoCloche2Status" then
  274. return potatoCloche2Status;
  275. elseif data == "hempCloche1Status" then
  276. return hempCloche1Status;
  277. elseif data == "hempCloche2Status" then
  278. return hempCloche2Status;
  279. elseif data == "mainPowerStatus" then
  280. return mainPowerStatus;
  281. elseif data == "turbineStatus" then
  282. return turbineStatus;
  283. elseif data == "breakerStatus" then
  284. return breakerStatus;
  285. elseif data == "fuelLoaded" then
  286. return fuelLoaded;
  287. elseif data == "powerOutput" then
  288. return powerOutput;
  289. elseif data == "energyStored" then
  290. return energyStored;
  291. elseif data == "checkCloche" then
  292. return checkCloches;
  293. else
  294. return "Variable Not Found";
  295. end
  296. end
  297. os.execute("clear");
  298. local handler = thread.create(serverHandler);
  299. local serverUpdateHandler = thread.create(serverUpdater);
  300. updateScreen();
  301. while true do
  302. os.sleep(1);
  303. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement