Advertisement
CreeperNukeBoom

Working computercraft tollway v1.1

Dec 7th, 2019
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.47 KB | None | 0 0
  1. --Tollway by CreeperGoBoom
  2. --v1.1
  3.  
  4.  
  5. --User vars. Change these as you like--
  6. local tolldebt=500 --This is to determine the overall cost of the toll before it becomes free
  7. local deptpaid=0 --program controlled, this keeps track of the payment progress
  8. local hasdebt=true --set to false to overwrite debt requirement.
  9. --Making it free until you decide to "resume" OR toll gets moved
  10. local chest=peripheral.wrap("top")
  11. local toll=4
  12. local paytype="Iron Ingot" --Display name of item to use.
  13. --just don't tell anyone it works off this or that it's even my code!
  14. local pushdir="east" --what direction do items need to go from input chest?
  15. local consize=27 --How many slots in the container used? normal chest=27
  16. local admit=false --controls default behavior for the tollway.
  17. --set to false for active tollway.
  18. --set to true for free passage.
  19. local redout="bottom" --for redstone output
  20. local redpass="right" --for detecting when an admit has been fulfilled
  21. local redin="front" --Where will the signal come from for pay query?
  22.  
  23.  
  24.  
  25. --Program vars. Do not change these
  26. local list={}
  27. local paid=0
  28. local topay=0
  29. local count=0
  30. local ispaid=false
  31. local rs=redstone
  32.  
  33.  
  34. --Code--
  35. term.clear()
  36. term.setCursorPos(1,1)
  37. --rs.setOutput(redout,true)
  38. print("Current Config")
  39. print("Player admit query side: "..redin)
  40. print("Redstone out control side: "..redout)
  41. print("Admit fulfill detection side: ",redpass)
  42.  
  43. while true do
  44.   while (ispaid==true) and (admit==false) do
  45.     local event=os.pullEvent()
  46.     if event=="redstone" then
  47.       if rs.getInput(redpass,true) then
  48.         ispaid=false
  49.         admit=false
  50.         break
  51.       end
  52.     end
  53.   end
  54.   while (ispaid==false) and (admit==false) do
  55.     rs.setOutput(redout,false)
  56.     local event=os.pullEvent()
  57.     if event=="redstone" then
  58.       if rs.getInput(redin,true) then
  59.         --sleep(0.25)
  60.         for c= 1,consize do
  61.           if chest.getStackInSlot(c) then
  62.             for i,v in pairs(chest.getStackInSlot(c)) do
  63.               list[i]=v --Gets item info and saves it for slot check of item type
  64.             end
  65.             if list["display_name"]==paytype then --This is where the tollway / item push code should go
  66.               count=count+tonumber(list["qty"]) --Troubleshooting only. this can be commented out
  67.               if list["qty"]>= toll then
  68.                 rs.setOutput(redout,true)
  69.                 chest.pushItem(pushdir,c,toll)
  70.                 paid = toll
  71.                 ispaid=true
  72.                 break
  73.               end
  74.             end
  75.           end
  76.         end
  77.       end
  78.     end
  79.     -- while (admit==true) do
  80.       -- rs.setOutput(redout,false)
  81.       -- sleep(0.25)
  82.       -- local event=os.pullEvent()
  83.       -- if event=="redstone" then
  84.         -- if rs.getInput(redpass,true) then
  85.           -- rs.setOutput(redout,false)
  86.           -- ispaid=true
  87.           -- admit=false
  88.           -- break
  89.         -- end
  90.       -- end
  91.     -- end
  92.     -- while (admit==false) do
  93.       -- rs.setOutput(redout,true)
  94.       -- sleep(0.25)
  95.       -- local event=os.pullEvent()
  96.       -- if event=="redstone" then
  97.         -- if rs.getInput(redpass,true) then
  98.           -- rs.setOutput(redout,true)
  99.           -- ispaid=true
  100.           -- admit=false
  101.           -- break
  102.         -- end
  103.       -- end
  104.       -- --print("payment detected: "..count)
  105.     -- end
  106.   end
  107.   while admit do
  108.     sleep(0)
  109.     rs.setOutput(redout,false)
  110.   end
  111. end
  112.  
  113. -- while ispaid do
  114.   -- print("access granted")
  115.   -- ispaid=false
  116. -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement