Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 11.25 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. --White = Item send 1
  4. --Orange = back 2
  5. --Magenta = forward 4
  6. --Light blue = start item counter 8
  7.  
  8. --Yellow = done getting items 16
  9.  
  10. --Green = iron 32
  11. --Pink = gold 64
  12. --Gray = diamond 128
  13.  
  14. --light gray = iron give back 256
  15. --cyan = gold give back 512
  16. --purple = diamond give back 1024
  17.  
  18. --variabels
  19.  
  20. Run=true
  21.  
  22. X=1
  23. Y=1
  24. Z=0
  25. Side="bottom"
  26. Money=0
  27. Amount=0
  28. Buyitems=false
  29. Count=0
  30. Add=0
  31.  
  32. Check=0
  33. Pos=12
  34. CurrentPos=0
  35.  
  36. Price=0
  37. Name="none"
  38.  
  39. --Functions
  40.  
  41. function PrintShopLine()
  42. io.write(Linenumber)
  43. io.write(")  ")
  44. io.write(Name)
  45. while Y>0 do
  46. io.write(" ")
  47. Y=Y-1
  48. end
  49. io.write(" - ")
  50. if Price<10000 then
  51. io.write(" ")
  52. end
  53. if Price<1000 then
  54. io.write(" ")
  55. end
  56. if Price<100 then
  57. io.write(" ")
  58. end
  59. if Price<10 then
  60. io.write(" ")
  61. end
  62. io.write(PriceA)
  63. io.write(" - ")
  64. if Amount<100000 then
  65. io.write(" ")
  66. end
  67. if Amount<10000 then
  68. io.write(" ")
  69. end
  70. if Amount<1000 then
  71. io.write(" ")
  72. end
  73. if Amount<100 then
  74. io.write(" ")
  75. end
  76. if Amount<10 then
  77. io.write(" ")
  78. end
  79. io.write(Amount)
  80. print(" ")
  81. end
  82.  
  83. --Setup
  84.  
  85. print("Starting up...")
  86.  
  87. while Pos>0 do
  88. rs.setBundledOutput(Side, 2)
  89. sleep(0.2)
  90. rs.setBundledOutput(Side, 0)
  91. sleep(0.8)
  92. Pos=Pos-1
  93. end
  94.  
  95. --Preset data (will be used if it fails to load file)
  96.  
  97. --item 1
  98. NameA="Bread"
  99. PriceA=72
  100. PosA=0
  101. CountA=0
  102.  
  103. --item 2
  104. NameB="Bread"
  105. PriceB=72
  106. PosB=2
  107. CountB=0
  108.  
  109. --item 3
  110. NameC="Bread"
  111. PriceC=72
  112. PosC=4
  113. CountC=0
  114.  
  115. --item 4
  116. NameD="Bread"
  117. PriceD=72
  118. PosD=6
  119. CountD=0
  120.  
  121. --item 5
  122. NameE="Bread"
  123. PriceE=72
  124. PosE=8
  125. CountE=0
  126.  
  127. --item 6
  128. NameF="Bread"
  129. PriceF=72
  130. PosF=10
  131. CountF=0
  132.  
  133. --Program
  134.  
  135. while Run==true do
  136.  
  137. --Check/Create for goods file
  138.  
  139. file = io.open("goods.txt", "r")
  140. if file==nil then
  141.  
  142. file = io.open("goods.txt", "w")
  143. file:write("0") --A
  144. file:write("\n")
  145. file:write("0") --B
  146. file:write("\n")
  147. file:write("0") --C
  148. file:write("\n")
  149. file:write("0") --D
  150. file:write("\n")
  151. file:write("0") --E
  152. file:write("\n")
  153. file:write("0") --F
  154. file:close()
  155.  
  156. end
  157.  
  158. --Check/Create for name file
  159.  
  160. file = io.open("name.txt", "r")
  161. if file==nil then
  162.  
  163. file = io.open("name.txt", "w")
  164. file:write("Bread") --A
  165. file:write("\n")
  166. file:write("Bread") --B
  167. file:write("\n")
  168. file:write("Bread") --C
  169. file:write("\n")
  170. file:write("Bread") --D
  171. file:write("\n")
  172. file:write("Bread") --E
  173. file:write("\n")
  174. file:write("Bread") --F
  175. file:close()
  176.  
  177. end
  178.  
  179. --Reading goods file
  180.  
  181. file = io.open("goods.txt", "r")
  182. A = file:read()
  183. B = file:read()
  184. C = file:read()
  185. D = file:read()
  186. E = file:read()
  187. F = file:read()
  188. file:close()
  189.  
  190. CountA=tonumber(A)
  191. CountB=tonumber(B)
  192. CountC=tonumber(C)
  193. CountD=tonumber(D)
  194. CountE=tonumber(E)
  195. CountF=tonumber(F)
  196.  
  197. --Reading name file
  198.  
  199. file = io.open("name.txt", "r")
  200. A = file:read()
  201. B = file:read()
  202. C = file:read()
  203. D = file:read()
  204. E = file:read()
  205. F = file:read()
  206. file:close()
  207.  
  208. NameA=A
  209. NameB=B
  210. NameC=C
  211. NameD=D
  212. NameE=E
  213. NameF=F
  214.  
  215. --Checking lenght of names
  216.  
  217. LenghtA=15-string.len(NameA)
  218. LenghtB=15-string.len(NameB)
  219. LenghtC=15-string.len(NameC)
  220. LenghtD=15-string.len(NameD)
  221. LenghtE=15-string.len(NameE)
  222. LenghtF=15-string.len(NameF)
  223.  
  224. --Print menu
  225.  
  226. term.clear()
  227. term.setCursorPos(1,1)
  228.  
  229. print("    Item name       - Price - Amount")
  230.  
  231. ---
  232.  
  233. Y=LenghtA
  234. Price=PriceA
  235. Amount=CountA
  236. Name=NameA
  237. Linenumber=1
  238.  
  239. PrintShopLine(Y,Price,Amount,Name,Linenumber)
  240.  
  241. ---
  242.  
  243. Y=LenghtB
  244. Price=PriceB
  245. Amount=CountB
  246. Name=NameB
  247. Linenumber=2
  248.  
  249. PrintShopLine(Y,Price,Amount,Name,Linenumber)
  250.  
  251. ---
  252.  
  253. Y=LenghtC
  254. Price=PriceC
  255. Amount=CountC
  256. Name=NameC
  257. Linenumber=3
  258.  
  259. PrintShopLine(Y,Price,Amount,Name,Linenumber)
  260.  
  261. ---
  262.  
  263. Y=LenghtD
  264. Price=PriceD
  265. Amount=CountD
  266. Name=NameD
  267. Linenumber=4
  268.  
  269. PrintShopLine(Y,Price,Amount,Name,Linenumber)
  270.  
  271. ---
  272.  
  273. Y=LenghtE
  274. Price=PriceE
  275. Amount=CountE
  276. Name=NameE
  277. Linenumber=5
  278.  
  279. PrintShopLine(Y,Price,Amount,Name,Linenumber)
  280.  
  281. ---
  282.  
  283. Y=LenghtF
  284. Price=PriceF
  285. Amount=CountF
  286. Name=NameF
  287. Linenumber=6
  288.  
  289. PrintShopLine(Y,Price,Amount,Name,Linenumber)
  290.  
  291.  
  292. print("--------------------------------------------------")
  293. print("Amount of money:", Money)
  294. print("--------------------------------------------------")
  295. print("7)  Add money")
  296. print("8)  Info")
  297. print("9)  Give money back and exit")
  298. print("10) Admin mode")
  299. X=io.read()
  300.  
  301. --item 1
  302.  
  303. if X=="1" then
  304. Count=CountA
  305. Price=PriceA
  306. Name=NameA
  307. CurrentPos=PosA
  308. Buyitems=true
  309. end
  310.  
  311. if X=="2" then
  312. Count=CountB
  313. Price=PriceB
  314. Name=NameB
  315. CurrentPos=PosB
  316. Buyitems=true
  317. end
  318.  
  319. if X=="3" then
  320. Count=CountC
  321. Price=PriceC
  322. Name=NameC
  323. CurrentPos=PosC
  324. Buyitems=true
  325. end
  326.  
  327. if X=="4" then
  328. Count=CountD
  329. Price=PriceD
  330. Name=NameD
  331. CurrentPos=PosD
  332. Buyitems=true
  333. end
  334.  
  335. if X=="5" then
  336. Count=CountE
  337. Price=PriceE
  338. Name=NameE
  339. CurrentPos=PosE
  340. Buyitems=true
  341. end
  342.  
  343. if X=="6" then
  344. Count=CountF
  345. Price=PriceF
  346. Name=NameF
  347. CurrentPos=PosF
  348. Buyitems=true
  349. end
  350.  
  351. if Buyitems==true then
  352.  
  353. term.clear()
  354. term.setCursorPos(1,1)
  355. print("How much ", Name," do you wish to buy?")
  356. Y=io.read()
  357. Amount=tonumber(Y)
  358.  
  359. Check=Price*Amount
  360.  
  361. if Check<=Money and Count>=Amount then
  362.  
  363. while Pos<CurrentPos do
  364. rs.setBundledOutput(Side, 4)
  365. sleep(0.2)
  366. rs.setBundledOutput(Side, 0)
  367. sleep(0.8)
  368. Pos=Pos+1
  369. end
  370.  
  371. while Pos>CurrentPos do
  372. rs.setBundledOutput(Side, 2)
  373. sleep(0.2)
  374. rs.setBundledOutput(Side, 0)
  375. sleep(0.8)
  376. Pos=Pos-1
  377. end
  378.  
  379. print("You should receive: ", Amount," ", Name)
  380. print("In the lower chest")
  381.  
  382. while Amount>0 and Money>0 do
  383. rs.setBundledOutput(Side, 1)
  384. sleep(0.2)
  385. rs.setBundledOutput(Side, 0)
  386. sleep(0.8)
  387. Amount=Amount-1
  388. Money=Money-Price
  389. Count=Count-1
  390. end
  391.  
  392. else
  393.  
  394. if Count<Amount then
  395. print("Not enough items in stock")
  396. else
  397. print("Not enough money")
  398. end
  399.  
  400. end
  401.  
  402. sleep(4)
  403.  
  404. Buyitems=false
  405.  
  406. if X=="1" then
  407. CountA=Count
  408. end
  409.  
  410. if X=="2" then
  411. CountB=Count
  412. end
  413.  
  414. if X=="3" then
  415. CountC=Count
  416. end
  417.  
  418. if X=="4" then
  419. CountD=Count
  420. end
  421.  
  422. if X=="5" then
  423. CountE=Count
  424. end
  425.  
  426. if X=="6" then
  427. CountF=Count
  428. end
  429.  
  430. end
  431.  
  432.  
  433. --Add money
  434.  
  435. if X=="7" then
  436.  
  437. term.clear()
  438. term.setCursorPos(1,1)
  439. print("                 Addning money...")
  440. print("              This may take a while")
  441.  
  442. rs.setBundledOutput(Side, 8)
  443. sleep(0.2)
  444. rs.setBundledOutput(Side, 0)
  445. sleep(1.5)
  446.  
  447. while rs.testBundledInput(Side, 16)==false do
  448.  
  449. if rs.testBundledInput(Side, 32) then
  450. Money=Money+256
  451. end
  452.  
  453. if rs.testBundledInput(Side, 64) then
  454. Money=Money+2048
  455. end
  456.  
  457. if rs.testBundledInput(Side, 128) then
  458. Money=Money+8192
  459. end
  460.  
  461. sleep(0.1)
  462. end
  463. end
  464.  
  465.  
  466. --Info
  467.  
  468. if X=="8" then
  469. term.clear()
  470. term.setCursorPos(1,1)
  471. print("Put diamond, ironbars or goldbars in the top chest")
  472. print("--------------------------------------------------")
  473. print("                 Diamond=8192")
  474. print("                 Goldbar=2048")
  475. print("                 Ironbar=256")
  476. print("--------------------------------------------------")
  477. print("   Enter the number of the item you wish to buy")
  478. print("             Then how many you want")
  479. print("--------------------------------------------------")
  480. print("             Press enter to continue")
  481. io.read()
  482. end
  483.  
  484. --Exit
  485. if X=="9" then
  486.  
  487. Diamond=0
  488. Gold=0
  489. Iron=0
  490.  
  491. while Money>=8192 do
  492. Money=Money-8192
  493. rs.setBundledOutput(Side, 1024)
  494. sleep(0.5)
  495. rs.setBundledOutput(Side, 0)
  496. sleep(0.5)
  497. Diamond=Diamond+1
  498. end
  499.  
  500. while Money>=2048 do
  501. Money=Money-2048
  502. rs.setBundledOutput(Side, 512)
  503. sleep(0.5)
  504. rs.setBundledOutput(Side, 0)
  505. sleep(0.5)
  506. Gold=Gold+1
  507. end
  508.  
  509. while Money>=256 do
  510. Money=Money-256
  511. rs.setBundledOutput(Side, 256)
  512. sleep(0.5)
  513. rs.setBundledOutput(Side, 0)
  514. sleep(0.5)
  515. Iron=Iron+1
  516. end
  517.  
  518. term.clear()
  519. term.setCursorPos(1,1)
  520. print("Your money was equal to:")
  521. print(Diamond, " Diamonds")
  522. print(Gold, " Goldbars")
  523. print(Diamond, " Ironbars")
  524.  
  525. Money=0
  526.  
  527. sleep(5)
  528.  
  529. end
  530.  
  531. if X=="10" then
  532. print("Enter Password")
  533. Z=io.read()
  534. if Z=="1995" then
  535. term.clear()
  536. term.setCursorPos(1,1)
  537. print("What do you wish to do?")
  538. print("1) Edit item count")
  539. print("2) Rename items")
  540. print("3) Shut down program")
  541.  
  542. Z=io.read()
  543.  
  544. if Z=="1" then
  545. while Z~="0" do
  546.  
  547. term.clear()
  548. term.setCursorPos(1,1)
  549. print("Edit the amount of items")
  550. print("1) ",NameA," Count: ",CountA)
  551. print("2) ",NameB," Count: ",CountB)
  552. print("3) ",NameC," Count: ",CountC)
  553. print("4) ",NameD," Count: ",CountD)
  554. print("5) ",NameE," Count: ",CountE)
  555. print("6) ",NameF," Count: ",CountF)
  556. print("0) Save and exit")
  557. Z=io.read()
  558.  
  559. if Z=="1" then
  560. print("How many",NameA,"have you added?")
  561. print("Enter 0 to reset")
  562. Z=io.read()
  563. if Z=="0" then
  564. CountA=0
  565. else
  566. Add=tonumber(Z)
  567. CountA=CountA+Add
  568. end
  569. end
  570.  
  571. if Z=="2" then
  572. print("How many",NameB,"have you added?")
  573. print("Enter 0 to reset")
  574. Z=io.read()
  575. if Z=="0" then
  576. CountB=0
  577. else
  578. Add=tonumber(Z)
  579. CountB=CountB+Add
  580. end
  581. end
  582.  
  583. if Z=="3" then
  584. print("How many",NameC,"have you added?")
  585. print("Enter 0 to reset")
  586. Z=io.read()
  587. if Z=="0" then
  588. CountC=0
  589. else
  590. Add=tonumber(Z)
  591. CountC=CountC+Add
  592. end
  593. end
  594.  
  595. if Z=="4" then
  596. print("How many",NameD,"have you added?")
  597. print("Enter 0 to reset")
  598. Z=io.read()
  599. if Z=="0" then
  600. CountD=0
  601. else
  602. Add=tonumber(Z)
  603. CountD=CountD+Add
  604. end
  605. end
  606.  
  607. if Z=="5" then
  608. print("How many",NameE,"have you added?")
  609. print("Enter 0 to reset")
  610. Z=io.read()
  611. if Z=="0" then
  612. CountE=0
  613. else
  614. Add=tonumber(Z)
  615. CountE=CountE+Add
  616. end
  617. end
  618.  
  619. if Z=="6" then
  620. print("How many",NameF,"have you added?")
  621. print("Enter 0 to reset")
  622. Z=io.read()
  623. if Z=="0" then
  624. CountF=0
  625. else
  626. Add=tonumber(Z)
  627. CountF=CountF+Add
  628. end
  629. end
  630.  
  631. end
  632. Z="0"
  633. end
  634.  
  635. if Z=="2" then
  636. while Z~="0" do
  637. term.clear()
  638. term.setCursorPos(1,1)
  639.  
  640. print("         Change names of items in store")
  641. print("--------------------------------------------------")
  642. print("    The name must be shorter than 15 characters")
  643. print("1) ",NameA)
  644. print("2) ",NameB)
  645. print("3) ",NameC)
  646. print("4) ",NameD)
  647. print("5) ",NameE)
  648. print("6) ",NameF)
  649. print("0) Save and exit")
  650. Z=io.read()
  651.  
  652. if Z=="1" then
  653. print("Enter new name for: ",NameA)
  654. Z=io.read()
  655. if string.len(Z)>15 then
  656. print("Name too long!")
  657. sleep(4)
  658. else
  659. NameA=Z
  660. end
  661. end
  662.  
  663. if Z=="2" then
  664. print("Enter new name for: ",NameB)
  665. Z=io.read()
  666. if string.len(Z)>15 then
  667. print("Name too long!")
  668. sleep(4)
  669. else
  670. NameB=Z
  671. end
  672. end
  673.  
  674. if Z=="3" then
  675. print("Enter new name for: ",NameC)
  676. Z=io.read()
  677. if string.len(Z)>15 then
  678. print("Name too long!")
  679. sleep(4)
  680. else
  681. NameC=Z
  682. end
  683. end
  684.  
  685. if Z=="4" then
  686. print("Enter new name for: ",NameD)
  687. Z=io.read()
  688. if string.len(Z)>15 then
  689. print("Name too long!")
  690. sleep(4)
  691. else
  692. NameD=Z
  693. end
  694. end
  695.  
  696. if Z=="5" then
  697. print("Enter new name for: ",NameE)
  698. Z=io.read()
  699. if string.len(Z)>15 then
  700. print("Name too long!")
  701. sleep(4)
  702. else
  703. NameE=Z
  704. end
  705. end
  706.  
  707. if Z=="6" then
  708. print("Enter new name for: ",NameF)
  709. Z=io.read()
  710. if string.len(Z)>15 then
  711. print("Name too long!")
  712. sleep(4)
  713. else
  714. NameF=Z
  715. end
  716. end
  717.  
  718. end
  719.  
  720. file = io.open("name.txt", "w")
  721. file:write(NameA) --A
  722. file:write("\n")
  723. file:write(NameB) --B
  724. file:write("\n")
  725. file:write(NameC) --C
  726. file:write("\n")
  727. file:write(NameD) --D
  728. file:write("\n")
  729. file:write(NameE) --E
  730. file:write("\n")
  731. file:write(NameF) --F
  732. file:close()
  733.  
  734. end
  735.  
  736. if Z=="3" then
  737. Run=false
  738. Z="0"
  739. term.clear()
  740. term.setCursorPos(1,1)
  741. end
  742.  
  743.  
  744.  
  745. end
  746. end
  747. --Save to file
  748.  
  749.  
  750. file = io.open("goods.txt", "w")
  751. file:write(CountA) --A
  752. file:write("\n")
  753. file:write(CountB) --B
  754. file:write("\n")
  755. file:write(CountC) --C
  756. file:write("\n")
  757. file:write(CountD) --D
  758. file:write("\n")
  759. file:write(CountE) --E
  760. file:write("\n")
  761. file:write(CountF) --F
  762. file:close()
  763.  
  764. --Endings
  765.  
  766. end