Advertisement
Guest User

Crash message system

a guest
Nov 12th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. --[[> Crash Message System by XenusSoft <]]--
  2. --[[> Copyright 2020 XenusSoft <]]--
  3.  
  4.  
  5. --<[] INIT VARIABLES []>--
  6. local w, h = term.getSize()
  7. local wm, hm = (w/2), (h/2)
  8. local args = { ... } -- Grab arguments needed in a table that ran with the program
  9.  
  10.  
  11. --<[] INIT FUNCTIONS []>--
  12.  
  13. --< Http >--
  14.  
  15. function downloadFile(url, dest)
  16. if not http then
  17. error("no http api, check with your server admin or enable it in the config file of the mod", 0)
  18. end
  19. local x, y = term.getCursorPos()
  20. term.setCursorPos(-1000000000, -10000000000) -- Bring off the screen so it does not show the temp api installed.
  21. if not fs.exists(dest) then
  22. shell.run("wget " .. url .. " " .. dest)
  23. else
  24. fs.delete(dest)
  25. shell.run("wget " .. url .. " " .. dest)
  26. end
  27. term.setCursorPos(x, y) -- Bring back whenever the file is installed or updated.
  28. end
  29.  
  30. --< Text API - Credit to IgorTimofeev for this one >--
  31.  
  32. function string.split(s, delimiter)
  33. local parts, index = {}, 1
  34. for part in s:gmatch(delimiter) do
  35. parts[index] = part
  36. index = index + 1
  37. end
  38.  
  39. return parts
  40. end
  41.  
  42. function string.limit(s, limit, mode, noDots)
  43. local length = string.len(s)
  44.  
  45. if length <= limit then
  46. return s
  47. elseif mode == "left" then
  48. if noDots then
  49. return string.sub(s, length - limit + 1, -1)
  50. else
  51. return "?" .. string.sub(s, length - limit + 2, -1)
  52. end
  53. elseif mode == "center" then
  54. local integer, fractional = math.modf(limit / 2)
  55. if fractional == 0 then
  56. return string.sub(s, 1, integer) .. "?" .. string.sub(s, -integer + 1, -1)
  57. else
  58. return string.sub(s, 1, integer) .. "?" .. string.sub(s, -integer, -1)
  59. end
  60. else
  61. if noDots then
  62. return string.sub(s, 1, limit)
  63. else
  64. return string.sub(s, 1, limit - 1) .. "?"
  65. end
  66. end
  67. end
  68.  
  69. function string.wrap(data, limit)
  70. if type(data) == "string" then
  71. data = { data }
  72. end
  73.  
  74. local wrappedLines, result, preResult, position = {}
  75.  
  76. for i = 1, #data do
  77. wrappedLines[i] = data[i]
  78. end
  79.  
  80. local i = 1
  81. while i <= #wrappedLines do
  82. local position = wrappedLines[i]:find("\n")
  83. if position then
  84. table.insert(wrappedLines, i + 1, string.sub(wrappedLines[i], position + 1, -1))
  85. wrappedLines[i] = string.sub(wrappedLines[i], 1, position - 1)
  86. end
  87.  
  88. i = i + 1
  89. end
  90.  
  91. local i = 1
  92. while i <= #wrappedLines do
  93. result = ""
  94.  
  95. for word in wrappedLines[i]:gmatch("[^%s]+") do
  96. preResult = result .. word
  97.  
  98. if string.len(preResult) > limit then
  99. if string.len(word) > limit then
  100. table.insert(wrappedLines, i + 1, string.sub(wrappedLines[i], limit + 1, -1))
  101. result = string.sub(wrappedLines[i], 1, limit)
  102. else
  103. table.insert(wrappedLines, i + 1, string.sub(wrappedLines[i], string.len(result) + 1, -1))
  104. end
  105.  
  106. break
  107. else
  108. result = preResult .. " "
  109. end
  110. end
  111.  
  112. wrappedLines[i] = result:gsub("%s+$", "")
  113. wrappedLines[i] = wrappedLines[i]:gsub("^%s+", "")
  114.  
  115. i = i + 1
  116. end
  117.  
  118. return wrappedLines
  119. end
  120.  
  121. --<[] START DISPLAY []>--
  122.  
  123. function display()
  124. -- This part is functioned because we'll want to execute it later on.
  125. term.setBackgroundColor(colors.blue)
  126. term.setTextColor(colors.white)
  127. term.clear()
  128. term.setCursorPos(1, 1)
  129.  
  130. print("A error has occurred or something has been detected that may harm your ComputerCraft PC and iGP OS has stopped all running apps to prevent damage to your ComputerCraft computer.")
  131. print("")
  132. print("If this is your first time seeing this error, reboot the computer, or go to support by emailing to t4w5wz2fgn7s@fwd.drifttmail.com or going to https://igp-os-community.tribe.so/")
  133. print("If this error keeps on popping up, this is urgent and needs to be fixed by contacting support.")
  134. print("")
  135. print("ERR_CODE: " .. (args[1] and args[1] or "GENERAL"))
  136. end
  137.  
  138. function init()
  139. print("")
  140. if args[2] then shell.run(args[2]) end
  141. end
  142.  
  143. display()
  144. init()
  145.  
  146. if not args[2] then
  147. print("Press enter...")
  148. while true do
  149. local ev, p1 = os.pullEventRaw()
  150. if ev == "key" then
  151. if p1 == keys.enter or p1 == keys.numPadEnter then
  152. break
  153. end
  154. end
  155. end
  156. local scrollPoint = (math.random(1, 2) == 1 and 1 or -1)
  157. term.setBackgroundColor(colors.lightBlue)
  158. term.scroll(scrollPoint)
  159. term.setBackgroundColor(colors.white)
  160. for i = 1, h do
  161. term.scroll(scrollPoint)
  162. sleep(0.01)
  163. end
  164. sleep(0.1)
  165. term.setBackgroundColor(colors.lightGray)
  166. term.clear()
  167. sleep(0.1)
  168. term.setBackgroundColor(colors.gray)
  169. term.clear()
  170. sleep(0.1)
  171. end
  172.  
  173. term.setBackgroundColor(colors.black)
  174. term.setTextColor(colors.white)
  175. term.clear()
  176. term.setCursorPos(1,1)
  177.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement