Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local Data = component.data
- local m = component.modem
- local SER = require("serialization")
- local PortO = 123
- m.open(PortO)
- ServerS = "31ef9c76-ab30-4bf1-a5d4-a1524e13bfb1"
- while true do
- local _, _, _, _, _, serialized_message = event.pull("modem_message")
- local received_table = SER.unserialize(serialized_message)
- local Iron = received_table.Iron
- local Gold = received_table.Gold
- local Diamond = received_table.Diamond
- local Stone = received_table.Stone
- local Cobble = received_table.Cobble
- local DSI = received_table.DSI
- local DIL = received_table.DIL
- if Iron <= 25 then
- local IFileR = io.open("Iron", "r")
- if IFileR == nil then
- local CIFile = io.open("Iron", "a")
- CIFile:write("100")
- CIFile:close()
- local IFileR = io.open("Iron", "r")
- local Balance = IFileR:read("*l")
- IFileR:close()
- local IFileW = io.open("Iron", "w")
- newBalanceI = Balance - 1
- IFileW:write(newBalanceI)
- io.write("Iron DOWN: ", newBalanceI, "$\n")
- IFileW:close()
- else
- local Balance = IFileR:read("*l")
- IFileR:close()
- local IFileW = io.open("Iron", "w")
- newBalanceI = Balance - 1
- IFileW:write(newBalanceI)
- io.write("Iron DOWN: ", newBalanceI, "$\n")
- IFileW:close()
- end
- elseif Iron >= 26 and Iron <= 51 then
- local IFileR = io.open("Iron", "r")
- if IFileR == nil then
- local CIFile = io.open("Iron", "a")
- CIFile:write("100")
- CIFile:close()
- local IFileR = io.open("Iron", "r")
- local Balance = IFileR:read("*l")
- IFileR:close()
- local IFileW = io.open("Iron", "w")
- newBalanceI = Balance
- IFileW:write(newBalanceI)
- io.write("Iron STAY: ", newBalanceI, "$\n")
- IFileW:close()
- else
- local Balance = IFileR:read("*l")
- IFileR:close()
- local IFileW = io.open("Iron", "w")
- newBalanceI = Balance
- IFileW:write(newBalanceI)
- io.write("Iron STAY: ", newBalanceI, "$\n")
- IFileW:close()
- end
- else
- local IFileR = io.open("Iron", "r")
- if IFileR == nil then
- local CIFile = io.open("Iron", "a")
- CIFile:write("100")
- CIFile:close()
- local IFileR = io.open("Iron", "r")
- local Balance = IFileR:read("*l")
- IFileR:close()
- local IFileW = io.open("Iron", "w")
- newBalanceI = Balance + 1
- IFileW:write(newBalanceI)
- io.write("Iron UP: ", newBalanceI, "$\n")
- IFileW:close()
- else
- local Balance = IFileR:read("*l")
- IFileR:close()
- local IFileW = io.open("Iron", "w")
- newBalanceI = Balance + 1
- IFileW:write(newBalanceI)
- io.write("Iron UP: ", newBalanceI, "$\n")
- IFileW:close()
- end
- end
- if Gold <= 25 then
- local GFileR = io.open("Gold", "r")
- if GFileR == nil then
- local CGFile = io.open("Gold", "a")
- CGFile:write("1000")
- CGFile:close()
- local GFileR = io.open("Gold", "r")
- local Balance = GFileR:read("*l")
- GFileR:close()
- local GFileW = io.open("Gold", "w")
- newBalanceG = Balance - 1
- GFileW:write(newBalanceG)
- io.write("Gold: DOWN ", newBalanceG, "$\n")
- GFileW:close()
- else
- local Balance = GFileR:read("*l")
- GFileR:close()
- local GFileW = io.open("Gold", "w")
- newBalanceG = Balance - 1
- GFileW:write(newBalanceG)
- io.write("Gold: DOWN ", newBalanceG, "$\n")
- GFileW:close()
- end
- elseif Gold >= 26 and Gold <= 51 then
- local GFileR = io.open("Gold", "r")
- if GFileR == nil then
- local CGFile = io.open("Gold", "a")
- CGFile:write("1000")
- CGFile:close()
- local GFileR = io.open("Gold", "r")
- local Balance = GFileR:read("*l")
- GFileR:close()
- local GFileW = io.open("Gold", "w")
- newBalanceG = Balance
- GFileW:write(newBalanceG)
- io.write("Gold: STAY ", newBalanceG, "$\n")
- GFileW:close()
- else
- local Balance = GFileR:read("*l")
- GFileR:close()
- local GFileW = io.open("Gold", "w")
- newBalanceG = Balance
- GFileW:write(newBalanceG)
- io.write("Gold: STAY ", newBalanceG, "$\n")
- GFileW:close()
- end
- else
- local GFileR = io.open("Gold", "r")
- if GFileR == nil then
- local CGFile = io.open("Gold", "a")
- CGFile:write("1000")
- CGFile:close()
- local GFileR = io.open("Gold", "r")
- local Balance = GFileR:read("*l")
- GFileR:close()
- local GFileW = io.open("Gold", "w")
- newBalanceG = Balance + 1
- GFileW:write(newBalanceG)
- io.write("Gold: UP ", newBalanceG, "$\n")
- GFileW:close()
- else
- local Balance = GFileR:read("*l")
- GFileR:close()
- local GFileW = io.open("Gold", "w")
- newBalanceG = Balance + 1
- GFileW:write(newBalanceG)
- io.write("Gold: UP ", newBalanceG, "$\n")
- GFileW:close()
- end
- end
- if Diamond <= 25 then
- local DFileR = io.open("Diamond", "r")
- if DFileR == nil then
- local CDFile = io.open("Diamond", "a")
- CDFile:write("10000")
- CDFile:close()
- local DFileR = io.open("Diamond", "r")
- local Balance = DFileR:read("*l")
- DFileR:close()
- local DFileW = io.open("Diamond", "w")
- newBalanceD = Balance - 1
- DFileW:write(newBalanceD)
- io.write("Diamond: DOWN ", newBalanceD, "$\n")
- DFileW:close()
- else
- local Balance = DFileR:read("*l")
- DFileR:close()
- local DFileW = io.open("Diamond", "w")
- newBalanceD = Balance - 1
- DFileW:write(newBalanceD)
- io.write("Diamond: DOWN ", newBalanceD, "$\n")
- DFileW:close()
- end
- elseif Diamond >= 26 and Diamond <= 51 then
- local DFileR = io.open("Diamond", "r")
- if DFileR == nil then
- local CDFile = io.open("Diamond", "a")
- CDFile:write("10000")
- CDFile:close()
- local DFileR = io.open("Diamond", "r")
- local Balance = DFileR:read("*l")
- DFileR:close()
- local DFileW = io.open("Diamond", "w")
- newBalanceD = Balance
- DFileW:write(newBalanceD)
- io.write("Diamond: STAY ", newBalanceD, "$\n")
- DFileW:close()
- else
- local Balance = DFileR:read("*l")
- DFileR:close()
- local DFileW = io.open("Diamond", "w")
- newBalanceD = Balance
- DFileW:write(newBalanceD)
- io.write("Diamond: STAY ", newBalanceD, "$\n")
- DFileW:close()
- end
- else
- local DFileR = io.open("Diamond", "r")
- if DFileR == nil then
- local CDFile = io.open("Diamond", "a")
- CDFile:write("10000")
- CDFile:close()
- local DFileR = io.open("Diamond", "r")
- local Balance = DFileR:read("*l")
- DFileR:close()
- local DFileW = io.open("Diamond", "w")
- newBalanceD = Balance + 1
- DFileW:write(newBalanceD)
- io.write("Diamond: UP ", newBalanceD, "$\n")
- DFileW:close()
- else
- local Balance = DFileR:read("*l")
- DFileR:close()
- local DFileW = io.open("Diamond", "w")
- newBalanceD = Balance + 1
- DFileW:write(newBalanceD)
- io.write("Diamond: UP ", newBalanceD, "$\n")
- DFileW:close()
- end
- end
- if Stone <= 25 then
- local SFileR = io.open("Stone", "r")
- if SFileR == nil then
- local CSFile = io.open("Stone", "a")
- CSFile:write("10")
- CSFile:close()
- local SFileR = io.open("Stone", "r")
- local Balance = SFileR:read("*l")
- SFileR:close()
- local SFileW = io.open("Stone", "w")
- newBalanceS = Balance - 1
- SFileW:write(newBalanceS)
- io.write("Stone: DOWN ", newBalanceS, "$\n")
- SFileW:close()
- else
- local Balance = SFileR:read("*l")
- SFileR:close()
- local SFileW = io.open("Stone", "w")
- newBalanceS = Balance - 1
- SFileW:write(newBalanceS)
- io.write("Stone: DOWN ", newBalanceS, "$\n")
- SFileW:close()
- end
- elseif Stone >= 26 and Stone <= 51 then
- local SFileR = io.open("Stone", "r")
- if SFileR == nil then
- local CSFile = io.open("Stone", "a")
- CSFile:write("10")
- CSFile:close()
- local SFileR = io.open("Stone", "r")
- local Balance = SFileR:read("*l")
- SFileR:close()
- local SFileW = io.open("Stone", "w")
- newBalanceS = Balance
- SFileW:write(newBalanceS)
- io.write("Stone: STAY ", newBalanceS, "$\n")
- SFileW:close()
- else
- local Balance = SFileR:read("*l")
- SFileR:close()
- local SFileW = io.open("Stone", "w")
- newBalanceS = Balance
- SFileW:write(newBalanceS)
- io.write("Stone: STAY ", newBalanceS, "$\n")
- SFileW:close()
- end
- else
- local SFileR = io.open("Stone", "r")
- if SFileR == nil then
- local CSFile = io.open("Stone", "a")
- CSFile:write("10")
- CSFile:close()
- local SFileR = io.open("Stone", "r")
- local Balance = SFileR:read("*l")
- SFileR:close()
- local SFileW = io.open("Stone", "w")
- newBalanceS = Balance + 1
- SFileW:write(newBalanceS)
- io.write("Stone: UP ", newBalanceS, "$\n")
- SFileW:close()
- else
- local Balance = SFileR:read("*l")
- SFileR:close()
- local SFileW = io.open("Stone", "w")
- newBalanceS = Balance + 1
- SFileW:write(newBalanceS)
- io.write("Stone: UP ", newBalanceS, "$\n")
- SFileW:close()
- end
- end
- if Cobble <= 25 then
- local CFileR = io.open("Cobble", "r")
- if CFileR == nil then
- local CCFile = io.open("Cobble", "a")
- CCFile:write("5")
- CCFile:close()
- local CFileR = io.open("Cobble", "r")
- local Balance = CFileR:read("*l")
- CFileR:close()
- local CFileW = io.open("Cobble", "w")
- newBalanceC = Balance - 1
- CFileW:write(newBalanceC)
- io.write("Cobble: DOWN ", newBalanceC, "$\n")
- CFileW:close()
- else
- local Balance = CFileR:read("*l")
- CFileR:close()
- local CFileW = io.open("Cobble", "w")
- newBalanceC = Balance - 1
- CFileW:write(newBalanceC)
- io.write("Cobble: DOWN ", newBalanceC, "$\n")
- CFileW:close()
- end
- elseif Cobble >= 26 and Cobble <= 51 then
- local CFileR = io.open("Cobble", "r")
- if CFileR == nil then
- local CCFile = io.open("Cobble", "a")
- CCFile:write("5")
- CCFile:close()
- local CFileR = io.open("Cobble", "r")
- local Balance = CFileR:read("*l")
- CFileR:close()
- local CFileW = io.open("Cobble", "w")
- newBalanceC = Balance
- CFileW:write(newBalanceC)
- io.write("Cobble: STAY ", newBalanceC, "$\n")
- CFileW:close()
- else
- local Balance = CFileR:read("*l")
- CFileR:close()
- local CFileW = io.open("Cobble", "w")
- newBalanceC = Balance
- CFileW:write(newBalanceC)
- io.write("Cobble: STAY ", newBalanceC, "$\n")
- CFileW:close()
- end
- else
- local CFileR = io.open("Cobble", "r")
- if CFileR == nil then
- local CCFile = io.open("Cobble", "a")
- CCFile:write("5")
- CCFile:close()
- local CFileR = io.open("Cobble", "r")
- local Balance = CFileR:read("*l")
- CFileR:close()
- local CFileW = io.open("Cobble", "w")
- newBalanceC = Balance + 1
- CFileW:write(newBalanceC)
- io.write("Cobble: UP ", newBalanceC, "$\n")
- CFileW:close()
- else
- local Balance = CFileR:read("*l")
- CFileR:close()
- local CFileW = io.open("Cobble", "w")
- newBalanceC = Balance + 1
- CFileW:write(newBalanceC)
- io.write("Cobble: UP ", newBalanceC, "$\n")
- CFileW:close()
- end
- end
- if DSI <= 25 then
- local DSFileR = io.open("DSI", "r")
- if DSFileR == nil then
- local CDSFile = io.open("DSI", "a")
- CDSFile:write("500")
- CDSFile:close()
- local DSFileR = io.open("DSI", "r")
- local Balance = DSFileR:read("*l")
- DSFileR:close()
- local DSFileW = io.open("DSI", "w")
- newBalanceDSI = Balance - 1
- DSFileW:write(newBalanceDSI)
- io.write("DSI: DOWN ", newBalanceDSI, "$\n")
- DSFileW:close()
- else
- local Balance = DSFileR:read("*l")
- DSFileR:close()
- local DSFileW = io.open("DSI", "w")
- newBalanceDSI = Balance - 1
- DSFileW:write(newBalanceDSI)
- io.write("DSI: DOWN ", newBalanceDSI, "$\n")
- DSFileW:close()
- end
- elseif DSI >= 26 and DSI <= 51 then
- local DSFileR = io.open("DSI", "r")
- if DSFileR == nil then
- local CDSFile = io.open("DSI", "a")
- CDSFile:write("500")
- CDSFile:close()
- local DSFileR = io.open("DSI", "r")
- local Balance = DSFileR:read("*l")
- DSFileR:close()
- local DSFileW = io.open("DSI", "w")
- newBalanceDSI = Balance
- DSFileW:write(newBalanceDSI)
- io.write("DSI: STAY ", newBalanceDSI, "$\n")
- DSFileW:close()
- else
- local Balance = DSFileR:read("*l")
- DSFileR:close()
- local DSFileW = io.open("DSI", "w")
- newBalanceDSI = Balance
- DSFileW:write(newBalanceDSI)
- io.write("DSI: STAY ", newBalanceDSI, "$\n")
- DSFileW:close()
- end
- else
- local DSFileR = io.open("DSI", "r")
- if DSFileR == nil then
- local CDSFile = io.open("DSI", "a")
- CDSFile:write("500")
- CDSFile:close()
- local DSFileR = io.open("DSI", "r")
- local Balance = DSFileR:read("*l")
- DSFileR:close()
- local DSFileW = io.open("DSI", "w")
- newBalanceDSI = Balance + 1
- DSFileW:write(newBalanceDSI)
- io.write("DSI: UP ", newBalanceDSI, "$\n")
- DSFileW:close()
- else
- local Balance = DSFileR:read("*l")
- DSFileR:close()
- local DSFileW = io.open("DSI", "w")
- newBalanceDSI = Balance + 1
- DSFileW:write(newBalanceDSI)
- io.write("DSI: UP ", newBalanceDSI, "$\n")
- DSFileW:close()
- end
- end
- if DIL <= 25 then
- local DIFileR = io.open("DIL", "r")
- if DIFileR == nil then
- local CDIFile = io.open("DIL", "a")
- CDIFile:write("400")
- CDIFile:close()
- local DIFileR = io.open("DIL", "r")
- local Balance = DIFileR:read("*l")
- DIFileR:close()
- local DIFileW = io.open("DIL", "w")
- newBalanceDIL = Balance - 1
- DIFileW:write(newBalanceDIL)
- io.write("DIL: DOWN ", newBalanceDIL, "$\n")
- DIFileW:close()
- else
- local Balance = DIFileR:read("*l")
- DIFileR:close()
- local DIFileW = io.open("DIL", "w")
- newBalanceDIL = Balance - 1
- DIFileW:write(newBalanceDIL)
- io.write("DIL: DOWN ", newBalanceDIL, "$\n")
- DIFileW:close()
- end
- elseif DIL >= 26 and DIL <= 51 then
- local DIFileR = io.open("DIL", "r")
- if DIFileR == nil then
- local CDIFile = io.open("DIL", "a")
- CDIFile:write("400")
- CDIFile:close()
- local DIFileR = io.open("DIL", "r")
- local Balance = DIFileR:read("*l")
- DIFileR:close()
- local DIFileW = io.open("DIL", "w")
- newBalanceDIL = Balance
- DIFileW:write(newBalanceDIL)
- io.write("DIL: STAY ", newBalanceDIL, "$\n")
- DIFileW:close()
- else
- local Balance = DIFileR:read("*l")
- DIFileR:close()
- local DIFileW = io.open("DIL", "w")
- newBalanceDIL = Balance
- DIFileW:write(newBalanceDIL)
- io.write("DIL: STAY ", newBalanceDIL, "$\n")
- DIFileW:close()
- end
- else
- local DIFileR = io.open("DIL", "r")
- if DIFileR == nil then
- local CDIFile = io.open("DIL", "a")
- CDIFile:write("400")
- CDIFile:close()
- local DIFileR = io.open("DIL", "r")
- local Balance = DIFileR:read("*l")
- DIFileR:close()
- local DIFileW = io.open("DIL", "w")
- newBalanceDIL = Balance + 1
- DIFileW:write(newBalanceDIL)
- io.write("DIL: UP ", newBalanceDIL, "$\n")
- DIFileW:close()
- else
- local Balance = DIFileR:read("*l")
- DIFileR:close()
- local DIFileW = io.open("DIL", "w")
- newBalanceDIL = Balance + 1
- DIFileW:write(newBalanceDIL)
- io.write("DIL: UP ", newBalanceDIL, "$\n")
- DIFileW:close()
- end
- end
- table_to_send = {
- Iron = newBalanceI,
- Gold = newBalanceG,
- Diamond = newBalanceD,
- Stone = newBalanceS,
- Cobble = newBalanceC,
- DSI = newBalanceDSI,
- DIL = newBalanceDIL
- }
- local message_to_send = SER.serialize(table_to_send)
- m.send(ServerS, PortO, message_to_send)
- os.sleep(12)
- term.clear()
- end
Add Comment
Please, Sign In to add comment