SuicidalSTDz

[Firewolf!]EnderOS v2.5 EXPERIMENTAL

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