Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --zdarova
- connection = false
- ID = 0
- myMessage = ""
- if not term.isColor() then
- print("Need advanced computer!")
- return
- end
- sides = {"front","back","left","right","top","bottom"}
- for i=1,6 do
- if peripheral.getType(sides[i]) == "modem" then
- rednet.open(sides[i])
- break
- end
- end
- if not rednet.isOpen() then
- print("Need wireless modem!")
- return
- end
- rednet.broadcast("zdarova", "ChatProto")
- term.clear()
- term.setCursorPos(1,1)
- print("Searching...")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(1,6)
- term.write("Exit")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,4)
- while true do
- event, arg1, arg2, arg3 = os.pullEvent()
- if event == "rednet_message" and arg3 == "ChatProto" then
- if not connection and arg2 == "zdarova" then
- connection = true
- ID = arg1
- term.clearLine()
- print("Connection created with "..ID.." ")
- term.setCursorPos(1,5)
- term.clearLine()
- term.setCursorPos(1,1)
- print("You: ")
- print("> ")
- rednet.send(ID, "connected", "ChatProto")
- elseif not connection and arg2 == "connected" then
- connection = true
- ID = arg1
- term.clearLine()
- print("Connection created with "..ID.." ")
- term.setCursorPos(1,1)
- print("You: ")
- print("> ")
- elseif connection and arg2 == "disconnected" and arg1 == ID then
- term.clear()
- term.setCursorPos(1,1)
- print("Searching...")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(1,6)
- term.write("Exit")
- term.setCursorPos(1,4)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write("Your chat partner has disconnected ")
- term.setTextColor(colors.white)
- connection = false
- term.setCursorPos(1,4)
- elseif connection and arg1 == ID then
- term.setCursorPos(1,2)
- term.clearLine()
- write("> "..arg2)
- end
- elseif event == "key" then
- if connection and arg1 == 28 and myMessage ~= "" then
- rednet.send(ID, myMessage, "ChatProto")
- term.setCursorPos(6,1)
- term.setTextColor(colors.gray)
- write(myMessage)
- term.setTextColor(colors.white)
- myMessage = ""
- elseif arg1 == 14 then
- myMessage = string.sub(myMessage,1,string.len(myMessage)-1)
- term.setCursorPos(1,1)
- term.clearLine()
- write("You: "..myMessage)
- end
- elseif event == "char" then
- myMessage = myMessage..arg1
- term.setCursorPos(1,1)
- term.clearLine()
- write("You: "..myMessage)
- elseif event == "mouse_click" and arg2 < 5 and arg3 == 6 then
- rednet.send(ID, "disconnected", "ChatProto")
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment