Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local deb = component.debug
- local pim = component.pim
- local item
- local tWList = {
- ['Obsidian'] = "minecraft:obsidian:0",
- ['Block of Redstone'] = "minecraft:redstone_block:0",
- ['Block of Coal'] = "minecraft:coal_block:0",
- ['Lapis Lazuli Block'] = "minecraft:lapis_block:0",
- ['Block of Iron'] = "minecraft:iron_block:0",
- ['Block of Gold'] = "minecraft:gold_block:0",
- ['Block of Diamond'] = "minecraft:diamond_block:0",
- ['Block of Emerald'] = "emerald:block:0",
- ['Steak'] = "minecraft:cooked_beef:0",
- ['Cooked Chiken'] = "minecraft:cooked_chiken:0",
- ['Cooked Porkchop'] = "minecraft:cooked_porkchop:0",
- ['Baked Potato'] = "minecraft:baked_potato:0",
- ['Bread'] = "minecraft:bread:0",
- ['Melon'] = "minecraft:melon:0",
- ['Apple'] = "minecraft:apple:0",
- ['Redstone'] = "minecraft:redstone:0",
- ['Coal'] = "minecraft:coal:0",
- ['Lapis Lazuli'] = "minecraft:dye:4",
- ['Iron Ingot'] = "minecraft:iron_ingot:0",
- ['Gold Ingot'] = "minecraft:gold_ingot:0",
- ['Diamond'] = "minecraft:diamond:0",
- ['Emerald'] = "minecraft:emerald:0",
- }
- local tMarket = {} -- список товаров на рынке
- local tGoods = {} -- список товаров игрока
- --[[
- local tGoods = {
- [лейбл итема] = {
- [0] = общее количество
- [слот] = количество
- }
- }
- ]]
- local function market(i_tem, amount, tpl) -- количество под индексом 0, для совместимости с tGoods
- if tpl == 1 then
- if tMarket[i_tem] = nil then
- tMarket[i_tem] = {[0] = amount}
- else
- tMarket[i_tem][0] = tMarket[i_tem][0] + amount
- end
- elseif tpl == 0
- if tMarket[i_tem][0] < amount then
- tMarket[i_tem][0] = tMarket[i_tem][0] - tMarket[i_tem][0]
- else
- tMarket[i_tem][0] = tMarket[i_tem][0] - amount
- end
- end
- end
- local function scanner() -- сканирует инвентарь
- for slot = 1, 36 do
- item = pim.getStackInSlot(slot)
- if item ~= nil then
- if tWList[item.display_name] ~= nil then -- проверка, есть ли он в вайтлисте
- if tWList[item.display_name] == item.id .. ':' .. item.dmg then -- проверка ID и дамага
- if tGoods[item.display_name] == nil then
- tGoods[item.display_name] = {[0] = item.qty}
- tGoods[item.display_name][slot] = item.qty
- end
- tGoods[item.display_name][slot] = item.qty
- tGoods[item.display_name][0] = tGoods[item.display_name][0] + item.qty
- end
- else
- if tGoods[item.display_name] == nil then
- tGoods[item.display_name] = {[0] = item.qty}
- tGoods[item.display_name][slot] = item.qty
- end
- tGoods[item.display_name][slot] = item.qty
- tGoods[item.display_name][0] = tGoods[item.display_name][0] + item.qty
- end
- end
- end
- end
- local function disintegrator(i_tem, amount) -- перемещает указанные предметы из инвентаря в утилизатор
- if tGoods[i_tem][0] >= amount
- for slot = 1, 36 do
- if tGoods[i_tem][slot] >= amount then
- pim.pushItem('DOWN', slot, amount)
- tGoods[i_tem][slot] = tGoods[i_tem][slot] - amount
- tGoods[i_tem][0] = tGoods[i_tem][0] - amount
- amount = amount - amount
- market(i_tem, amount, 1)
- elseif tGoods[i_tem][slot] < amount then
- pim.pushItem('DOWN', slot, tGoods[i_tem][slot])
- tGoods[i_tem][slot] = tGoods[i_tem][slot] - tGoods[i_tem][slot]
- tGoods[i_tem][0] = tGoods[i_tem][0] - tGoods[i_tem][slot]
- amount = amount - tGoods[i_tem][slot]
- market(i_tem, amount, 1)
- end
- if amount == 0 then
- break
- end
- end
- end
- end
- local function giver(i_tem, amount, dmg) -- выдает указанные предметы
- if dmg == nil then
- dmg = 0
- end
- deb.runCommand('give ' .. player .. ' ' .. i_tem .. ' ' .. amount .. ' ' .. dmg)
- market(i_tem, amount, 0)
- end
- --------------------------------------------
- local component =require('component')
- local gpu = component.gpu
- local tListA, tListP = {}, {} -- список всех товаров под цифровыми индексами, список товаров на текущей странице
- local page = 0
- --gpu.setResolution(80, 25)
- local function center(text, line)
- gpu.set(20-(#text/2), line, text)
- end
- local function clear()
- gpu.fill(1, 1, 80, 25, ' ')
- end
- local tButtons = { -- x1, x2, y1
- {2, 39, 4}, {42, 79, 4},
- {2, 39, 6}, {42, 79, 6},
- {2, 39, 8}, {42, 79, 8},
- {2, 39, 10}, {42, 79, 10},
- {2, 39, 12}, {42, 79, 12},
- {2, 39, 14}, {42, 79, 14},
- {2, 39, 16}, {42, 79, 16},
- {2, 39, 18}, {42, 79, 18},
- {2, 39, 20}, {42, 79, 20},
- {2, 39, 22}, {42, 79, 22},
- {2, 8, 24}, {73, 79, 24}
- }
- local tGoodsList = {
- '╔══════════════════════╦═══════╦═══════╦╦══════════════════════╦═══════╦═══════╗',
- '║ название товара ║ кол-во║ цена ║║ название товара ║ кол-во║ цена ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║1 ║ ║ ║║2 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║3 ║ ║ ║║4 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║5 ║ ║ ║║6 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║7 ║ ║ ║║8 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║9 ║ ║ ║║10 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║11 ║ ║ ║║12 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║13 ║ ║ ║║14 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║15 ║ ║ ║║16 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║17 ║ ║ ║║18 ║ ║ ║',
- '╠══════════════════════╬═══════╬═══════╬╬══════════════════════╬═══════╬═══════╣',
- '║19 ║ ║ ║║20 ║ ║ ║',
- '╠═══════╦══════════════╩═══════╩═════╦═╩╩═╦════════════════════╩═══════╬═══════╣',
- '║ <<< ║ ║0001║ ║ >>> ║',
- '╚═══════╩════════════════════════════╩════╩════════════════════════════╩═══════╝'
- }
- local function goodsList(tbl) -- tbl = {[1] = {'название товара', 'количество', 'стоимость'}}
- for d = 1, #tTradeScreen do
- gpu.set(1, d, tTradeScreen[d])
- end
- for f = 1, #tbl do
- gpu.set(tButtons[f][1], tButtons[f][3], string.sub(tbl[f][1], 1, 22))
- gpu.set(tButtons[f][1]+23, tButtons[f][3], tostring(tbl[f][2]))
- gpu.set(tButtons[f][1]+31, tButtons[f][3], tostring(tbl[f][3]))
- end
- end
- local function refresh(tbl) -- принимает tGoods и tMarket, {['лейбл'] = {[0] = количество}}
- for label, amount in pairs(tbl) do
- table.insert(tListA, {label, amount[0]})
- end
- end
- local function filler() -- заполняет текущую страницу из общего списка предметов
- tListP = {}
- for list = 1, 20 do
- tListP[list] = tListA[list+page]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement