This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
BlueMond's profile picture

Private Chat Code

Started by BlueMond, 17 March 2012 - 10:45 PM
BlueMond #1
Posted 17 March 2012 - 11:45 PM
Things to know:
-Involves two computers only.
-Needs monitor attached to one side.
-Host must be ready before the connecting client computer.
-If you find any bugs report it to the comments section of this post.
-Must include a wireless modem on any side.
-Recommended Monitor size: 7x2 as shown below
m = monitor / a = air / c = computer
m m m m m m m a
m m m m m m m c

The actual code:

canReceive = false
rednet.open("right")
rednet.open("left")
rednet.open("bottom")
rednet.open("top")
rednet.open("back")
rednet.open("front")
function os.pullEvent()
local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
if event == "rednet_message" then
if canReceive then
if p1 == id1 then
mon.setTextScale(1)
mon.write("<"..user2..">"..p2.."n")
colom,row = mon.getCursorPos()
row == row + 1
mon.setCursorPos(1,row)
end
end
end
return event, p1, p2, p3, p4, p5
end
shell.run("clear")
print("-PrivateChat- By BlueMond")
print("Which side is your monitor on?")
side = read()
mon = peripheral.wrap(side)
write("Chat Username: ")
user = read()
print("Host OR Connect?: ")
entry = read()
--host
if entry == "host" or entry == "Host" then
print("Waiting for another user to connect...")
stop = 0
repeat
id1,start = rednet.receive()
if start == "pchat" then
print("Connection found!")
rednet.send(id1,"found")
sleep(1)
rednet.send(id1,user)
print("Waiting for reply...")
repeat
id2,user2 = rednet.receive()
until id2 == id1 --check if same person
print("Would you like to chat with "..user2.."?(y/n)")
ans = read()
if ans == "y" then
rednet.send(id2,"y")
stop = 1
else
os.reboot()
end
end
until stop == 1
else
--connect
if entry == "connect" or entry == "Connect" then
print("Searching for host...")
rednet.broadcast("pchat")
id1,start = rednet.receive()
if id1 == null then
print("Could not find a host!")
sleep(3)
os.reboot()
else
if start == "found" then
print("Host found!")
repeat
id2,user2 = rednet.receive()
until id2 == id1
print("Connecting to "..user2.."...")
rednet.send(id2,user)
repeat
id3,reply = rednet.receive()
until id3 == id2
if reply == "y" then
stop = 1
else
print("You have been declined by the host...")
sleep(3)
os.reboot()
end
else
print("Could not find a host!")
sleep(3)
os.reboot()
end
end
end
end
--chat
shell.run("clear")
print("-PrivateChat- By BlueMond")
print("In chat with "..user2..".")
print("Received messages will be displayed on the attached monitor!")
canReceive = true
other = 0
repeat
pre = "<"..user..">"
write(pre)
send = read()
rednet.send(id1,send)
mon.setTextScale(1)
mon.write(pre..send)
colom2,row2 = mon.getCursorPos()
row2 == row2 + 1
mon.setCursorPos(1,row2)
until other == 1

Notice you will have to auto-type or paste it into computercraft using a program or of some sorts. (Unless you want to type the whole thing…)
Tigerlife #2
Posted 18 March 2012 - 03:01 AM
you can copy this and put it in a txt file in .minecraft/mods/computercraft/lua/rom/programs/computer and then to run it in game type what you named the file with .txt at the end.
TheOddByte #3
Posted 06 October 2012 - 06:26 PM
Or just download notepad++
And copy to that, Then press save as and write the name of the file and choose all types below, Then save to where you want
you save it ofcourse :D/>/>