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. (stays open permanently)
- 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=toll
- 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)
- --Functions--
- function checkRSInput(inputside,val)
- os.pullEvent("redstone")
- if rs.getInput(inputside,val) then
- local result=val
- return result
- end
- end
- while true do
- while (ispaid==true) and (admit==false) do
- os.pullEvent("redstone")
- if rs.getInput(redpass,true) then
- ispaid=false
- admit=false
- break
- end
- end
- while (ispaid==false) and (admit==false) do
- rs.setOutput(redout,false)
- os.pullEvent("redstone")
- if rs.getInput(redin,true) then
- --sleep(0.25)
- print("player query detected")
- 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) and (list["qty"]>= toll) then --This is where the tollway / item push code should go
- print("Granting access: Code 1")
- rs.setOutput(redout,true)
- chest.pushItem(pushdir,c,toll)
- paid = toll
- ispaid=true
- break
- elseif topay==0 then
- print("Granting access: Code 2")
- rs.setOutput(redout,true)
- ispaid=true
- break
- elseif (list["display_name"]==paytype) and (list["qty"] < toll) and (topay > 0 ) then
- print("Counting pennies")
- if list["qty"] >= 1 then
- topay=topay-list["qty"]
- chest.pushItem(pushdir,c,list["qty"])
- print("Amount left to pay: ",topay)
- if topay==0 then
- print("Granting access: code 3")
- rs.setOutput(redout,true)
- topay=toll
- ispaid=true
- end
- elseif topay==1 then
- topay=topay-1
- chest.pushItem(pushdir,c,1)
- print("Amount left to pay: ",topay)
- if topay==0 then
- print("Granting access: code 3")
- rs.setOutput(redout,true)
- topay=toll
- ispaid=true
- end
- end
- else
- topay=toll-list["qty"]
- print("Amount left to pay: ",topay)
- 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