· 5 years ago · Nov 12, 2020, 04:38 PM
1--[[> Crash Message System by XenusSoft <]]--
2--[[> Copyright 2020 XenusSoft <]]--
3
4
5--<[] INIT VARIABLES []>--
6local w, h = term.getSize()
7local wm, hm = (w/2), (h/2)
8local args = { ... } -- Grab arguments needed in a table that ran with the program
9
10
11--<[] INIT FUNCTIONS []>--
12
13--< Http >--
14
15function 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.
28end
29
30--< Text API - Credit to IgorTimofeev for this one >--
31
32function 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
40end
41
42function 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
67end
68
69function 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
119end
120
121--<[] START DISPLAY []>--
122
123function display()
124-- This part is functioned because we'll want to execute it later on.
125term.setBackgroundColor(colors.blue)
126term.setTextColor(colors.white)
127term.clear()
128term.setCursorPos(1, 1)
129
130print("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.")
131print("")
132print("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/")
133print("If this error keeps on popping up, this is urgent and needs to be fixed by contacting support.")
134print("")
135print("ERR_CODE: " .. (args[1] and args[1] or "GENERAL"))
136end
137
138function init()
139print("")
140if args[2] then shell.run(args[2]) end
141end
142
143display()
144init()
145
146if not args[2] then
147print("Press enter...")
148while 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
155end
156local scrollPoint = (math.random(1, 2) == 1 and 1 or -1)
157term.setBackgroundColor(colors.lightBlue)
158term.scroll(scrollPoint)
159term.setBackgroundColor(colors.white)
160for i = 1, h do
161 term.scroll(scrollPoint)
162 sleep(0.01)
163end
164sleep(0.1)
165term.setBackgroundColor(colors.lightGray)
166term.clear()
167sleep(0.1)
168term.setBackgroundColor(colors.gray)
169term.clear()
170sleep(0.1)
171end
172
173term.setBackgroundColor(colors.black)
174term.setTextColor(colors.white)
175term.clear()
176term.setCursorPos(1,1)
177
178