Marlingaming

Tax Collection System 1

Sep 3rd, 2021 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.42 KB | None | 0 0
  1. local oldPull = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. --this is my newest idea for CC Tweaked to allow a tax Collection system that counts the resources and makes sure its equal to the required amount, then if it is done correctly, it will print a receipt with the date, town taxes paid at, and ATM ID.
  5. Settings_ATMID = "0001"
  6. Settings_Settlement = "Test"
  7. Settings_AdminAccount = "Guest"
  8. Settings_ReqCredits = 2
  9. Settings_UseAdvTaxDatabase = false
  10. Settings_AllowedResources[true,false,false,false]--Resources: Diamonds, Netherite, XPOrbs, Emeralds
  11. System_State = "Unlocked"
  12. --Credit Value
  13. Value_Diamond = 1
  14. Value_Netherite = 100
  15. Value_XPOrb = 100
  16. Value_Emeralds
  17. --PlayerInput
  18. PaidAmount = 0
  19. ReqAmount = 2
  20. Account = "Guest"
  21. --Program
  22. local printer = peripheral.wrap("top")
  23. local Dispenser = peripheral.find("minecraft:dispenser")
  24. start()
  25. function start()
  26.     if fs.exists(".TerminalState") == false then
  27.         SystemSetup()
  28.     else
  29.         local h = fs.open(".AdminAccount","r")
  30.         Settings_AdminAccount = h.readAll()
  31.         h.close()
  32.         local h = fs.open(".TerminalState","r")
  33.         System_State = h.readAll()
  34.         h.close()
  35.         if System_State == "Locked" then
  36.             LockedScreen()
  37.         else if System_State == "Unlocked" then
  38.             if fs.exists("Accounts") == false && Settings_UseAdvTaxDatabase == true then
  39.                 ERROR("Accounts", 2)
  40.             else
  41.                 term.setCursorPos(0,1)
  42.                 term.write("---Tax Dropoff System---")
  43.                 term.setCursorPos(0,2)
  44.                 term.write("Please Place Payment in the Dispenser Below, then pickup Receipt from Above")
  45.                 term.setCursorPos(0,3)
  46.                 term.write("Required Credits = "+Settings_ReqCredits)
  47.                 term.setCursorPos(0,6)
  48.                 term.write("the following is a converstion Sheet")
  49.                 term.setCursorPos(0,7)
  50.                 term.write("---------------------")
  51.                 term.setCursorPos(0,8)
  52.                 if Settings_AllowedResources[0] == true then
  53.                     term.write("1 Diamond == "+Value_Diamond)
  54.                 else
  55.                     term.write("Diamonds are not accepted")
  56.                 end
  57.                 term.setCursorPos(0,9)
  58.                 if Settings_AllowedResources[1] == true then
  59.                     term.write("1 Netherite == "+Value_Netherite)
  60.                 else
  61.                     term.write("Netherite are not accepted")
  62.                 end
  63.                 term.setCursorPos(0,10)
  64.                 if Settings_AllowedResources[2] == true then
  65.                     term.write("1 XPOrb == "+Value_XPOrb)
  66.                 else
  67.                     term.write("XPOrb are not accepted")
  68.                 end
  69.                 term.setCursorPos(0,11)
  70.                 if Settings_AllowedResources[3] == true then
  71.                     term.write("1 Emerald == "+Value_Emeralds)
  72.                 else
  73.                     term.write("Emeralds are not accepted")
  74.                 end
  75.                 term.setCursorPos(0,12)
  76.                 term.write("Standing By, waiting for Payment")
  77.                 StandBy()
  78.             end
  79.         end
  80.     end
  81. end
  82.  
  83. function Reset()
  84.     PaidResources = "Credits"
  85.     term.clear()
  86.     local Paper == printer.getPaperLevel()
  87.     local INK = printer.getInkLevel()
  88.     if Paper = 0 then
  89.         ERROR("Paper",1)
  90.     else if INK == 0 then
  91.         ERROR("Ink",1)
  92.     else
  93.         start()
  94.     end
  95. end
  96.  
  97. function Standby()
  98.     if Settings_UseAdvTaxDataBase == true then
  99.         term.setCursorPos(0,4)
  100.         term.write("Please Login, press enter to confirm")
  101.         Login()
  102.     else if Settings_UseAdvTaxDataBase == false then
  103.         Input()
  104.     end
  105. end
  106.  
  107. function Login()
  108.     local User = read()
  109.     local event, key = os.pullEvent("key")
  110.     while true do
  111.         if key == keys.enter then
  112.             if User == Settings_AdminAccount then
  113.                 AdminMenu()
  114.                 break
  115.             else
  116.                 CheckAccounts(User)
  117.                 break
  118.             end
  119.         end
  120.     end
  121. end
  122.  
  123. function CheckAccounts(Account)
  124.     local s = fs.open(".Accounts","r")
  125.     for i=1, #accounts do  
  126.         if s.readLine(i*2) == Account then
  127.             ReqAmount = s.readLine((i*2)+1)
  128.             Input()
  129.         end
  130.     end
  131. end
  132.  
  133. function AdminMenu()
  134.     term.clear()
  135.     term.setCursorPos(0,1)
  136.     term.write("-------ADMIN---MENU------")
  137.     term.setCursorPos(19,2)
  138.     term.write("OPTIONS")
  139.     term.setCursorPos(0,3)
  140.     term.write("1 = Accounts")
  141.     term.setCursorPos(0,4)
  142.     term.write("2 = Stop Program")
  143.     term.setCursorPos(0,5)
  144.     term.write("3 = Lock/Unlock Terminal")
  145.     local event, key = os.pullEvent("key")
  146.     while true do
  147.         if key == keys.1 then
  148.             Admin_Accounts()
  149.         else if key == keys.2 then
  150.             shell.stop()
  151.         else if key == keys.3 then
  152.             break
  153.             if System_State == Lock then
  154.                 ChangeState("Unlocked")
  155.             else if System_State == Unlocked then
  156.                 ChangeState("Locked")
  157.             end
  158.         end
  159.     end
  160. end
  161.  
  162. function Input()
  163.     while true do
  164.         local Items = Dispenser.list()
  165.         if Items.length > 0 then
  166.             PaidAmount = 0
  167.             for slot, item in pairs(Dispenser.list()) do
  168.                 local item = Dispenser.getItemDetail(slot)
  169.                 if item.name == "Diamond" && Settings_AllowedResources[0] == true then
  170.                     PaidAmount = PaidAmount + (item.count*Value_Diamond)
  171.                 else if item.name == "Netherite" && Settings_AllowedResources[1] == true then
  172.                     PaidAmount = PaidAmount + (item.count*Value_Netherite)
  173.                 else if item.name == "-----" && Settings_AllowedResources[2] == true then
  174.                     PaidAmount = PaidAmount + (item.count*Value_XPOrbs)
  175.                 else if item.name == "Emerald" && Settings_AllowedResources[3] == true then
  176.                     PaidAmount = PaidAmount + (item.count*Value_Emeralds)
  177.                 else if item.name == "1 Credit" then
  178.                     PaidAmount = PaidAmount + item.count
  179.                 else if item.name == "10 Credits" then
  180.                     PaidAmount = PaidAmount + (item.count*10)
  181.                 else if item.name == "100 Credits" then
  182.                     PaidAmount = PaidAmount + (item.count*100)
  183.                 end
  184.             end
  185.             if PaidAmount >= Settings_ReqCredits && Settings_UseAdvTaxDatabase == false then
  186.                 break
  187.                 Transaction()
  188.             else if PaidAmount == ReqAmount && Settings_UseAdvTaxDatabase == true then
  189.                 break
  190.                 Transaction()
  191.             end
  192.         end
  193.     end
  194. end
  195.  
  196. function Transaction()
  197.     local Items = Dispenser.list
  198.     while true do
  199.         setOutput("bottom","on")
  200.         sleep(2)
  201.         setOutput("bottom","off")
  202.         if Items.length == 0 then
  203.             break
  204.             Receipt()
  205.         end
  206.     end
  207. end
  208.  
  209. function Receipt()
  210.     term.setCursorPos(5,12)
  211.     term.write("Printing Receipt")
  212.     printer.newPage()
  213.     printer.setPageTitle(Settings_Settlement+" Tax Receipt")
  214.     printer.setCursorPos(0,1)
  215.     printer.write("Tax Receipt")
  216.     printer.setCursorPos(0,2)
  217.     printer.write("Settlement = "+Settings_Settlement)
  218.     printer.setCursorPos(0,3)
  219.     printer.write("Req Tax Payment: "+Settings_ReqCredits+" Credits")
  220.     printer.setCursorPos(0,4)
  221.     printer.write("Paid Amount = "+PaidAmount)
  222.     printer.setCursorPos(0,5)
  223.     printer.write("Date: "+)
  224.     printer.setCursorPos(0,6)
  225.     printer.write("ATM ID: "+Settings_ATMID)
  226.     printer.endPage()
  227.     sleep(20)
  228.     Reset()
  229. end
  230.  
  231. function ERROR(Item, Cause)
  232.     term.clear
  233.     term.setCursorPos(0,1)
  234.     term.write("----------ERROR---FOUND------------")
  235.     if Cause == 1 then --missing Resource
  236.         term.setCursorPos(0,2)
  237.         term.write("Cant Continue with Operations Due to Lack of Items")
  238.         term.setCursorPos(0,3)
  239.         term.write("Lacking "+Item)
  240.         sleep(15)
  241.         ChangeState("Locked")
  242.     else if Cause == 2 then --missing File
  243.         term.setCursorPos(0,2)
  244.         term.write("cant Continue with operations due to Missing Resources")
  245.         term.setCursorPos(0,3)
  246.         term.write("missing file named: "+Item)
  247.         if Item == "Accounts" then
  248.             term.setCursorPos(0,4)
  249.             term.write("a Example File has Been downloaded to help you make a account file")
  250.             term.setCursorPos(0,5)
  251.             term.write("the file should be named 'EX_Accounts'")
  252.             local h = fs.open("EX_Accounts","w")
  253.             h.setCursorPos(0,1)
  254.             h.writeLine("(keep this blank, but make sure the file is named '.Account')")
  255.             h.writeLine("<Account Name>")
  256.             h.writeLine("<Req Credits>")
  257.             h.writeLine("<Account Name>")
  258.             h.writeLine("<Req Credits")
  259.             h.writeLine("<Account Name>")
  260.             h.writeLine("<Req Credits")
  261.             h.close()
  262.         end
  263.         term.setCursorPos(0,10)
  264.         term.write("program will be set to Locked Screen to prevent anymore Errors")
  265.         sleep(15)
  266.         ChangeState("Locked")
  267.     end
  268. end
  269.  
  270. function SystemSetup()
  271.     term.setCursorPos(0,1)
  272.     term.write("Installing Files for first time Setup")
  273.     term.setCursorPos(0,3)
  274.     term.write("Please enter the desired Name for Admin Account")
  275.     local admin = read()
  276.     local event, key = os.pullEvent("key")
  277.     while true do
  278.         print(admin)
  279.         if key = keys.enter then
  280.             Settings_AdminAccount = admin
  281.             break
  282.         end
  283.     end
  284.     term.setCursorPos(0,5)
  285.     term.write("Admin Account Set, now Installing final Files, then a restart will begin")
  286.     local h = fs.open(".AdminAccount","w")
  287.     h.write(Settings_AdminAccount)
  288.     h.close()
  289.     h = fs.open(".TerminalState","w")
  290.     h.write("Locked")
  291.     h.close()
  292.     os.reboot()
  293. end
  294.  
  295. function AdminAccouts()
  296.     term.clear()
  297.     local h = fs.open(".Accounts","a")
  298.     local AC = h.readAll()
  299.     for i=1, list(h).length, do
  300.         term.setCursorPos(0,i)
  301.         write(h.readLine(i)
  302.     end
  303.     h.close()
  304.     h.open(".Accounts","w")
  305.     read() = AC
  306.     AC = read()
  307.     while true do
  308.         if key == keys.enter then
  309.             break
  310.             h.write(AC)
  311.         end
  312.     end
  313.     AdminMenu()
  314. end
  315.  
  316. function LockedScreen()
  317.     paintutils.drawFilledBox(0,0,51,19,colors.blue)
  318.     term.setCursorPos(0,4)
  319.     term.write("---------LOCKED----TERMINAL-------")
  320.     term.setCursorPos(0,8)
  321.     term.write("this terminal has been locked by an adminstrator. to unlock this terminal")
  322.     term.setCursorPos(0,9)
  323.     term.write("please login to the admin account now")
  324.     local Admin = read()
  325.     local event, key = os.pullEvent("key")
  326.     while true do
  327.         term.setCursorPos(0,10)
  328.         print(Admin)
  329.         if key == keys.enter && Admin == Settings_AdminAccout then
  330.             term.setCursorPos(0,11)
  331.             term.write("Account Accepted, now entering AdminMenu")
  332.             sleep(10)
  333.             term.clear()
  334.             break
  335.             AdminMenu()
  336.         end
  337.     end
  338. end
  339.  
  340. function ChangeState(State)
  341.     local h = fs.open(".TerminalState","w")
  342.     h.write(State)
  343.     h.close()
  344.     sleep(10)
  345.     os.reboot()
  346. end
  347.  
  348. os.pullEvent = oldPull
Add Comment
Please, Sign In to add comment