Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local ser = require("serialization")
- local event = require("event")
- local deb = component.debug
- local mod = component.modem
- local wName, plName = "warehouse.tbl", "up.tbl"
- local tWarehouse = {
- -- [PlayerName] = {[ItemName:ItemMeta] = Amount}
- }
- local tUP = {
- -- [PlayerName] = Password
- }
- local function sL(tbl, f)
- local file = io.open(f, 'w')
- file:write(ser.serialize(tbl))
- file:close()
- end
- local function lL(f)
- local file = io.open(f, 'r')
- if not file then
- file = io.open(f, 'a')
- else
- return ser.unserialize(file:read('*a'))
- end
- file:close()
- end
- local function wList(PlayerName) -- получение информации о хранилище
- return tWarehouse[PlayerName]
- end
- ----------------------------------------------------------
- local function getPassword(PlayerName) -- получение пароля к хранилищу
- local ps = ""
- for i = 1, 16 do
- ps = ps..string.char(math.random(33, 126))
- end
- tUP[PlayerName] = ps
- deb.runCommand("give "..PlayerName.." minecraft:paper 1 0 {display:{Name:"..ps.."}}")
- end
- local function DEL(PlayerName, ItemName, ItemMeta, Amount) -- отнимание предмета у игрока
- local s, f = deb.runCommand("clear "..PlayerName.." "..ItemName.." "..ItemMeta.." "..Amount)
- if s == 1 then
- return tonumber(f:sub(37+#PlayerName):match("[0-9+]"))
- else
- return false
- end
- end
- local function ADD(PlayerName, ItemName, ItemMeta, Amount) -- добавление предмета игроку
- if Amount <= 64 then
- if deb.runCommand("give "..PlayerName.." "..ItemName.." "..Amount..""..ItemMeta) == 1 then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- ----------------------------------------------------------
- local actions = {
- ["PtW"] = function(PlayerName, ItemName, ItemMeta, Amount) -- перемещение предмета из инвентаря в хранилище
- local getA = DEL(PlayerName, ItemName, ItemMeta, Amount)
- if getA then
- if not tWarehouse[PlayerName] then
- tWarehouse[PlayerName] = {}
- end
- if not tWarehouse[PlayerName][ItemName .."@".. ItemMeta] then
- tWarehouse[PlayerName][ItemName .."@".. ItemMeta] = getA
- else
- tWarehouse[PlayerName][ItemName .."@".. ItemMeta] = tWarehouse[PlayerName][ItemName .."@".. ItemMeta] + getA
- end
- end
- end,
- ["WtP"] = function(PlayerName, ItemName, ItemMeta, Amount) -- перемещение предмета из хранилища в инвентарь
- if tWarehouse[PlayerName] then
- local getA = tWarehouse[PlayerName][ItemName .."@".. ItemMeta]
- if getA then
- if getA >= Amount then
- ADD(PlayerName, ItemName, ItemMeta, Amount)
- else
- ADD(PlayerName, ItemName, ItemMeta, getA)
- end
- end
- end
- end,
- ["PtP"] = function(PlayerS, PlayerT, ItemName, ItemMeta, Amount) -- перемещение предмета от одного игрока другому
- local getA = DEL(PlayerS, ItemName, ItemMeta, Amount)
- ADD(PlayerT, ItemName, ItemMeta, Amount)
- end,
- ["WtW"] = function(PlayerS, PlayerT, ItemName, ItemMeta, Amount) -- перемещение предмета из хранилища одного игрока в хранилище другого
- if tWarehouse[PlayerS] then
- if not tWarehouse[PlayerT] then
- tWarehouse[PlayerT] = {}
- end
- if not tWarehouse[PlayerT][ItemName .."@".. ItemMeta] then
- tWarehouse[PlayerT][ItemName .."@".. ItemMeta] = 0
- end
- local getA = tWarehouse[PlayerS][ItemName .."@".. ItemMeta]
- if getA then
- if getA >= Amount then
- tWarehouse[PlayerS][ItemName .."@".. ItemMeta] = tWarehouse[PlayerS][ItemName .."@".. ItemMeta] - Amount
- tWarehouse[PlayerT][ItemName .."@".. ItemMeta] = tWarehouse[PlayerT][ItemName .."@".. ItemMeta] + Amount
- else
- tWarehouse[PlayerS][ItemName .."@".. ItemMeta] = nil
- tWarehouse[PlayerT][ItemName .."@".. ItemMeta] = tWarehouse[PlayerT][ItemName .."@".. ItemMeta] + getA
- end
- end
- end
- end
- }
- mod.open(999)
- lL(wName)
- lL(plName)
- -- password\0action\0player ...
- while true do
- local tbl = {}
- local e = {event.pull()}
- if e[1] == "modem_message" then
- for i in e[6]:gmatch("[^\0]+") do table.insert(tbl, i) end
- if tUP[tbl[3]] == tbl[1] then
- actions[tbl[2]](table.unpack(tbl, 3))
- end
- elseif e[1] == "touch" then
- getPassword(e[6])
- elseif e[1] == "key_down" then
- sL(tWarehouse, wName)
- sL(tUP, plName)
- os.exit()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement