Advertisement
NanoBob

NanoShop Sellbot

Jul 22nd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local mainFrame=24
  2.  
  3. local sensor=peripheral.wrap("right")
  4. local range=4
  5. rednet.open("left")
  6.  
  7. function getNearbyUser()
  8.     local players=sensor.getPlayers()
  9.     for i,d in pairs(players) do
  10.         local playerFunctions=sensor.getPlayerByName(d.name)
  11.         local playerData=playerFunctions.select(1)
  12.         local pos=playerData.position
  13.         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
  14.             return d.name
  15.         end
  16.     end
  17. end
  18.  
  19. function checkForItems()
  20.     turtle.suck()
  21.     turtle.select(1)
  22.     local detail=turtle.getItemDetail(1)
  23.     if detail==nil then return end
  24.     local id=detail.name
  25.     local value=value
  26.     local user=getNearbyUser() 
  27.     repeat
  28.         rednet.send(mainFrame,"getValue,"..id,"NanoShop")
  29.         local i,value=rednet.receive(5)
  30.         if i==mainFrame then
  31.             if value=="false" then
  32.                 turtle.select(1)
  33.                 turtle.drop()
  34.                 os.setComputerLabel("This item is worthless")
  35.                 sleep(5)
  36.                 os.setComputerLabel("Earn NanoCredits")
  37.             elseif user==nil then  
  38.                 turtle.select(1)
  39.                 turtle.drop()
  40.                 os.setComputerLabel("Could not identify any users.")
  41.                 sleep(5)
  42.                 os.setComputerLabel("Earn NanoCredits")
  43.             else
  44.                 redstone.setOutput("bottom",true)
  45.                 repeat
  46.                     rednet.send(mainFrame,"addCredit,"..user..","..value,"NanoShop")
  47.                     local i,added=rednet.receive(5)
  48.                 until added=="true" and i==mainFrame
  49.                 os.setComputerLabel(value.." has been added to your account.")
  50.                 redstone.setOutput("bottom",false)
  51.                 sleep(3)
  52.                 os.setComputerLabel("Earn NanoCredits")
  53.             end
  54.         end
  55.     until i==mainFrame
  56. end
  57.  
  58. function setup()
  59.     term.clear()
  60.     term.setCursorPos(1,1)
  61.     print([[Welcome to the NanoTech shop!
  62.    
  63. I will assist you by exchanging your items for NanoCredits.
  64.  
  65. Place an item on the ground in front of me and I will exchange it for NanoCredits.]])
  66. end
  67. setup()
  68.  
  69.  
  70. while true do
  71.     checkForItems()
  72.     sleep(2)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement