Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SirChat v1.2.0 -Created by Sir.Mongoose
- local IDs = {}
- local ex = false
- local ID = os.getComputerID()
- local cle = false
- local cle2 = false
- local line = 0
- local mLine = 1
- local targetID = nil
- local x = true
- local monitor = term
- local w = 1
- local p = 2
- local c = 3
- local cl = 4
- local s = 5
- local m = 6
- local sp = true
- local curx = 0
- local cury = 0
- local he = 0
- local ms = 7
- local wi = 0
- local he = 0
- function termToMon(a,b,d)
- if monitor ~= term then
- if a == ms then
- if d == line then
- monitor.setCursorPos(b,mLine)
- else
- monitor.setCursorPos(b,d)
- end
- elseif a == m and b == c and d == c then
- monitor.clear()
- elseif a == m and b == p then
- curx, cury = monitor.getCursorPos()
- if sp == false then
- monitor.setCursorPos(1,cury+1)
- monitor.write(d)
- else
- sp = false
- monitor.write(d)
- end
- elseif a == m and b == w then
- curx, cury = monitor.getCursorPos()
- if sp == false then
- monitor.setCursorPos(1, cury+1)
- monitor.write(d)
- sp = true
- else
- monitor.write(d)
- end
- elseif a == w and b == w then
- curx, cury = monitor.getCursorPos()
- if sp == false then
- monitor.setCursorPos(1, cury+1)
- monitor.write(d)
- sp = true
- else
- monitor.write(d)
- end
- write(d)
- elseif a == p and b == p then
- curx, cury = monitor.getCursorPos()
- if sp == false then
- monitor.setCursorPos(1,cury+1)
- monitor.write(d)
- else
- sp = false
- monitor.write(d)
- end
- print(d)
- elseif a == c and b == c and d == c then
- monitor.clear()
- term.clear()
- elseif a == cl and b == cl and d == cl then
- monitor.clearLine()
- term.clearLine()
- elseif a == s then
- if d == line then
- monitor.setCursorPos(b,mLine)
- term.setCursorPos(b,d)
- else
- monitor.setCursorPos(b,d)
- term.setCursorPos(b,d)
- end
- end
- else
- if a == w and b == w then
- write(d)
- elseif a == p and b == p then
- print(d)
- elseif a == c and b == c and d == c then
- term.clear()
- elseif a == cl and b == cl and d == cl then
- term.clearLine()
- elseif a == s then
- term.setCursorPos(b,d)
- end
- end
- end
- function receive()
- local senderID, message = rednet.receive()
- if message == "::sirchat" then
- IDs[senderID] = true
- termToMon(cl,cl,cl)
- termToMon(s,1,line)
- elseif IDs[senderID] == true then
- termToMon(cl,cl,cl)
- termToMon(s,1,line)
- termToMon(p,p,"<ID#"..senderID.."> "..(tostring(message)))
- line = line + 1
- mLine = mLine + 1
- table.remove(IDs, senderID)
- else
- termToMon(cl,cl,cl)
- termToMon(s,1,line)
- end
- end
- function send()
- termToMon(w,w,"<ID#"..ID.."> ")
- local mesg = read()
- termToMon(m,p,mesg)
- if mesg == "/exit" then
- ex = true
- termToMon(c,c,c)
- termToMon(s,1,1)
- elseif mesg == "/commands" then
- termToMon(p,p,"> '/exit' terminates the program.")
- termToMon(p,p,"> '/clear' clears chat completely.")
- termToMon(p,p,"> '/connect' connects you to a different ID.")
- termToMon(p,p,"> '/info' Tells you about SirChat.")
- line = line + 5
- mLine = mLine + 5
- elseif mesg == "/clear" then
- cleA = true
- elseif mesg == "/connect" then
- connect()
- elseif mesg == "/info" then
- termToMon(p,p,"> SirChat was a program made by Sir.Mongoose.")
- termToMon(p,p,"> SirChat is currently in version 1.2.0.")
- line = line + 3
- mLine = mLine + 3
- elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
- rednet.send((tonumber(targetID)), "::sirchat")
- rednet.send((tonumber(targetID)), (tostring(mesg)))
- line = line + 1
- mLine = mLine + 1
- end
- end
- function chat()
- x = false
- termToMon(c,c,c)
- termToMon(s,1,1)
- termToMon(p,p,"**Connected with ComputerID#"..(tostring(targetID)).."**")
- termToMon(p,p,"**Type '/commands' for the list of commands**")
- while ex == false do
- parallel.waitForAny(receive, send)
- if line > 17 then
- cle = true
- elseif mLine > he-2 then
- cle2 = true
- end
- if cleA == true then
- line = 1
- mLine = 0
- termToMon(c,c,c)
- termToMon(s,1,line)
- termToMon(p,p,"**Connected with ComputerID#"..(tostring(targetID)).."**")
- termToMon(p,p,"**Type '/commands' for the list of commands**")
- line = 3
- mLine = 4
- cleA = false
- elseif cle == true then
- term.clear()
- term.setCursorPos(1,1)
- print("**Connected with ComputerID#"..(tostring(targetID)).."**")
- print("**Type '/commands' for the list of commands**")
- line = 3
- cle = false
- elseif cle2 == true then
- termToMon(m,c,c)
- termToMon(ms,1,0)
- termToMon(m,p,"**Connected with ComputerID#"..(tostring(targetID)).."**")
- termToMon(m,p,"**Type '/commands' for the list of commands**")
- mLine = 4
- cle2 = false
- end
- end
- end
- function numCheck(a)
- if ((tonumber(a)) == nil) == true then
- return false
- else
- return true
- end
- end
- function connect()
- termToMon(p,p,"**Enter the ComputerID you want to connect to**")
- line = line + 2
- mLine = mLine + 2
- termToMon(s,1,line)
- termToMon(w,w,">>")
- target = read()
- if numCheck(target) == true then
- targetID = target
- termToMon(m,w,target)
- line = line + 1
- mLine = mLine + 1
- else
- while numCheck(target) == false do
- termToMon(s,1,line)
- termToMon(cl,cl,cl)
- termToMon(w,w,">>")
- target = read()
- end
- targetID = target
- termToMon(m,w,target)
- line = line + 1
- end
- if x == true then
- x = false
- termToMon(c,c,c)
- line = 3
- mLine = 3
- termToMon(s,1,1)
- chat()
- else
- termToMon(s,1,1)
- termToMon(cl,cl,cl)
- termToMon(p,p,"**Connected with ComputerID#"..(tostring(targetID)).."**")
- termToMon(s,1,line)
- end
- end
- function connectModem()
- if monitor ~= term then
- wi, he = monitor.getSize()
- if wi < 50 then
- monitor.setTextScale(0.9)
- wi, he = monitor.getSize()
- end
- end
- termToMon(c,c,c)
- termToMon(s,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
- termToMon(p,p,"**No modem connected, please place one on an available side and press enter**")
- read()
- termToMon(c,c,c)
- termToMon(s,1,1)
- connectModem()
- end
- end
- function connectMonitor()
- if peripheral.isPresent("back") and peripheral.getType("back") == "monitor" then
- monitor = peripheral.wrap("back")
- connectModem()
- elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "monitor" then
- monitor = peripheral.wrap("bottom")
- connectModem()
- elseif peripheral.isPresent("front") and peripheral.getType("front") == "monitor" then
- monitor = peripheral.wrap("front")
- connectModem()
- elseif peripheral.isPresent("left") and peripheral.getType("left") == "monitor" then
- monitor = peripheral.wrap("left")
- connectModem()
- elseif peripheral.isPresent("right") and peripheral.getType("right") == "monitor" then
- monitor = peripheral.wrap("right")
- connectModem()
- elseif peripheral.isPresent("top") and peripheral.getType("top") == "monitor" then
- monitor = peripheral.wrap("top")
- connectModem()
- else
- connectModem()
- end
- end
- connectMonitor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement