Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("/apis/appdata")
- os.loadAPI("/apis/json")
- os.loadAPI("/apis/tables")
- os.loadAPI("utils")
- -- Variable --
- local args = {...}
- local packs = tables.get("packs")
- -- Fonctions Importante -
- function getPackByName(name)
- local tmp = json.decode(packs:getData())
- for k,v in pairs(tmp) do
- if v.name == name then
- return v
- end
- end
- return false
- end
- function addPack(pack)
- local tmp = json.decode(packs:getData())
- if tmp == nil or type(tmp) ~= "table" then
- tmp = {}
- end
- local tmpLength = utils.tableLength(tmp)
- if tmpLength > 0 and getPackByName(pack.name) then
- term.setTextColor(colors.red)
- print("Un pack porte deja ce nom")
- return
- else
- pack.id = tmpLength
- tmp[tostring(tmpLength)] = pack
- packs["data"] = json.encode(tmp)
- packs:save()
- end
- end
- function requestPack(Name, wrap, direction)
- wrap = wrap or "top"
- direction = direction or "WEST"
- local pack = getPackByName(Name)
- local p = peripheral.wrap(wrap)
- if p == nil or pack == nil or pack == false then
- return false
- else
- for k,v in pairs(pack.fingerPrints) do
- local tmpItem = "{id=\""..v.item.."\",dmg="..v.damage.."}"
- term.setTextColor(colors.yellow)
- print("Requete effectuee")
- p.exportItem(tmpItem, direction, v.quantity)
- end
- end
- end
- if #args == 0 then
- term.setTextColor(colors.yellow)
- print("add [Name][fingerPrints]")
- print("get [Name]")
- print("request [Name][Wrap][Direction]")
- return
- end
- if args[1] == "add" then
- if utils.commandVerif(args, 3, "add [Name][fingerPrints]") then
- local pack = {}
- pack.name = args[2]
- pack.fingerPrints = {}
- s = utils.split(args[3]:gsub("[%s{}]", ""), "-")
- for k,v in pairs(s) do
- pack.fingerPrints[k] = {}
- propertyFingPrints = utils.split(v, ",")
- pack.fingerPrints[k].item = propertyFingPrints[1]
- if #propertyFingPrints == 2 then
- pack.fingerPrints[k].damage = "0"
- pack.fingerPrints[k].quantity = propertyFingPrints[2]
- elseif #propertyFingPrints == 3 then
- pack.fingerPrints[k].damage = propertyFingPrints[2]
- pack.fingerPrints[k].quantity = propertyFingPrints[3]
- end
- term.setTextColor(colors.lime)
- print("Item " .. k .. " - " .. v)
- end
- addPack(pack)
- end
- elseif args[1] == "get" then
- if commandVerif(2, "get [Name]") then
- local pack = {}
- pack = getPackByName(args[2])
- term.setTextColor(colors.lime)
- print("Id: " .. pack.id)
- print("Name: " .. pack.name)
- print("FingerPrints: ")
- for k,v in pairs(pack.fingerPrints) do
- print(k .. " - " ..v)
- end
- end
- elseif args[1] == "request" then
- if utils.commandVerif(args, 4, "request [Name][Wrap][Direction]") then
- requestPack(args[2], args[3], args[4])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement