- os.pullEvent = os.pullEventRaw
- --White = Item send 1
- --Orange = back 2
- --Magenta = forward 4
- --Light blue = start item counter 8
- --Yellow = done getting items 16
- --Green = iron 32
- --Pink = gold 64
- --Gray = diamond 128
- --light gray = iron give back 256
- --cyan = gold give back 512
- --purple = diamond give back 1024
- --variabels
- Run=true
- X=1
- Y=1
- Z=0
- Side="bottom"
- Money=0
- Amount=0
- Buyitems=false
- Count=0
- Add=0
- Check=0
- Pos=12
- CurrentPos=0
- Price=0
- Name="none"
- --Functions
- function PrintShopLine()
- io.write(Linenumber)
- io.write(") ")
- io.write(Name)
- while Y>0 do
- io.write(" ")
- Y=Y-1
- end
- io.write(" - ")
- if Price<10000 then
- io.write(" ")
- end
- if Price<1000 then
- io.write(" ")
- end
- if Price<100 then
- io.write(" ")
- end
- if Price<10 then
- io.write(" ")
- end
- io.write(PriceA)
- io.write(" - ")
- if Amount<100000 then
- io.write(" ")
- end
- if Amount<10000 then
- io.write(" ")
- end
- if Amount<1000 then
- io.write(" ")
- end
- if Amount<100 then
- io.write(" ")
- end
- if Amount<10 then
- io.write(" ")
- end
- io.write(Amount)
- print(" ")
- end
- --Setup
- print("Starting up...")
- while Pos>0 do
- rs.setBundledOutput(Side, 2)
- sleep(0.2)
- rs.setBundledOutput(Side, 0)
- sleep(0.8)
- Pos=Pos-1
- end
- --Preset data (will be used if it fails to load file)
- --item 1
- NameA="Bread"
- PriceA=72
- PosA=0
- CountA=0
- --item 2
- NameB="Bread"
- PriceB=72
- PosB=2
- CountB=0
- --item 3
- NameC="Bread"
- PriceC=72
- PosC=4
- CountC=0
- --item 4
- NameD="Bread"
- PriceD=72
- PosD=6
- CountD=0
- --item 5
- NameE="Bread"
- PriceE=72
- PosE=8
- CountE=0
- --item 6
- NameF="Bread"
- PriceF=72
- PosF=10
- CountF=0
- --Program
- while Run==true do
- --Check/Create for goods file
- file = io.open("goods.txt", "r")
- if file==nil then
- file = io.open("goods.txt", "w")
- file:write("0") --A
- file:write("\n")
- file:write("0") --B
- file:write("\n")
- file:write("0") --C
- file:write("\n")
- file:write("0") --D
- file:write("\n")
- file:write("0") --E
- file:write("\n")
- file:write("0") --F
- file:close()
- end
- --Check/Create for name file
- file = io.open("name.txt", "r")
- if file==nil then
- file = io.open("name.txt", "w")
- file:write("Bread") --A
- file:write("\n")
- file:write("Bread") --B
- file:write("\n")
- file:write("Bread") --C
- file:write("\n")
- file:write("Bread") --D
- file:write("\n")
- file:write("Bread") --E
- file:write("\n")
- file:write("Bread") --F
- file:close()
- end
- --Reading goods file
- file = io.open("goods.txt", "r")
- A = file:read()
- B = file:read()
- C = file:read()
- D = file:read()
- E = file:read()
- F = file:read()
- file:close()
- CountA=tonumber(A)
- CountB=tonumber(B)
- CountC=tonumber(C)
- CountD=tonumber(D)
- CountE=tonumber(E)
- CountF=tonumber(F)
- --Reading name file
- file = io.open("name.txt", "r")
- A = file:read()
- B = file:read()
- C = file:read()
- D = file:read()
- E = file:read()
- F = file:read()
- file:close()
- NameA=A
- NameB=B
- NameC=C
- NameD=D
- NameE=E
- NameF=F
- --Checking lenght of names
- LenghtA=15-string.len(NameA)
- LenghtB=15-string.len(NameB)
- LenghtC=15-string.len(NameC)
- LenghtD=15-string.len(NameD)
- LenghtE=15-string.len(NameE)
- LenghtF=15-string.len(NameF)
- --Print menu
- term.clear()
- term.setCursorPos(1,1)
- print(" Item name - Price - Amount")
- ---
- Y=LenghtA
- Price=PriceA
- Amount=CountA
- Name=NameA
- Linenumber=1
- PrintShopLine(Y,Price,Amount,Name,Linenumber)
- ---
- Y=LenghtB
- Price=PriceB
- Amount=CountB
- Name=NameB
- Linenumber=2
- PrintShopLine(Y,Price,Amount,Name,Linenumber)
- ---
- Y=LenghtC
- Price=PriceC
- Amount=CountC
- Name=NameC
- Linenumber=3
- PrintShopLine(Y,Price,Amount,Name,Linenumber)
- ---
- Y=LenghtD
- Price=PriceD
- Amount=CountD
- Name=NameD
- Linenumber=4
- PrintShopLine(Y,Price,Amount,Name,Linenumber)
- ---
- Y=LenghtE
- Price=PriceE
- Amount=CountE
- Name=NameE
- Linenumber=5
- PrintShopLine(Y,Price,Amount,Name,Linenumber)
- ---
- Y=LenghtF
- Price=PriceF
- Amount=CountF
- Name=NameF
- Linenumber=6
- PrintShopLine(Y,Price,Amount,Name,Linenumber)
- print("--------------------------------------------------")
- print("Amount of money:", Money)
- print("--------------------------------------------------")
- print("7) Add money")
- print("8) Info")
- print("9) Give money back and exit")
- print("10) Admin mode")
- X=io.read()
- --item 1
- if X=="1" then
- Count=CountA
- Price=PriceA
- Name=NameA
- CurrentPos=PosA
- Buyitems=true
- end
- if X=="2" then
- Count=CountB
- Price=PriceB
- Name=NameB
- CurrentPos=PosB
- Buyitems=true
- end
- if X=="3" then
- Count=CountC
- Price=PriceC
- Name=NameC
- CurrentPos=PosC
- Buyitems=true
- end
- if X=="4" then
- Count=CountD
- Price=PriceD
- Name=NameD
- CurrentPos=PosD
- Buyitems=true
- end
- if X=="5" then
- Count=CountE
- Price=PriceE
- Name=NameE
- CurrentPos=PosE
- Buyitems=true
- end
- if X=="6" then
- Count=CountF
- Price=PriceF
- Name=NameF
- CurrentPos=PosF
- Buyitems=true
- end
- if Buyitems==true then
- term.clear()
- term.setCursorPos(1,1)
- print("How much ", Name," do you wish to buy?")
- Y=io.read()
- Amount=tonumber(Y)
- Check=Price*Amount
- if Check<=Money and Count>=Amount then
- while Pos<CurrentPos do
- rs.setBundledOutput(Side, 4)
- sleep(0.2)
- rs.setBundledOutput(Side, 0)
- sleep(0.8)
- Pos=Pos+1
- end
- while Pos>CurrentPos do
- rs.setBundledOutput(Side, 2)
- sleep(0.2)
- rs.setBundledOutput(Side, 0)
- sleep(0.8)
- Pos=Pos-1
- end
- print("You should receive: ", Amount," ", Name)
- print("In the lower chest")
- while Amount>0 and Money>0 do
- rs.setBundledOutput(Side, 1)
- sleep(0.2)
- rs.setBundledOutput(Side, 0)
- sleep(0.8)
- Amount=Amount-1
- Money=Money-Price
- Count=Count-1
- end
- else
- if Count<Amount then
- print("Not enough items in stock")
- else
- print("Not enough money")
- end
- end
- sleep(4)
- Buyitems=false
- if X=="1" then
- CountA=Count
- end
- if X=="2" then
- CountB=Count
- end
- if X=="3" then
- CountC=Count
- end
- if X=="4" then
- CountD=Count
- end
- if X=="5" then
- CountE=Count
- end
- if X=="6" then
- CountF=Count
- end
- end
- --Add money
- if X=="7" then
- term.clear()
- term.setCursorPos(1,1)
- print(" Addning money...")
- print(" This may take a while")
- rs.setBundledOutput(Side, 8)
- sleep(0.2)
- rs.setBundledOutput(Side, 0)
- sleep(1.5)
- while rs.testBundledInput(Side, 16)==false do
- if rs.testBundledInput(Side, 32) then
- Money=Money+256
- end
- if rs.testBundledInput(Side, 64) then
- Money=Money+2048
- end
- if rs.testBundledInput(Side, 128) then
- Money=Money+8192
- end
- sleep(0.1)
- end
- end
- --Info
- if X=="8" then
- term.clear()
- term.setCursorPos(1,1)
- print("Put diamond, ironbars or goldbars in the top chest")
- print("--------------------------------------------------")
- print(" Diamond=8192")
- print(" Goldbar=2048")
- print(" Ironbar=256")
- print("--------------------------------------------------")
- print(" Enter the number of the item you wish to buy")
- print(" Then how many you want")
- print("--------------------------------------------------")
- print(" Press enter to continue")
- io.read()
- end
- --Exit
- if X=="9" then
- Diamond=0
- Gold=0
- Iron=0
- while Money>=8192 do
- Money=Money-8192
- rs.setBundledOutput(Side, 1024)
- sleep(0.5)
- rs.setBundledOutput(Side, 0)
- sleep(0.5)
- Diamond=Diamond+1
- end
- while Money>=2048 do
- Money=Money-2048
- rs.setBundledOutput(Side, 512)
- sleep(0.5)
- rs.setBundledOutput(Side, 0)
- sleep(0.5)
- Gold=Gold+1
- end
- while Money>=256 do
- Money=Money-256
- rs.setBundledOutput(Side, 256)
- sleep(0.5)
- rs.setBundledOutput(Side, 0)
- sleep(0.5)
- Iron=Iron+1
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Your money was equal to:")
- print(Diamond, " Diamonds")
- print(Gold, " Goldbars")
- print(Diamond, " Ironbars")
- Money=0
- sleep(5)
- end
- if X=="10" then
- print("Enter Password")
- Z=io.read()
- if Z=="1995" then
- term.clear()
- term.setCursorPos(1,1)
- print("What do you wish to do?")
- print("1) Edit item count")
- print("2) Rename items")
- print("3) Shut down program")
- Z=io.read()
- if Z=="1" then
- while Z~="0" do
- term.clear()
- term.setCursorPos(1,1)
- print("Edit the amount of items")
- print("1) ",NameA," Count: ",CountA)
- print("2) ",NameB," Count: ",CountB)
- print("3) ",NameC," Count: ",CountC)
- print("4) ",NameD," Count: ",CountD)
- print("5) ",NameE," Count: ",CountE)
- print("6) ",NameF," Count: ",CountF)
- print("0) Save and exit")
- Z=io.read()
- if Z=="1" then
- print("How many",NameA,"have you added?")
- print("Enter 0 to reset")
- Z=io.read()
- if Z=="0" then
- CountA=0
- else
- Add=tonumber(Z)
- CountA=CountA+Add
- end
- end
- if Z=="2" then
- print("How many",NameB,"have you added?")
- print("Enter 0 to reset")
- Z=io.read()
- if Z=="0" then
- CountB=0
- else
- Add=tonumber(Z)
- CountB=CountB+Add
- end
- end
- if Z=="3" then
- print("How many",NameC,"have you added?")
- print("Enter 0 to reset")
- Z=io.read()
- if Z=="0" then
- CountC=0
- else
- Add=tonumber(Z)
- CountC=CountC+Add
- end
- end
- if Z=="4" then
- print("How many",NameD,"have you added?")
- print("Enter 0 to reset")
- Z=io.read()
- if Z=="0" then
- CountD=0
- else
- Add=tonumber(Z)
- CountD=CountD+Add
- end
- end
- if Z=="5" then
- print("How many",NameE,"have you added?")
- print("Enter 0 to reset")
- Z=io.read()
- if Z=="0" then
- CountE=0
- else
- Add=tonumber(Z)
- CountE=CountE+Add
- end
- end
- if Z=="6" then
- print("How many",NameF,"have you added?")
- print("Enter 0 to reset")
- Z=io.read()
- if Z=="0" then
- CountF=0
- else
- Add=tonumber(Z)
- CountF=CountF+Add
- end
- end
- end
- Z="0"
- end
- if Z=="2" then
- while Z~="0" do
- term.clear()
- term.setCursorPos(1,1)
- print(" Change names of items in store")
- print("--------------------------------------------------")
- print(" The name must be shorter than 15 characters")
- print("1) ",NameA)
- print("2) ",NameB)
- print("3) ",NameC)
- print("4) ",NameD)
- print("5) ",NameE)
- print("6) ",NameF)
- print("0) Save and exit")
- Z=io.read()
- if Z=="1" then
- print("Enter new name for: ",NameA)
- Z=io.read()
- if string.len(Z)>15 then
- print("Name too long!")
- sleep(4)
- else
- NameA=Z
- end
- end
- if Z=="2" then
- print("Enter new name for: ",NameB)
- Z=io.read()
- if string.len(Z)>15 then
- print("Name too long!")
- sleep(4)
- else
- NameB=Z
- end
- end
- if Z=="3" then
- print("Enter new name for: ",NameC)
- Z=io.read()
- if string.len(Z)>15 then
- print("Name too long!")
- sleep(4)
- else
- NameC=Z
- end
- end
- if Z=="4" then
- print("Enter new name for: ",NameD)
- Z=io.read()
- if string.len(Z)>15 then
- print("Name too long!")
- sleep(4)
- else
- NameD=Z
- end
- end
- if Z=="5" then
- print("Enter new name for: ",NameE)
- Z=io.read()
- if string.len(Z)>15 then
- print("Name too long!")
- sleep(4)
- else
- NameE=Z
- end
- end
- if Z=="6" then
- print("Enter new name for: ",NameF)
- Z=io.read()
- if string.len(Z)>15 then
- print("Name too long!")
- sleep(4)
- else
- NameF=Z
- end
- end
- end
- file = io.open("name.txt", "w")
- file:write(NameA) --A
- file:write("\n")
- file:write(NameB) --B
- file:write("\n")
- file:write(NameC) --C
- file:write("\n")
- file:write(NameD) --D
- file:write("\n")
- file:write(NameE) --E
- file:write("\n")
- file:write(NameF) --F
- file:close()
- end
- if Z=="3" then
- Run=false
- Z="0"
- term.clear()
- term.setCursorPos(1,1)
- end
- end
- end
- --Save to file
- file = io.open("goods.txt", "w")
- file:write(CountA) --A
- file:write("\n")
- file:write(CountB) --B
- file:write("\n")
- file:write(CountC) --C
- file:write("\n")
- file:write(CountD) --D
- file:write("\n")
- file:write(CountE) --E
- file:write("\n")
- file:write(CountF) --F
- file:close()
- --Endings
- end