Advertisement
minimite

haxtype

Mar 16th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. local tArgs = {...}
  2. if tArgs[1] == "set" then
  3.   if tArgs[2] then
  4.     if not fs.exists(tArgs[2]) then
  5.       printError("File does not exist!")
  6.       return
  7.     end
  8.     fs.delete("/haxtype.txt")
  9.     local open = fs.open(tArgs[2], "r")
  10.     local all = open.readAll()
  11.     open.close()
  12.     local open = fs.open("/haxtype.txt", "w")
  13.     open.write(all)
  14.     open.close()
  15.     print("Set HAXType text to file " .. tArgs[2] .. "!")
  16.     return
  17.   else
  18.     print("Usage: haxtype set <path>")
  19.     return
  20.   end
  21. elseif tArgs[1] == "reset" then
  22.   fs.delete("/haxtype.txt")
  23.   print("Reset HAXType!")
  24.   return
  25. end
  26.  
  27. if term.isColor() then
  28.   term.setTextColor(colors.lime)
  29. end
  30. print("Initalizing HAXType..")
  31. if not fs.exists("/haxtype.txt") then
  32.   print("haxtype.txt does not exist, creating..")
  33.   if not http then
  34.     printError("Cannot create haxtype.txt! Reason: HTTP API disabled")
  35.     printError("Please enable the HTTP API for first setup, or create haxtype.txt.")
  36.     error()
  37.   end
  38.   local open = fs.open("/haxtype.txt", "w")
  39.   open.write(http.get("http://pastebin.com/raw/A7wGH3ty").readAll())
  40.   open.close()
  41. end
  42.  
  43. local open = fs.open("/haxtype.txt", "r")
  44. local code = open.readAll()
  45. open.close()
  46. local dex = 0
  47. local c = 0
  48. local len = string.len(code)
  49. term.clear()
  50. term.setCursorPos(1,1)
  51. print("HAXType by Atenefyr. Press ENTER to exit or F1 to auto-complete and exit.")
  52. print("")
  53. while true do
  54.   local event, v = os.pullEvent()
  55.   if event == "key" then
  56.     if v == keys.enter then
  57.       write("\n")
  58.       if term.isColor() then
  59.         term.setTextColor(colors.white)
  60.       end
  61.       return
  62.     elseif v == keys.f1 then
  63.       if dex < len then
  64.         write(string.sub(code,dex+1,len))
  65.       end
  66.       write("\n")
  67.       if term.isColor() then
  68.         term.setTextColor(colors.white)
  69.       end
  70.       return
  71.     end
  72.   elseif event == "char" then
  73.     local speed = math.random(3,5)
  74.     for i = 1, speed do
  75.         dex = dex + 1
  76.         if dex <= len then
  77.           write(string.sub(code,dex,dex))
  78.         end
  79.     end
  80.     if dex > len then
  81.       write("\n")
  82.       if term.isColor() then
  83.         term.setTextColor(colors.white)
  84.       end
  85.       return
  86.     end
  87.   end
  88. end
  89.  
  90. --if somehow you reach this part of of the code we'll leave safely
  91. write("\n")
  92. if term.isColor() then
  93.   term.setTextColor(colors.white)
  94. end
  95. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement