Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SirChat v1.1.2 -Created by Sir.Mongoose
- local IDs = {}
- local ex = false
- local ID = os.getComputerID()
- local cl = false
- local line = 0
- local targetID = nil
- local x = true
- function receive()
- local senderID, message = rednet.receive()
- if message == "::sirchat" then
- IDs[senderID] = true
- term.clearLine()
- term.setCursorPos(1,line)
- elseif IDs[senderID] == true then
- term.clearLine()
- term.setCursorPos(1,line)
- print("<ID#"..senderID.."> "..(tostring(message)))
- line = line + 1
- table.remove(IDs, senderID)
- else
- term.clearLine()
- term.setCursorPos(1,line)
- end
- 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.2.")
- line = line + 3
- elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
- rednet.broadcast("::sirchat")
- rednet.send((tonumber(targetID)), (tostring(mesg)))
- line = line + 1
- end
- end
- function chat()
- x = false
- 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 line > 17 then
- cl = true
- end
- 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()
- print("**Enter the ComputerID you want to connect to**")
- line = line + 2
- term.setCursorPos(1,line)
- io.write(">>")
- target = read()
- if numCheck(target) == true then
- targetID = target
- line = line + 1
- else
- while numCheck(target) == false do
- term.setCursorPos(1,line)
- term.clearLine()
- io.write(">>")
- target = read()
- end
- targetID = target
- line = line + 1
- end
- if x == true then
- x = false
- term.clear()
- line = 3
- term.setCursorPos(1,1)
- chat()
- else
- term.setCursorPos(1,1)
- term.clearLine()
- print("**Connected with ComputerID#"..(tostring(targetID)).."**")
- term.setCursorPos(1,line)
- 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()
- term.clear()
- term.setCursorPos(1,1)
- connectModem()
- end
- end
- connectModem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement