Advertisement
Guest User

chat

a guest
Aug 1st, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. --Simpler chat client by Tyab
  2. --This one actually WORKS and has USER HANDLES
  3. --I feel sad you cannot SAVE YOUR HANDLE, tho.
  4.  
  5. function clear()
  6.  term.clear()
  7.  term.setCursorPos(1,1)
  8. end
  9.  
  10. rednet.open("right")
  11. username = "Chum"
  12. local chatBuddy = nil
  13.  
  14. function help()
  15.  print("Welcome to Pesterchum 1.0")
  16.  print("Press C to Connect")
  17.  print("Press H to set your Handle")
  18.  print("Press A to Abscond to menu")
  19.  print("Press T to Type")
  20. end
  21.  
  22. clear()
  23. help()
  24.  
  25. while true do
  26.  event, id, msg = os.pullEvent()
  27.  
  28.  if event == "rednet_message" and id == chatBuddy then
  29.   print(msg)
  30.  
  31.  elseif event == "char" then
  32.  
  33.   if id == "t" then
  34.    write(username.." > ")
  35.    msgsent = read()
  36.    if chatBuddy ~= nil then
  37.     rednet.send(chatBuddy,username.." > "..msgsent)
  38.    else
  39.     print("Quit talking to yourself, dumbass!")
  40.     --always punish users for doing stuff wrong
  41.    end
  42.  
  43.   elseif id == "h" then
  44.    write("New username: ")
  45.    username = read()
  46.  
  47.   elseif id == "c" then
  48.    write("Chum ID: ") --put your chum's computer ID here
  49.    chatBuddy = tonumber(read())
  50.    clear()
  51.    print("Conncted. You may chat if your chum")
  52.    print("is connected to you right now")
  53.  
  54.   elseif id == "a" then
  55.    chatBuddy = nil
  56.    clear()
  57.    help()
  58.  
  59.   end
  60.  
  61.  end
  62.  
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement