Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local lan
- local chest
- for k,v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "LAN NIC" then
- lan = peripheral.wrap(v)
- elseif peripheral.getType(v) == "chest" then
- chest = peripheral.wrap(v)
- end
- end
- if not lan then
- print("[ERROR] " .. textutils.formatTime(os.time()) .. " - No LAN modem attached. The collection host will now terminate.")
- return
- end
- if not chest then
- print("[ERROR] " .. textutils.formatTime(os.time()) .. " - No chest above turtle. The collection host will now terminate.")
- return
- end
- if turtle.getItemCount(16) == 0 then
- print("[ERROR] " .. textutils.formatTime(os.time()) .. " - No item found in slot 16. Place a gold ingot in this slot for item comparison. The collection host will now terminate.")
- return
- end
- turtle.select(16)
- print("[INFO] " .. textutils.formatTime(os.time()) .. " - The collection host is now active and listening.")
- while true do
- local eventData = { os.pullEvent("lan_message") }
- if textutils.unserialize(eventData[5])[1] == 0 then
- print("[INFO] " .. textutils.formatTime(os.time()) .. " - A deposit session was requested by terminal and accepted.")
- lan.send(textutils.serialize({1}))
- local addedIngots = 0
- repeat
- eventData = { os.pullEvent() }
- if eventData[1] == "turtle_inventory" and turtle.compareTo(eventData[2]) then
- addedIngots = addedIngots + 1
- end
- until eventData[1] == "lan_message" and textutils.unserialize(eventData[5])[1] == 3
- lan.send(textutils.serialize({4,addedIngots}))
- print("[INFO] " .. textutils.formatTime(os.time()) .. " - The deposit session was ended and the final value sent to the terminal.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement