Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mainFrame=24
- local sensor=peripheral.wrap("right")
- local range=4
- rednet.open("left")
- function getNearbyUser()
- local players=sensor.getPlayers()
- for i,d in pairs(players) do
- local playerFunctions=sensor.getPlayerByName(d.name)
- local playerData=playerFunctions.select(1)
- local pos=playerData.position
- if pos.x<range and pos.x>-range and pos.y<range and pos.y>-range and pos.z<range and pos.z>-range then
- return d.name
- end
- end
- end
- function checkForItems()
- turtle.suck()
- turtle.select(1)
- local detail=turtle.getItemDetail(1)
- if detail==nil then return end
- local id=detail.name
- local value=value
- local user=getNearbyUser()
- repeat
- rednet.send(mainFrame,"getValue,"..id,"NanoShop")
- local i,value=rednet.receive(5)
- if i==mainFrame then
- if value=="false" then
- turtle.select(1)
- turtle.drop()
- os.setComputerLabel("This item is worthless")
- sleep(5)
- os.setComputerLabel("Earn NanoCredits")
- elseif user==nil then
- turtle.select(1)
- turtle.drop()
- os.setComputerLabel("Could not identify any users.")
- sleep(5)
- os.setComputerLabel("Earn NanoCredits")
- else
- redstone.setOutput("bottom",true)
- repeat
- rednet.send(mainFrame,"addCredit,"..user..","..value,"NanoShop")
- local i,added=rednet.receive(5)
- until added=="true" and i==mainFrame
- os.setComputerLabel(value.." has been added to your account.")
- redstone.setOutput("bottom",false)
- sleep(3)
- os.setComputerLabel("Earn NanoCredits")
- end
- end
- until i==mainFrame
- end
- function setup()
- term.clear()
- term.setCursorPos(1,1)
- print([[Welcome to the NanoTech shop!
- I will assist you by exchanging your items for NanoCredits.
- Place an item on the ground in front of me and I will exchange it for NanoCredits.]])
- end
- setup()
- while true do
- checkForItems()
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement