Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Tollway by CreeperGoBoom
- --v1.1
- --User vars. Change these as you like--
- local tolldebt=500 --This is to determine the overall cost of the toll before it becomes free
- local deptpaid=0 --program controlled, this keeps track of the payment progress
- local hasdebt=true --set to false to overwrite debt requirement.
- --Making it free until you decide to "resume" OR toll gets moved
- local chest=peripheral.wrap("top")
- local toll=4
- local paytype="Iron Ingot" --Display name of item to use.
- --just don't tell anyone it works off this or that it's even my code!
- local pushdir="east" --what direction do items need to go from input chest?
- local consize=27 --How many slots in the container used? normal chest=27
- local admit=false --controls default behavior for the tollway.
- --set to false for active tollway.
- --set to true for free passage.
- local redout="bottom" --for redstone output
- local redpass="right" --for detecting when an admit has been fulfilled
- local redin="front" --Where will the signal come from for pay query?
- --Program vars. Do not change these
- local list={}
- local paid=0
- local topay=0
- local count=0
- local ispaid=false
- local rs=redstone
- --Code--
- term.clear()
- term.setCursorPos(1,1)
- --rs.setOutput(redout,true)
- print("Current Config")
- print("Player admit query side: "..redin)
- print("Redstone out control side: "..redout)
- print("Admit fulfill detection side: ",redpass)
- while true do
- while (ispaid==true) and (admit==false) do
- local event=os.pullEvent()
- if event=="redstone" then
- if rs.getInput(redpass,true) then
- ispaid=false
- admit=false
- break
- end
- end
- end
- while (ispaid==false) and (admit==false) do
- rs.setOutput(redout,false)
- local event=os.pullEvent()
- if event=="redstone" then
- if rs.getInput(redin,true) then
- --sleep(0.25)
- for c= 1,consize do
- if chest.getStackInSlot(c) then
- for i,v in pairs(chest.getStackInSlot(c)) do
- list[i]=v --Gets item info and saves it for slot check of item type
- end
- if list["display_name"]==paytype then --This is where the tollway / item push code should go
- count=count+tonumber(list["qty"]) --Troubleshooting only. this can be commented out
- if list["qty"]>= toll then
- rs.setOutput(redout,true)
- chest.pushItem(pushdir,c,toll)
- paid = toll
- ispaid=true
- break
- end
- end
- end
- end
- end
- end
- -- while (admit==true) do
- -- rs.setOutput(redout,false)
- -- sleep(0.25)
- -- local event=os.pullEvent()
- -- if event=="redstone" then
- -- if rs.getInput(redpass,true) then
- -- rs.setOutput(redout,false)
- -- ispaid=true
- -- admit=false
- -- break
- -- end
- -- end
- -- end
- -- while (admit==false) do
- -- rs.setOutput(redout,true)
- -- sleep(0.25)
- -- local event=os.pullEvent()
- -- if event=="redstone" then
- -- if rs.getInput(redpass,true) then
- -- rs.setOutput(redout,true)
- -- ispaid=true
- -- admit=false
- -- break
- -- end
- -- end
- -- --print("payment detected: "..count)
- -- end
- end
- while admit do
- sleep(0)
- rs.setOutput(redout,false)
- end
- end
- -- while ispaid do
- -- print("access granted")
- -- ispaid=false
- -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement