Advertisement
minimite

turtleapigive

Mar 22nd, 2015
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. local tArgs = {...}
  2. if #tArgs ~= 3 then
  3.   print("Usage: give <id> <count> <metadata>")
  4.   error()
  5. end
  6. if not fs.isDir("disk") then
  7.   printError("No disk drive connected!")
  8.   error()
  9. end
  10. local tabl = {}
  11. if fs.exists("disk/inventory.txt") then
  12.   local open = fs.open("disk/inventory.txt", "r")
  13.   tabl = textutils.unserialize(open.readAll())
  14.   open.close()
  15. end
  16. local itemdetails = {}
  17. itemdetails["name"] = tArgs[1]
  18. itemdetails["count"] = tArgs[2]
  19. itemdetails["damage"] = tArgs[3]
  20. local numb = #tabl+1
  21. tabl[numb] = itemdetails
  22. local open = fs.open("disk/inventory.txt", "w")
  23. open.write(textutils.serialize(tabl))
  24. open.close()
  25. print("Added " .. tArgs[2] .. " of item " .. tArgs[1] .. " in slot " .. numb .. "!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement