Advertisement
ecco7777

CC Item Value Reader

Jun 12th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. shell.run("rm price")
  2. shell.run("pastebin get KkUbsxEG price")
  3.  
  4. is=peripheral.wrap("bottom")
  5. function fileToTable(file)
  6. if fs.exists(file)~=true then
  7. print("file"..file.." not found")
  8. return(false)
  9. end
  10. fp=fs.open(file,"r")
  11. line={}
  12. i=1
  13. line[i]=fp.readLine()
  14. if line[i]==nil then return(false) end
  15. while line[i]~=nil do
  16. i=i+1
  17. line[i]=fp.readLine()
  18. end
  19. return(line)
  20. end
  21.  
  22. function printMoney(money)
  23. term.clear()
  24. term.setCursorPos(1,1)
  25. term.write("Click here to reset")
  26. term.setCursorPos(1,2)
  27. term.write("Money: "..tostring(money))
  28. end
  29.  
  30. function main()
  31. money=0
  32. printMoney(money)
  33. price=fileToTable("price")
  34.  
  35. while true do
  36. i=1
  37. e, id, amount =os.pullEvent()
  38. if e=="isort_item" then
  39. while price[i]~=nil do
  40. if id==tonumber(price[i]) then
  41. money=money+tonumber(price[i+2])*amount
  42. printMoney(money)
  43. end
  44. i=i+3
  45. end
  46. is.sort(3,amount)
  47. end
  48. if e=="key" then
  49. if id==28 then money=0 end
  50. printMoney(money)
  51. end
  52. if e=="monitor_touch" then
  53. money=0
  54. printMoney(money)
  55. end
  56. sleep(0)
  57. end
  58. end
  59.  
  60. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement