Savage_Me55iah

message

Nov 5th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1.  
  2.  
  3. function find_peripheral(name, name2)
  4.   sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  5.   peripheral_found = false
  6.   for num=1, 6 do
  7.     type = peripheral.getType(sides[num])
  8.     if type == name then
  9.       peripheral_side = sides[num]
  10.       peripheral_found = true
  11.     end
  12.   end
  13.   if peripheral_found ~= true then
  14.     error("No " .. t .. " attached to the computer", 0)
  15.   end
  16.   name2 = peripheral.wrap(peripheral_side)
  17. end
  18.  
  19. function save(name, location)
  20.   print("Saving: " .. name)
  21.   filehandle = fs.open(location, 'w')
  22.   filehandle.write(textutils.serialize(name))
  23.   filehandle.close()
  24. end
  25.  
  26. function load(name, location)
  27.   print("Loading: " .. name)
  28.   filehandle = fs.open(location, 'r')
  29.   name = textutils.unserialize(filehandle.readAll())
  30.   filehandle.close()
  31. end
  32.  
  33. function change_colors(command, color_1, color_2)
  34.   command.setTextColor(color_1 or colors.white)
  35.   command.setBackgroundColor(color_2 or colors.black)
  36. end
  37.  
  38. function mon_write(text, loc_x, loc_y, color_back, color_text)
  39.   mon.setCursorPos(loc_x, loc_y)
  40.   mon.setTextColor(color_text or colors.white)
  41.   mon.setBackground(color_back or colors.black)
  42.   mon.write(text:upper())
  43. end
  44.  
  45. messages = {}
  46.  
  47. function add_table(text)
  48.   num = 1
  49.   while names[num] ~= nil do
  50.     num = num + 1
  51.   end
  52.  
  53.   messages[num] = text
  54. end
  55.  
  56. add_table("Savage: hey poke, just type name or p, enter, then type the meassage, enter")
  57.  
  58. if fs.exists("msg") then
  59.   load(messages, "messages")
  60. else
  61.   save(messages, "messages")
  62. end
  63.  
  64. find_peripheral("monitor", mon)
  65.  
  66. oa_x, oa_y = mon.getSize()
  67. oa_y = oa_y - 4
  68.  
  69. function monitor_draw()
  70.   z = 1
  71.   while messages[z] ~= nil do
  72.     z = z + 1
  73.   end
  74.   z = z - 1
  75.  
  76.  
  77.   x, y = 3, oa_y
  78.   while y ~= 4 do
  79.     mon_write(messages[z], x, y)
  80.     z = z - 1
  81.     y = y - 1
  82.   end
  83. end
  84.    
  85. monitor_draw()
  86. while true do
  87.   user = read()
  88.   user = user:lower()
  89.   if user == "s" then
  90.     user = "Savage"
  91.   elseif user == "p" then
  92.     user = "Pokefan710"
  93.   end
  94.   msg = read()
  95.   text = (user .. ": " .. msg)
  96.   add_table(text)
  97.   save(messages, "messages")
  98.   monitor_draw()
  99. end
Advertisement
Add Comment
Please, Sign In to add comment