Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SirChat v1.0.0 -Created by Sir.Mongoose
- local ex = false
- local ID = os.getComputerID()
- local cl = false
- local line = 3
- function receive()
- local senderID, message = rednet.receive()
- 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.0.")
- elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
- rednet.send((tonumber(targetID)), (tostring(mesg)))
- 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)
- print("**Enter the side of an available Modem** (back,right,left,top,front,bottom, or exit to exit)")
- local side = read()
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- rednet.open(side)
- connect()
- elseif side == "exit" then
- term.clear()
- term.setCursorPos(1,1)
- else
- connectModem()
- end
- end
- connectModem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement