SuicidalSTDz

[Uninstallation!]EnderOS v2.6

Feb 11th, 2013
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 74.59 KB | None | 0 0
  1. --Coded by SuicidalSTDz
  2. --License:
  3. --The code of "EnderOS" in any form is intellectual
  4. --property of SuicidalSTDz. You may not reproduce,
  5. --redistribute, or modify it in any way!
  6.  
  7. --This OS stores User information in a hashed form. Making "hackers" tremble in fear >:) Not really...
  8. --The hash that EnderOS uses is Sha-256 and makes storage safer :)
  9.  
  10. --If you find any bugs(I know there are a few) please report them on the CC Forums on the EnderOS thread!
  11. --Thank you for using EnderOS and enjoy!
  12.  
  13. --Games
  14. --EnderOS includes SkullPong by Skullblade, AdventureCraft by Mikee251, and soon FireWolf by GravityScore
  15.  
  16. x = 354
  17. while x == 354 do
  18. os.pullEvent = os.pullEventRaw
  19. version = "v2.6"
  20. saltHash = "T01hFg62zY"
  21. firewolf = "A7wGH3ty"
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. function sha256(msg)
  25. function band(int1, int2, int3, ...)
  26. local ret =
  27. ((int1%0x00000002>=0x00000001 and int2%0x00000002>=0x00000001 and 0x00000001) or 0)+
  28. ((int1%0x00000004>=0x00000002 and int2%0x00000004>=0x00000002 and 0x00000002) or 0)+
  29. ((int1%0x00000008>=0x00000004 and int2%0x00000008>=0x00000004 and 0x00000004) or 0)+
  30. ((int1%0x00000010>=0x00000008 and int2%0x00000010>=0x00000008 and 0x00000008) or 0)+
  31. ((int1%0x00000020>=0x00000010 and int2%0x00000020>=0x00000010 and 0x00000010) or 0)+
  32. ((int1%0x00000040>=0x00000020 and int2%0x00000040>=0x00000020 and 0x00000020) or 0)+
  33. ((int1%0x00000080>=0x00000040 and int2%0x00000080>=0x00000040 and 0x00000040) or 0)+
  34. ((int1%0x00000100>=0x00000080 and int2%0x00000100>=0x00000080 and 0x00000080) or 0)+
  35. ((int1%0x00000200>=0x00000100 and int2%0x00000200>=0x00000100 and 0x00000100) or 0)+
  36. ((int1%0x00000400>=0x00000200 and int2%0x00000400>=0x00000200 and 0x00000200) or 0)+
  37. ((int1%0x00000800>=0x00000400 and int2%0x00000800>=0x00000400 and 0x00000400) or 0)+
  38. ((int1%0x00001000>=0x00000800 and int2%0x00001000>=0x00000800 and 0x00000800) or 0)+
  39. ((int1%0x00002000>=0x00001000 and int2%0x00002000>=0x00001000 and 0x00001000) or 0)+
  40. ((int1%0x00004000>=0x00002000 and int2%0x00004000>=0x00002000 and 0x00002000) or 0)+
  41. ((int1%0x00008000>=0x00004000 and int2%0x00008000>=0x00004000 and 0x00004000) or 0)+
  42. ((int1%0x00010000>=0x00008000 and int2%0x00010000>=0x00008000 and 0x00008000) or 0)+
  43. ((int1%0x00020000>=0x00010000 and int2%0x00020000>=0x00010000 and 0x00010000) or 0)+
  44. ((int1%0x00040000>=0x00020000 and int2%0x00040000>=0x00020000 and 0x00020000) or 0)+
  45. ((int1%0x00080000>=0x00040000 and int2%0x00080000>=0x00040000 and 0x00040000) or 0)+
  46. ((int1%0x00100000>=0x00080000 and int2%0x00100000>=0x00080000 and 0x00080000) or 0)+
  47. ((int1%0x00200000>=0x00100000 and int2%0x00200000>=0x00100000 and 0x00100000) or 0)+
  48. ((int1%0x00400000>=0x00200000 and int2%0x00400000>=0x00200000 and 0x00200000) or 0)+
  49. ((int1%0x00800000>=0x00400000 and int2%0x00800000>=0x00400000 and 0x00400000) or 0)+
  50. ((int1%0x01000000>=0x00800000 and int2%0x01000000>=0x00800000 and 0x00800000) or 0)+
  51. ((int1%0x02000000>=0x01000000 and int2%0x02000000>=0x01000000 and 0x01000000) or 0)+
  52. ((int1%0x04000000>=0x02000000 and int2%0x04000000>=0x02000000 and 0x02000000) or 0)+
  53. ((int1%0x08000000>=0x04000000 and int2%0x08000000>=0x04000000 and 0x04000000) or 0)+
  54. ((int1%0x10000000>=0x08000000 and int2%0x10000000>=0x08000000 and 0x08000000) or 0)+
  55. ((int1%0x20000000>=0x10000000 and int2%0x20000000>=0x10000000 and 0x10000000) or 0)+
  56. ((int1%0x40000000>=0x20000000 and int2%0x40000000>=0x20000000 and 0x20000000) or 0)+
  57. ((int1%0x80000000>=0x40000000 and int2%0x80000000>=0x40000000 and 0x40000000) or 0)+
  58. ((int1>=0x80000000 and int2>=0x80000000 and 0x80000000) or 0)
  59.  
  60. return (int3 and band(ret, int3, ...)) or ret
  61. end
  62.  
  63. local function bxor(int1, int2, int3, ...)
  64. local ret =
  65. ((int1%0x00000002>=0x00000001 ~= (int2%0x00000002>=0x00000001) and 0x00000001) or 0)+
  66. ((int1%0x00000004>=0x00000002 ~= (int2%0x00000004>=0x00000002) and 0x00000002) or 0)+
  67. ((int1%0x00000008>=0x00000004 ~= (int2%0x00000008>=0x00000004) and 0x00000004) or 0)+
  68. ((int1%0x00000010>=0x00000008 ~= (int2%0x00000010>=0x00000008) and 0x00000008) or 0)+
  69. ((int1%0x00000020>=0x00000010 ~= (int2%0x00000020>=0x00000010) and 0x00000010) or 0)+
  70. ((int1%0x00000040>=0x00000020 ~= (int2%0x00000040>=0x00000020) and 0x00000020) or 0)+
  71. ((int1%0x00000080>=0x00000040 ~= (int2%0x00000080>=0x00000040) and 0x00000040) or 0)+
  72. ((int1%0x00000100>=0x00000080 ~= (int2%0x00000100>=0x00000080) and 0x00000080) or 0)+
  73. ((int1%0x00000200>=0x00000100 ~= (int2%0x00000200>=0x00000100) and 0x00000100) or 0)+
  74. ((int1%0x00000400>=0x00000200 ~= (int2%0x00000400>=0x00000200) and 0x00000200) or 0)+
  75. ((int1%0x00000800>=0x00000400 ~= (int2%0x00000800>=0x00000400) and 0x00000400) or 0)+
  76. ((int1%0x00001000>=0x00000800 ~= (int2%0x00001000>=0x00000800) and 0x00000800) or 0)+
  77. ((int1%0x00002000>=0x00001000 ~= (int2%0x00002000>=0x00001000) and 0x00001000) or 0)+
  78. ((int1%0x00004000>=0x00002000 ~= (int2%0x00004000>=0x00002000) and 0x00002000) or 0)+
  79. ((int1%0x00008000>=0x00004000 ~= (int2%0x00008000>=0x00004000) and 0x00004000) or 0)+
  80. ((int1%0x00010000>=0x00008000 ~= (int2%0x00010000>=0x00008000) and 0x00008000) or 0)+
  81. ((int1%0x00020000>=0x00010000 ~= (int2%0x00020000>=0x00010000) and 0x00010000) or 0)+
  82. ((int1%0x00040000>=0x00020000 ~= (int2%0x00040000>=0x00020000) and 0x00020000) or 0)+
  83. ((int1%0x00080000>=0x00040000 ~= (int2%0x00080000>=0x00040000) and 0x00040000) or 0)+
  84. ((int1%0x00100000>=0x00080000 ~= (int2%0x00100000>=0x00080000) and 0x00080000) or 0)+
  85. ((int1%0x00200000>=0x00100000 ~= (int2%0x00200000>=0x00100000) and 0x00100000) or 0)+
  86. ((int1%0x00400000>=0x00200000 ~= (int2%0x00400000>=0x00200000) and 0x00200000) or 0)+
  87. ((int1%0x00800000>=0x00400000 ~= (int2%0x00800000>=0x00400000) and 0x00400000) or 0)+
  88. ((int1%0x01000000>=0x00800000 ~= (int2%0x01000000>=0x00800000) and 0x00800000) or 0)+
  89. ((int1%0x02000000>=0x01000000 ~= (int2%0x02000000>=0x01000000) and 0x01000000) or 0)+
  90. ((int1%0x04000000>=0x02000000 ~= (int2%0x04000000>=0x02000000) and 0x02000000) or 0)+
  91. ((int1%0x08000000>=0x04000000 ~= (int2%0x08000000>=0x04000000) and 0x04000000) or 0)+
  92. ((int1%0x10000000>=0x08000000 ~= (int2%0x10000000>=0x08000000) and 0x08000000) or 0)+
  93. ((int1%0x20000000>=0x10000000 ~= (int2%0x20000000>=0x10000000) and 0x10000000) or 0)+
  94. ((int1%0x40000000>=0x20000000 ~= (int2%0x40000000>=0x20000000) and 0x20000000) or 0)+
  95. ((int1%0x80000000>=0x40000000 ~= (int2%0x80000000>=0x40000000) and 0x40000000) or 0)+
  96. ((int1>=0x80000000 ~= (int2>=0x80000000) and 0x80000000) or 0)
  97.  
  98. return (int3 and bxor(ret, int3, ...)) or ret
  99. end
  100.  
  101. local function bnot(int)
  102. return 4294967295 - int
  103. end
  104.  
  105. local function rshift(int, by)
  106. local shifted = int / (2 ^ by)
  107. return shifted - shifted % 1
  108. end
  109.  
  110. local function rrotate(int, by)
  111. local shifted = int / (2 ^ by)
  112. local fraction = shifted % 1
  113. return (shifted - fraction) + fraction * (2 ^ 32)
  114. end
  115.  
  116. local k = {
  117. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  118. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  119. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  120. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  121. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  122. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  123. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  124. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  125. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  126. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  127. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  128. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  129. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  130. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  131. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  132. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  133. }
  134.  
  135. local function str2hexa(s)
  136. local h = string.gsub(s, ".", function(c)
  137. return string.format("%02x", string.byte(c))
  138. end)
  139. return h
  140. end
  141.  
  142. local function num2s(l, n)
  143. local s = ""
  144. for i = 1, n do
  145. local rem = l % 256
  146. s = string.char(rem) .. s
  147. l = (l - rem) / 256
  148. end
  149. return s
  150. end
  151.  
  152. local function s232num(s, i)
  153. local n = 0
  154. for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  155. return n
  156. end
  157.  
  158. local function preproc(msg, len)
  159. local extra = 64 - ((len + 1 + 8) % 64)
  160. len = num2s(8 * len, 8)
  161. msg = msg .. "\128" .. string.rep("\0", extra) .. len
  162. return msg
  163. end
  164.  
  165. local function initH256(H)
  166. H[1] = 0x6a09e667
  167. H[2] = 0xbb67ae85
  168. H[3] = 0x3c6ef372
  169. H[4] = 0xa54ff53a
  170. H[5] = 0x510e527f
  171. H[6] = 0x9b05688c
  172. H[7] = 0x1f83d9ab
  173. H[8] = 0x5be0cd19
  174. return H
  175. end
  176.  
  177. local function digestblock(msg, i, H)
  178. local w = {}
  179. for j = 1, 16 do w[j] = s232num(msg, i + (j - 1) * 4) end
  180. for j = 17, 64 do
  181. local v = w[j - 15]
  182. local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  183. v = w[j - 2]
  184. local s1 = bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  185. w[j] = w[j - 16] + s0 + w[j - 7] + s1
  186. end
  187.  
  188. local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
  189. for i = 1, 64 do
  190. local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  191. local maj = bxor(band(a, b), band(a, c), band(b, c))
  192. local t2 = s0 + maj
  193. local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  194. local ch = bxor (band(e, f), band(bnot(e), g))
  195. local t1 = h + s1 + ch + k[i] + w[i]
  196. h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  197. end
  198.  
  199. H[1] = band(H[1], a)
  200. H[2] = band(H[2], b)
  201. H[3] = band(H[3], c)
  202. H[4] = band(H[4], d)
  203. H[5] = band(H[5], e)
  204. H[6] = band(H[6], f)
  205. H[7] = band(H[7], g)
  206. H[8] = band(H[8], h)
  207. end
  208.  
  209. msg = preproc(msg, #msg)
  210. local H = initH256({})
  211. for i = 1, #msg, 64 do digestblock(msg, i, H) end
  212. return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  213. num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  214. end
  215. function settingsChangeUser()
  216. reset()
  217. term.setTextColor(colors.orange)
  218. local passFile = io.open("/.EnderOS/.passInfo", "r")
  219. local passContents = passFile:read()
  220. passFile:close()
  221. print("Please enter your password: ")
  222. term.setTextColor(colors.white)
  223. local input = read("*")
  224. local hash = sha256(input)
  225. if hash..saltHash ~= passContents then
  226. term.setTextColor(colors.red)
  227. print("Invalid password")
  228. sleep(1.5)
  229. settingsChangeUser()
  230. else
  231. local user = ("/.EnderOS/.userInfo")
  232. local username = io.open(user, "w")
  233. term.setTextColor(colors.orange)
  234. print("Enter new username: ")
  235. term.setTextColor(colors.white)
  236. writeUser = read()
  237. if #writeUser <2 then
  238. term.setTextColor(colors.red)
  239. print("The Endermen hack you in their sleep!")
  240. sleep(3)
  241. settingsChangeUser()
  242. end
  243. local hash = sha256(writeUser)
  244. writeN = username:write(hash..saltHash)
  245. username:close()
  246. term.setTextColor(colors.lightBlue)
  247. print("Your new username is "..writeUser)
  248. sleep(2)
  249. startScreen()
  250. end
  251. term.setTextColor(colors.white)
  252. end
  253. function settingsChangePass()
  254. reset()
  255. term.setTextColor(colors.orange)
  256. local passFile = io.open("/.EnderOS/.passInfo", "r")
  257. local passContents = passFile:read()
  258. passFile:close()
  259. print("Please enter your password: ")
  260. term.setTextColor(colors.white)
  261. local input = read("*")
  262. local hash = sha256(input)
  263. if hash..saltHash ~= passContents then
  264. term.setTextColor(colors.red)
  265. print("Invalid password")
  266. sleep(1.5)
  267. settingsChangePass()
  268. else
  269. local pass = ("/.EnderOS/.passInfo")
  270. local password = io.open(pass, "w")
  271. term.setTextColor(colors.orange)
  272. print("Enter new password: ")
  273. term.setTextColor(colors.white)
  274. local writePass = read("*")
  275. if #writePass <2 then
  276. term.setTextColor(colors.red)
  277. print("The Endermen hack you in their sleep!")
  278. sleep(3)
  279. settingsChangePass()
  280. end
  281. local hash = sha256(writePass)
  282. local writeN = password:write(hash..saltHash)
  283. password:close()
  284. term.setTextColor(colors.lightBlue)
  285. print("Your new password is "..writePass)
  286. sleep(2)
  287. startScreen()
  288. end
  289. term.setTextColor(colors.white)
  290. end
  291. function settingsChangeHint()
  292. reset()
  293. term.setTextColor(colors.orange)
  294. local passFile = io.open("/.EnderOS/.passInfo", "r")
  295. local passContents = passFile:read()
  296. passFile:close()
  297. print("Please enter your password: ")
  298. term.setTextColor(colors.white)
  299. local input = read("*")
  300. local hash = sha256(input)
  301. if hash..saltHash ~= passContents then
  302. term.setTextColor(colors.red)
  303. print("Invalid password")
  304. sleep(1.5)
  305. settingsChangeHint()
  306. else
  307. local hint = ("/.EnderOS/.userHint")
  308. local uHint = io.open(hint, "w")
  309. term.setTextColor(colors.orange)
  310. print("Enter new hint: ")
  311. term.setTextColor(colors.white)
  312. local writeHint = read()
  313. if #writeHint >30 then
  314. term.setTextColor(colors.red)
  315. print("This Hint exceeds the max hint length of 30!")
  316. sleep(3)
  317. uHint:close()
  318. settingsChangeHint()
  319. else
  320. local writeN = uHint:write(writeHint)
  321. uHint:close()
  322. term.setTextColor(colors.lightBlue)
  323. print("Your new hint is "..writeHint)
  324. sleep(2)
  325. startScreen()
  326. end
  327. end
  328. term.setTextColor(colors.white)
  329. end
  330. function calculator()
  331. reset()
  332. term.setTextColor(colors.orange)
  333. print("What would you like to do?")
  334. term.setCursorPos(1,3)
  335. term.setTextColor(colors.lime)
  336. print("{Add} {Subtract} {Multiply} {Divide}")
  337. term.setCursorPos(1,5)
  338. print("{Generate a random number}")
  339. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  340. if button == 1 then
  341. if (xPos >=1 and xPos <=5 and yPos == 3) then
  342. reset()
  343. term.setTextColor(colors.orange)
  344. print("Please enter your first number")
  345. term.setTextColor(colors.white)
  346. firstNum = read()
  347. if #firstNum >6 then
  348. reset()
  349. term.setTextColor(colors.red)
  350. print("I'm sorry, us Endermen cannot calculate that much")
  351. sleep(3)
  352. calculator()
  353. end
  354. numOneIsValid = tonumber(firstNum)
  355. if type(numOneIsValid) == "number" then
  356. term.setTextColor(colors.orange)
  357. print("Please type your second number")
  358. term.setTextColor(colors.white)
  359. secondNum = read()
  360. if #secondNum >6 then
  361. reset()
  362. term.setTextColor(colors.red)
  363. print("I'm sorry, us Endermen cannot calculate that much")
  364. sleep(3)
  365. calculator()
  366. end
  367. numTwoIsValid = tonumber(secondNum)
  368. if type(numTwoIsValid) == "number" then
  369. reset()
  370. local sum = (firstNum+secondNum)
  371. term.setTextColor(colors.lightBlue)
  372. print("The sum of your numbers is "..sum)
  373. term.setCursorPos(1,3)
  374. term.setTextColor(colors.lime)
  375. print("{Clear} {Exit}")
  376. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  377. if button == 1 then
  378. if (xPos >=1 and xPos <=7 and yPos == 3) then
  379. calculator()
  380. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  381. startScreen()
  382. else
  383. calculator()
  384. end
  385. else
  386. calculator()
  387. end
  388. else
  389. reset()
  390. term.setTextColor(colors.red)
  391. print("The Endermen are not amused!")
  392. sleep(3)
  393. startScreen()
  394. end
  395. else
  396. reset()
  397. term.setTextColor(colors.red)
  398. print("The Endermen are not amused!")
  399. sleep(3)
  400. startScreen()
  401. end
  402. elseif (xPos >=7 and xPos <=16 and yPos == 3) then
  403. reset()
  404. term.setTextColor(colors.orange)
  405. print("Please enter your first number")
  406. term.setTextColor(colors.white)
  407. firstNum = read()
  408. if #firstNum >6 then
  409. reset()
  410. term.setTextColor(colors.red)
  411. print("I'm sorry, us Endermen cannot calculate that much")
  412. sleep(3)
  413. calculator()
  414. end
  415. numOneIsValid = tonumber(firstNum)
  416. if type(numOneIsValid) == "number" then
  417. term.setTextColor(colors.orange)
  418. print("Please type your second number")
  419. term.setTextColor(colors.white)
  420. secondNum = read()
  421. if #secondNum >6 then
  422. reset()
  423. term.setTextColor(colors.red)
  424. print("I'm sorry, us Endermen cannot calculate that much")
  425. sleep(3)
  426. calculator()
  427. end
  428. numTwoIsValid = tonumber(secondNum)
  429. if type(numTwoIsValid) == "number" then
  430. reset()
  431. local diff = (firstNum-secondNum)
  432. term.setTextColor(colors.lightBlue)
  433. term.write("The difference of your numbers is "..diff)
  434. term.setCursorPos(1,3)
  435. term.setTextColor(colors.lime)
  436. print("{Clear} {Exit}")
  437. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  438. if button == 1 then
  439. if (xPos >=1 and xPos <=7 and yPos == 3) then
  440. calculator()
  441. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  442. startScreen()
  443. else
  444. calculator()
  445. end
  446. else
  447. calculator()
  448. end
  449. else
  450. reset()
  451. term.setTextColor(colors.red)
  452. print("The Endermen are not amused!")
  453. sleep(3)
  454. startScreen()
  455. end
  456. else
  457. reset()
  458. term.setTextColor(colors.red)
  459. print("The Endermen are not amused!")
  460. sleep(3)
  461. startScreen()
  462. end
  463. elseif (xPos >=18 and xPos <=27 and yPos == 3) then
  464. reset()
  465. term.setTextColor(colors.orange)
  466. print("Please enter your first number")
  467. term.setTextColor(colors.white)
  468. firstNum = read()
  469. if #firstNum >6 then
  470. reset()
  471. term.setTextColor(colors.red)
  472. print("I'm sorry, us Endermen cannot calculate that much")
  473. sleep(3)
  474. calculator()
  475. end
  476. numOneIsValid = tonumber(firstNum)
  477. if type(numOneIsValid) == "number" then
  478. term.setTextColor(colors.orange)
  479. print("Please type your second number")
  480. term.setTextColor(colors.white)
  481. secondNum = read()
  482. if #secondNum >6 then
  483. reset()
  484. term.setTextColor(colors.red)
  485. print("I'm sorry, us Endermen cannot calculate that much")
  486. sleep(3)
  487. calculator()
  488. end
  489. numTwoIsValid = tonumber(secondNum)
  490. if type(numTwoIsValid) == "number" then
  491. local product = (firstNum*secondNum)
  492. reset()
  493. term.setTextColor(colors.lightBlue)
  494. term.write("The product of your two numbers is "..product)
  495. term.setCursorPos(1,3)
  496. term.setTextColor(colors.lime)
  497. print("{Clear} {Exit}")
  498. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  499. if button == 1 then
  500. if (xPos >=1 and xPos <=7 and yPos == 3) then
  501. calculator()
  502. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  503. startScreen()
  504. else
  505. calculator()
  506. end
  507. else
  508. calculator()
  509. end
  510. else
  511. reset()
  512. term.setTextColor(colors.red)
  513. print("The Endermen are not amused!")
  514. sleep(3)
  515. startScreen()
  516. end
  517. else
  518. reset()
  519. term.setTextColor(colors.red)
  520. print("The Endermen are not amused!")
  521. sleep(3)
  522. startScreen()
  523. end
  524. elseif (xPos >=29 and xPos <=36 and yPos == 3) then
  525. reset()
  526. term.setTextColor(colors.orange)
  527. print("Please enter your first number")
  528. term.setTextColor(colors.white)
  529. firstNum = read()
  530. if #firstNum >6 then
  531. reset()
  532. term.setTextColor(colors.red)
  533. print("I'm sorry, us Endermen cannot calculate that much")
  534. sleep(3)
  535. calculator()
  536. end
  537. numOneIsValid = tonumber(firstNum)
  538. if type(numOneIsValid) == "number" then
  539. term.setTextColor(colors.orange)
  540. print("Please type your second number")
  541. term.setTextColor(colors.white)
  542. secondNum = read()
  543. if #firstNum >6 then
  544. reset()
  545. term.setTextColor(colors.red)
  546. print("I'm sorry, us Endermen cannot calculate that much")
  547. sleep(3)
  548. calculator()
  549. end
  550. numTwoIsValid = tonumber(secondNum)
  551. if type(numTwoIsValid) == "number" then
  552. reset()
  553. local quotient = (firstNum/secondNum)
  554. term.setTextColor(colors.lightBlue)
  555. term.write("The quotient of your two numbers is "..quotient)
  556. term.setCursorPos(1,3)
  557. term.setTextColor(colors.lime)
  558. print("{Clear} {Exit}")
  559. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  560. if button == 1 then
  561. if (xPos >=1 and xPos <=7 and yPos == 3) then
  562. calculator()
  563. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  564. startScreen()
  565. else
  566. calculator()
  567. end
  568. else
  569. calculator()
  570. end
  571. else
  572. reset()
  573. term.setTextColor(colors.red)
  574. print("The Endermen are not amused!")
  575. sleep(3)
  576. startScreen()
  577. end
  578. else
  579. reset()
  580. term.setTextColor(colors.red)
  581. print("The Endermen are not amused!")
  582. sleep(3)
  583. startScreen()
  584. end
  585. elseif (xPos >=1 and xPos <=26 and yPos == 5) then
  586. reset()
  587. term.setTextColor(colors.orange)
  588. print("Please enter your first number")
  589. term.setTextColor(colors.white)
  590. firstNum = read()
  591. numOneIsValid = tonumber(firstNum)
  592. if type(numOneIsValid) == "number" then
  593. term.setTextColor(colors.orange)
  594. print("Please type your second number")
  595. term.setTextColor(colors.white)
  596. secondNum = read()
  597. if #secondNum >6 then
  598. reset()
  599. term.setTextColor(colors.red)
  600. print("I'm sorry, us Endermen cannot calculate that much")
  601. sleep(3)
  602. calculator()
  603. end
  604. numTwoIsValid = tonumber(secondNum)
  605. if type(numTwoIsValid) == "number" then
  606. if firstNum > secondNum then
  607. term.setTextColor(colors.red)
  608. print("Try reversing your numbers, smaller first, larger last")
  609. sleep(3)
  610. calculator()
  611. end
  612. reset()
  613. local randomNum = math.random(firstNum,secondNum)
  614. term.setTextColor(colors.lightBlue)
  615. term.write("A random number between "..firstNum.." and "..secondNum.." is "..randomNum)
  616. term.setCursorPos(1,3)
  617. term.setTextColor(colors.lime)
  618. print("{Clear} {Exit}")
  619. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  620. if button == 1 then
  621. if (xPos >=1 and xPos <=7 and yPos == 3) then
  622. calculator()
  623. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  624. startScreen()
  625. else
  626. calculator()
  627. end
  628. else
  629. calculator()
  630. end
  631. else
  632. reset()
  633. term.setTextColor(colors.red)
  634. print("The Endermen are not amused!")
  635. sleep(3)
  636. startScreen()
  637. end
  638. else
  639. reset()
  640. term.setTextColor(colors.red)
  641. print("The Endermen are not amused!")
  642. sleep(3)
  643. startScreen()
  644. end
  645. else
  646. calculator()
  647. end
  648. else
  649. calculator()
  650. end
  651. end
  652. function Edit()
  653. reset()
  654. term.setTextColor(colors.orange)
  655. print("What file do you wish to edit?")
  656. -- Get file to edit
  657. term.setTextColor(colors.white)
  658. local input = read()
  659. reset()
  660.  
  661. -- Error checking
  662. local sPath = shell.resolve(input)
  663. local bReadOnly = fs.isReadOnly( sPath )
  664. if fs.exists( sPath ) and fs.isDir( sPath ) then
  665. term.setTextColor(colors.red)
  666. print( "Cannot edit a directory." )
  667. term.setTextColor(colors.white)
  668. sleep(3)
  669. Edit()
  670. end
  671.  
  672. if fs.exists( sPath ) and sPath == shell.getRunningProgram() then
  673. term.setTextColor(colors.red)
  674. print( "Cannot edit the file EnderOS is contained in!" )
  675. term.setTextColor(colors.white)
  676. sleep(3)
  677. Edit()
  678. end
  679.  
  680. local x,y = 1,1
  681. local w,h = term.getSize()
  682. local scrollX, scrollY = 0,0
  683.  
  684. local tLines = {}
  685. local bRunning = true
  686.  
  687. -- Colours
  688. local highlightColour, keywordColour, commentColour, textColour, bgColour
  689. if term.isColour() then
  690. bgColour = colours.black
  691. textColour = colours.white
  692. highlightColour = colours.orange
  693. keywordColour = colours.lightBlue
  694. commentColour = colours.lime
  695. stringColour = colours.red
  696. else
  697. bgColour = colours.black
  698. textColour = colours.white
  699. highlightColour = colours.white
  700. keywordColour = colours.white
  701. commentColour = colours.white
  702. stringColour = colours.white
  703. end
  704.  
  705. -- Menus
  706. local bMenu = false
  707. local nMenuItem = 1
  708. local tMenuItems = {"Save", "Exit", "Print"}
  709. local sStatus = "Press Ctrl to access menu"
  710.  
  711. local function load(_sPath)
  712. tLines = {}
  713. if fs.exists( _sPath ) then
  714. local file = io.open( _sPath, "r" )
  715. local sLine = file:read()
  716. while sLine do
  717. table.insert( tLines, sLine )
  718. sLine = file:read()
  719. end
  720. file:close()
  721. end
  722.  
  723. if #tLines == 0 then
  724. table.insert( tLines, "" )
  725. end
  726. end
  727.  
  728. local function save( _sPath )
  729. -- Create intervening folder
  730. local sDir = sPath:sub(1, sPath:len() - fs.getName(sPath):len() )
  731. if not fs.exists( sDir ) then
  732. fs.makeDir( sDir )
  733. end
  734.  
  735. -- Save
  736. local file = nil
  737. local function innerSave()
  738. file = fs.open( _sPath, "w" )
  739. if file then
  740. for n, sLine in ipairs( tLines ) do
  741. file.write( sLine .. "\n" )
  742. end
  743. else
  744. term.setTextColor(colors.red)
  745. error( "EnderOS failed to open ".._sPath )
  746. term.setTextColor(colors.white)
  747. end
  748. end
  749.  
  750. local ok = pcall( innerSave )
  751. if file then
  752. file.close()
  753. end
  754. return ok
  755. end
  756.  
  757. local tKeywords = {
  758. ["and"] = true,
  759. ["break"] = true,
  760. ["do"] = true,
  761. ["else"] = true,
  762. ["elseif"] = true,
  763. ["end"] = true,
  764. ["false"] = true,
  765. ["for"] = true,
  766. ["function"] = true,
  767. ["if"] = true,
  768. ["in"] = true,
  769. ["local"] = true,
  770. ["nil"] = true,
  771. ["not"] = true,
  772. ["or"] = true,
  773. ["repeat"] = true,
  774. ["return"] = true,
  775. ["then"] = true,
  776. ["true"] = true,
  777. ["until"]= true,
  778. ["while"] = true,
  779. }
  780.  
  781. local function tryWrite( sLine, regex, colour )
  782. local match = string.match( sLine, regex )
  783. if match then
  784. if type(colour) == "number" then
  785. term.setTextColour( colour )
  786. else
  787. term.setTextColour( colour(match) )
  788. end
  789. term.write( match )
  790. term.setTextColour( textColour )
  791. return string.sub( sLine, string.len(match) + 1 )
  792. end
  793. return nil
  794. end
  795.  
  796. local function writeHighlighted( sLine )
  797. while string.len(sLine) > 0 do
  798. sLine =
  799. tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or
  800. tryWrite( sLine, "^%-%-.*", commentColour ) or
  801. tryWrite( sLine, "^\".-[^\\]\"", stringColour ) or
  802. tryWrite( sLine, "^\'.-[^\\]\'", stringColour ) or
  803. tryWrite( sLine, "^%[%[.-%]%]", stringColour ) or
  804. tryWrite( sLine, "^[%w_]+", function( match )
  805. if tKeywords[ match ] then
  806. return keywordColour
  807. end
  808. return textColour
  809. end ) or
  810. tryWrite( sLine, "^[^%w_]", textColour )
  811. end
  812. end
  813.  
  814. local function redrawText()
  815. for y=1,h-1 do
  816. term.setCursorPos( 1 - scrollX, y )
  817. term.clearLine()
  818.  
  819. local sLine = tLines[ y + scrollY ]
  820. if sLine ~= nil then
  821. writeHighlighted( sLine )
  822. end
  823. end
  824. term.setCursorPos( x - scrollX, y - scrollY )
  825. end
  826.  
  827. local function redrawLine(_nY)
  828. local sLine = tLines[_nY]
  829. term.setCursorPos( 1 - scrollX, _nY - scrollY )
  830. term.clearLine()
  831. writeHighlighted( sLine )
  832. term.setCursorPos( x - scrollX, _nY - scrollY )
  833. end
  834.  
  835. local function setLeftStatus()
  836. end
  837.  
  838. local function redrawMenu()
  839. term.setCursorPos( 1, h )
  840. term.clearLine()
  841.  
  842. local sLeft, sRight
  843. local nLeftColour, nLeftHighlight1, nLeftHighlight2
  844. if bMenu then
  845. local sMenu = ""
  846. for n,sItem in ipairs( tMenuItems ) do
  847. if n == nMenuItem then
  848. nLeftHighlight1 = sMenu:len() + 1
  849. nLeftHighlight2 = sMenu:len() + sItem:len() + 2
  850. end
  851. sMenu = sMenu.." "..sItem.." "
  852. end
  853. sLeft = sMenu
  854. nLeftColour = textColour
  855. else
  856. sLeft = sStatus
  857. nLeftColour = highlightColour
  858. end
  859.  
  860. -- Left goes last so that it can overwrite the line numbers.
  861. sRight = "Ln "..y
  862. term.setTextColour( highlightColour )
  863. term.setCursorPos( w-sRight:len() + 1, h )
  864. term.write(sRight)
  865.  
  866. sRight = tostring(y)
  867. term.setTextColour( textColour )
  868. term.setCursorPos( w-sRight:len() + 1, h )
  869. term.write(sRight)
  870.  
  871. if sLeft then
  872. term.setCursorPos( 1, h )
  873. term.setTextColour( nLeftColour )
  874. term.write(sLeft)
  875. if nLeftHighlight1 then
  876. term.setTextColour( highlightColour )
  877. term.setCursorPos( nLeftHighlight1, h )
  878. term.write( "[" )
  879. term.setCursorPos( nLeftHighlight2, h )
  880. term.write( "]" )
  881. end
  882. term.setTextColour( textColour )
  883. end
  884.  
  885. -- Cursor highlights selection
  886. term.setCursorPos( x - scrollX, y - scrollY )
  887. end
  888.  
  889. local tMenuFuncs = {
  890. Save=function()
  891. if bReadOnly then
  892. sStatus = "You cannot access this file!"
  893. else
  894. local ok, err = save( sPath )
  895. if ok then
  896. sStatus="EnderOS saved this file to "..sPath
  897. else
  898. sStatus="EnderOS could not save this file to "..sPath
  899. end
  900. end
  901. redrawMenu()
  902. end,
  903. Print=function()
  904. local sPrinterSide = nil
  905. for n,sSide in ipairs(rs.getSides()) do
  906. if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "printer" then
  907. sPrinterSide = sSide
  908. break
  909. end
  910. end
  911.  
  912. if not sPrinterSide then
  913. sStatus = "EnderOS could not find any printers!"
  914. return
  915. end
  916.  
  917. local nPage = 0
  918. local sName = fs.getName( sPath )
  919. local printer = peripheral.wrap(sPrinterSide)
  920. if printer.getInkLevel() < 1 then
  921. sStatus = "EnderOS detected no ink!"
  922. return
  923. elseif printer.getPaperLevel() < 1 then
  924. sStatus = "EnderOS detected no paper!"
  925. return
  926. end
  927.  
  928. local terminal = {
  929. getCursorPos = printer.getCursorPos,
  930. setCursorPos = printer.setCursorPos,
  931. getSize = printer.getPageSize,
  932. write = printer.write,
  933. }
  934. terminal.scroll = function()
  935. if nPage == 1 then
  936. printer.setPageTitle( sName.." (page "..nPage..")" )
  937. end
  938.  
  939. while not printer.newPage() do
  940. if printer.getInkLevel() < 1 then
  941. sStatus = "EnderOS has detected low ink levels, please refill"
  942. elseif printer.getPaperLevel() < 1 then
  943. sStatus = "EnderOS has detected low paper levels, please refill"
  944. else
  945. sStatus = "EnderOS has detected a full output tray, please empty"
  946. end
  947.  
  948. term.restore()
  949. redrawMenu()
  950. term.redirect( terminal )
  951.  
  952. local timer = os.startTimer(0.5)
  953. sleep(0.5)
  954. end
  955.  
  956. nPage = nPage + 1
  957. if nPage == 1 then
  958. printer.setPageTitle( sName )
  959. else
  960. printer.setPageTitle( sName.." (page "..nPage..")" )
  961. end
  962. end
  963.  
  964. bMenu = false
  965. term.redirect( terminal )
  966. local ok, error = pcall( function()
  967. term.scroll()
  968. for n, sLine in ipairs( tLines ) do
  969. print( sLine )
  970. end
  971. end )
  972. term.restore()
  973. if not ok then
  974. print( error )
  975. end
  976.  
  977. while not printer.endPage() do
  978. sStatus = "EnderOS has detected a full output tray, please empty"
  979. redrawMenu()
  980. sleep( 0.5 )
  981. end
  982. bMenu = true
  983.  
  984. if nPage > 1 then
  985. sStatus = "EnderOS printed "..nPage.." Pages"
  986. else
  987. sStatus = "EnderOS printed 1 Page"
  988. end
  989. redrawMenu()
  990. end,
  991. Exit=function()
  992. bRunning = false
  993. end
  994. }
  995.  
  996. local function doMenuItem( _n )
  997. tMenuFuncs[tMenuItems[_n]]()
  998. if bMenu then
  999. bMenu = false
  1000. term.setCursorBlink( true )
  1001. end
  1002. redrawMenu()
  1003. end
  1004.  
  1005. local function setCursor( x, y )
  1006. local screenX = x - scrollX
  1007. local screenY = y - scrollY
  1008.  
  1009. local bRedraw = false
  1010. if screenX < 1 then
  1011. scrollX = x - 1
  1012. screenX = 1
  1013. bRedraw = true
  1014. elseif screenX > w then
  1015. scrollX = x - w
  1016. screenX = w
  1017. bRedraw = true
  1018. end
  1019.  
  1020. if screenY < 1 then
  1021. scrollY = y - 1
  1022. screenY = 1
  1023. bRedraw = true
  1024. elseif screenY > h-1 then
  1025. scrollY = y - (h-1)
  1026. screenY = h-1
  1027. bRedraw = true
  1028. end
  1029.  
  1030. if bRedraw then
  1031. redrawText()
  1032. end
  1033. term.setCursorPos( screenX, screenY )
  1034.  
  1035. -- Statusbar now pertains to menu, it would probably be safe to redraw the menu on every key event.
  1036. redrawMenu()
  1037. end
  1038.  
  1039. -- Actual program functionality begins
  1040. load(sPath)
  1041.  
  1042. term.setBackgroundColour( bgColour )
  1043. term.clear()
  1044. term.setCursorPos(x,y)
  1045. term.setCursorBlink( true )
  1046.  
  1047. redrawText()
  1048. redrawMenu()
  1049.  
  1050. -- Handle input
  1051. while bRunning do
  1052. local sEvent, param, param2, param3 = os.pullEvent()
  1053. if sEvent == "key" then
  1054. if param == keys.up then
  1055. -- Up
  1056. if not bMenu then
  1057. if y > 1 then
  1058. -- Move cursor up
  1059. y = y - 1
  1060. x = math.min( x, string.len( tLines[y] ) + 1 )
  1061. setCursor( x, y )
  1062. end
  1063. end
  1064. elseif param == keys.down then
  1065. -- Down
  1066. if not bMenu then
  1067. -- Move cursor down
  1068. if y < #tLines then
  1069. y = y + 1
  1070. x = math.min( x, string.len( tLines[y] ) + 1 )
  1071. setCursor( x, y )
  1072. end
  1073. end
  1074. elseif param == keys.tab then
  1075. -- Tab
  1076. if not bMenu then
  1077. local sLine = tLines[y]
  1078.  
  1079. -- Indent line
  1080. -- IN CASE OF INSERT TAB IN PLACE:
  1081. -- tLines[y] = string.sub(sLine,1,x-1) .. " " .. string.sub(sLine,x)
  1082. tLines[y]=" "..tLines[y]
  1083. x = x + 2
  1084. setCursor( x, y )
  1085. redrawLine(y)
  1086. end
  1087. elseif param == keys.pageUp then
  1088. -- Page Up
  1089. if not bMenu then
  1090. -- Move up a page
  1091. local sx,sy=term.getSize()
  1092. y=y-sy-1
  1093. if y<1 then y=1 end
  1094. x = math.min( x, string.len( tLines[y] ) + 1 )
  1095. setCursor( x, y )
  1096. end
  1097. elseif param == keys.pageDown then
  1098. -- Page Down
  1099. if not bMenu then
  1100. -- Move down a page
  1101. local sx,sy=term.getSize()
  1102. if y<#tLines-sy-1 then
  1103. y = y+sy-1
  1104. else
  1105. y = #tLines
  1106. end
  1107. x = math.min( x, string.len( tLines[y] ) + 1 )
  1108. setCursor( x, y )
  1109. end
  1110. elseif param == keys.home then
  1111. -- Home
  1112. if not bMenu then
  1113. -- Move cursor to the beginning
  1114. x=1
  1115. setCursor(x,y)
  1116. end
  1117. elseif param == keys["end"] then
  1118. -- End
  1119. if not bMenu then
  1120. -- Move cursor to the end
  1121. x = string.len( tLines[y] ) + 1
  1122. setCursor(x,y)
  1123. end
  1124. elseif param == keys.left then
  1125. -- Left
  1126. if not bMenu then
  1127. if x > 1 then
  1128. -- Move cursor left
  1129. x = x - 1
  1130. elseif x==1 and y>1 then
  1131. x = string.len( tLines[y-1] ) + 1
  1132. y = y - 1
  1133. end
  1134. setCursor( x, y )
  1135. else
  1136. -- Move menu left
  1137. nMenuItem = nMenuItem - 1
  1138. if nMenuItem < 1 then
  1139. nMenuItem = #tMenuItems
  1140. end
  1141. redrawMenu()
  1142. end
  1143. elseif param == keys.right then
  1144. -- Right
  1145. if not bMenu then
  1146. if x < string.len( tLines[y] ) + 1 then
  1147. -- Move cursor right
  1148. x = x + 1
  1149. elseif x==string.len( tLines[y] ) + 1 and y<#tLines then
  1150. x = 1
  1151. y = y + 1
  1152. end
  1153. setCursor( x, y )
  1154. else
  1155. -- Move menu right
  1156. nMenuItem = nMenuItem + 1
  1157. if nMenuItem > #tMenuItems then
  1158. nMenuItem = 1
  1159. end
  1160. redrawMenu()
  1161. end
  1162. elseif param == keys.delete then
  1163. -- Delete
  1164. if not bMenu then
  1165. if x < string.len( tLines[y] ) + 1 then
  1166. local sLine = tLines[y]
  1167. tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1)
  1168. redrawLine(y)
  1169. elseif y<#tLines then
  1170. tLines[y] = tLines[y] .. tLines[y+1]
  1171. table.remove( tLines, y+1 )
  1172. redrawText()
  1173. redrawMenu()
  1174. end
  1175. end
  1176. elseif param == keys.backspace then
  1177. -- Backspace
  1178. if not bMenu then
  1179. if x > 1 then
  1180. -- Remove character
  1181. local sLine = tLines[y]
  1182. tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x)
  1183. redrawLine(y)
  1184.  
  1185. x = x - 1
  1186. setCursor( x, y )
  1187. elseif y > 1 then
  1188. -- Remove newline
  1189. local sPrevLen = string.len( tLines[y-1] )
  1190. tLines[y-1] = tLines[y-1] .. tLines[y]
  1191. table.remove( tLines, y )
  1192. redrawText()
  1193.  
  1194. x = sPrevLen + 1
  1195. y = y - 1
  1196. setCursor( x, y )
  1197. end
  1198. end
  1199. elseif param == keys.enter then
  1200. -- Enter
  1201. if not bMenu then
  1202. -- Newline
  1203. local sLine = tLines[y]
  1204. local _,spaces=string.find(sLine,"^[ ]+")
  1205. if not spaces then
  1206. spaces=0
  1207. end
  1208. tLines[y] = string.sub(sLine,1,x-1)
  1209. table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) )
  1210. redrawText()
  1211.  
  1212. x = spaces+1
  1213. y = y + 1
  1214. setCursor( x, y )
  1215. else
  1216. -- Menu selection
  1217. doMenuItem( nMenuItem )
  1218. end
  1219. elseif param == keys.leftCtrl or param == keys.rightCtrl then
  1220. -- Menu toggle
  1221. bMenu = not bMenu
  1222. if bMenu then
  1223. term.setCursorBlink( false )
  1224. nMenuItem = 1
  1225. else
  1226. term.setCursorBlink( true )
  1227. end
  1228. redrawMenu()
  1229. end
  1230.  
  1231. elseif sEvent == "char" then
  1232. if not bMenu then
  1233. -- Input text
  1234. local sLine = tLines[y]
  1235. tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)
  1236. redrawLine(y)
  1237.  
  1238. x = x + string.len( param )
  1239. setCursor( x, y )
  1240. else
  1241. -- Select menu items
  1242. for n,sMenuItem in ipairs( tMenuItems ) do
  1243. if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then
  1244. doMenuItem( n )
  1245. break
  1246. end
  1247. end
  1248. end
  1249.  
  1250. elseif sEvent == "mouse_click" then
  1251. if not bMenu then
  1252. if param == 1 then
  1253. -- Left click
  1254. local cx,cy = param2, param3
  1255. if cy < h then
  1256. y = math.min( math.max( scrollY + cy, 1 ), #tLines )
  1257. x = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[y] ) + 1 )
  1258. setCursor( x, y )
  1259. end
  1260. end
  1261. end
  1262.  
  1263. elseif sEvent == "mouse_scroll" then
  1264. if not bMenu then
  1265. if param == -1 then
  1266. -- Scroll up
  1267. if scrollY > 0 then
  1268. -- Move cursor up
  1269. scrollY = scrollY - 1
  1270. redrawText()
  1271. end
  1272.  
  1273. elseif param == 1 then
  1274. -- Scroll down
  1275. local nMaxScroll = #tLines - (h-1)
  1276. if scrollY < nMaxScroll then
  1277. -- Move cursor down
  1278. scrollY = scrollY + 1
  1279. redrawText()
  1280. end
  1281.  
  1282. end
  1283. end
  1284. end
  1285. end
  1286.  
  1287. -- Cleanup
  1288. term.clear()
  1289. term.setCursorBlink( false )
  1290. term.setCursorPos( 1, 1 )
  1291. startScreen()
  1292. end
  1293. function programs()
  1294. term.setTextColor(colors.purple)
  1295. frame()
  1296. term.setCursorPos(17,1)
  1297. term.setTextColor(colors.lime)
  1298. print("[User Programs]")
  1299. term.setCursorPos(3,1)
  1300. term.setTextColor(colors.orange)
  1301. term.write("[Back]")
  1302. term.setTextColor(colors.white)
  1303. local programs = shell.programs()
  1304. term.setCursorPos(3,3)
  1305. local pTable = textutils.pagedTabulate(programs)
  1306. term.setCursorPos(3,3)
  1307. print(pTable)
  1308. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1309. if button == 1 then
  1310. if (xPos >=3 and xPos <=8 and yPos == 1) then
  1311. startScreen()
  1312. else
  1313. programs()
  1314. end
  1315. else
  1316. programs()
  1317. end
  1318. end
  1319. function reset()
  1320. term.clear()
  1321. term.setCursorPos(1,1)
  1322. end
  1323. function userInfo()
  1324. repeat
  1325. reset()
  1326. fs.makeDir("/.EnderOS/")
  1327. user = ("/.EnderOS/.userInfo")
  1328. username = io.open(user, "w")
  1329. term.setTextColor(colors.orange)
  1330. print("Please enter your desired Username")
  1331. term.setTextColor(colors.white)
  1332. writeUser = read()
  1333. if #writeUser <2 or writeUser == "Username" or writeUser == "username" then
  1334. term.setTextColor(colors.red)
  1335. print("The Endermen hack you in their sleep!")
  1336. sleep(3)
  1337. userInfo()
  1338. end
  1339. until #writeUser >2 or writeUser ~= "Username" or writeUser ~= "username"
  1340. local hash = sha256(writeUser)
  1341. writeIsFailUser = username:write(hash..saltHash)
  1342. username:close()
  1343. repeat
  1344. pass = ("/.EnderOS/.passInfo")
  1345. password = io.open(pass, "w")
  1346. term.setTextColor(colors.orange)
  1347. print("Please enter your desired Password")
  1348. term.setTextColor(colors.white)
  1349. writePass = read("*")
  1350. if #writePass <2 or writePass == "Password" or writePass == "password" then
  1351. term.setTextColor(colors.red)
  1352. print("The Endermen hack you in their sleep!")
  1353. sleep(3)
  1354. userInfo()
  1355. end
  1356. until #writePass >2 or writePass ~= "Password" or writePass ~= "password"
  1357. local hash = sha256(writePass)
  1358. writeIsFailPass = password:write(hash..saltHash)
  1359. password:close()
  1360. hint = ("/.EnderOS/.userHint")
  1361. uHint = io.open(hint, "w")
  1362. term.setTextColor(colors.orange)
  1363. print("Please enter your desired Password hint")
  1364. term.setTextColor(colors.white)
  1365. writeHint = read()
  1366. if #writeHint >30 then
  1367. term.setTextColor(colors.red)
  1368. print("The Endermen revoke any hint greater than 30 characters!")
  1369. shell.run("delete","/.EnderOS/.userInfo")
  1370. shell.run("delete","/.EnderOS/.passInfo")
  1371. uHint:close()
  1372. sleep(2)
  1373. userInfo()
  1374. else
  1375. writeIsFailHint = uHint:write(writeHint)
  1376. uHint:close()
  1377. local installC = fs.open("/.EnderOS/.EnderOSisInstalled", "w")
  1378. installC:close()
  1379. end
  1380. end
  1381. function frame()
  1382. print("+-------------------------------------------------+")
  1383. for i = 1,17 do
  1384. print("| |")
  1385. end
  1386. term.write("+-------------------------------------------------+")
  1387. end
  1388. function screen()
  1389. reset()
  1390. term.setTextColor(colors.lime)
  1391. print("+-------------------------------------------------+")
  1392. print("| |")
  1393. print("| ")
  1394. term.setCursorPos(19,3)
  1395. term.setTextColor(colors.purple)
  1396. write("EnderOS "..version)
  1397. term.setTextColor(colors.lime)
  1398. term.setCursorPos(31,3)
  1399. print(" |")
  1400. print("| |")
  1401. print("| |")
  1402. print("| |")
  1403. print("| |")
  1404. print("| ")
  1405. term.setCursorPos(10,8)
  1406. term.setTextColor(colors.orange)
  1407. print("Username:")
  1408. term.setCursorPos(19,8)
  1409. print(" ")
  1410. term.setCursorPos(50,8)
  1411. term.setTextColor(colors.lime)
  1412. print(" |")
  1413. print("| |")
  1414. print("| ")
  1415. term.setTextColor(colors.orange)
  1416. term.setCursorPos(10,10)
  1417. print("Password:")
  1418. term.setCursorPos(19,10)
  1419. print(" ")
  1420. term.setCursorPos(50,10)
  1421. term.setTextColor(colors.lime)
  1422. print(" |")
  1423. print("| |")
  1424. print("| |")
  1425. print("| ")
  1426. term.setCursorPos(8,13)
  1427. term.setTextColor(colors.blue)
  1428. print("Password Hint: ")
  1429. term.setCursorPos(50,13)
  1430. term.setTextColor(colors.lime)
  1431. print(" |")
  1432. print("| |")
  1433. print("| |")
  1434. print("| |")
  1435. print("| |")
  1436. print("| |")
  1437. write("+-------------------------------------------------+")
  1438. end
  1439. function login()
  1440. repeat
  1441. screen()
  1442. local userHint = io.open("/.EnderOS/.userHint", "r")
  1443. hintContents = userHint:read()
  1444. userHint:close()
  1445. term.setCursorPos(23,13)
  1446. term.setTextColor(colors.lightGray)
  1447. print(hintContents)
  1448. term.setTextColor(colors.white)
  1449. term.setCursorPos(20,8)
  1450. local userFile = io.open("/.EnderOS/.userInfo", "r")
  1451. userContents = userFile:read()
  1452. userFile:close()
  1453. term.setTextColor(colors.white)
  1454. local input = read()
  1455. local hash = sha256(input)
  1456. if hash..saltHash ~= hash..saltHash then
  1457. screen()
  1458. login()
  1459. end
  1460. until hash..saltHash == userContents
  1461. repeat
  1462. term.setCursorPos(20,10)
  1463. term.setTextColor(colors.white)
  1464. local passFile = io.open("/.EnderOS/.passInfo", "r")
  1465. passContents = passFile:read()
  1466. passFile:close()
  1467. local input = read("*")
  1468. local hash = sha256(input)
  1469. if hash..saltHash ~= passContents then
  1470. screen()
  1471. login()
  1472. end
  1473. until hash..saltHash == passContents
  1474. startScreen()
  1475. end
  1476. function run()
  1477. reset()
  1478. term.setTextColor(colors.orange)
  1479. print("What program do you wish to run?")
  1480. term.setTextColor(colors.white)
  1481. input = read()
  1482. if not fs.exists(input) then
  1483. term.setTextColor(colors.red)
  1484. print("Invalid Arguement: File not found")
  1485. sleep(3)
  1486. startScreen()
  1487. end
  1488. if input == shell.getRunningProgram() then
  1489. term.setTextColor(colors.red)
  1490. print("The Endermen are not fond of your jokes!")
  1491. sleep(3)
  1492. startScreen()
  1493. else
  1494. shell.run(input)
  1495. sleep(1.5)
  1496. startScreen()
  1497. end
  1498. end
  1499. function settings()
  1500. term.setTextColor(colors.purple)
  1501. frame()
  1502. term.setCursorPos(17,1)
  1503. term.setTextColor(colors.lime)
  1504. print("[EnderOS Settings]")
  1505. term.setCursorPos(7,3)
  1506. print("{Change Username} {Change Password}")
  1507. term.setCursorPos(3,5)
  1508. print("{Change Password Hint} {Uninstall EnderOS}")
  1509. term.setCursorPos(3,1)
  1510. term.setTextColor(colors.orange)
  1511. term.write("[Back]")
  1512. term.setTextColor(colors.white)
  1513. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1514. if button == 1 then
  1515. if (xPos >=7 and xPos <=23 and yPos == 3) then
  1516. settingsChangeUser()
  1517. elseif (xPos >=27 and xPos <=43 and yPos == 3) then
  1518. settingsChangePass()
  1519. elseif (xPos >=3 and xPos <=24 and yPos == 5) then
  1520. settingsChangeHint()
  1521. elseif (xPos >=28 and xPos <=46 and yPos == 5) then
  1522. reset()
  1523. term.setCursorPos(15,7)
  1524. term.setTextColor(colors.purple)
  1525. print("Uninstalling EnderOS")
  1526. term.setCursorPos(17,9)
  1527. term.setTextColor(colors.lime)
  1528. term.write("[XX----------]")
  1529. sleep(1)
  1530. fs.delete("/.EnderOS/.EnderOSisInstalled")
  1531. term.setCursorPos(17,9)
  1532. term.write("[XXXX--------]")
  1533. sleep(1)
  1534. fs.delete("/.EnderOS/.userInfo")
  1535. term.setCursorPos(17,9)
  1536. term.write("[XXXXXX------]")
  1537. sleep(1)
  1538. fs.delete("/.EnderOS/.userHint")
  1539. term.setCursorPos(17,9)
  1540. term.write("[XXXXXXXX----]")
  1541. sleep(1)
  1542. fs.delete("/.EnderOS/.passInfo")
  1543. term.setCursorPos(17,9)
  1544. term.write("[XXXXXXXXXX--]")
  1545. sleep(1)
  1546. fs.delete("/.EnderOS/.firewolf")
  1547. fs.delete("/.EnderOS")
  1548. fs.delete(".Firewolf_Data")
  1549. fs.delete(".Installer")
  1550. term.setCursorPos(17,9)
  1551. term.write("[XXXXXXXXXXXX]")
  1552. sleep(1)
  1553. reset()
  1554. term.setCursorPos(12,7)
  1555. term.setTextColor(colors.purple)
  1556. term.write("Until next time - The Endermen")
  1557. enderOS = shell.getRunningProgram()
  1558. sleep(3)
  1559. x = nil
  1560. if fs.exists("EnderOS") then
  1561. fs.delete("EnderOS")
  1562. end
  1563. ender = io.open("EnderOS","w")
  1564. ender:write("The file the Endermen made is called .Endermen")
  1565. ender:close()
  1566. reset()
  1567. term.setTextColor(colors.white)
  1568. print("The Endermen seem to have made a file that contains EnderOS for later use")
  1569. sleep(4)
  1570. if fs.exists(".Endermen") then
  1571. fs.delete(".Endermen")
  1572. end
  1573. fs.move("startup",".Endermen")
  1574. os.reboot()
  1575. reset()
  1576. return
  1577. elseif (xPos >=3 and xPos <=9 and yPos == 1) then
  1578. startScreen()
  1579. else
  1580. settings()
  1581. end
  1582. else
  1583. settings()
  1584. end
  1585. end
  1586. function games()
  1587. term.setTextColor(colors.purple)
  1588. frame()
  1589. term.setCursorPos(18,1)
  1590. term.setTextColor(colors.lime)
  1591. print("[EnderOS Games]")
  1592. term.setCursorPos(3,3)
  1593. print("{SkullPong} {AdventureCraft}")
  1594. term.setCursorPos(3,1)
  1595. term.setTextColor(colors.orange)
  1596. term.write("[Back]")
  1597. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1598. if button == 1 then
  1599. if (xPos >=3 and xPos <=13 and yPos == 3) then
  1600. SkullPong()
  1601. elseif (xPos >=3 and xPos <=9 and yPos == 1) then
  1602. startScreen()
  1603. elseif (xPos >=17 and xPos <=32 and yPos == 3) then
  1604. AdventureCraft()
  1605. else
  1606. games()
  1607. end
  1608. else
  1609. games()
  1610. end
  1611. end
  1612. function delete()
  1613. reset()
  1614. term.setTextColor(colors.orange)
  1615. print("What file do you wish to delete?")
  1616. term.setTextColor(colors.white)
  1617. file = read()
  1618. if not fs.exists(file) then
  1619. term.setTextColor(colors.red)
  1620. print("Invalid Arguement: File not found")
  1621. sleep(2)
  1622. startScreen()
  1623. end
  1624. if file == shell.getRunningProgram() or file == "/.EnderOS/.userInfo" or file == "/.EnderOS/.passInfo" or file == "startup" or file == shell.getRunningProgram() or file == "/.EnderOS/.EnderOSisInstalled" or file == "/.EnderOS/.firewolf" then
  1625. term.setTextColor(colors.red)
  1626. print("The Endermen will not allow you to delete: "..file)
  1627. sleep(3)
  1628. startScreen()
  1629. else
  1630. reset()
  1631. term.setTextColor(colors.orange)
  1632. print("Are you sure you want to delete the file: "..file)
  1633. term.setCursorPos(1,3)
  1634. term.setTextColor(colors.white)
  1635. input = read()
  1636. if input == "Yes" or input == "yes" then
  1637. shell.run("delete",file)
  1638. reset()
  1639. term.setTextColor(colors.lightBlue)
  1640. print(file.." deleted!")
  1641. sleep(2)
  1642. startScreen()
  1643. else
  1644. startScreen()
  1645. end
  1646. end
  1647. end
  1648. function startScreen()
  1649. reset()
  1650. term.setTextColor(colors.purple)
  1651. frame()
  1652. term.setCursorPos(3,19)
  1653. term.setTextColor(colors.orange)
  1654. term.write("[Log Out]")
  1655. term.setCursorPos(17,1)
  1656. term.setTextColor(colors.lime)
  1657. print("[EnderOS Commands]")
  1658. term.setCursorPos(3,3)
  1659. print("{Settings} {Games} {Edit} {Programs}")
  1660. term.setCursorPos(3,5)
  1661. print("{Delete} {Run} {Calculator} {Firewolf}")
  1662. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1663. if button == 1 then
  1664. if (xPos >=3 and xPos <=12 and yPos == 3) then --SETTINGS
  1665. settings()
  1666. elseif (xPos >=16 and xPos <=22 and yPos == 3) then --GAMES
  1667. games()
  1668. elseif (xPos >=26 and xPos <=31 and yPos == 3) then --EDIT
  1669. Edit()
  1670. elseif (xPos >=35 and xPos <=44 and yPos == 3) then --PROGRAMS
  1671. programs()
  1672. elseif (xPos >=3 and xPos <=10 and yPos == 5) then --DELETE
  1673. delete()
  1674. elseif (xPos >=14 and xPos <=18 and yPos == 5) then --RUN
  1675. run()
  1676. elseif (xPos >=22 and xPos <=33 and yPos == 5) then --CALCULATOR
  1677. calculator()
  1678. elseif (xPos >=3 and xPos <=11 and yPos == 19) then --LOG OFF
  1679. reset()
  1680. screen()
  1681. login()
  1682. elseif (xPos >=37 and xPos <=46 and yPos == 5) then
  1683. shell.run("/.EnderOS/.firewolf")
  1684. sleep(6)
  1685. startScreen()
  1686. else
  1687. startScreen()
  1688. end
  1689. else
  1690. startScreen()
  1691. end
  1692. end
  1693. function SkullPong()
  1694. --Code By SkullBlade(Skullblade213)
  1695. --You are allowed to modify and redistribute
  1696. --You are not allowed to modify this header
  1697. function Draw()
  1698. term.setBackgroundColor(counter)
  1699. term.clear()
  1700. term.setBackgroundColor(colors.white)
  1701. term.setCursorPos(Ball[1], Ball[2])
  1702. print(" ")
  1703. term.setBackgroundColor(colors.lime)
  1704. term.setCursorPos(You[1], You[2])
  1705. print(" ")
  1706. term.setCursorPos(You[1], You[3])
  1707. print(" ")
  1708. term.setCursorPos(You[1], You[4])
  1709. print(" ")
  1710. term.setBackgroundColor(colors.red)
  1711. term.setCursorPos(Op[1], Op[2])
  1712. print(" ")
  1713. term.setCursorPos(Op[1], Op[3])
  1714. print(" ")
  1715. term.setCursorPos(Op[1], Op[4])
  1716. print(" ")
  1717. end
  1718. function Update()
  1719. Ball={Ball[1]+Ball[3],Ball[2]+Ball[4],Ball[3],Ball[4]}
  1720. if Ball[1]==3 or Ball[1]==49 then
  1721. if Ball[1]==3 then
  1722. Check="L"
  1723. end
  1724. if Ball[1]==49 then
  1725. Check="R"
  1726. end
  1727. if (Ball[2]==You[2] and Check=="L") or (Ball[2]==Op[2] and Check=="R") then
  1728. Ball[3]=Ball[3]*-1
  1729. Ball[4]=-1
  1730. rans=math.random(1,5)
  1731. end
  1732. if (Ball[2]==You[3] and Check=="L") or (Ball[2]==Op[3] and Check=="R") then
  1733. Ball[3]=Ball[3]*-1
  1734. Ball[4]=Ball[4]*-1
  1735. end
  1736. if (Ball[2]==You[4] and Check=="L") or (Ball[2]==Op[4] and Check=="R") then
  1737. Ball[3]=Ball[3]*-1
  1738. Ball[4]=1
  1739. end
  1740. end
  1741. if Ball[2]==1 or Ball[2]==18 or Ball[2]==0 or Ball[2]==19 then
  1742. Ball[4]=Ball[4]*-1
  1743. end
  1744. if Ball[1]==1 then
  1745. score2=score2+1
  1746. Start()
  1747. end
  1748. if Ball[1]==51 then
  1749. score=score+1
  1750. Start()
  1751. end
  1752. end
  1753. function Move()
  1754. if key==200 then
  1755. You[2]=You[2]-1
  1756. end
  1757. if key==208 then
  1758. You[2]=You[2]+1
  1759. end
  1760. end
  1761. function AI()
  1762. if Ball[2]+Ball[4]>Op[2]+2 then
  1763. if Op[2]+3~=19 then
  1764. Op={Op[1],Op[2]+1,Op[2]+2,Op[2]+3}
  1765. end
  1766. end
  1767. if Ball[2]+Ball[4]<Op[2] then
  1768. if Op[2]-1~=0 then
  1769. Op={Op[1],Op[2]-1,Op[2],Op[2]+1}
  1770. end
  1771. end
  1772. end
  1773. function Start()
  1774. You={2,9,10,11}
  1775. Op={50,9,10,11}
  1776. ran=math.random(-1,1)
  1777. ran2=math.random(-1,1)
  1778. while ran==0 do
  1779. ran=math.random(-1,1)
  1780. end
  1781. while ran2==0 do
  1782. ran2=math.random(-1,1)
  1783. end
  1784. Ball={25,10,ran,ran2}
  1785. term.setCursorPos(20,10)
  1786. print(score.." VS "..score2)
  1787. if vars=="surv" and score2==1 then
  1788. ends="true"
  1789. end
  1790. sleep(1)
  1791. end
  1792. function Single(v)
  1793. vars=v
  1794. ends="false"
  1795. score=0
  1796. score2=0
  1797. if resume~="true" then
  1798. Start()
  1799. end
  1800. counter=1
  1801. breaks="false"
  1802. while true do
  1803. if vars=="surv" then
  1804. counter=counter*2
  1805. if counter==32 or counter==16384 then
  1806. counter=counter*2
  1807. end
  1808. if counter==32768 then
  1809. counter=2
  1810. end
  1811. term.setBackgroundColor(counter)
  1812. end
  1813. if vars~="surv" then
  1814. counter=32768
  1815. end
  1816. Draw()
  1817. os.startTimer(.1)
  1818. while true do
  1819. event, key = os.pullEvent()
  1820. if event=="key" then
  1821. if vars~="Local" then
  1822. Move()
  1823. end
  1824. if key==59 and (vars=="surv" or vars=="norm" or vars=="Local") then
  1825. Menu("Paused","Resume","Info/Help","Quit")
  1826. breaks="true"
  1827. break
  1828. end
  1829. if vars=="Local" then
  1830. if key==17 then
  1831. You[2]=You[2]-1
  1832. end
  1833. if key==31 then
  1834. You[2]=You[2]+1
  1835. end
  1836. if key==200 then
  1837. Op[2]=Op[2]-1
  1838. end
  1839. if key==208 then
  1840. Op[2]=Op[2]+1
  1841. end
  1842. if You[2]==0 then
  1843. You[2]=1
  1844. end
  1845. if You[2]==17 then
  1846. You[2]=16
  1847. end
  1848. if Op[2]==0 then
  1849. Op[2]=1
  1850. end
  1851. if Op[2]==17 then
  1852. Op[2]=16
  1853. end
  1854. You={You[1],You[2],You[2]+1,You[2]+2}
  1855. Op={Op[1],Op[2],Op[2]+1,Op[2]+2}
  1856. end
  1857. if You[2]==0 then
  1858. You[2]=1
  1859. end
  1860. if You[2]==17 then
  1861. You[2]=16
  1862. end
  1863. You={You[1],You[2],You[2]+1,You[2]+2}
  1864. end
  1865. if event=="timer" then
  1866. break
  1867. end
  1868. end
  1869. if breaks=="true" then
  1870. break
  1871. end
  1872. if vars~="Local" then
  1873. AI()
  1874. end
  1875. Update()
  1876. if ends=="true" then
  1877. ends="false"
  1878. Menu("SinglePlayer","Normal","Survival","Back")
  1879. break
  1880. end
  1881. end
  1882. end
  1883. function Set(x1,y1)
  1884. x=x1
  1885. y=y1
  1886. term.setCursorPos(x1,y1)
  1887. end
  1888. function PrintCenter(text)
  1889. textLen=string.len(text)
  1890. x = ((51-textLen)/2)
  1891. term.setCursorPos(x,y)
  1892. print(text)
  1893. y=y+1
  1894. end
  1895. function Menu(title,opt1,opt2,opt3)
  1896. resume="false"
  1897. term.setBackgroundColor(colors.black)
  1898. select=1
  1899. while true do
  1900. term.clear()
  1901. term.setCursorPos(1,1)
  1902. term.setTextColor(colors.lime)
  1903. print("SkullPong V1.10")
  1904. Set(1,6)
  1905. PrintCenter(title)
  1906. PrintCenter("------------")
  1907. term.setTextColor(colors.white)
  1908. PrintCenter(opt1)
  1909. PrintCenter(opt2)
  1910. PrintCenter(opt3)
  1911. if select==1 then
  1912. Set(1,8)
  1913. term.setTextColor(colors.blue)
  1914. PrintCenter(opt1)
  1915. term.setTextColor(colors.white)
  1916. end
  1917. if select==2 then
  1918. Set(1,9)
  1919. term.setTextColor(colors.blue)
  1920. PrintCenter(opt2)
  1921. term.setTextColor(colors.white)
  1922. end
  1923. if select==3 then
  1924. Set(1,10)
  1925. term.setTextColor(colors.blue)
  1926. PrintCenter(opt3)
  1927. term.setTextColor(colors.white)
  1928. end
  1929. event, param1, param2, param3 = os.pullEvent()
  1930. if event=="mouse_click" then
  1931. if param3==8 or param3==9 or param3==10 then
  1932. sel=select
  1933. if param3==8 then
  1934. text=opt1
  1935. select=1
  1936. end
  1937. if param3==9 then
  1938. text=opt2
  1939. select=2
  1940. end
  1941. if param3==10 then
  1942. text=opt3
  1943. select=3
  1944. end
  1945. strLen=string.len(text)
  1946. start=(51-strLen)/2-1
  1947. if param2>start and param2<start+strLen then
  1948. if select==1 then
  1949. if opt1=="SinglePlayer" then
  1950. Menu("SinglePlayer","Normal","Survival","Back")
  1951. break
  1952. end
  1953. if opt1=="Normal" then
  1954. Single("norm")
  1955. break
  1956. end
  1957. if opt1=="Resume" then
  1958. resume="true"
  1959. Single(vars)
  1960. break
  1961. end
  1962. if opt1=="Local" then
  1963. Single("Local")
  1964. break
  1965. end
  1966. end
  1967. if select==2 then
  1968. if opt1=="SinglePlayer" then
  1969. Menu("MultiPlayer","Local","Rednet","Back")
  1970. break
  1971. end
  1972. if opt1=="Normal" then
  1973. Single("surv")
  1974. break
  1975. end
  1976. if opt1=="Resume" then
  1977. if vars~="Local" then
  1978. term.clear()
  1979. term.setTextColor(colors.lime)
  1980. term.setBackgroundColor(colors.black)
  1981. term.setCursorPos(1,1)
  1982.  
  1983. print("SkullPong V1.10")
  1984. print("Help")
  1985. print("---------------")
  1986. term.setTextColor(colors.white)
  1987. print("")
  1988. print("Controls")
  1989. print("UpArrow: Paddle Up")
  1990. print("DownArrow: Paddle Down")
  1991. print("Objective")
  1992. print("Don't let the ball get pass the green paddle{You}")
  1993. print("Get the ball pass the red paddle{AI}")
  1994. print("")
  1995. print("Press any key to continue")
  1996. os.pullEvent("key")
  1997. end
  1998. if vars=="Local" then
  1999. term.clear()
  2000. term.setTextColor(colors.lime)
  2001. term.setBackgroundColor(colors.black)
  2002. term.setCursorPos(1,1)
  2003. print("SkullPong V1.10")
  2004. print("Help")
  2005. print("---------------")
  2006. term.setTextColor(colors.white)
  2007. print("")
  2008. print("Controls")
  2009. print("UpArrow: Paddle Up-Red")
  2010. print("DownArrow: Paddle Down-Red")
  2011. print("W: Paddle Up-Green")
  2012. print("A: Paddle Down-Green")
  2013. print("Objective")
  2014. print("Don't let the ball get pass the your paddle")
  2015. print("Get the ball pass your opponent's paddle")
  2016. print("")
  2017. print("Press any key to continue")
  2018. os.pullEvent("key")
  2019. end
  2020. end
  2021. if opt1=="Local" then
  2022. error("Not Implimented!")
  2023. end
  2024. end
  2025. if select==3 then
  2026. if opt1=="SinglePlayer" then
  2027. term.clear()
  2028. term.setCursorPos(1,1)
  2029. break
  2030. else
  2031. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  2032. break
  2033. end
  2034. end
  2035. else
  2036. select=sel
  2037. end
  2038. end
  2039. end
  2040. if event=="key" then
  2041. if param1==200 then
  2042. select=select-1
  2043. end
  2044. if param1==208 then
  2045. select=select+1
  2046. end
  2047. if param1==28 then
  2048. if select==1 then
  2049. if opt1=="SinglePlayer" then
  2050. Menu("SinglePlayer","Normal","Survival","Back")
  2051. break
  2052. end
  2053. if opt1=="Normal" then
  2054. Single("norm")
  2055. break
  2056. end
  2057. if opt1=="Resume" then
  2058. resume="true"
  2059. Single(vars)
  2060. break
  2061. end
  2062. if opt1=="Local" then
  2063. Single("Local")
  2064. break
  2065. end
  2066. end
  2067. if select==2 then
  2068. if opt1=="SinglePlayer" then
  2069. Menu("MultiPlayer","Local","Rednet","Back")
  2070. break
  2071. end
  2072. if opt1=="Normal" then
  2073. Single("surv")
  2074. break
  2075. end
  2076. if opt1=="Resume" then
  2077. if vars~="Local" then
  2078. term.clear()
  2079. term.setTextColor(colors.lime)
  2080. term.setBackgroundColor(colors.black)
  2081. term.setCursorPos(1,1)
  2082.  
  2083. print("SkullPong V1.10")
  2084. print("Help")
  2085. print("---------------")
  2086. term.setTextColor(colors.white)
  2087. print("")
  2088. print("Controls")
  2089. print("UpArrow: Paddle Up")
  2090. print("DownArrow: Paddle Down")
  2091. print("Objective")
  2092. print("Don't let the ball get pass the green paddle{You}")
  2093. print("Get the ball pass the red paddle{AI}")
  2094. print("")
  2095. print("Press any key to continue")
  2096. os.pullEvent("key")
  2097. end
  2098. if vars=="Local" then
  2099. term.clear()
  2100. term.setTextColor(colors.lime)
  2101. term.setBackgroundColor(colors.black)
  2102. term.setCursorPos(1,1)
  2103. print("SkullPong V1.10")
  2104. print("Help")
  2105. print("---------------")
  2106. term.setTextColor(colors.white)
  2107. print("")
  2108. print("Controls")
  2109. print("UpArrow: Paddle Up-Red")
  2110. print("DownArrow: Paddle Down-Red")
  2111. print("W: Paddle Up-Green")
  2112. print("A: Paddle Down-Green")
  2113. print("Objective")
  2114. print("Don't let the ball get pass the your paddle")
  2115. print("Get the ball pass your opponent's paddle")
  2116. print("")
  2117. print("Press any key to continue")
  2118. os.pullEvent("key")
  2119. end
  2120. end
  2121. if opt1=="Local" then
  2122. error("Not Implimented!")
  2123. end
  2124. end
  2125. if select==3 then
  2126. if opt1=="SinglePlayer" then
  2127. term.clear()
  2128. term.setCursorPos(1,1)
  2129. break
  2130. else
  2131. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  2132. break
  2133. end
  2134. end
  2135. end
  2136. if select==0 then
  2137. select=3
  2138. end
  2139. if select==4 then
  2140. select=1
  2141. end
  2142. end
  2143. end
  2144. end
  2145. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  2146. games()
  2147. end
  2148. function AdventureCraft()
  2149. term.setTextColor(colors.white)
  2150. --Misc stats
  2151. numbertext = 0
  2152. --Player stats
  2153. PlayerGold = 0
  2154. PlayerName = ("Player")
  2155. PlayerArmor = 0
  2156. PlayerSword = 0
  2157. PlayerHealth = 100
  2158. PlayerDamage = 5
  2159. PlayerWeapon = ("Fists")
  2160. PlayerArmorType = ("None")
  2161. Block = 0
  2162.  
  2163. rouge = {
  2164. }
  2165.  
  2166.  
  2167.  
  2168. playerokaya = {
  2169. " (o o) ",
  2170. "()||[=]|| ",
  2171. " | | "
  2172. }
  2173. playerhappy = {
  2174. " (o o) /",
  2175. "()||[=]||/ ",
  2176. " | | "
  2177. }
  2178. playerokay = {
  2179. " (o o) /",
  2180. " ||( )||/ ",
  2181. " | | "
  2182. }
  2183. playersad = {
  2184. " (o o) ",
  2185. " ||( )|| ",
  2186. " | | "
  2187. }
  2188.  
  2189. --Npcs
  2190. shopkeeper = {
  2191. " _____ ",
  2192. " |O O| ",
  2193. " | U | ",
  2194. " |_____| ",
  2195. " Shopkeeper"
  2196. }
  2197. --items
  2198. sword = {
  2199. " ___ ",
  2200. "| /|",
  2201. "|-/-|",
  2202. "|/ |",
  2203. "|---|"
  2204. }
  2205. armor = {
  2206. " ___ ",
  2207. "| _ |",
  2208. "|/ \\|",
  2209. "||_||",
  2210. "|---|"
  2211. }
  2212. potion = {
  2213. " ___ ",
  2214. "|/^\\|",
  2215. "|| ||",
  2216. "||_||",
  2217. "|---|"
  2218. }
  2219. bow = {
  2220. " ___ ",
  2221. "||\\ |",
  2222. "|==>|",
  2223. "||/ |",
  2224. "|---|"
  2225. }
  2226. nextpage = {
  2227. " ___ ",
  2228. "| |",
  2229. "|==>|",
  2230. "| |",
  2231. "|---|"
  2232. }
  2233. prevpage = {
  2234. " ___ ",
  2235. "| |",
  2236. "|<==|",
  2237. "| |",
  2238. "|---|"
  2239. }
  2240. --Creature Features
  2241.  
  2242. CurrentCreatureGold = 0
  2243. CurrentCreatureHealth = 0
  2244. CurrentCreatureAttack = 0
  2245.  
  2246. spider = {
  2247. ". (o-o) .",
  2248. ". // \\\\ .",
  2249. ". / \\ .",
  2250. ". .",
  2251. ". Spider .",
  2252. "Spider"
  2253. }
  2254.  
  2255. slime = {
  2256. " ___ ",
  2257. " [o.o] ",
  2258. " [ _ ] ",
  2259. " ",
  2260. " Slime ",
  2261. "Slime"
  2262. }
  2263. magmacube = {
  2264. " ^___^ ",
  2265. " ^[o.o]^ ",
  2266. " ^[___]^ ",
  2267. " ^ ^ ",
  2268. " magmacube ",
  2269. "Magmacube"
  2270. }
  2271. ghast = {
  2272. " ___ ",
  2273. " [-.-] ",
  2274. " [_O_] ",
  2275. " \\\\\\\\ ",
  2276. " Ghast ",
  2277. "Ghast"
  2278. }
  2279. enderdragon = {
  2280. " ^_^ ",
  2281. "- [=.=] --",
  2282. "X- [ - ]-XX",
  2283. "XX--||--XXX",
  2284. "EnderDragon",
  2285. "EnderDragon"
  2286. }
  2287. spiderhp = 20
  2288. slimehp = 15
  2289. spiderattack = 5
  2290. slimeattack = 10
  2291.  
  2292. --drawing functions
  2293.  
  2294. function drawClasses()
  2295. term.setCursorPos(1,4)
  2296. print(string.rep("X",w-13))
  2297. term.setCursorPos(1,h-4)
  2298. print(string.rep("X",w-13))
  2299. for i = 1,3 do
  2300. end
  2301. end
  2302.  
  2303.  
  2304.  
  2305. function drawShopItems(name,name2,type,num,num2,gold)
  2306. -- in each
  2307. --37total
  2308. for i = 1, 5 do
  2309. term.setCursorPos(1 + ((num-1)*5),3+num2 + i)
  2310. print(type[i])
  2311. end
  2312. term.setCursorPos(1 + ((num-1)*5),3+num2 + 6)
  2313. print(name)
  2314. term.setCursorPos(1 + ((num-1)*5),3+num2 + 7)
  2315. print(name2)
  2316. term.setCursorPos(1 + ((num-1)*5),3+num2)
  2317. print(" " .. gold .. "G")
  2318. resetCursor()
  2319.  
  2320. end
  2321.  
  2322.  
  2323. function drawShopOutline()
  2324. term.setCursorPos(1,2)
  2325. print(string.rep("-",w-13))
  2326. term.setCursorPos(1,(h-5))
  2327. print(string.rep("-",w-13))
  2328. end
  2329.  
  2330.  
  2331. w,h = term.getSize()
  2332.  
  2333. function drawscreen()
  2334. term.clear()
  2335. end
  2336.  
  2337. function resetCursor()
  2338. term.setCursorPos(1,h)
  2339. end
  2340.  
  2341. function text(input)
  2342. if numbertext > 6 then
  2343. draw()
  2344. numbertext = 0
  2345. term.setCursorPos(1,(numbertext + 1))
  2346. print(input)
  2347. numbertext = numbertext + 1
  2348. else
  2349. term.setCursorPos(1,(numbertext + 1))
  2350. print(input)
  2351. numbertext = numbertext + 1
  2352. end
  2353. term.setCursorPos(1,h)
  2354. end
  2355.  
  2356. function draw()
  2357. term.clear()
  2358. term.setCursorPos(1,1)
  2359. print(string.rep("=",w))
  2360. term.setCursorPos(1,(h-1))
  2361. print(string.rep("=",w))
  2362. for i = 1,h do
  2363. term.setCursorPos(w-12,i)
  2364. print("|")
  2365. end
  2366. term.setCursorPos(1,(h-4))
  2367. print("attack,block")
  2368. resetCursor()
  2369. end
  2370.  
  2371. function drawBlank()
  2372. term.clear()
  2373. term.setCursorPos(1,1)
  2374. print(string.rep("=",w))
  2375. term.setCursorPos(1,(h-1))
  2376. print(string.rep("=",w))
  2377. for i = 1,h do
  2378. term.setCursorPos(w-12,i)
  2379. print("|")
  2380. end
  2381. term.setCursorPos(1,(h-4))
  2382. print(" ")
  2383. resetCursor()
  2384. end
  2385.  
  2386. function drawWalk()
  2387. term.clear()
  2388. term.setCursorPos(1,1)
  2389. print(string.rep("=",w))
  2390. term.setCursorPos(1,(h-1))
  2391. print(string.rep("=",w))
  2392. for i = 1,h do
  2393. term.setCursorPos(w-12,i)
  2394. print("|")
  2395. end
  2396. term.setCursorPos(1,(h-3))
  2397. print("forward,left,right")
  2398. resetCursor()
  2399. end
  2400.  
  2401. function drawShop(page)
  2402. term.clear()
  2403. term.setCursorPos(1,1)
  2404. print(string.rep("=",w))
  2405. term.setCursorPos(1,(h-1))
  2406. print(string.rep("=",w-13))
  2407. for i = 1,h do
  2408. term.setCursorPos(w-12,i)
  2409. print("|")
  2410. end
  2411. term.setCursorPos(1,(h-3))
  2412. print("purchase,leave,page " .. page)
  2413. resetCursor()
  2414. end
  2415.  
  2416. function displayFunctions(func)
  2417. for i = 1, 5 do
  2418. term.setCursorPos((w-11), i)
  2419. local textdisplay = func[i]
  2420. print(textdisplay)
  2421. end
  2422. resetCursor()
  2423. displayPlayerStats()
  2424. end
  2425.  
  2426. function Reset(C)
  2427. draw()
  2428. displayFunctions(C)
  2429. displayStats(CurrentCreatureHealth)
  2430. displayPlayerStats()
  2431. resetCursor()
  2432. numbertext = 0
  2433. end
  2434.  
  2435. function reset()
  2436. draw()
  2437. displayPlayerStats()
  2438. numbertext = 0
  2439. end
  2440.  
  2441. function resetWalk()
  2442. drawWalk()
  2443. displayPlayerStats()
  2444. numbertext = 0
  2445. end
  2446.  
  2447. function displayStats(func)
  2448. --for i = 1, #func do
  2449. term.setCursorPos((w-11), 6)
  2450. --local textdisplay = func[i]
  2451. print("Health:" .. func .. " ")
  2452. --end
  2453. resetCursor()
  2454. end
  2455.  
  2456. function displayPlayerStats()
  2457.  
  2458. if PlayerSword == 1 and PlayerArmor > 0 then
  2459. for i = 1, 3 do
  2460. term.setCursorPos((w-11), 7+i-1)
  2461. local textdisplay = playerhappy[i]
  2462. print(textdisplay)
  2463. end
  2464. else if PlayerSword == 1 then
  2465. for i = 1, 3 do
  2466. term.setCursorPos((w-11), 7+i-1)
  2467. local textdisplay = playerokay[i]
  2468. print(textdisplay)
  2469. end
  2470. else if PlayerArmor > 0 then
  2471. for i = 1, 3 do
  2472. term.setCursorPos((w-11), 7+i-1)
  2473. local textdisplay = playerokaya[i]
  2474. print(textdisplay)
  2475. end
  2476. else
  2477. for i = 1, 3 do
  2478. term.setCursorPos((w-11), 7+i-1)
  2479. local textdisplay = playersad[i]
  2480. print(textdisplay)
  2481. end
  2482. end end end
  2483. term.setCursorPos((w-11), 10)
  2484. print(PlayerName)
  2485. term.setCursorPos((w-11), 11)
  2486. print("Health: " .. PlayerHealth .. " ")
  2487. term.setCursorPos((w-11), 12)
  2488. print("Dmg/Hit: " .. PlayerDamage)
  2489. term.setCursorPos((w-11), 13)
  2490. print("Weapon: ")
  2491. term.setCursorPos((w-11), 14)
  2492. print(PlayerWeapon)
  2493. term.setCursorPos((w-11), 15)
  2494. print("Gold:" .. PlayerGold)
  2495. term.setCursorPos((w-11), 16)
  2496. print("Armor:")
  2497. term.setCursorPos((w-11), 17)
  2498. print(PlayerArmorType)
  2499.  
  2500. resetCursor()
  2501. end
  2502. --^^ Uses table of monster created upon start of fight
  2503. --{health: {name:
  2504.  
  2505.  
  2506. --game reloads
  2507.  
  2508. function Walk()
  2509. text("Action:")
  2510. command = io.read()
  2511. resetCursor()
  2512. if command == ("forward") then
  2513. resetWalk()
  2514. text("You walk forward through some brush")
  2515. else if command == ("left") then
  2516. resetWalk()
  2517. text("You turn left and continue on")
  2518. else if command == ("right") then
  2519. resetWalk()
  2520. text("You turn right and continue")
  2521. else
  2522. resetWalk()
  2523. Walk()
  2524. end end end
  2525. resetCursor()
  2526. sleep(2)
  2527. random()
  2528. end
  2529. function WalkShop()
  2530. text("Action:")
  2531. command = io.read()
  2532. resetCursor()
  2533. if command == ("forward") then
  2534. resetWalk()
  2535. text("You walk forward through some brush")
  2536. else if command == ("left") then
  2537. resetWalk()
  2538. text("You turn left and enter the shop")
  2539. sleep(1)
  2540. shop()
  2541. else if command == ("right") then
  2542. resetWalk()
  2543. text("You turn right and continue")
  2544. else
  2545. resetWalk()
  2546. Walk()
  2547. end end end
  2548. resetCursor()
  2549. sleep(2)
  2550. random()
  2551.  
  2552. end
  2553. function pageone()
  2554. term.clear()
  2555. drawShop("two")
  2556. drawShopOutline()
  2557. displayFunctions(shopkeeper)
  2558. term.setCursorPos(1,1)
  2559. text("Welcome to my store!")
  2560. drawShopItems("Wood","Sword",sword,1,1,15)
  2561. drawShopItems("Leath.","Armor",armor,2,1,15)
  2562. drawShopItems("Iron","Sword",sword,3,1,60)
  2563. drawShopItems("Iron","Armor",armor,4,1,60)
  2564. drawShopItems("Gold","Sword",sword,5,1,85)
  2565. drawShopItems("Gold","Armor",armor,6,1,85)
  2566. drawShopItems("Next","Page",nextpage,7,1,0)
  2567. end
  2568.  
  2569. function pagetwo()
  2570. drawShop("one")
  2571. drawShopOutline()
  2572. displayFunctions(shopkeeper)
  2573. term.setCursorPos(1,1)
  2574. text("Welcome to my store!")
  2575. drawShopItems("Dia.","Sword",sword,1,1,120)
  2576. drawShopItems("Dia.","Armor",armor,2,1,120)
  2577. drawShopItems("Health","Potion",potion,3,1,10)
  2578. drawShopItems("Prev.","Page",prevpage,4,1,0)
  2579. end
  2580.  
  2581. function bought(name,page)
  2582. if page == 1 then
  2583. term.clear()
  2584. drawShop("two")
  2585. drawShopOutline()
  2586. displayFunctions(shopkeeper)
  2587. term.setCursorPos(1,1)
  2588. text("You bought a " .. name)
  2589. drawShopItems("Wood","Sword",sword,1,1,15)
  2590. drawShopItems("Leath.","Armor",armor,2,1,15)
  2591. drawShopItems("Iron","Sword",sword,3,1,60)
  2592. drawShopItems("Iron","Armor",armor,4,1,60)
  2593. drawShopItems("Gold","Sword",sword,5,1,85)
  2594. drawShopItems("Gold","Armor",armor,6,1,85)
  2595. drawShopItems("Next","Page",nextpage,7,1,0)
  2596. else if page == 2 then
  2597. drawShop("one")
  2598. drawShopOutline()
  2599. displayFunctions(shopkeeper)
  2600. term.setCursorPos(1,1)
  2601. text("You bought a " .. name)
  2602. drawShopItems("Dia.","Sword",sword,1,1,120)
  2603. drawShopItems("Dia.","Armor",armor,2,1,120)
  2604. drawShopItems("Health","Potion",potion,3,1,10)
  2605. drawShopItems("Prev.","Page",prevpage,4,1,0)
  2606. else
  2607. end end
  2608. end
  2609.  
  2610.  
  2611. function shop()
  2612. pageone()
  2613. while true do
  2614. numbertext = 0
  2615. command = io.read()
  2616. if command == ("leave") then
  2617. drawBlank()
  2618. text("Leaving Shop")
  2619. numbertext = 0
  2620. sleep(2)
  2621. random()
  2622. else if command == ("page one") then
  2623. pageone()
  2624. else if command == ("page two") then
  2625. pagetwo()
  2626. else if command == ("purchase wood sword") then
  2627. if PlayerGold >= 15 then
  2628. PlayerGold = PlayerGold - 15
  2629. PlayerDamage = PBD + 8
  2630. PlayerWeapon = ("Wooden Sword")
  2631. PlayerSword = 1
  2632. bought("Wooden Sword", 1)
  2633. displayPlayerStats()
  2634. else end
  2635. else if command == ("purchase iron sword") then
  2636. if PlayerGold >= 60 then
  2637. PlayerGold = PlayerGold - 60
  2638. PlayerDamage = PBD + 12
  2639. bought("Iron Sword", 1)
  2640. PlayerWeapon = ("Iron Sword")
  2641. PlayerSword = 1
  2642. displayPlayerStats()
  2643. else end
  2644. else if command == ("purchase gold sword") then
  2645. if PlayerGold >= 85 then
  2646. PlayerGold = PlayerGold - 85
  2647. PlayerDamage = PBD + 16
  2648. bought("Gold Sword", 1)
  2649. PlayerWeapon = ("Gold Sword")
  2650. PlayerSword = 1
  2651. displayPlayerStats()
  2652. else end
  2653. else if command == ("purchase diamond sword") then
  2654. if PlayerGold >= 120 then
  2655. PlayerGold = PlayerGold - 120
  2656. PlayerDamage = PBD + 20
  2657. bought("Diamond Sword", 2)
  2658. PlayerWeapon = ("Dia. Sword")
  2659. PlayerSword = 1
  2660. displayPlayerStats()
  2661. else end
  2662. else if command == ("purchase leather armor") then
  2663. if PlayerGold >= 15 then
  2664. PlayerGold = PlayerGold - 15
  2665. bought("Leather Armor", 1)
  2666. PlayerArmor = 1
  2667. PlayerArmorType = ("Leather")
  2668. displayPlayerStats()
  2669. else end
  2670. else if command == ("purchase iron armor") then
  2671. if PlayerGold >= 60 then
  2672. PlayerGold = PlayerGold - 60
  2673. bought("Iron Armor", 1)
  2674. PlayerArmor = 3
  2675. PlayerArmorType = ("Iron")
  2676. displayPlayerStats()
  2677. else end
  2678. else if command == ("purchase gold armor") then
  2679. if PlayerGold >= 85 then
  2680. PlayerGold = PlayerGold - 85
  2681. bought("Gold Armor", 1)
  2682. PlayerArmor = 5
  2683. PlayerArmorType = ("Gold")
  2684. displayPlayerStats()
  2685. else end
  2686. else if command == ("purchase diamond armor") then
  2687. if PlayerGold >= 120 then
  2688. PlayerGold = PlayerGold - 120
  2689. bought("Diamond Armor", 2)
  2690. PlayerArmorType = ("Diamond")
  2691. PlayerArmor = 7
  2692. displayPlayerStats()
  2693. else end
  2694. else if command == ("purchase health potion") then
  2695. if PlayerGold >= 10 then
  2696. PlayerGold = PlayerGold - 10
  2697. bought("Health Potion", 2)
  2698. PlayerHealth = PHM
  2699. displayPlayerStats()
  2700. else end
  2701. else
  2702. pageone()
  2703. end end end
  2704. end end end end end end end end end
  2705.  
  2706. end
  2707. end
  2708.  
  2709. function gameOver()
  2710. drawBlank()
  2711. term.setCursorPos((w/2)-7,(h/2))
  2712. print("YOU HAVE DIED")
  2713. term.setCursorPos((w/2)-5,(h/2)+1)
  2714. print("GAME OVER")
  2715. sleep(3)
  2716. shell.run("AdventureCraft")
  2717. end
  2718.  
  2719.  
  2720. --fighting
  2721.  
  2722. function battle(creature)
  2723. draw()
  2724. while true do
  2725. displayFunctions(creature)
  2726. displayStats(CurrentCreatureHealth)
  2727. if PlayerHealth <= 0 then
  2728. gameOver()
  2729. else
  2730. end
  2731. if CurrentCreatureHealth < 1 then
  2732. text("You have slain the " .. creature[6])
  2733. PlayerGold = PlayerGold + CurrentCreatureGold
  2734. sleep(3)
  2735. CurrentCreatureGold = 0
  2736. reset()
  2737. random()
  2738. else
  2739. Block = 0
  2740. term.setCursorPos(1,1)
  2741. text("Action:")
  2742. reaction = io.read()
  2743. if reaction == ("attack") then
  2744. Reset(creature)
  2745. text("You swing your " .. PlayerWeapon .. " at the " .. creature[6])
  2746. randomvar = math.random(1,2)
  2747. if randomvar == 1 then
  2748. randomvar = math.random(-1 * (PBD/3), PBD/3)
  2749. if randomvar == PBD/3 then print("Critical hit!") else end
  2750. CurrentCreatureHealth = CurrentCreatureHealth - PlayerDamage - randomvar
  2751. CPD = PlayerDamage + randomvar
  2752. text("You hit the " .. creature[6] .. " for " .. CPD .. " damage")
  2753. else text("It dodges your attack!")
  2754. end
  2755. else if reaction == ("block") then
  2756. Reset(creature)
  2757. text("Using your " .. PlayerWeapon .. " you block")
  2758. randomvar = math.random(1,3)
  2759. if randomvar < 2 then
  2760. Block = 2
  2761. else
  2762. Block = 1
  2763. end
  2764. else
  2765. resetCursor()
  2766. text("That is not a valid action!")
  2767. draw()
  2768. Reset(creature)
  2769. end end
  2770. sleep(2)
  2771. --creature attacks player
  2772. if Block == 0 then
  2773. randomvar = math.random(1, 3)
  2774. if randomvar > 1 then
  2775. text("The " .. creature[6] .. " missed its attack!")
  2776. else if randomvar < 2 then
  2777. randomvar = math.random(-2,2)
  2778. PlayerHealth = PlayerHealth - CurrentCreatureAttack - randomvar + PlayerArmor
  2779. text("The " .. creature[6] .. " hit you for " .. (CurrentCreatureAttack + randomvar - PlayerArmor) .. " damage")
  2780. else
  2781.  
  2782. end end
  2783. else if Block == 1 then
  2784. randomvar = math.random(1, 7)
  2785. if randomvar > 1 then
  2786. text("You successfully blocked the " .. creature[6] .. "'s attack!")
  2787. else if randomvar < 2 then
  2788. randomvar = math.random(-2,2)
  2789. PlayerHealth = PlayerHealth - CurrentCreatureAttack - randomvar + PlayerArmor
  2790. text("Your block failed, you received " .. (CurrentCreatureAttack + randomvar - PlayerArmor) .. " dmg")
  2791. end end
  2792. else
  2793. end end
  2794.  
  2795. end
  2796. end
  2797. end
  2798. --random events
  2799. count = 0
  2800. function random()
  2801. count = count + 1
  2802. randomevent = math.random(1,7)
  2803. if count == 5 or count == 15 or count == 25 or count == 35 or count == 45 or count == 55 or count == 65 or count == 75 or count == 85 then
  2804. shop()
  2805. elseif randomevent == 1 then
  2806. CurrentCreatureGold = 5
  2807. CurrentCreatureHealth = 15
  2808. CurrentCreatureAttack = 10
  2809. battle(slime)
  2810. elseif randomevent == 2 then
  2811. CurrentCreatureGold = 7
  2812. CurrentCreatureHealth = 25
  2813. CurrentCreatureAttack = 5
  2814. battle(spider)
  2815. elseif randomevent == 3 then
  2816. resetWalk()
  2817. text("You are in the middle of a meadow")
  2818. RandomShop = math.random(1,2)
  2819. if RandomShop == 2 then
  2820. text("There is a shop to the left")
  2821. WalkShop()
  2822. else
  2823. text("There is nothing around you")
  2824. Walk()
  2825. end
  2826. elseif randomevent == 4 then
  2827. shop()
  2828. elseif randomevent == 5 and count > 20 then
  2829. CurrentCreatureGold = 15
  2830. CurrentCreatureHealth = 50
  2831. CurrentCreatureAttack = 15
  2832. battle(magmacube)
  2833. elseif randomevent == 6 and count > 40 then
  2834. CurrentCreatureGold = 40
  2835. CurrentCreatureHealth = 40
  2836. CurrentCreatureAttack = 35
  2837. battle(ghast)
  2838. elseif randomevent == 7 and count > 60 then
  2839. CurrentCreatureGold = 100
  2840. CurrentCreatureHealth = 100
  2841. CurrentCreatureAttack = 25
  2842. battle(enderdragon)
  2843.  
  2844.  
  2845. else
  2846. random()
  2847. end
  2848. end
  2849.  
  2850.  
  2851. --mastercontrol
  2852. --start
  2853. numbertext = 0
  2854. drawBlank()
  2855. text("Hello adventurer!")
  2856. text("Choose a class to continue!")
  2857. text("Barbarian,Rouge,RoyalGuard")
  2858. class = io.read()
  2859. if class == ("Barbarian") then
  2860. PHM = 85
  2861. PBD = 13
  2862. PlayerHealth = 85
  2863. PlayerDamage = 13
  2864. elseif class == ("Rouge") then
  2865. PHM = 60
  2866. PBD = 20
  2867. PlayerHealth = 60
  2868. PlayerDamage = 20
  2869. elseif class == ("RoyalGuard") then
  2870. PHM = 120
  2871. PBD = 7
  2872. PlayerHealth = 120
  2873. PlayerDamage = 7
  2874. else
  2875. end
  2876. random()
  2877. startScreen()
  2878. end
  2879.  
  2880. --EnderOS
  2881. if not http then --Checks if the user has HTTP enabled
  2882. reset()
  2883. print("EnderOS will soon require HTTP to be enabled!")
  2884. sleep(3)
  2885. end
  2886. file = shell.getRunningProgram()
  2887. if not file == "startup" then --Ensures the running file is labeled startup
  2888. print("EnderOS MUST be in a file named startup!")
  2889. sleep(3)
  2890. reset()
  2891. return
  2892. end
  2893. if not fs.exists("/.EnderOS/.EnderOSisInstalled") then --If this file is not present, EnderOS will ask for user info
  2894. userInfo()
  2895. end
  2896. if not fs.exists("/.EnderOS/.firewolf") then --Checks if Firewolf is installed
  2897. reset()
  2898. print("Firewolf seems to be missing *Gasp*")
  2899. sleep(2.5)
  2900. reset()
  2901. print("EnderOS is now downloading Firewolf")
  2902. sleep(2.5)
  2903. shell.run("pastebin","get",firewolf,"/.EnderOS/.firewolf")
  2904. end
  2905. if fs.exists(".Endermen") then --If the user previously uninstalled EnderOS, it will delete this file
  2906. fs.delete(".Endermen")
  2907. end
  2908. reset()
  2909. term.setTextColor(colors.purple)
  2910. term.setCursorPos(13,7)
  2911. print("EnderOS "..version.." Initializing")
  2912. term.setTextColor(colors.white)
  2913. term.setBackgroundColor(colors.lime)
  2914. for i = 14,36 do
  2915. term.setCursorPos(i,9)
  2916. term.write(" ")
  2917. sleep(0.1)
  2918. end
  2919. term.setBackgroundColor(colors.black)
  2920. sleep(0.5)
  2921. screen()
  2922. login()
  2923. startScreen()
  2924. end
Advertisement
Add Comment
Please, Sign In to add comment