Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SirChat v1.1.0 -Created by Sir.Mongoose
- local ex = false
- local ID = os.getComputerID()
- local cl = false
- local line = 3
- function receive()
- local senderID, message, protocol = rednet.receive("sirchat")
- term.clearLine()
- term.setCursorPos(1,line)
- print("<ID#"..senderID.."> "..(tostring(message)))
- line = line + 1
- end
- function send()
- term.write("<ID#"..ID.."> ")
- local mesg = read()
- if mesg == "/exit" then
- ex = true
- term.clear()
- term.setCursorPos(1,1)
- elseif mesg == "/commands" then
- print("> '/exit' terminates the program.")
- print("> '/clear' clears chat completely.")
- print("> '/connect' connects you to a different ID.")
- print("> '/info' Tells you about SirChat.")
- line = line + 5
- elseif mesg == "/clear" then
- cl = true
- elseif mesg == "/connect" then
- connect()
- elseif mesg == "/info" then
- print("> SirChat was a program made by Sir.Mongoose.")
- print("> SirChat is currently in version 1.1.")
- elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
- rednet.send((tonumber(targetID)), (tostring(mesg)), "sirchat")
- line = line + 1
- end
- end
- function chat()
- term.clear()
- term.setCursorPos(1,1)
- print("**Connected with ComputerID#"..(tostring(targetID)).."**")
- print("**Type '/commands' for the list of commands**")
- while ex == false do
- parallel.waitForAny(receive, send)
- if cl == true then
- term.clear()
- term.setCursorPos(1,1)
- print("**Connected with ComputerID#"..(tostring(targetID)).."**")
- print("**Type '/commands' for the list of commands**")
- line = 3
- cl = false
- end
- end
- end
- function numCheck(a)
- if ((tonumber(a)) == nil) == true then
- return false
- else
- return true
- end
- end
- function connect()
- term.clear()
- term.setCursorPos(1,1)
- print("**Enter the ComputerID you want to connect to**")
- targetID = read()
- if numCheck(targetID) == true then
- chat()
- else
- while numCheck(targetID) == false do
- term.setCursorPos(1,2)
- term.clearLine()
- targetID = read()
- end
- chat()
- end
- end
- function connectModem()
- term.clear()
- term.setCursorPos(1,1)
- if peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
- rednet.open("back")
- connect()
- elseif peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
- rednet.open("front")
- connect()
- elseif peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
- rednet.open("left")
- connect()
- elseif peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
- rednet.open("right")
- connect()
- elseif peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
- rednet.open("top")
- connect()
- elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
- rednet.open("bottom")
- connect()
- else
- print("**No modem connected, please place one on an available side and press enter**")
- read()
- connectModem()
- end
- end
- connectModem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement