Advertisement
CreeperNukeBoom

not workling

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