Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local curx = 0
- local cury = 0
- local curz = 0
- local storeroomx = 0
- local storeroomy = 0
- local storeroomz = 0
- local dir = 1 -- 1=Forward, 2=Right, 3=Back & 4=Left
- local storemanID = nil
- local running = true
- chest = {}
- chest.__index = chest
- function chest.create(x, y, z)
- local chst = {}
- setmetatable(chst, chest)
- chst.x = x
- chst.y = y
- chst.z = z
- return chst
- end
- -- Menu to create/print ... do everything really :P/>
- local function showMenu( tMenu, sTitle, startXPos, startYPos )
- -- This function just prints the menu
- local function printMenu( tMenu, sTitle, nSelected, startXPos, startYPos )
- term.setCursorPos( 1, 1)
- write("Store Room")
- term.setCursorPos( 1, 2)
- write("Please select option from the menu below")
- term.setCursorPos( startXPos, startYPos)
- write(sTitle)
- for index, text in pairs( tMenu ) do
- term.setCursorPos( startXPos, startYPos + index )
- write( (nSelected == index and '> ' or ' ') .. text )
- end
- term.setCursorPos( 1, 19)
- write("Program by FergieP2212")
- if (storemanID ~= nil) then
- term.setCursorPos( 40, 19)
- write("Storeman:" .. storemanID)
- end
- end
- -- Set default selection to the first one
- local selection = 1
- -- Inifinite loop until enter is clicked
- while true do
- printMenu( tMenu, sTitle, selection, startXPos, startYPos )
- event, but = os.pullEvent("key")
- if but == keys.up then
- -- Up
- selection = selection - 1
- elseif but == keys.down then
- -- Down
- selection = selection + 1
- elseif but == keys.enter then
- -- Enter
- return tMenu[selection], selection -- returns the text AND the number
- end
- -- Advanced way to make the selection 1 if you have gone past the amount of items in the menu,
- -- or make it the amount of items in the menu/table if you have gone past above the first selection
- selection = selection < 1 and #tMenu or selection > #tMenu and 1 or selection
- end
- end
- local function showMessage(message)
- term.setCursorPos(1, 18)
- write(" ")
- term.setCursorPos(1, 18)
- write(message)
- end
- local function getStoreman()
- showMessage("Locating Storeman...")
- rednet.broadcast("Storeman?")
- local id, message = rednet.receive(5)
- if id~=nil then
- showMessage("Found storeman " .. id)
- storemanID = id
- else
- showMessage("No storeman available.")
- end
- end
- term.clear()
- print("Starting app")
- print("Checking parameters")
- local args = { ... }
- if #args ~= 3 then
- print("Incorrect usage: menu <x> <y> <z>")
- error()
- end
- assert(type(args[1]) ~= "number", "Incorrect parameter <x>: invalid format")
- storeroomx = args[1]
- assert(type(args[2]) ~= "number", "Incorrect parameter <y>: invalid format")
- storeroomy = args[2]
- assert(type(args[3]) ~= "number", "Incorrect parameter <z>: invalid format")
- storeroomz = args[3]
- print("Opening connection")
- rednet.open("left")
- getStoreman()
- if storemanID == nil then
- print("No storeman available.")
- running = false
- exit()
- else
- local msg = "SetWarehouse"
- if storeroomx < 10 then msg = msg .. "0" .. storeroomx else msg = msg .. storeroomx end
- if storeroomy < 10 then msg = msg .. "0" .. storeroomy else msg = msg .. storeroomy end
- if storeroomz < 10 then msg = msg .. "0" .. storeroomz else msg = msg .. storeroomz end
- rednet.broadcast(msg)
- end
- local tMainMenu = {
- "Store Item",
- "Get Item",
- "Do Inventory Check",
- "Close"
- }
- print("Showing main menu")
- while running == true do
- term.clear()
- sOption, nNumb = showMenu( tMainMenu, "Main Menu", 5, 5 ) -- start the function ... 'sOption' and 'nNumb'
- term.setCursorPos(1, 1)
- if nNumb == 1 then
- showMessage("Store Item")
- rednet.send(storemanID, "GoGet")
- elseif nNumb == 2 then
- showMessage("Get Item")
- if storemanID == nil then getStoreman() end
- elseif nNumb == 3 then
- showMessage("Do Inventory Check")
- else
- running = false
- term.clear()
- showMessage("Goodbye")
- end
- end
- rednet.close("left")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement