Advertisement
Dojnaz

CC InvPaste

Dec 6th, 2020 (edited)
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local pim = peripheral.wrap("pim_1")
  2. local mon = peripheral.wrap("monitor_71")
  3.  
  4. --Don't change anything below this line
  5.  
  6. if (not fs.exists("invjson")) then
  7.     shell.run("pastebin", "get", "4nRg9CHU", "invjson")
  8. end
  9. os.loadAPI("invjson")
  10.  
  11. local lastPlayer
  12.  
  13. function renderBottom(_color)
  14.     mon.setBackgroundColor(_color)
  15.     _x, _y = mon.getSize()
  16.     for x = 1, _x, 1 do
  17.         mon.setCursorPos(x, _y)
  18.         mon.write(" ")
  19.     end
  20.     mon.setBackgroundColor(colors.black)
  21. end
  22.  
  23. function playerOn()
  24.     event, lastPlayer, side = os.pullEvent("player_on")
  25. end
  26.  
  27. function playerOff()
  28.     event, side = os.pullEvent("player_off")
  29.     lastPlayer = nil
  30. end
  31.  
  32. function paste()
  33.     pasteObject = {}
  34.     pasteObject.player = lastPlayer
  35.     pasteObject.items = {}
  36.     for i = 1, pim.getInventorySize(), 1 do
  37.         pasteObject.items[""..i] = pim.getStackInSlot(i)
  38.         if (i % 2 == 1) then
  39.             renderBottom(colors.cyan)
  40.         else
  41.             renderBottom(colors.blue)
  42.         end
  43.     end
  44.     --print(invjson.encode(pasteObject.items[""..1]))
  45.     --print(invjson.encode(pasteObject))
  46.     sName = "invpaste"
  47.     sText = invjson.encode(pasteObject)
  48.     key = "0ec2eb25b6166c0c27a394ae118ad829"
  49.     response, arg0, arg1 = http.post(
  50.         "https://pastebin.com/api/api_post.php",
  51.         "api_option=paste&"..
  52.         "api_dev_key="..key.."&"..
  53.         "api_paste_format=lua&"..
  54.         "api_paste_name="..textutils.urlEncode(sName).."&"..
  55.         "api_paste_code="..textutils.urlEncode(sText)
  56.     )
  57.     if response then
  58.         print("Success")
  59.         sResponse = response.readAll()
  60.         response.close()
  61.        
  62.         sCode = string.match(sResponse, "[^/]+$")
  63.         print(sCode)
  64.         mon.setCursorPos(1,1)
  65.         mon.write(sCode)
  66.         renderBottom(colors.lime)
  67.     else
  68.         printError("Failed")
  69.         mon.setCursorPos(1,1)
  70.         mon.write("Upload failed") 
  71.         renderBottom(colors.red)
  72.     end
  73. end
  74.  
  75. mon.setTextScale(2)
  76. mon.clear()
  77. renderBottom(colors.red)
  78. while (true) do
  79.     if (parallel.waitForAny(playerOn, playerOff) == 1) then
  80.         mon.clear()
  81.         renderBottom(colors.cyan)
  82.         if (parallel.waitForAny(playerOff, paste) == 1) then
  83.             mon.setCursorPos(1,1)
  84.             mon.write("Don't step off")
  85.             renderBottom(colors.red)
  86.         end
  87.     else
  88.         renderBottom(colors.red)
  89.     end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement