Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CB
- local IM
- function splitString(str)
- local fields = {}
- str:gsub("([^ ]+)", function(c) table.insert(fields, c) end)
- return fields
- end
- function init()
- IM = peripheral.find("inventoryManager")
- if IM == nil then error("inventoryManager not found") end
- CB = peripheral.find("chatBox")
- if CB == nil then error("chatBox not found") end
- end
- function mainLoop()
- while true do
- event, username, message = os.pullEvent("chat")
- if username == "_LK005_" then
- splitMessage = splitString(message)
- local identifier = splitMessage[1]
- local command = splitMessage[2]
- local itemName = splitMessage[3]
- local itemAmount = splitMessage[4]
- if identifier == "-" then
- print("Command: "..command)
- if command == "get" then
- print("giving "..itemAmount.." "..itemName.." to "..username)
- IM.addItemToPlayer("LEFT", tonumber(itemAmount), -1, itemName)
- elseif command == "put" then
- print("putting "..itemAmount.." "..itemName.." into the system from "..username)
- IM.removeItemFromPlayer("LEFT", tonumber(itemAmount), -1, itemName)
- elseif command == "select" then
- for key,value in pairs(IM.getItemInHand()) do print(key,value) end
- end
- end
- end
- end
- end
- init()
- mainLoop()
Add Comment
Please, Sign In to add comment