Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function deposit(atmID, blocklist, valuelist)
- total = 0
- while true do
- senderID, message, protocol = rednet.receive(1)
- if senderID == atmID and message == "stop" then
- print("Deposit Stopping")
- break
- end
- if turtle.suckUp() then
- local itemDetail = turtle.getItemDetail()
- for index, blockName in ipairs(blocklist) do
- if blockName == itemDetail.name then
- total += valuelist[index] * turtle.getItemCount()
- rednet.send(atmID, total)
- rednet.send(serverID, total)
- turtle.drop()
- end
- end
- turtle.dropDown()
- end
- end
- rednet.send(serverID, "stop")
- end
- -- Open a rednet connection
- rednet.open("right")
- serverID = 6
- atmID = 0
- -- Listen for messages
- while true do
- local senderID, message, protocol = rednet.receive()
- print("Received")
- -- Check if the message is for this turtle
- if senderID == serverID then
- -- Deserialize the received message into a table containing blockList and valueList
- local data = textutils.unserialize(message)
- -- Extract blockList and valueList from the received data
- local blockList = data.blockList
- local valueList = data.valueList
- -- Do something with the block list and value list
- for i, block in ipairs(blockList) do
- local value = valueList[i]
- print("Received block: " .. block .. ", Value: " .. value)
- end
- -- Stop listening for more messages
- break
- end
- end
- -- Listen for messages
- while true do
- local senderID, message, protocol = rednet.receive()
- print("Received")
- -- Check if the message is for this turtle
- if senderID == atmID then
- if message ~= "deposit" then
- print("Depositing")
- deposit(atmID, blockList, valueList)
- end
- end
- if senderID == serverID then
- print("Updating")
- -- Deserialize the received message into a table containing blockList and valueList
- local data = textutils.unserialize(message)
- -- Extract blockList and valueList from the received data
- local blockList = data.blockList
- local valueList = data.valueList
- -- Do something with the block list and value list
- for i, block in ipairs(blockList) do
- local value = valueList[i]
- print("Received block: " .. block .. ", Value: " .. value)
- end
- end
- end
- -- Close the rednet connection
- rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement