Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- *//
- -- edit dbMarket_slot
- -- hts4 SanyaRamzik dwcity:Materia 3 minecraft:iron_ore 60
- -- hts4 FeyMen minecraft:iron_ingot 60 minecraft:iron_ore 25
- -- hts1 EnergyHuman minecraft:iron_ingot 56 minecraft:iron_block 7
- -- hts2 NoName_ dwcity:Powder11 1 dwcity:Materia 4
- -- //*
- local component = require('component')
- local gpu=component.gpu
- local computer = require('computer')
- local event=require('event')
- local pull_e = event.pull
- local me_inv=component.proxy('')
- local chest_bank=component.proxy('be5e1869-67ed-4193-afd5-01f2826ea47b')
- local me_bank=component.proxy('237662c0-722f-4aac-96da-c30f9d98e014')
- local rs_bank=component.proxy('1fe0abb4-ab8f-485e-bff0-2f26c878fae4')
- me_sclad=component.proxy('0ea38a30-6426-455b-ab22-a812909cc4e1')
- rs_sclad=component.proxy('fcd7dc67-5ef5-4126-8dca-758b1b079fd5')
- local W, H = gpu.getResolution()
- b_color, f_color = gpu.getBackground(), gpu.getForeground()
- local timeout=30
- local background_color=0x000040
- log_nickname="TEST"
- local status='.'
- local active_slot='.'
- Slots={
- {X=36,
- Y=5,
- W=110,
- H=1,
- color=background_color,
- textColor=0xFFFFFF,
- Server='htc4',
- Seller='user',
- Slot='mc:iron_block',
- Slot_count='1',
- Price='em',
- Price_count='1',
- action = function()
- computer.beep();
- end
- }
- }
- function event.shouldInterrupt()
- return false
- end
- function check_timeout()
- if timeout<=0 then
- logOut()
- return false
- end
- timeout=timeout-1;
- set_str_timeout()
- end
- function add_bank_str(server,seller,reward_item,reward_count)
- local file=io.open("\\dbMarket_bank","a")
- file:write(server.." "..seller.." "..reward_item.." "..reward_count.."\n")
- file:close()
- end
- function clear_plane()
- gpu.setBackground(background_color); gpu.fill(3,4,32,7,' ')
- end
- function clear_log()
- gpu.setBackground(background_color)
- gpu.setForeground(background_color)
- gpu.fill(10,19,25,3,' ')
- end
- function set_str_timeout()
- gpu.fill(30,45,5,1,' ')
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x3324FF)
- gpu.set(30,45,tostring(timeout))
- end
- function split( str, del )
- local t = {}
- repeat
- local b, e = str:find( del, 1, true )
- if b ~= nil then
- t[ #t + 1 ] = str:sub( 1, b - 1 )
- str = str:sub( e + 1 )
- end
- until b == nil
- t[ #t + 1 ] = str
- return t
- end
- function show_list()
- for i=1,#Slots-1 do table.remove(Slots,#Slots) end
- gpu.setBackground(0x3324FF)
- gpu.fill(36,4,W,H,' ')
- gpu.setForeground(0xFFFFFF)
- gpu.set(40,3,'Server')
- gpu.set(48,3,'|')
- gpu.set(50,3,'Seller')
- gpu.set(65,3,'Slot')
- gpu.set(90,3,'Count')
- gpu.set(100,3,'Price')
- gpu.set(130,3,'Count')
- fill_slots()
- end
- function gift(slot,slot_count)
- me_sclad.exportItem({id=slot},"UP",slot_count)
- end
- function check_valide(server,seller,slot,slot_count,price,price_count)
- local count=0
- local t=0
- for i=1,chest_bank.getInventorySize() do
- local slot_item=chest_bank.getStackInSlot(i)
- if slot_item~=nil then t=t+1
- --print(slot_item.id.." "..slot_item.qty.." | "..price.." "..price_count)
- if slot_item.id==tostring(price) then count=count+slot_item.qty end
- end
- end
- if count>=tonumber(price_count) then
- for i=1,t do rs_bank.setOutput(1,15) os.sleep(1) rs_bank.setOutput(1,0) end
- count=0
- t=0
- gift(slot,slot_count)
- check_valide_gpu(true)
- add_bank_str(server,seller,price,price_count)
- remove_slot(active_slot)
- else check_valide_gpu(false)
- end
- end
- function check_valide_gpu(bool)
- clear_plane()
- gpu.setForeground(0xFFFFFF)
- if bool then
- gpu.setBackground(0x33B600)
- gpu.set(8,7,"Покупка оформлена!")
- else
- gpu.setBackground(0xCC0040)
- gpu.set(8,7,"Недостаточно средств!")
- end
- gpu.set(3,4,"┌"); gpu.set(32,4,"┐")
- gpu.set(3,10,"└"); gpu.set(32,10,"┘")
- gpu.fill(4,4,28,1,"─"); gpu.fill(4,10,28,1,"─")
- gpu.fill(3,5,1,5,"│"); gpu.fill(32,5,1,5,"│")
- end
- function fill_slots()
- local t={}
- for line in io.lines("\\dbMarket_slot") do
- local slot=split(line,' ')
- Slots[#Slots+1]={
- Server=slot[1],
- Seller=slot[2],
- Slot=slot[3],
- Slot_count=slot[4],
- Price=slot[5],
- Price_count=slot[6],
- W=110,
- H=1,
- X=36,
- Y=Slots[#Slots].Y+2,
- color=background_color,
- textColor=0xFFFFFF,
- action = function()
- computer.beep()
- end
- }
- end
- for i=1,#Slots do drawSlot(i) end
- end
- function remove_slot(active_slot)
- local line=Slots[active_slot].Server.." "..Slots[active_slot].Seller.." "..Slots[active_slot].Slot.." "..Slots[active_slot].Slot_count.." "..Slots[active_slot].Price.." "..Slots[active_slot].Price_count
- table.remove(Slots,active_slot)
- local f = io.open("\\dbMarket_slot", "r")
- local content = f:read("*all")
- f:close()
- content = content:gsub(line.."\n", ""); content=content:gsub(line,"")
- local f = io.open("\\dbMarket_slot", "w")
- f:write(content)
- f:close()
- show_list()
- end
- function drawSlot(n)
- gpu.setBackground(Slots[n].color) -- задаем цвет кнопки
- gpu.setForeground(Slots[n].textColor) -- задаем цвет текста
- gpu.fill(Slots[n].X, Slots[n].Y, Slots[n].W, Slots[n].H, ' ') -- заливаем область
- gpu.set(40,Slots[n].Y,Slots[n].Server)
- gpu.set(48,Slots[n].Y,'|') gpu.set(48,Slots[n].Y-1,'|')
- gpu.set(50,Slots[n].Y,Slots[n].Seller)
- gpu.set(65,Slots[n].Y,Slots[n].Slot)
- gpu.set(90,Slots[n].Y,Slots[n].Slot_count)
- gpu.set(100,Slots[n].Y,Slots[n].Price)
- gpu.set(130,Slots[n].Y,Slots[n].Price_count)
- end
- tButtons = {
- {
- visible = false,
- X = W-5,
- Y = 2,
- W = 4,
- H = 1,
- color = 0xff0000,
- textColor = 0xffffff,
- text = 'X',
- action = function()
- event.cancel(1)
- gpu.setBackground(b_color)
- gpu.setForeground(f_color)
- gpu.fill(1, 1, W, H, ' ')
- os.exit()
- end
- },
- {
- visible = true,
- X = 12.5,
- Y = 35,
- W = 15,
- H = 3,
- color = 0x3324FF,
- textColor = 0xFFFFFF,
- text = 'Expose',
- action = function()
- computer.beep()
- event.cancel(1)
- timeout=30
- set_str_timeout()
- clear_plane()
- event.timer(1, function() check_timeout() end, 31)
- end
- },
- {
- visible=true,
- X=12.5,
- Y=40,
- W=15,
- H=3,
- color= 0x3324FF,
- textColor=0xFFFFFF,
- text = 'Login',
- action = function()
- computer.beep()
- clear_log()
- gpu.setForeground(0xFFFFFF)
- gpu.set(12.5,20,log_nickname)
- toggleVisible(3)
- toggleVisible(2)
- toggleVisible(4)
- toggleVisible(5)
- status = computer.addUser(log_nickname)
- event.timer(1,function() check_timeout() end, 31)
- end
- },
- {
- visible=true,
- X=12.5,
- Y=40,
- W=15,
- H=3,
- color=0x3324FF,
- textColor=0xFFFFFF,
- text='Unlogin',
- action = function()
- computer.beep()
- clear_plane()
- logOut()
- end
- },
- {
- visible = true,
- X = 12.5,
- Y = 30,
- W = 15,
- H = 3,
- color = 0x3324FF,
- textColor = 0xFFFFFF,
- text = 'Auction',
- action = function()
- computer.beep()
- event.cancel(1)
- timeout=30
- set_str_timeout()
- show_list()
- event.timer(1, function() check_timeout() end, 31)
- end
- }
- }
- function logOut()
- event.cancel(1)
- timeout=30
- clear_log()
- status=computer.removeUser(log_nickname)
- log_nickname=" "
- toggleVisible(4)
- toggleVisible(5)
- toggleVisible(3)
- toggleVisible(2)
- end
- function drawButton(n) -- функция рисования кнопки
- gpu.setBackground(tButtons[n].color) -- задаем цвет кнопки
- gpu.setForeground(tButtons[n].textColor) -- задаем цвет текста
- gpu.fill(tButtons[n].X, tButtons[n].Y, tButtons[n].W, tButtons[n].H, ' ') -- заливаем область
- gpu.set(tButtons[n].X+(tButtons[n].W/2)-(#tButtons[n].text/2), tButtons[n].Y+(tButtons[n].H/2), tButtons[n].text) -- пишем текст по центру
- end
- function toggleVisible(n) -- переключение видимости кнопки
- if tButtons[n].visible then -- если кнопка видима
- tButtons[n].visible = false -- отключаем
- gpu.setBackground(background_color) -- берем цвет фона, полученный при старте программы
- gpu.fill(tButtons[n].X, tButtons[n].Y, tButtons[n].W, tButtons[n].H, ' ') -- стираем кнопку
- else -- если кнопка не активна
- tButtons[n].visible = true -- активируем
- drawButton(n) -- запускаем отрисовку
- end
- end
- function blink(type,n) -- мигание кнопки
- if type==1 then
- tButtons[n].color, tButtons[n].textColor = tButtons[n].textColor, tButtons[n].color -- меняем местами цвета фона и текста
- drawButton(n) -- отрисовываем кнопку
- os.sleep(0.09) -- делаем задержку
- tButtons[n].color, tButtons[n].textColor = tButtons[n].textColor, tButtons[n].color -- меняем цвета обратно
- drawButton(n) -- перерисовываем кнопку
- else
- Slots[n].color, Slots[n].textColor = Slots[n].textColor, Slots[n].color -- меняем местами цвета фона и текста
- drawSlot(n) -- отрисовываем кнопку
- os.sleep(0.09) -- делаем задержку
- Slots[n].color, Slots[n].textColor = Slots[n].textColor, Slots[n].color -- меняем цвета обратно
- drawSlot(n) -- перерисовываем кнопку
- end
- end
- gpu.setBackground(background_color)
- gpu.setForeground(background_color)
- gpu.fill(1, 1, W, H, ' ') -- очищаем экран
- for i = 1, #tButtons do
- toggleVisible(i) -- активируем каждую кнопку
- end
- toggleVisible(3)
- gpu.setBackground(background_color)
- gpu.setForeground(0xFFFFFF)
- gpu.fill(1,1,W,1,'─') --горизонтальные черты
- gpu.fill(1,H,W,1,'─')
- gpu.set(W-30,H,"|-edited by SanyaRamzik-|") --подпись
- gpu.set(13,1,'|Warp LEGEND|')
- gpu.setForeground(0x66B6FF)
- gpu.set(5,45,'Таймаут, выход через: ')
- set_str_timeout()
- gpu.setBackground(background_color)
- for i=1,H do
- gpu.set(35,i,"│") --вертикальная черта
- end
- while true do
- local tEvent = {pull_e('touch')} -- ждем клика
- for i = 1, #tButtons do -- перебираем все кнопки
- if tButtons[i].visible then -- если кнопка активна
- if tEvent[3] >= tButtons[i].X and tEvent[3] <= tButtons[i].X+tButtons[i].W and tEvent[4] >= tButtons[i].Y and tEvent[4] <= tButtons[i].Y+tButtons[i].H then -- если клик произведен в пределах кнопки
- local usr={computer.users()}
- log_nickname=tostring(tEvent[6])
- if log_nickname==tostring(usr[1]) and tButtons[3].visible==false then
- blink(1,i) -- мигнуть кнопкой
- tButtons[i].action() -- выполнить назначенный код
- break
- elseif tButtons[3].visible==true then
- blink(1,i)
- tButtons[i].action()
- break
- end
- end
- end
- end
- for i = 1, #Slots do
- if tEvent[3] >= Slots[i].X and tEvent[3] <= Slots[i].X+Slots[i].W and tEvent[4] >= Slots[i].Y and tEvent[4] <= Slots[i].Y+Slots[i].H then
- local usr={computer.users()}
- log_nickname=tostring(tEvent[6])
- if log_nickname==tostring(usr[1]) then
- active_slot=i
- blink(2,i) -- мигнуть кнопкой
- Slots[i].action() -- выполнить назначенный код
- check_valide(Slots[i].Server,Slots[i].Seller,Slots[i].Slot,Slots[i].Slot_count,Slots[i].Price,Slots[i].Price_count)
- break
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment