Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TradeOS
- local version = 0.51
- -- By: NuAoA
- -- Feel free to share/modify
- if not fs.exists("Draw") then print("Needs Draw api") end
- os.loadAPI("Draw")
- --[[
- TODO:
- - see !done
- - Add a check when trying to push items into a full player inventory to see if there is a stack
- Done:
- - Wraps all modem peripherals and exits if one is missing
- - Logs PIM location on startup (need to add name selection if multiple people in range)
- - creates settings file
- - loads settings file (if exists)
- - keeps currentPlayer up to date.
- ]]--
- ae_direction = "west"
- PimDir = "east"
- --[[
- Global Variables:
- ]]--
- currentPlayer = nil
- modem = {["exists"] = false, ["face"] = nil}
- monitor = {["exists"] = false, ["faces"] = nil}
- Admins = {} --Have unlimited currency.
- PIM_xyz = {}
- default_credits = nil
- --global_iList_ench = {}
- global_iList_IDs = {}
- global_iList_trades = {}
- player_iList_inv = {}
- player_iList = {}
- global_alt_names = {}
- validAddress = {}
- maxTrades = 15
- dontUpdate = false
- local notFirstBoot = true
- money_name = "Creddits" --ONLY CHANGE THIS IF NO PLAYERDATA IS PRESENT (AKA THE FIRST TIME YOU RUN THE PROGRAM)
- localSaves = false --Saves playerData locally, not recomended since CC has a 2mb limit, which would fill up pretty quick with 100+ players and 1000+ unique items.
- header_sel = {"deposit","withdraw","selling","buy"}
- header_current = "deposit"
- --[[
- PreDefined Usefulls:
- ]]--
- local directions = {"back","front","left","right","top","bottom"}
- local dir2 = {"up","down","east","west","south","north"}
- --[[
- error handling
- --]]
- function ERR(fun,mes,argz,bool)
- local file
- local prev = ""
- if fs.exists("debug.txt") then
- file = fs.open("debug.txt","r")
- prev = file.readAll()
- file.close()
- else
- prev = "TradeOS Debug File".."\n".."\n"
- end
- file = fs.open("debug.txt","w")
- file.write(prev.."\n")
- local str = ""
- if bool then
- str = " "..tostring(argz)
- end
- file.write("[ERROR]["..fun.."]".."["..os.day()..","..os.time().."]["..tostring(currentPlayer).."] "..mes..str)
- file.close()
- if terminate then
- print("Press Enter to restart...")
- io.read()
- os.reboot()
- else
- end
- end
- --Just a key to add to each screen that allows a quick reboot.
- function restart(key)
- if key == 41 then return true else return false end
- end
- --[[
- Making modem functions easier to call
- ]]--
- sensor = {}
- -- Functions:
- -- sensor.names()
- -- Returns a table of names of players in range of the sensor
- -- sensor.location(name[optional])
- -- Returns a table of the location of player [name] or the first player it finds
- function sensor.names()
- return modem.wrapped.callRemote(modem.sensor,"getPlayerNames")
- end
- function fixNames(item)
- if item == nil or item.id == nil or item.dmg == nil then ERR("fixNames","nil item ID or damage") end
- if type(item) == "string" then error("fixedNames, I was passed a string",2) end
- local unique = IDtoUnique(item.id,item.dmg)
- if global_alt_names[unique] ~= nil then
- return tostring(global_alt_names[unique])
- else
- return tostring(item.name)
- end
- end
- function sensor.location(...)
- local playername = nil
- local pass=false
- if #arg>0 then
- playername = arg[1]
- for k,v in pairs(sensor.names()) do
- if playername==v then
- pass = true
- break
- end
- end
- else
- playername = sensor.names()[1]
- pass = true
- end
- if pass then
- return modem.wrapped.callRemote(modem.sensor,"getPlayerData",playername)
- else
- ERR("sensor.location","Tried to look up location data on a player that does not exist")
- end
- end
- PIM = {}
- -- Functions:
- -- PIM.getAllStacks()
- -- Returns a table the currentPlayers inventory.
- -- PIM.
- function PIM.getAllStacks()
- return modem.wrapped.callRemote(modem.PIM,"getAllStacks")
- end
- --from chest to player
- function PIM.pullItem(slot,amount)
- return modem.wrapped.callRemote(modem.PIM,"pullItem",PimDir,slot,amount)
- end
- --from player to chest
- function PIM.pushItem(slot,amount)
- return modem.wrapped.callRemote(modem.PIM,"pushItem",PimDir,slot,amount)
- end
- --will dump all the items in the chest into the player inventory
- function PIM.dumpAll()
- for k,v in pairs(getChestData()) do
- PIM.pullItem(k,v.qty)
- end
- end
- function PIM.getFreeSlots()
- local tab = PIM.getAllStacks()
- local count = 4
- for k,v in pairs(tab) do
- if k<37 then
- count = count+1
- end
- end
- return modem.wrapped.callRemote(modem.PIM,"getInventorySize")-count
- end
- ae = {}
- -- Functions:
- -- ae.suckAll(...)
- -- sucks all items into chest, records them as currentPlayer's items or arg[1]
- -- ae.extractItem(item,qty)
- -- extracts a item from the ae network into a chest. item is default item table.
- function ae.suckAll(...)
- local name
- if #arg >0 then
- name = arg[1]
- else
- name = currentPlayer
- end
- local sum = 0
- if not string.match(tostring(modem.wrapped.callRemote(modem.interface,"canHoldNewItem")),"false") then --funky, but format might change down the line
- local tab = getChestData()
- if tab ~= nil then
- for k,v in pairs(tab) do
- modem.wrapped.callRemote(modem.interface,"insertItem",k,v.qty,ae_direction)
- updatePlayerTable(v,v.qty)
- sum = sum +v.qty
- end
- end
- else
- userInput("AE Inventory is full, please contact an admin/owner RIGHT MEOW, also talk to them about recovering your item") -- Doesnt work? item appears to dissappear.
- end
- save_player(name)
- return sum
- end
- --extracts item from AE network to chest. returnts true if qty of item is extracted, false if something went wrong.
- function ae.extractItem(item,qty)
- if qty <= 0 then return end
- local temp_tab = modem.wrapped.callRemote(modem.interface,"getAvailableItems")
- for index,item_ae in pairs(temp_tab) do
- if item_ae.id == item.id then
- if item_ae.dmg == item.dmg and item_ae.name == item.name then
- if compareEnchantments(item_ae,item) then --we found the item to extract
- if item_ae.qty >= qty then --enough items
- local extract_tab = deepcopy(item_ae) --Copy AE item incase of any odd NBT data
- extract_tab.qty = qty
- local extracted = modem.wrapped.callRemote(modem.interface,"extractItem",extract_tab,ae_direction)
- if extracted ~= qty then
- ERR("ae.extractItem","Wrong amount of items extracted from AE. Perhaps they were not found?")
- ERR("ae.extractItem","Attempted "..qty.." of "..fixNames(item).." got",extracted,true)
- return false
- end
- return true
- else
- ERR("ae.extractItem", "AE NETWORK IS MISSING ITEMS")
- ERR("ae.extractItem", "Item:",fixNames(item_ae),true)
- ERR("ae.extractItem", "Items in AE:",item_ae.qty,true)
- ERR("ae.extractItem", "Attempted:",qty,true)
- end
- else
- ERR("ae.extractItem","Ench check failed")
- end
- end
- end
- end
- ERR("ae.extractItem","Item not extracted! x"..qty,fixNames(item),true)
- return false
- --modem.wrapped.callRemote(modem.interface,"extractItem",test[1],ae_direction)
- end
- --gets the data from the chest under the computer
- function getChestData()
- local p = peripheral.wrap("bottom")
- p.condenseItems()
- local retTab = p.getAllStacks()
- --sometimes retTab is a number, tested this loop and found it runs only 3 times, so no idea whats going on.
- while type(retTab) ~= "table" do
- retTab = p.getAllStacks()
- end
- return deepcopy(retTab)
- end
- --add or remove items from the player_iList. if arg[1] is iList then dont change player_iList, just return change.
- function updatePlayerTable(item,amount,...)
- local temp_tab = deepcopy(item)
- local uniqueID = IDtoUnique(item.id,item.dmg)
- temp_tab.qty = amount
- local iList = {}
- if arg[1] ~= nil then iList = deepcopy(arg[1]) else iList = player_iList end
- if iList["items"] == nil then
- iList["items"] = {}
- end
- if iList["items"][uniqueID] == nil then
- local temp1 = {}
- local temp2 = {}
- table.insert(temp1,temp_tab)
- temp2[item.name] = temp1
- iList["items"][uniqueID] = deepcopy(temp2)
- elseif iList["items"][uniqueID][item.name] == nil then
- local temp1 = {}
- table.insert(temp1,temp_tab)
- iList["items"][uniqueID][item.name] = deepcopy(temp1)
- else
- local check,index = compareEnchantments(iList["items"],temp_tab)
- if not check then -- item not found
- table.insert(iList["items"][uniqueID][item.name],deepcopy(temp_tab))
- else
- --item exists
- if amount+iList["items"][uniqueID][item.name][index].qty < 0 then
- error("UpdatePlayerTable tried to remove more items than existed for that player!")
- else
- iList["items"][uniqueID][item.name][index].qty = iList["items"][uniqueID][item.name][index].qty+amount
- end
- end
- end
- if arg[1] ~= nil then return iList else player_iList = deepcopy(iList) end
- end
- --[[
- Setup
- ]]--
- function startup()
- -- find the modem
- for i=1,#directions do
- if peripheral.getType(directions[i]) == "modem" then
- modem["exists"] = true
- modem["face"] = directions[i]
- break
- end
- end
- modem.wrapped = peripheral.wrap(modem.face)
- modem.wrapped.open(0) --number is nessassary, but irrelvant?
- --for i,v in pairs(peripheral.getMethods(modem.face)) do print(i..". "..v) end
- local tab = modem.wrapped.getNamesRemote()
- for k,v in pairs(tab) do
- if string.match(v,"openperipheral_sensor") then
- modem.sensor = v
- --sensor.names = modem.wrapped.callRemote(modem.sensor,"getPlayerNames")
- elseif string.match(v,"pim_") then
- modem.PIM = v
- elseif string.match(v,"me_interface_") then
- modem.interface = v
- end
- end
- --check that we have all peripherals.
- if modem.sensor == nil then
- ERR("startup","Missing Sensor!",true)
- elseif modem.PIM == nil then
- ERR("startup","Missing PIM!",true)
- elseif modem.interface == nil then
- ERR("startup","Missing ME Interface!",true)
- end
- local temp_validAddress = {}
- rednet.open("back")
- local function one()
- rednet.broadcast("Ping")
- sleep(1)
- end
- local function two()
- while true do
- local ID,message = rednet.receive()
- if message == "Pong" then
- table.insert(temp_validAddress,ID)
- end
- end
- end
- parallel.waitForAny(one,two)
- if not localSave and #temp_validAddress == 0 then
- error("no computers to save to!")
- else
- table.sort(temp_validAddress)
- validAddress[1] = os.getComputerID()
- for i=1,#temp_validAddress do
- validAddress[i+1] = temp_validAddress[i]
- end
- end
- rednet.broadcast("ValidAddress "..textutils.serialize(validAddress))
- loadStuff()
- end
- function getPIMLocation()
- print()
- print("Need to log PIM location relative to sensor")
- print("Please stand on the PIM (get off first if you are already on it, or just jump)")
- while true do
- local event = os.pullEvent()
- if string.match(event,"player_on") then
- local name = sensor.names()[1]
- local x = math.floor(sensor.location()["position"]["x"])
- local y = math.floor(sensor.location()["position"]["y"])
- local z = math.floor(sensor.location()["position"]["z"])
- print(name.." is on PIM (x,y,z): "..x..","..y..","..z)
- print("Is the player name correct? (y/n)")
- local str = string.lower(io.read())
- if str == "yes" or str == "y" then
- print("PIM Position set")
- return x,y,z,name
- end
- end
- end
- end
- function firstBoot()
- notFirstBoot = false
- sleep(1)
- term.setCursorPos(1,1)
- term.clear()
- print("No settings file found, starting configuration")
- local x,y,z,name = getPIMLocation()
- print("Writing configuration file.")
- print(name.." Set as admin. Open settings.txt in computer "..os.computerID().." To make changes or add more")
- print("to log out press ctrl+~ and type in password")
- print("Opening settings.txt for review. close file to reboot")
- local file = fs.open("settings.txt","w")
- file.write("TradeHub Configuration File \n")
- file.write("Version: "..version.."\n")
- file.write("--------------------------------------------".."\n")
- file.write("Admins: "..name..",Notch".."\n")
- file.write("--Admins have unlimited credits, and can access logs".."\n")
- file.write("PIM_Position: "..x.." "..y.." "..z.."\n")
- file.write("--Leave this alone unless you know what you are doing".."\n")
- file.write("Default_Player_Credits: "..(1000).."\n")
- file.write("--The amount of credits each player starts with".."\n")
- file.write("Maximum_number_of_active_trades: "..(maxTrades).."\n")
- file.write("--The total amount of trades a player can have at the same time".."\n")
- file.close()
- sleep(4)
- shell.run("edit", "settings.txt")
- os.reboot()
- end
- --Called on startup
- function loadStuff()
- if not fs.exists("settings.txt") then
- firstBoot()
- end
- local efile = fs.open("settings.txt","r")
- if efile.readAll() ~= nil then
- efile:close()
- file = io.open("settings.txt","r")
- for line in file:lines() do
- if string.match(line,"Admins: .") then
- for name in string.gmatch(line,"%a+") do
- if name ~= "Admins" then
- table.insert(Admins,name)
- end
- end
- end
- if string.match(line,"PIM_Position: .") then
- PIM_xyz["x"] = tonumber(string.match(line,"PIM_Position: (%S+) %S+ %S+"))
- PIM_xyz["y"] = tonumber(string.match(line,"PIM_Position: %S+ (%S+) %S+"))
- PIM_xyz["z"] = tonumber(string.match(line,"PIM_Position: %S+ %S+ (%S+)"))
- end
- if string.match(line,"Default_Player_Credits: .") then
- default_credits = tonumber(string.match(line,"Default_Player_Credits: (%d+)"))
- end
- if string.match(line,"Maximum_number_of_active_trades:") then
- maxTrades = tonumber(string.match(line,"Maximum_number_of_active_trades: (%d+)"))
- end
- end
- file:close()
- end
- if fs.exists("Items.data") then
- local file = fs.open("Items.data","r")
- local temp_tab = textutils.unserialize(file.readAll())
- for uniqueID,u_tab in pairs(temp_tab) do
- for item_name,n_tab in pairs(u_tab) do
- for index,val in pairs(n_tab) do
- temp_tab[uniqueID][item_name][index]["name"] = item_name
- local id,dam = uniqueToID(uniqueID)
- temp_tab[uniqueID][item_name][index]["dmg"] = dam
- temp_tab[uniqueID][item_name][index]["id"] = id
- end
- end
- end
- global_iList_IDs = deepcopy(temp_tab)
- file.close()
- else
- local cred_temp = {}
- cred_temp["name"] = money_name
- cred_temp["id"] = 1
- cred_temp["dmg"] = 1
- cred_temp["maxSize"] = 1000000000
- cred_temp["ench"] = {}
- local tt = {}
- tt[1] = cred_temp
- local tt2 = {}
- tt2[money_name] = tt
- global_iList_IDs[IDtoUnique(1,1)] = deepcopy(tt2)
- end
- --Load Trade Data:
- for i=2,#validAddress do
- rednet.send(validAddress[i],"DataDump")
- while true do
- local ID,message = rednet.receive(2)
- if ID ~= validAddress[i] then
- -- bad computer sending data
- ERR("loadStuff","Wrong computer sent message. ID: "..tostring(ID).." message:",message,true)
- elseif message == "DataDump Finished" then break
- else
- local tab = textutils.unserialize(message)
- if tab.trades ~= nil then
- --Save trades to database
- --[[
- local found,index = compareEnchantments(global_iList_IDs,item)
- if not found then ERR("loadStuff","item not found in global list! name:",item.name,true) end
- local uniqueID = IDtoUnique(item.id,item.dmg)
- local tab1 = {}
- local tab2 = {}
- local tab3 = {}
- tab1[tab.name] = tab["trades"]
- tab2[index] = tab1
- tab3[item.name] = tab2
- if global_iList_trades[uniqueID] == nil then
- global_iList_trades[uniqueID] = deepcopy(tab3)
- elseif global_iList_trades[uniqueID][item.name] == nil then
- global_iList_trades[uniqueID][item.name] = deepcopy(tab2)
- elseif global_iList_trades[uniqueID][item.name][index] == nil then
- global_iList_trades[uniqueID][item.name][index] = deepcopy(tab1)
- elseif global_iList_trades[uniqueID][item.name][index][tab.name] == nil then
- global_iList_trades[uniqueID][item.name][index][tab.name] = deepcopy(player_iList["trades"])
- end
- ]]--
- if global_iList_trades[tab.name] ~= nil then ERR("loadStuff","Name already exists in database (save network has duplicates). Player:",tab.name,true) end
- global_iList_trades[tab.name] = deepcopy(tab.trades)
- end
- end
- end
- end
- local file = fs.open("itempanel.csv","r")
- global_alt_names = textutils.unserialize(file.readAll())
- file.close()
- end
- function save()
- local temp_tab = deepcopy(global_iList_IDs)
- local file = fs.open("Items.data","w")
- local iter = 0
- for uniqueID,u_tab in pairs(temp_tab) do
- for item_name,n_tab in pairs(u_tab) do
- for index,val in pairs(n_tab) do
- iter = iter+1
- temp_tab[uniqueID][item_name][index]["name"] = nil
- temp_tab[uniqueID][item_name][index]["dmg"] = nil
- temp_tab[uniqueID][item_name][index]["id"] = nil
- end
- end
- end
- file.write(textutils.serialize(temp_tab))
- file.close()
- end
- function save_player(name,...)
- if type(name) ~= "string" then
- error("[save_player] arg is not a string",2)
- end
- if name == "nilPlayer" then
- local function getLine() error("Line",3) end
- ERR("save_player","Attempted to save 'nilPlayer'")
- ERR("save_player","At the line",pcall(getLine))
- end
- if not fs.exists("PlayerData") and localSaves then
- fs.makeDir("PlayerData")
- end
- local temp_tab = {}
- if arg[1] == nil then
- temp_tab = deepcopy(player_iList)
- else
- temp_tab = deepcopy(arg[1])
- end
- --Convert from program table to one with zero redundancy. (get rid of ID,name, and rawname)
- -- seems setting the value to nil should do the trick
- for uniqueID,u_tab in pairs(temp_tab["items"]) do
- for item_name,n_tab in pairs(u_tab) do
- for index,val in pairs(n_tab) do
- temp_tab["items"][uniqueID][item_name][index]["name"] = nil
- temp_tab["items"][uniqueID][item_name][index]["dmg"] = nil
- temp_tab["items"][uniqueID][item_name][index]["rawName"] = nil
- temp_tab["items"][uniqueID][item_name][index]["id"] = nil
- temp_tab["items"][uniqueID][item_name][index]["maxSize"] = nil
- end
- end
- end
- if temp_tab["trades"] ~= nil then global_iList_trades[name] = deepcopy(temp_tab["trades"]) end
- --save to file
- if localSaves then
- --local str = string.gsub(name,"%s+","_")
- local str = name
- local file = fs.open("PlayerData/"..str,"w")
- file.write(textutils.serialize(temp_tab))
- file.close()
- else
- local function one()
- rednet.send(validAddress[2],"Save "..textutils.serialize(temp_tab))
- sleep(.1)
- end
- local function two()
- local id,mess = rednet.receive()
- if mess == "Saved" then return
- elseif mess == "NoSpace" then
- error("Not enough space to save!") --todo, remove
- localSave = true
- save_player(name,temp_tab)
- end
- end
- parallel.waitForAny(one,two)
- end
- sleep(0) -- needed to slow down multiple quick saves
- end
- function load_player(name,...)
- if name == nil and arg[1] then error("called load_player with nil name",2) end
- if name == nil or name == "" then
- player_iList["name"] = "nilPlayer"
- player_iList["items"] = {}
- player_iList["trades"] = {}
- player_iList[money_name] = default_credits
- return nil
- end
- --local str = string.gsub(name,"%s+","_")
- local temp_tab = {}
- local found_player = false
- if localSaves then
- local str = name
- if fs.exists("PlayerData") and fs.exists("PlayerData/"..str) then
- --fix table format.
- local file = fs.open("PlayerData/"..str,"r")
- temp_tab = textutils.unserialize(file.readAll())
- file.close()
- found_player = true
- end
- else
- local function one()
- rednet.broadcast("Load "..name)
- sleep(1)
- end
- local function two()
- local ID,message = rednet.receive()
- if ID ~= nil then
- found_player = true
- temp_tab = textutils.unserialize(message)
- end
- end
- parallel.waitForAny(two,one)
- if temp_tab == nil and found_player then error("Found player but did not recieve table") end
- end
- if not found_player then
- player_iList["name"] = name
- player_iList["items"] = {}
- player_iList["trades"] = {}
- player_iList[money_name] = default_credits
- if arg[1] ~= nil then error("trying to load a player who was not found "..name) end --todo: think about
- return
- end
- for uniqueID,u_tab in pairs(temp_tab["items"]) do
- for item_name,n_tab in pairs(u_tab) do
- for index,val in pairs(n_tab) do
- temp_tab["items"][uniqueID][item_name][index]["name"] = item_name
- local id,dam = uniqueToID(uniqueID)
- temp_tab["items"][uniqueID][item_name][index]["dmg"] = dam
- temp_tab["items"][uniqueID][item_name][index]["id"] = id
- local temp_itemTab = getItemTable(temp_tab["items"][uniqueID][item_name][index])
- --temp_tab["items"][uniqueID][item_name][index]["rawName"] = temp_itemTab.rawName
- temp_tab["items"][uniqueID][item_name][index]["maxSize"] = temp_itemTab.maxSize
- end
- end
- end
- if not arg[1] then
- player_iList = deepcopy(temp_tab)
- else
- return temp_tab
- end
- end
- --[[
- Utility
- ]]--
- -- will hunt global_iList_IDs for a item
- -- takes in a partial item table (only ID,Dam,name)
- function getItemTable(partial_itemTab)
- local found,tab = compareEnchantments(global_iList_IDs,partial_itemTab,true)
- if not found then
- --throw a error? could easily check elsewhere
- else
- return tab
- end
- end
- --Converts a unique identifer to an item/damage value
- function uniqueToID(unique,...)
- if type(unique) ~= "number" or unique == nil then
- if unique == nil then error("[uniqueToID] nil passed to function!",2) end
- error("[uniqueToID] invalid type passed to function! "..type(unique),2)
- end
- local Dam = math.floor(unique/2^15)
- local ID = unique%(2^15)
- if arg[1] then return ID..":"..Dam else return ID,Dam end
- end
- -- converts a ID,dam to a unique number
- function IDtoUnique(ID,...)
- if type(ID) == "string" then
- if string.match(ID,"%d+:%d+") then
- return tonumber(string.match(ID,"(%d+):%d+")) +(2^15)*tonumber(string.match(ID,"%d+:(%d+)"))
- else
- error("[IDtoUnique] Invalid string passed to function. "..ID,2)
- end
- elseif ID == nil or arg[1] == nil then
- term.clear()
- print(ID)
- print(arg[1])
- error("[IDtoUnique] Invalid arguments passed to function.",2)
- else
- return ID+arg[1]*2^15
- end
- end
- --shortens a string to str..".." if its longer than len, else does nothing
- function ss(str,len)
- if str == nil then
- ERR("ss","str is nil")
- return "nil"
- end
- if string.len(str) > len then
- return string.sub(item_name,0,len-3)..".."
- else
- return str
- end
- end
- -- Makes a copy of a table
- function deepcopy(orig)
- local orig_type = type(orig)
- local copy
- if orig_type == 'table' then
- copy = {}
- for orig_key, orig_value in next, orig, nil do
- copy[deepcopy(orig_key)] = deepcopy(orig_value)
- end
- setmetatable(copy, deepcopy(getmetatable(orig)))
- else -- number, string, boolean, etc
- copy = orig
- end
- return copy
- end
- --don't change the current player if dontUpdate
- function modifyCurrentPlayer(newPlayer)
- while dontUpdate do
- sleep(0)
- end
- --if currentPlayer ~= nil then save_player(currentPlayer) end --Removed becuase it shouldnt ever be nessassary. Changes are saved instantly
- currentPlayer = newPlayer
- load_player(currentPlayer)
- end
- -- Will update the currentPlayer Variable based on the player at the location of the PIM when it is stepped on.
- function updateCurrentPlayer()
- local function getPlayer()
- local player_list = sensor.names()
- if player_list[1] == nil then return nil end
- if #player_list == 0 then return nil end
- local player_name = player_list[1]
- if #player_list > 1 then
- for i=1,#player_list do
- if math.floor(sensor.location(player_list[i])["position"]["x"]) == PIM_xyz["x"]
- and math.floor(sensor.location(player_list[i])["position"]["y"]) == PIM_xyz["y"]
- and math.floor(sensor.location(player_list[i])["position"]["z"]) == PIM_xyz["z"] then
- player_name = player_list[i]
- break
- end
- end
- end
- return player_name
- end
- local onboot = getPlayer()
- if onboot ~= nil then
- modifyCurrentPlayer(onboot)
- os.queueEvent("updatePlayer")
- --load_player(currentPlayer)
- end
- while true do
- local event = os.pullEvent()
- if event == "player_on" then
- modifyCurrentPlayer(getPlayer())
- os.queueEvent("updatePlayer")
- --if currentPlayer ~= nil then load_player(currentPlayer) end
- elseif event == "player_off" then
- --if currentPlayer ~= nil then ae.suckAll() end
- modifyCurrentPlayer(nil)
- os.queueEvent("updatePlayer")
- end
- end
- end
- -- will interate over a item table of the format table[uniqueID][name][#] = item_table and return the next item_table and enchantment index [#]
- -- do not call this with a empty table, or you will crash.
- function tableIter(tabl)
- if type(tabl) ~= "table" or tabl == nil then
- term.clear()
- print("caught it")
- return function () return nil,nil end
- end
- local done = false
- local tab = tabl --deepcopy(tabl)
- local uniqueID_key = next(tab,nil)
- local u,n,e
- local name_key
- local ench_key
- --Some odd formatting to prevent crashing:
- if type(tabl) ~= "table" then error("[tableIter] arg1 is not a table? "..type(tabl),2) end
- if uniqueID_key == nil then done=true else
- if type(tab[uniqueID_key]) ~= "table" then error("[tableIter] arg1 is not a table? "..type(tabl),2) end
- name_key = next(tab[uniqueID_key],nil)
- if name_key == nil then done=true else
- if type(tab[uniqueID_key][name_key]) ~= "table" then error("[tableIter] arg1 is not a table? "..type(tabl),2) end
- ench_key = next(tab[uniqueID_key][name_key],nil)
- if ench_key == nil then done=true end
- end
- end
- return function ()
- if done then return nil,nil end --nil,xxx
- local ret = tab[uniqueID_key][name_key][ench_key]
- local ret_ench_key = ench_key
- ench_key,e = next(tab[uniqueID_key][name_key],ench_key)
- while ench_key == nil do
- name_key,n = next(tab[uniqueID_key],name_key)
- while name_key == nil do
- uniqueID_key,u = next(tab,uniqueID_key)
- if uniqueID_key == nil then
- done = true
- return ret,ret_ench_key
- end
- name_key,n = next(tab[uniqueID_key],name_key)
- end
- ench_key,e = next(tab[uniqueID_key][name_key],ench_key)
- end
- return ret,ret_ench_key
- end
- end
- --stri = search string
- --list = ?
- -- ... = ?
- --returns list[i]=item_table,total found. where list is sorted by the difference in length of str and the item_name/ID
- function search(stri,list,...)
- local str = string.lower(stri)
- local found_list = {}
- local iter = 0
- local search_list = list --TODO: try without deepcopy()
- local function addItem(ind1,inqid,ky,val)
- if val.ench ~= nil and #val.ench>0 then ind1 = ind1 +1 end --give priority to non enchanted items, could be improved.
- local l_temp = found_list[ind1]
- local l_temp1 = {}
- local l_temp2 = {}
- local l_temp3 = {}
- l_temp3[ky] = val
- l_temp2[val.name] = l_temp3
- --l_temp1[unqid] = l_temp2
- if found_list[ind1] == nil then
- l_temp = {}
- l_temp[inqid] = l_temp2
- found_list[ind1] = l_temp
- elseif found_list[ind1][inqid] == nil then
- found_list[ind1][inqid] = l_temp2
- elseif found_list[ind1][inqid][val.name] == nil then
- found_list[ind1][inqid][val.name] = l_temp3
- else
- local l_temp4 = found_list[ind1][inqid][val.name]
- l_temp4[ky] = val
- found_list[ind1][inqid][val.name] = deepcopy(l_temp4)
- end
- iter = iter+1
- end
- if search_list ~= nil then
- if string.match(str,":") then --ID:Dam
- for item,key in tableIter(search_list) do
- local uniqueID = IDtoUnique(item.id,item.dmg)
- local k = item.id
- local n = item.dmg
- if string.match(k..":"..n,str) then
- addItem((string.len(k..":"..n)-#str)+1,uniqueID,key,search_list[uniqueID][item.name][key])
- end
- end
- elseif string.match(str,"%S") or string.match(str,"%s") then -- char
- for item,key in tableIter(search_list) do
- local uniqueID = IDtoUnique(item.id,item.dmg)
- if string.match(string.lower(fixNames(item)),str) then
- addItem((string.len(item.name)-#str)+1,uniqueID,key,search_list[uniqueID][item.name][key])
- end
- end
- else --just ID
- for item,key in tableIter(search_list) do
- local uniqueID = IDtoUnique(item.id,item.dmg)
- local k = item.id
- if string.match(k,str) then
- addItem((string.len(k)-#str)+1,uniqueID,key,search_list[uniqueID][item.name][key])
- end
- end
- end
- --[[
- for item,key in tableIter(search_list) do
- local uniqueID = IDtoUnique(item.id,item.dmg)
- local k = item.id
- local n = item.dmg
- if string.match(string.lower(item.name),str) then
- addItem((string.len(item.name)-#str)+1,uniqueID,key,search_list[uniqueID][item.name][key])
- elseif string.match(k,str) then
- addItem((string.len(k)-#str)+1,uniqueID,key,search_list[uniqueID][item.name][key])
- elseif string.match(k..":"..n,str) and search_list[uniqueID][item.name][key] ~= nil then
- addItem((string.len(k..":"..n)-#str)+1,uniqueID,key,search_list[uniqueID][item.name][key])
- end
- end
- ]]--
- end
- if #arg > 0 and arg[1] then --TODO
- for i=1,20 do
- if found_list[i] ~= nil then
- for k,v in pairs(found_list[i]) do
- return k,iter
- end
- end
- end
- --[[
- for k,v in pairs(found_list) do
- for n,m in pairs(v) do
- return n,iter
- end
- end
- ]]--
- return false,iter
- else
- return found_list,iter
- end
- end
- function draw1(list,total)
- local maxID = 12
- for l=0,40 do
- term.setCursorPos(1,9+l)
- term.clearLine()
- end
- term.setCursorPos(1,1)
- term.write("Total: "..total.." ")
- if total < 1 then
- sleep(0)
- else
- local iter =0
- for i=1,40 do
- if list[i] ~= nil then
- for items in tableIter(list[i]) do
- term.setCursorPos(1,9+iter)
- term.write("("..items.id..":"..items.dmg..")")
- term.setCursorPos(maxID+1,9+iter)
- term.write(fixNames(items))
- iter=iter+1
- end
- end
- if iter > 40 then break end
- end
- end
- end
- function cleanInput(curr_message,...)
- local event,param1,param2,param3,param4,param5
- local function char()
- event,param1,param2,param3,param4,param5 = os.pullEventRaw("char")
- end
- local function key()
- event,param1,param2,param3,param4,param5 = os.pullEventRaw("key")
- sleep(0) -- needed to make 'char' events win over 'key'
- end
- if arg[1] then term.write(curr_message) end
- parallel.waitForAny(key,char)
- return event,param1,param2,param3,param4,param5
- end
- function getCleanInputAt(x,y,...)
- local maxLen = 40
- local message = ""
- local display = true
- if type(arg[1]) == "boolean" then display = arg[1]
- elseif arg[1] ~= nil and type(arg[1]) ~= "string" then maxLen = arg[1] end
- if arg[2] ~= nil and type(arg[2]) == "string" then message = arg[2] end
- while true do
- if display then
- term.setCursorPos(x,y)
- for i=1,maxLen do
- term.write(" ")
- end
- term.setCursorPos(x,y)
- end
- local event,p1,p2 = cleanInput(message,display)
- if event == "char" then
- if string.len(message) < maxLen then
- if display then term.write(p1) end
- message = message..p1
- os.queueEvent("typing",message,string.len(message))
- end
- elseif event == "key" then
- if p1 == 14 then --backspace
- message = string.sub(message,0,string.len(message)-1)
- os.queueEvent("typing",message,string.len(message))
- elseif p1 == 28 then -- enter
- break
- end
- end
- end
- return message
- end
- --for now just use search as searchFunc
- --drawFunc needs args in format (Returnedlist,total found)
- -- arg[1] == last string to search
- function textSearch(x,y,drawFunc,searchFunc,...)
- local notDone = true
- local final = ""
- local itemList = {}
- local totalFound = 0
- local click = 1
- if arg[1] then error("is used") end --TODO
- local function messageListener()
- drawFunc(itemList,0,nil)
- while notDone do
- local event, message, len = os.pullEventRaw("typing")
- final = message
- if message ~= nil then
- if len>0 then
- itemList,totalFound = searchFunc(message,global_iList_IDs)
- drawFunc(itemList,totalFound,message)
- else
- totalFound = 0
- itemList = {}
- drawFunc(itemList,0)
- end
- end
- end
- end
- local function messageListener()
- drawFunc(itemList,0,nil)
- local event, message, len
- local function getEvent()
- event, message, len = os.pullEventRaw("typing")
- end
- local function getEvent2()
- local event2 = os.pullEventRaw("updateNotDone")
- sleep(0.1)
- end
- local function parallelSearch()
- final = message
- if message ~= nil then
- if len>0 then
- itemList,totalFound = searchFunc(message,global_iList_IDs)
- drawFunc(itemList,totalFound,message)
- else
- totalFound = 0
- itemList = {}
- drawFunc(itemList,0)
- end
- end
- while true do sleep(10000) end -- hang until next typing event.
- end
- while notDone do
- parallel.waitForAny(getEvent,parallelSearch,getEvent2)
- end
- end
- local function getText()
- getCleanInputAt(x,y,false)
- notDone = false
- os.queueEvent("updateNotDone")
- end
- local function getClick()
- while true do
- local event,key,xpos,ypos = os.pullEventRaw("mouse_click")
- if ypos> 5 then
- if totalFound >= ypos-5 then
- click = ypos-5
- break
- end
- elseif ypos == 1 then
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- end
- end
- parallel.waitForAny(messageListener,getText,getClick)
- for i=1,100 do
- for item in tableIter(itemList[i]) do
- click = click - 1
- if click <= 0 then
- return item,totalFound
- end
- end
- end
- end
- function testSearch()
- print("start search")
- while true do
- local func = draw1
- textSearch(1,7,func,search)
- sleep(2)
- end
- end
- --[[
- Program
- ]]--
- -- return true if 'item' exists in tab, false if not.
- -- also handles (item,item) compairson.
- --returns boolean,index#(if tab is a standard item list -> table[uniqueID][name][index#] = item table)
- -- if arg[1] then return item table in format boolean,item table/nil if item is not found.
- function compareEnchantments(tab,item,...)
- local unique = IDtoUnique(item.id,item.dmg)
- if tab[unique] == nil then --either bad format or tab is just a item.
- if tab.name ~= nil then --item
- if item.ench == nil or #item.ench == 0 then
- if tab.ench == nil or #tab.ench == 0 then
- return true,nil
- end
- elseif tab.ench == nil or #tab.ench == 0 then
- --nothing, just a check to prevent errors in else
- else
- local match = true
- if #item.ench == #item_tab.ench then
- for key,ench in pairs(item.ench) do
- local pass = false
- for key2,ench2 in pairs(tab.ench) do
- if ench == ench2 then
- pass = true
- break
- end
- end
- if not pass then
- match = false
- break
- end
- end
- if match then return true,nil end
- end
- end
- return false,nil
- else
- --if tab[unique][item.name] == nil then
- error("[compareEnchantments] Item doesn't exist, how do you expect me to check it?",2)
- end
- end
- if tab == nil or tab[unique] == nil or tab[unique][item.name] == nil then
- ERR("compareEnchantments","nil table found")
- ERR("compareEnchantments","item name:",fixNames(item),true)
- error("function is going to crash (nil table)",3)
- end
- for index,item_tab in pairs(tab[unique][item.name]) do
- if item.ench == nil or #item.ench == 0 then
- if item_tab.ench == nil or #item_tab.ench == 0 then
- if arg[1] then return true,deepcopy(item_tab) else return true,index end
- end
- elseif item_tab.ench == nil or #item_tab.ench == 0 then
- --nothing, just a check to prevent errors in else
- else
- local match = true
- if #item.ench == #item_tab.ench then
- for key,ench in pairs(item.ench) do
- local pass = false
- for key2,ench2 in pairs(item_tab.ench) do
- if ench == ench2 then
- pass = true
- break
- end
- end
- if not pass then
- match = false
- break
- end
- end
- if match then
- if arg[1] then return true,deepcopy(item_tab) else return true,index end
- end
- end
- end
- end
- return false,nil
- end
- -- Read the player inventory. Learns item names/IDs/enchantments and creates a table of the players inventory
- function readInventory()
- if currentPlayer == nil then
- ERR("readInventory","there is no current player yet this function was called.",false)
- error("IM THE BITCH WHO CALLED THIS FUNCTION",2)
- return
- end
- dontUpdate = true
- local inv = PIM.getAllStacks()
- if type(inv) ~= "table" then --glitch
- dontUpdate = false
- return
- end
- local need_save = false
- local debug_count = 0 --todo: cleanup
- player_iList_inv = {} -- clear inventory
- for k,v in pairs(inv) do
- if v.ench ~= nil and #v["ench"] == 0 then v["ench"] = deepcopy(v.ench) end -- needed for serialization
- --playerslot = k
- if v.electric == nil then --electric items can't be extracted. (problem with openP)
- local temp_tab = {}
- temp_tab.name = v.name
- temp_tab.id = v.id
- temp_tab.dmg = v.dmg
- --temp_tab.rawName = v.rawName
- temp_tab.maxSize = v.maxSize
- temp_tab.ench = v.ench
- temp_tab.qty = v.qty
- -- log player inventory.
- local uniqueID = IDtoUnique(v.id,v.dmg)
- if k<37 then -- 37-40 are armor slots
- if player_iList_inv[uniqueID] == nil then
- local temp1 = {}
- local temp2 = {}
- table.insert(temp1,temp_tab)
- temp2[v.name] = temp1
- player_iList_inv[uniqueID] = deepcopy(temp2)
- elseif player_iList_inv[uniqueID][v.name] == nil then
- --local temp1 = {}
- --table.insert(temp1,temp_tab)
- player_iList_inv[uniqueID][v.name] = {}
- player_iList_inv[uniqueID][v.name][1] = deepcopy(temp_tab)
- else
- local check,index = compareEnchantments(player_iList_inv,temp_tab)
- if check then -- item already found
- player_iList_inv[uniqueID][v.name][index].qty = player_iList_inv[uniqueID][v.name][index].qty+v.qty
- else
- table.insert(player_iList_inv[uniqueID][v.name],deepcopy(temp_tab))
- end
- end
- end
- temp_tab.qty = nil
- if global_iList_IDs[uniqueID] == nil then
- local temp1 = {}
- local temp2 = {}
- table.insert(temp1,temp_tab)
- temp2[v.name] = temp1
- global_iList_IDs[uniqueID] = deepcopy(temp2)
- need_save = true
- elseif global_iList_IDs[uniqueID][v.name] == nil then
- --local temp1 = {}
- --table.insert(temp1,temp_tab)
- global_iList_IDs[uniqueID][v.name] = {}
- global_iList_IDs[uniqueID][v.name][1] = deepcopy(temp_tab)
- need_save = true
- else
- local check,index = compareEnchantments(global_iList_IDs,temp_tab)
- if not check then -- item not found
- table.insert(global_iList_IDs[uniqueID][v.name],deepcopy(temp_tab))
- need_save = true
- elseif global_iList_IDs[uniqueID][v.name][index]["maxSize"] == nil then
- global_iList_IDs[uniqueID][v.name][index]["maxSize"] = temp_tab.maxSize
- need_save = true
- end
- end
- end
- end
- if need_save then save() end
- --term.setCursorPos(1,1)
- --print(debug_count.." New") --todo: cleanup
- dontUpdate = false
- end
- --[[
- Display
- ]]--
- --Changes a list from ilist[ID][Dam] to ilist[#] = {}
- function index_list(ilist)
- local ret_list = {}
- for val in tableIter(ilist) do
- if val.qty ~= 0 then
- local temp = val
- temp["IDdam"] = val.id..":"..val.dmg
- table.insert(ret_list,temp)
- end
- end
- return deepcopy(ret_list)
- end
- function getShortEnch(ench)
- local ret = ""
- for word in string.gmatch(ench,"%S+") do
- local firstChar=string.sub(word,1,1)
- if firstChar == "I" or firstChar == "V" then
- return ret..":"..word
- elseif word == "Power" then
- ret = "Po"
- elseif word == "Punch" then
- ret = "Pu"
- else
- ret = ret..firstChar
- end
- end
- error("you should never get here!")
- end
- --Displays the players current inventory and allows for items to be deposited into the network.
- function draw_deposit(index)
- local player_ilist_temp = index_list(player_iList_inv)
- if #player_ilist_temp == 0 then
- draw_header("deposit")
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,3,7," You have no items in your inventory to deposit",colors.black)
- Draw.tt(tt,3,8," try bringing some items next time!",colors.black)
- Draw.draw(term,tc,1,4,2^15,tt)
- return {},2
- else
- --[[
- Setting up item list
- --]]
- local item_c,item_t = Draw.emptyScreen(term,50,#player_ilist_temp*2+16)--+2)
- local switch_bg = true
- if index%2 == 1 then
- -- switch_bg = false
- end
- for i=1,#player_ilist_temp do
- local bg_
- if switch_bg then
- bg_ = colors.blue
- switch_bg = false
- else
- bg_ = colors.lightBlue
- switch_bg = true
- end
- local item_name = fixNames(player_ilist_temp[i])
- --item_name = "12345678901234567890123456789012345678901234567890"
- if string.len(item_name) > 43 then
- item_name = string.sub(item_name,0,40)..".."
- end
- Draw.tc(item_c,1,2*i-1,bg_,50,2*i)
- Draw.tt(item_t,1,2*i-1," &"..Draw.getHexOf(colors.yellow)..item_name.."&"..Draw.getHexOf(colors.red).." x"..player_ilist_temp[i].qty)
- local ench_str = ""
- if player_ilist_temp[i].ench ~= nil and #player_ilist_temp[i].ench >0 then
- ench_str = "&"..Draw.getHexOf(colors.red).."Ench: "
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#player_ilist_temp[i].ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(player_ilist_temp[i].ench[k]).." "
- end
- end
- Draw.tt(item_t,1,2*i," &"..Draw.getHexOf(colors.brown).."("..player_ilist_temp[i].IDdam..") "..ench_str)
- Draw.tt(item_t,41,2*i," &"..Draw.getHexOf(colors.white).." Deposit ")
- Draw.tc(item_c,41,2*i,colors.lime,50,2*i)
- end
- --[[
- Setting up scroll bar
- --]]
- local bar_c,bar_t = Draw.emptyScreen(term,1,16)
- Draw.tc(bar_c,1,1,colors.gray,1,16)
- Draw.tc(bar_c,1,1,colors.lightGray)
- Draw.tt(bar_t,1,1,"^")
- Draw.tc(bar_c,1,16,colors.lightGray)
- Draw.tt(bar_t,1,16,"v")
- local scroll_pos = 2
- if #player_ilist_temp > 8 then
- scroll_pos = math.floor(2+13*((index)/(#player_ilist_temp-8)))
- if scroll_pos > 15 then scroll_pos = 15 end
- end
- Draw.tc(bar_c,1,scroll_pos,colors.purple)
- Draw.draw(term,bar_c,1,4,2^15,bar_t)
- local item_c_f = {}
- local item_t_f = {}
- for i=(index*2+1),#item_c do --player_ilist_temp*2 do
- table.insert(item_c_f,item_c[i])
- table.insert(item_t_f,item_t[i])
- --item_c_f[i-(index*2+1)] = item_c[i]
- --item_t_f[i-(index*2+1)] = item_t[i]
- end
- Draw.draw(term,item_c_f,2,4,2^15,item_t_f)
- draw_header("deposit")
- return player_ilist_temp,scroll_pos
- end
- end
- --takes in a table for that item and transfers amount to the ae network
- function deposit(item,amount)
- --AE:
- --insertItem(slot...,amount...,direction...)
- --extractItem(stack...,direction...)
- local ID = tonumber(string.match(item.IDdam,"(%d+):%d+"))
- local dam = tonumber(string.match(item.IDdam,"%d+:(%d+)"))
- local amount_dep = 0
- please_wait()
- --scan player inventory for items
- dontUpdate = true
- local inv = PIM.getAllStacks()
- function depositItems()
- while amount_dep ~= amount do
- for slot,v in pairs(inv) do
- if v.name == item.name and v.id == ID and v.dmg == dam then -- surely this will locate the item.
- if (amount-amount_dep) > v.maxSize or (amount-amount_dep) > v.qty then
- --PIM.pullItem(slot,v.qty)
- PIM.pushItem(slot,v.qty)
- amount_dep = amount_dep + v.qty
- else
- --PIM.pullItem(slot,(amount-amount_dep))
- PIM.pushItem(slot,(amount-amount_dep))
- amount_dep = amount
- end
- end
- if amount_dep == amount then break end
- end
- --gets here after full inventory scan.
- if amount_dep < 0 or amount-amount_dep < 0 then
- ERR("deposit"," amount_dep less than zero!",amount_dep,true)
- break
- elseif amount-amount_dep>0 then
- userInput("not enough items were found, only "..(amount_dep).." were transfered")
- break
- end
- end
- end
- function watchPlayerExit()
- local event = os.pullEvent("player_off")
- end
- parallel.waitForAny(depositItems,watchPlayerExit)
- if ae.suckAll() ~= amount_dep then
- ERR("deposit","mismatch in item intake -> items taken from inventory != items moved to AE network")
- ERR("deposit"," -> Item:",fixNames(item),true)
- ERR("deposit"," -> Amount:",amount,true)
- end
- dontUpdate = false
- return amount-amount_dep
- end
- function display_deposit()
- local index = 0
- local amount = 0
- if currentPlayer ~= nil then readInventory() end
- while currentPlayer ~= nil and header_current == header_sel[1] do
- local list_temp,scroll_pos = draw_deposit(index)
- while true do
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if (xpos == 1 and #list_temp > 8) then --Scroll
- if ypos < scroll_pos+3 and index > 0 then
- index = index - 1
- elseif ypos > scroll_pos+3 and index < #list_temp -8 then
- index = index +1
- end
- break
- elseif xpos>40 and ypos%2 == 1 and (index+(ypos-3)/2) <= #list_temp then
- amount = math.abs(userInput("How much '"..fixNames(list_temp[index+(ypos-3)/2]).."' would you like to deposit?","number",list_temp[index+(ypos-3)/2].qty))
- if amount>list_temp[(ypos-3)/2].qty then
- --DEPOSIT ITEM
- userInput("You are trying to deposit more items than your inventory currently holds, depositing the maximum amount ("..list_temp[index+(ypos-3)/2].qty..") instead.")
- amount = list_temp[index+(ypos-3)/2].qty
- end
- deposit(list_temp[index+(ypos-3)/2],amount)
- term.clear()
- readInventory()
- break
- end
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if (key == 200 or key == 17) and index > 0 then
- index = index -1
- break
- elseif (key == 208 or key ==31) and index < #list_temp -8 then
- index = index +1
- break
- elseif restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- end
- function draw_withdraw(index)
- local player_ilist_temp = index_list(player_iList["items"])
- local tc1,tt1 = Draw.emptyScreen(term,3,1)
- Draw.tc(tc1,1,1,colors.lime,4,1)
- Draw.tt(tt1,1,1,"Sell",colors.black)
- --Draw.draw(term,tc1,3,string.len(money_name..": "..player_iList[money_name],colors.black)+1,2^15,tt1)
- if #player_ilist_temp == 0 then
- draw_header("withdraw")
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,3,7," You need to deposit or purchase items before you will ",colors.black)
- Draw.tt(tt,3,8," have any items to withdraw/sell",colors.black)
- Draw.draw(term,tc,1,4,2^15,tt)
- return {},2
- else
- --[[
- Setting up item list
- --]]
- local item_c,item_t = Draw.emptyScreen(term,50,#player_ilist_temp*2+16)--+2)
- local switch_bg = true
- if index%2 == 1 then
- -- switch_bg = false
- end
- for i=1,#player_ilist_temp do
- local bg_
- if switch_bg then
- bg_ = colors.blue
- switch_bg = false
- else
- bg_ = colors.lightBlue
- switch_bg = true
- end
- local item_name = fixNames(player_ilist_temp[i])
- --item_name = "12345678901234567890123456789012345678901234567890"
- if string.len(item_name) > 43 then
- item_name = string.sub(item_name,0,40)..".."
- end
- Draw.tc(item_c,1,2*i-1,bg_,50,2*i)
- Draw.tt(item_t,1,2*i-1," &"..Draw.getHexOf(colors.yellow)..item_name.."&"..Draw.getHexOf(colors.red).." x"..player_ilist_temp[i].qty)
- local ench_str = ""
- if player_ilist_temp[i].ench ~= nil and #player_ilist_temp[i].ench >0 then
- ench_str = "&"..Draw.getHexOf(colors.red).."Ench: "
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#player_ilist_temp[i].ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(player_ilist_temp[i].ench[k]).." "
- end
- end
- Draw.tt(item_t,1,2*i," &"..Draw.getHexOf(colors.brown).."("..player_ilist_temp[i].IDdam..") "..ench_str)
- Draw.tt(item_t,44,2*i-1," &"..Draw.getHexOf(colors.black).." Sell ")
- Draw.tc(item_c,44,2*i-1,colors.lime,50,2*i)
- Draw.tt(item_t,41,2*i," &"..Draw.getHexOf(colors.white).." Withdraw ")
- Draw.tc(item_c,41,2*i,colors.gray,50,2*i)
- end
- --[[
- Setting up scroll bar
- --]]
- local bar_c,bar_t = Draw.emptyScreen(term,1,16)
- Draw.tc(bar_c,1,1,colors.gray,1,16)
- Draw.tc(bar_c,1,1,colors.lightGray)
- Draw.tt(bar_t,1,1,"^")
- Draw.tc(bar_c,1,16,colors.lightGray)
- Draw.tt(bar_t,1,16,"v")
- local scroll_pos = 2
- if #player_ilist_temp > 8 then
- scroll_pos = math.floor(2+13*((index)/(#player_ilist_temp-8)))
- end
- Draw.tc(bar_c,1,scroll_pos,colors.purple)
- Draw.draw(term,bar_c,1,4,2^15,bar_t)
- local item_c_f = {}
- local item_t_f = {}
- for i=(index*2+1),#item_t do --#player_ilist_temp*2 do
- table.insert(item_c_f,item_c[i])
- table.insert(item_t_f,item_t[i])
- --item_c_f[i-(index*2+1)] = item_c[i]
- --item_t_f[i-(index*2+1)] = item_t[i]
- end
- Draw.draw(term,item_c_f,2,4,2^15,item_t_f)
- draw_header("withdraw")
- Draw.draw(term,tc1,string.len(money_name..": "..player_iList[money_name],colors.black)+1,3,2^15,tt1)
- return player_ilist_temp,scroll_pos
- end
- end
- function withdraw(item,amount)
- --AE:
- --insertItem(slot...,amount...,direction...)
- --extractItem(stack...,direction...)
- if amount <=0 then return end
- please_wait()
- local ID = tonumber(string.match(item.IDdam,"(%d+):%d+"))
- local dam = tonumber(string.match(item.IDdam,"%d+:(%d+)"))
- local amount_wd = 0
- --scan player inventory for items
- dontUpdate = true
- local count = 0
- local extracted = true
- for i=1,math.floor(amount/item.maxSize) do
- count = count+1
- end
- count = count + amount%item.maxSize
- for i=1,math.floor(amount/item.maxSize) do
- if not ae.extractItem(item,item.maxSize) then extracted = false end
- end
- if amount%item.maxSize ~= 0 then
- if not ae.extractItem(item,amount%item.maxSize) then extracted = false end
- end
- if not extracted then --need to count the amount that was extracted.
- local sum =0
- for k,v in pairs(getChestData()) do
- sum = sum + v.qty
- end
- if sum>0 then
- ERR("withdraw","Tried to extract x"..amount.." "..fixNames(item).." but only got x"..sum)
- ERR("withdraw","Refund x"..(amount-sum).." "..fixNames(item))
- end
- updatePlayerTable(item,-1*sum)
- else
- updatePlayerTable(item,-1*amount)
- end
- PIM.dumpAll()
- save_player(currentPlayer)
- dontUpdate = false
- if not extracted then userInput("There was an error extracting your items, please contact an admin") end
- end
- function display_withdraw()
- local index = 0
- local amount = 0
- local sell_pos =string.len(money_name..": "..player_iList[money_name],colors.black)+1
- while currentPlayer ~= nil and header_current == header_sel[2] do
- local list_temp,scroll_pos = draw_withdraw(index)
- while true do
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if (xpos == 1 and #list_temp > 8) then --Scroll
- if ypos < scroll_pos+3 and index > 0 then
- index = index - 1
- elseif ypos > scroll_pos+3 and index < #list_temp -8 then
- index = index +1
- end
- break
- elseif xpos>41 and ypos%2 == 1 and (index+(ypos-3)/2) <= #list_temp then
- amount = math.abs(userInput("How much '"..fixNames(list_temp[index+(ypos-3)/2]).."' would you like to withdraw?","number",list_temp[index+(ypos-3)/2].qty))
- if amount>list_temp[(ypos-3)/2].qty then
- --WITHDRAW ITEM
- userInput("You are trying to withdraw more items than your inventory currently holds, withdrawing the maximum amount ("..list_temp[index+(ypos-3)/2].qty..") instead.")
- amount = list_temp[index+(ypos-3)/2].qty
- end
- if checkIfFits(list_temp[index+(ypos-3)/2],amount) then
- withdraw(list_temp[index+(ypos-3)/2],amount)
- else
- userInput("Your inventory can't hold this many items, free up some space and try again")
- end
- break
- elseif xpos>44 and ypos%2 == 0 and (index+(ypos-3)/2) <= #list_temp then
- display_sell(list_temp[index+(ypos-2)/2])
- break
- end
- elseif ypos == 3 and xpos>= sell_pos and xpos <= sell_pos+3 then
- display_sell(money_name)
- break
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if (key == 200 or key == 17) and index > 0 then
- index = index -1
- break
- elseif (key == 208 or key == 31) and index < #list_temp -8 then
- index = index +1
- break
- elseif restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- end
- function setupTrade(item,amt,item_for,amt_for)
- if #player_iList["trades"] > maxTrades then
- userInput("you've reached the maximum number of items you can sell, consider ending the sale of a item (this item was not put up for sale)")
- return
- end
- local tab = {}
- if item_for == money_name then
- tab["cred"] = true
- else
- tab["cred"] = false
- end
- item_for.qty = amt_for
- item_for.rawName = nil
- item_for.maxSize = nil
- item.qty = amt
- item.rawName = nil
- item.maxSize = nil
- tab["wants"] = item_for
- tab["has"] = item
- tab["total"] = 0
- tab["players"] = ""
- table.insert(player_iList["trades"],deepcopy(tab))
- if currentPlayer == nil then ERR("setupTrade","Nil currentPlayer!") else
- global_iList_trades[currentPlayer] = deepcopy(player_iList["trades"])
- --[[
- local found,index = compareEnchantments(global_iList_IDs,item)
- if not found then ERR("setupTrade","item not found in global list! name:",item.name,true) end
- local uniqueID = IDtoUnique(item.id,item.dmg)
- local tab1 = {}
- local tab2 = {}
- local tab3 = {}
- tab1[currentPlayer] = player_iList["trades"]
- tab2[index] = tab1
- tab3[item.name] = tab2
- if global_iList_trades[uniqueID] == nil then
- global_iList_trades[uniqueID] = deepcopy(tab3)
- elseif global_iList_trades[uniqueID][item.name] == nil then
- global_iList_trades[uniqueID][item.name] = deepcopy(tab2)
- elseif global_iList_trades[uniqueID][item.name][index] == nil then
- global_iList_trades[uniqueID][item.name][index] = deepcopy(tab1)
- elseif global_iList_trades[uniqueID][item.name][index][currentPlayer] == nil then
- global_iList_trades[uniqueID][item.name][index][currentPlayer] = deepcopy(player_iList["trades"])
- end
- ]]--
- end
- save_player(currentPlayer)
- end
- function display_sell(item)
- local amount_for = 1
- local amount = 1
- local item_for = {["name"] = "Click to select item",["id"]=1,["dmg"]=1}
- if type(item) == "string" then -- credits.
- item = deepcopy(global_iList_IDs[IDtoUnique(1,1)][money_name][1])
- end
- while currentPlayer ~= nil and header_current == header_sel[2] do
- draw_sell(item,amount,item_for,amount_for)
- while true do
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if ypos == 7 and xpos>=11 and xpos<=16 then --Amount per sale
- while true do
- term.setCursorPos(11,7)
- term.write(" ")
- term.setCursorPos(11,7)
- amount = tonumber(io.read())
- if amount ~= nil then
- if amount > item.qty then amount = item.qty end
- break
- else
- --userInput("Please type in a number")
- end
- end
- elseif ypos == 11 and xpos>=15 and xpos<=35 then --For item
- item_for = search_list()
- elseif ypos == 13 and xpos>=11 and xpos<=16 then --For item per sale.
- while true do
- term.setCursorPos(11,13)
- term.write(" ")
- term.setCursorPos(11,13)
- amount_for = tonumber(io.read())
- if amount_for ~= nil then break else
- --userInput("Please type in a number")
- end
- end
- elseif ypos == 17 then
- if xpos <= 22 and xpos >=15 then -- accept
- if item_for.name ~= "Click to select item" then -- item selected
- --trade good, add to playertable.
- if userInput("Sell "..amount.." "..fixNames(item).." for "..amount_for.." "..fixNames(item_for).." ?",true) then
- --setupTrade
- setupTrade(item,amount,item_for,amount_for)
- return
- end
- else
- userInput("Invalid item, please select a item")
- end
- elseif xpos <=35 and xpos >= 28 then --cancel
- return
- end
- end
- --InsertShit
- break
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- end
- function search_list()
- local function draw1(list,total,mess)
- if mess == nil then mess = "(type ID:dmg or item name)" end
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.black,51,16)
- Draw.tt(tt,1,1,"Search: &"..Draw.getHexOf(colors.white)..mess,colors.red)
- Draw.tt(tt,1,2,"found: "..total,colors.lime)
- Draw.tc(tc,1,1,colors.lightBlue,51,2)
- Draw.tc(tc,9,1,colors.black,35,1)
- local iter = 3
- for i=1,20 do
- for item in tableIter(list[i]) do
- local ench_str = ""
- if item.ench ~= nil and #item.ench >0 then
- ench_str = "Ench: "
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#item.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(item.ench[k]).." "
- end
- end
- Draw.tt(tt,1,iter,ss(fixNames(item),30).." &"..Draw.getHexOf(colors.gray).."("..item.id..":"..item.dmg..") "..ench_str,colors.lime)
- if iter>=16 then break end
- iter = iter+1
- end
- if iter>=16 then break end
- end
- Draw.draw(term,tc,1,4,2^15,tt)
- draw_header("withdraw")
- end
- while true do
- local ret_item,total = textSearch(9,4,draw1,search)
- if ret_item == nil or ret_item.name == nil then
- --ERR("search_list","nil item returned, this should not happen! (but shouldnt be a issue)")
- --Happens when enter is pressed and no item in list
- --term.clear()
- elseif #ret_item.ench >0 then
- userInput("Sorry, I currently do not support setting up a trade that receives enchanted items. Please select another item.")
- else
- return deepcopy(ret_item)
- end
- end
- end
- function draw_sell(item,amount,item_for,amount_for)
- draw_header("withdraw")
- local itemName_c = colors.lime
- local item_for_name = "&"..Draw.getHexOf(itemName_c)..fixNames(item_for)
- if item_for.id ~= nil and item_for.dmg ~= nil then
- item_for_name = Draw.getHexOf(itemName_c)..ss(fixNames(item_for),38).." &"..Draw.getHexOf(colors.gray).."("..item_for.id..":"..item_for.dmg..")"
- end
- local ench_str = ""
- if item.ench ~= nil and #item.ench >0 then
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#item.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(item.ench[k]).." "
- end
- else
- ench_str = "none"
- end
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,1,1,"Selling:",colors.red)
- Draw.tt(tt,3,2,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item),38).." &"..Draw.getHexOf(colors.gray).."("..item.id..":"..item.dmg..")",colors.black)
- Draw.tt(tt,3,3,"Enchantments: "..ench_str,colors.black)
- Draw.tt(tt,3,4,"Amount: &"..Draw.getHexOf(colors.red)..amount,colors.black)
- Draw.tc(tc,11,4,colors.black,12+string.len(tostring(amount)),4)
- Draw.tt(tt,1,7,"For:",colors.black)
- Draw.tt(tt,3,8,"Item Name: &"..item_for_name,colors.black)
- Draw.tc(tc,14,8,colors.black,42,8)
- Draw.tt(tt,3,9,"Enchantments: (to be added)",colors.black) --TODO: enchantment pulldowns
- Draw.tt(tt,3,10,"Amount: &"..Draw.getHexOf(colors.red)..amount_for,colors.black)
- Draw.tc(tc,11,10,colors.black,12+string.len(tostring(amount_for)),10)
- Draw.tt(tt,16,14,"Accept",colors.black)
- Draw.tt(tt,29,14,"Cancel",colors.black)
- Draw.tc(tc,15,14,colors.lime,22,14)
- Draw.tc(tc,28,14,colors.green,35,14)
- Draw.draw(term,tc,1,4,2^15,tt)
- end
- function draw_selling(list,index)
- --Draw.draw(term,tc1,3,string.len(money_name..": "..player_iList[money_name],colors.black)+1,2^15,tt1)
- if list == nil then
- draw_header("selling")
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,3,7," No Items for sale. You'll never turn a profit that way. ",colors.black)
- Draw.draw(term,tc,1,4,2^15,tt)
- return {},2
- else
- local item_c,item_t = Draw.emptyScreen(term,50,100*2+16)
- local switch_bg = true
- local i = 1
- for name,tradeIndexTab in pairs(list) do
- for tradeIndex,tradeTab in pairs(tradeIndexTab) do
- local wants = tradeTab.wants
- local has = tradeTab.has
- local bg_
- if switch_bg then
- bg_ = colors.blue
- switch_bg = false
- else
- bg_ = colors.lightBlue
- switch_bg = true
- end
- local item_name = ss(fixNames(has),30)
- local ench_str = ""
- if has.ench ~= nil and #has.ench >0 then
- ench_str = ""
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#has.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(has.ench[k]).." "
- end
- end
- Draw.tc(item_c,1,2*i-1,bg_,50,2*i)
- if item_name ~= money_name then
- Draw.tt(item_t,1,2*i-1," &"..Draw.getHexOf(colors.lime)..item_name.."&"..Draw.getHexOf(colors.red).." x"..has.qty.." &"..Draw.getHexOf(colors.brown).."("..has.id..":"..has.dmg..") "..ench_str)
- else
- Draw.tt(item_t,1,2*i-1," &"..Draw.getHexOf(colors.yellow)..item_name.."&"..Draw.getHexOf(colors.red).." x"..has.qty)
- end
- if wants.ench ~= nil and #wants.ench >0 then
- ench_str = ""
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#wants.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(wants.ench[k]).." "
- end
- end
- if wants.name ~= money_name then
- Draw.tt(item_t,1,2*i,"For: &"..Draw.getHexOf(colors.orange)..fixNames(wants).."&"..Draw.getHexOf(colors.red).." x"..wants.qty.." &"..Draw.getHexOf(colors.brown).."("..wants.id..":"..wants.dmg..") "..ench_str,colors.lime)
- else
- Draw.tt(item_t,1,2*i,"For: &"..Draw.getHexOf(colors.yellow)..fixNames(wants).."&"..Draw.getHexOf(colors.red).." x"..wants.qty,colors.lime)
- end
- --Draw.tt(item_t,44,2*i-1," &"..Draw.getHexOf(colors.black)..name)
- --Draw.tc(item_c,44,2*i-1,colors.lime,50,2*i)
- Draw.tt(item_t,41,2*i," &"..Draw.getHexOf(colors.black).." Inspect ")
- Draw.tc(item_c,42,2*i,colors.lime,50,2*i)
- i=i+1
- end
- end
- i=i-1
- --Draw.draw(term,item_c,2,4,2^15,item_t)
- --[[
- Setting up scroll bar
- --]]
- local bar_c,bar_t = Draw.emptyScreen(term,1,16)
- Draw.tc(bar_c,1,1,colors.gray,1,16)
- Draw.tc(bar_c,1,1,colors.lightGray)
- Draw.tt(bar_t,1,1,"^")
- Draw.tc(bar_c,1,16,colors.lightGray)
- Draw.tt(bar_t,1,16,"v")
- local scroll_pos = 2
- if i > 8 then
- scroll_pos = math.floor(2+13*((index)/(i-8)))
- end
- Draw.tc(bar_c,1,scroll_pos,colors.purple)
- Draw.draw(term,bar_c,1,4,2^15,bar_t)
- local item_c_f = {}
- local item_t_f = {}
- for ii=(index*2+1),#item_t do --#player_ilist_temp*2 do
- table.insert(item_c_f,item_c[ii])
- table.insert(item_t_f,item_t[ii])
- --item_c_f[i-(index*2+1)] = item_c[i]
- --item_t_f[i-(index*2+1)] = item_t[i]
- end
- Draw.draw(term,item_c_f,2,4,2^15,item_t_f)
- draw_header("selling")
- --Draw.draw(term,tc1,string.len(money_name..": "..player_iList[money_name],colors.black)+1,3,2^15,tt1)
- return scroll_pos,i
- end
- end
- function selling_inquire(name,tradeIndex)
- local tradeTab = global_iList_trades[name][tradeIndex]
- local function draw_temp()
- local function get_amt(item_t,iList)
- if item_t.name == money_name then --creddits
- return math.floor(iList[money_name]/item_t.qty)
- elseif iList["items"] ~= nil
- and iList["items"][IDtoUnique(item_t.id,item_t.dmg)] ~= nil
- and iList["items"][IDtoUnique(item_t.id,item_t.dmg)][item_t.name] ~= nil then
- local bool,item_temp = compareEnchantments(iList["items"],item_t,true)
- if bool then
- --item found in players shit get quanty
- return math.floor(item_temp.qty/item_t.qty)
- end
- else
- return 0
- end
- end
- local item_for = tradeTab.wants
- local item = tradeTab.has
- -- load functions go here
- local amount = get_amt(item,player_iList)
- local itemName_c = colors.lime
- local ench_str = ""
- if item.ench ~= nil and #item.ench >0 then
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#item.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(item.ench[k]).." "
- end
- else
- ench_str = "none"
- end
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,1,1,"Selling:",colors.black)
- if item.name ~= money_name then
- Draw.tt(tt,3,2,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item),38).." &"..Draw.getHexOf(colors.gray).."("..item.id..":"..item.dmg..") &"..Draw.getHexOf(colors.red).."x"..item.qty,colors.black)
- else
- Draw.tt(tt,3,2,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item),38).." &"..Draw.getHexOf(colors.red).."x"..item.qty,colors.black)
- end
- Draw.tt(tt,3,3,"Enchantments: "..ench_str,colors.black)
- Draw.tt(tt,3,4,"Trades Available: &"..Draw.getHexOf(colors.red)..amount,colors.black)
- Draw.tt(tt,3,5,"Trades Completed: &"..Draw.getHexOf(colors.red)..tradeTab.total,colors.black)
- Draw.tt(tt,1,7,"For:",colors.black)
- if item_for.name ~= money_name then
- Draw.tt(tt,3,8,"Item Name: &"..Draw.getHexOf(itemName_c)..fixNames(item_for).." &"..Draw.getHexOf(colors.gray).."("..item_for.id..":"..item_for.dmg..") &"..Draw.getHexOf(colors.red).."x"..item_for.qty,colors.black)
- else
- Draw.tt(tt,3,8,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item_for),38).." &"..Draw.getHexOf(colors.red).."x"..item_for.qty,colors.black)
- end
- Draw.tt(tt,3,9,"Enchantments: (to be added)",colors.black) --TODO: enchantment pulldowns
- Draw.tt(tt,15,14,"Delete",colors.black)
- Draw.tt(tt,29,14,"Cancel",colors.black)
- Draw.tc(tc,14,14,colors.red,23,14)
- Draw.tc(tc,28,14,colors.green,35,14)
- Draw.draw(term,tc,1,4,2^15,tt)
- draw_header("selling")
- return
- end
- while true do
- sleep(0)
- draw_temp()
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if false and ypos == 13 and xpos>=11 and xpos<=16 then --For item per sale. --TODO
- while true do
- term.setCursorPos(11,13)
- term.write(" ")
- term.setCursorPos(11,13)
- amount_for = tonumber(io.read())
- if amount_for ~= nil then break else
- --userInput("Please type in a number")
- end
- end
- elseif ypos == 17 then
- if xpos <= 23 and xpos >=14 then --delete
- player_iList["trades"][tradeIndex] = nil
- global_iList_trades[name][tradeIndex] = nil
- userInput("This trade has been deleted")
- save_player(currentPlayer)
- return
- elseif xpos <=35 and xpos >= 28 then --cancel
- return
- end
- end
- --InsertShit
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- function display_selling()
- local index = 0
- local amount = 0
- local list = {}
- while currentPlayer ~= nil and header_current == header_sel[3] do
- list[currentPlayer] = deepcopy(global_iList_trades[currentPlayer])
- local scroll_pos,length = draw_selling(list,index)
- while true do
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if (xpos == 1 and length > 8) then --Scroll
- if ypos < scroll_pos+3 and index > 0 then
- index = index - 1
- elseif ypos > scroll_pos+3 and index < length -8 then
- index = index +1
- end
- break
- elseif xpos>41 and ypos%2 == 1 and (index+(ypos-3)/2) <= length then
- local function findItem()
- local i = 1
- for name,tradeIndexTab in pairs(list) do
- for tradeIndex,tradeTab in pairs(tradeIndexTab) do
- if i==(index+(ypos-3)/2) then
- selling_inquire(name,tradeIndex)
- return
- else
- i=i+1
- end
- end
- end
- end
- findItem()
- break
- end
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if (key == 200 or key == 17) and index > 0 then
- index = index -1
- break
- elseif (key == 208 or key == 31) and index < length -8 then
- index = index +1
- break
- elseif restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- end
- function draw_buy(list,index)
- local tc1,tt1 = Draw.emptyScreen(term,6,1)
- Draw.tc(tc1,1,1,colors.lime,7,1)
- Draw.tt(tt1,1,1,"Filters",colors.black)
- --Draw.draw(term,tc1,3,string.len(money_name..": "..player_iList[money_name],colors.black)+1,2^15,tt1)
- if list == nil then
- draw_header("buy")
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,3,7," No Items for sale, how depressing! ",colors.black)
- Draw.draw(term,tc,1,4,2^15,tt)
- return {},2
- else
- local item_c,item_t = Draw.emptyScreen(term,50,100*2+16)
- local switch_bg = true
- local i = 1
- for name,tradeIndexTab in pairs(list) do
- for tradeIndex,tradeTab in pairs(tradeIndexTab) do
- local wants = tradeTab.wants
- local has = tradeTab.has
- local bg_
- if switch_bg then
- bg_ = colors.blue
- switch_bg = false
- else
- bg_ = colors.lightBlue
- switch_bg = true
- end
- local item_name = ss(fixNames(has),30)
- local ench_str = ""
- if has.ench ~= nil and #has.ench >0 then
- ench_str = ""
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#has.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(has.ench[k]).." "
- end
- end
- Draw.tc(item_c,1,2*i-1,bg_,50,2*i)
- if item_name ~= money_name then
- Draw.tt(item_t,1,2*i-1," &"..Draw.getHexOf(colors.lime)..item_name.."&"..Draw.getHexOf(colors.red).." x"..has.qty.." &"..Draw.getHexOf(colors.brown).."("..has.id..":"..has.dmg..") "..ench_str)
- else
- Draw.tt(item_t,1,2*i-1," &"..Draw.getHexOf(colors.yellow)..item_name.."&"..Draw.getHexOf(colors.red).." x"..has.qty)
- end
- if wants.ench ~= nil and #wants.ench >0 then
- ench_str = ""
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#wants.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(wants.ench[k]).." "
- end
- end
- if wants.name ~= money_name then
- Draw.tt(item_t,1,2*i,"For: &"..Draw.getHexOf(colors.orange)..fixNames(wants).."&"..Draw.getHexOf(colors.red).." x"..wants.qty.." &"..Draw.getHexOf(colors.brown).."("..wants.id..":"..wants.dmg..") "..ench_str,colors.lime)
- else
- Draw.tt(item_t,1,2*i,"For: &"..Draw.getHexOf(colors.yellow)..fixNames(wants).."&"..Draw.getHexOf(colors.red).." x"..wants.qty,colors.lime)
- end
- --Draw.tt(item_t,44,2*i-1," &"..Draw.getHexOf(colors.black)..name)
- --Draw.tc(item_c,44,2*i-1,colors.lime,50,2*i)
- Draw.tt(item_t,41,2*i," &"..Draw.getHexOf(colors.black).." Inquire ")
- Draw.tc(item_c,42,2*i,colors.lime,50,2*i)
- i=i+1
- end
- end
- i=i-1
- --Draw.draw(term,item_c,2,4,2^15,item_t)
- --[[
- Setting up scroll bar
- --]]
- local bar_c,bar_t = Draw.emptyScreen(term,1,16)
- Draw.tc(bar_c,1,1,colors.gray,1,16)
- Draw.tc(bar_c,1,1,colors.lightGray)
- Draw.tt(bar_t,1,1,"^")
- Draw.tc(bar_c,1,16,colors.lightGray)
- Draw.tt(bar_t,1,16,"v")
- local scroll_pos = 2
- if i > 8 then
- scroll_pos = math.floor(2+13*((index)/(i-8)))
- end
- Draw.tc(bar_c,1,scroll_pos,colors.purple)
- Draw.draw(term,bar_c,1,4,2^15,bar_t)
- local item_c_f = {}
- local item_t_f = {}
- for ii=(index*2+1),#item_t do --#player_ilist_temp*2 do
- table.insert(item_c_f,item_c[ii])
- table.insert(item_t_f,item_t[ii])
- --item_c_f[i-(index*2+1)] = item_c[i]
- --item_t_f[i-(index*2+1)] = item_t[i]
- end
- Draw.draw(term,item_c_f,2,4,2^15,item_t_f)
- draw_header("buy")
- Draw.draw(term,tc1,string.len(money_name..": "..player_iList[money_name],colors.black)+1,3,2^15,tt1)
- return scroll_pos,i
- end
- end
- function buy_inquire(name,tradeIndex)
- local seller_iList = load_player(name,true)
- local tradeTab = global_iList_trades[name][tradeIndex]
- local function draw_temp()
- local function get_amt(item_t,iList)
- if item_t.name == money_name then --creddits
- return math.floor(iList[money_name]/item_t.qty)
- elseif iList["items"] ~= nil
- and iList["items"][IDtoUnique(item_t.id,item_t.dmg)] ~= nil
- and iList["items"][IDtoUnique(item_t.id,item_t.dmg)][item_t.name] ~= nil then
- local bool,item_temp = compareEnchantments(iList["items"],item_t,true)
- if bool then
- --item found in players shit get quanty
- return math.floor(item_temp.qty/item_t.qty)
- end
- else
- return 0
- end
- end
- local item_for = tradeTab.wants
- local item = tradeTab.has
- -- load functions go here
- local amount = get_amt(item,seller_iList)
- local amount_for = get_amt(item_for,player_iList)
- local itemName_c = colors.lime
- local ench_str = ""
- if item.ench ~= nil and #item.ench >0 then
- local colors_tab = {colors.purple,colors.lime,colors.magenta,colors.orange}
- for k=1,#item.ench do
- ench_str = ench_str.."&"..Draw.getHexOf(colors_tab[k])..getShortEnch(item.ench[k]).." "
- end
- else
- ench_str = "none"
- end
- local tc,tt = Draw.emptyScreen(term,51,16)
- Draw.tc(tc,1,1,colors.lightGray,51,16)
- Draw.tt(tt,1,1,"Selling:",colors.black)
- if item.name ~= money_name then
- Draw.tt(tt,3,2,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item),38).." &"..Draw.getHexOf(colors.gray).."("..item.id..":"..item.dmg..") &"..Draw.getHexOf(colors.red).."x"..item.qty,colors.black)
- else
- Draw.tt(tt,3,2,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item),38).." &"..Draw.getHexOf(colors.red).."x"..item.qty,colors.black)
- end
- Draw.tt(tt,3,3,"Enchantments: "..ench_str,colors.black)
- Draw.tt(tt,3,4,"Trades Available: &"..Draw.getHexOf(colors.red)..amount,colors.black)
- Draw.tt(tt,3,5,"Player: &"..Draw.getHexOf(colors.brown)..name,colors.black)
- Draw.tt(tt,1,7,"For:",colors.black)
- if item_for.name ~= money_name then
- Draw.tt(tt,3,8,"Item Name: &"..Draw.getHexOf(itemName_c)..fixNames(item_for).." &"..Draw.getHexOf(colors.gray).."("..item_for.id..":"..item_for.dmg..") &"..Draw.getHexOf(colors.red).."x"..item_for.qty,colors.black)
- else
- Draw.tt(tt,3,8,"Item Name: &"..Draw.getHexOf(itemName_c)..ss(fixNames(item_for),38).." &"..Draw.getHexOf(colors.red).."x"..item_for.qty,colors.black)
- end
- Draw.tt(tt,3,9,"Enchantments: (to be added)",colors.black) --TODO: enchantment pulldowns
- Draw.tt(tt,3,10,"Possible Trades: &"..Draw.getHexOf(colors.red)..amount_for,colors.black)
- Draw.tt(tt,15,14,"Purchase",colors.black)
- Draw.tt(tt,29,14,"Cancel",colors.black)
- if amount_for > 0 then
- Draw.tc(tc,14,14,colors.lime,23,14)
- else
- Draw.tc(tc,14,14,colors.gray,23,14)
- end
- Draw.tc(tc,28,14,colors.green,35,14)
- Draw.draw(term,tc,1,4,2^15,tt)
- draw_header("buy")
- return amount,amount_for
- end
- while true do
- sleep(0)
- local available,possible = draw_temp()
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if false and ypos == 13 and xpos>=11 and xpos<=16 then --For item per sale. --TODO
- while true do
- term.setCursorPos(11,13)
- term.write(" ")
- term.setCursorPos(11,13)
- amount_for = tonumber(io.read())
- if amount_for ~= nil then break else
- --userInput("Please type in a number")
- end
- end
- elseif ypos == 17 then
- if xpos <= 23 and xpos >=14 and possible > 0 then --purchace
- if available > 0 then
- -- swap items
- if currentPlayer ~= name then
- if tradeTab.wants.name ~= money_name then
- seller_iList = updatePlayerTable( tradeTab.wants, tradeTab.wants.qty,seller_iList)
- updatePlayerTable(tradeTab.wants,-1*tradeTab.wants.qty)
- else --transfer creds
- seller_iList[money_name] = seller_iList[money_name] + tradeTab.wants.qty
- player_iList[money_name] = player_iList[money_name] - tradeTab.wants.qty
- end
- if tradeTab.has.name ~= money_name then
- updatePlayerTable( tradeTab.has, tradeTab.has.qty) -- add items to players inventory
- seller_iList = updatePlayerTable( tradeTab.has, -1*tradeTab.has.qty,seller_iList)
- else --transfer creds
- seller_iList[money_name] = seller_iList[money_name] - tradeTab.has.qty
- player_iList[money_name] = player_iList[money_name] + tradeTab.has.qty
- end
- seller_iList["trades"][tradeIndex]["total"] = seller_iList["trades"][tradeIndex]["total"]+1
- save_player(currentPlayer)
- save_player(name,seller_iList)
- else
- userInput("You can't trade with yourself silly!")
- end
- else
- userInput("Sorry, this item is sold out!")
- end
- elseif xpos <=35 and xpos >= 28 then --cancel
- return
- end
- end
- --InsertShit
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- function display_buy()
- local index = 0
- local amount = 0
- local list = deepcopy(global_iList_trades)
- while currentPlayer ~= nil and header_current == header_sel[4] do
- local scroll_pos,length = draw_buy(list,index)
- while true do
- local event,key,xpos,ypos = os.pullEvent()
- if (event == "mouse_click") then
- if ypos>3 then
- if (xpos == 1 and length > 8) then --Scroll
- if ypos < scroll_pos+3 and index > 0 then
- index = index - 1
- elseif ypos > scroll_pos+3 and index < length -8 then
- index = index +1
- end
- break
- elseif xpos>41 and ypos%2 == 1 and (index+(ypos-3)/2) <= length then
- local function findItem()
- local i = 1
- for name,tradeIndexTab in pairs(list) do
- for tradeIndex,tradeTab in pairs(tradeIndexTab) do
- if i==(index+(ypos-3)/2) then
- buy_inquire(name,tradeIndex)
- return
- else
- i=i+1
- end
- end
- end
- end
- findItem()
- break
- end
- else
- local valid,sel = parse_header(xpos,ypos)
- if valid then
- header_current = sel
- os.queueEvent("updateHeader")
- break
- end
- end
- elseif event == "key" then
- if (key == 200 or key == 17) and index > 0 then
- index = index -1
- break
- elseif (key == 208 or key == 31) and index < length -8 then
- index = index +1
- break
- elseif restart(key) then
- os.reboot()
- end
- elseif event == "updatePlayer" then
- break --current_player changed
- end
- end
- end
- end
- function please_wait()
- local x1,y1 = term.getSize()
- local tt,tc = Draw.emptyScreen(term,x1,y1)
- Draw.tc(tc,1,1,colors.white,x1,y1)
- Draw.tc(tc,3,6,colors.lightBlue,x1-3,12)
- Draw.tt(tt,5,7," Please do not step off the PIM while ",colors.brown)
- Draw.tt(tt,5,8," the program moves your items. ",colors.brown)
- Draw.tt(tt,5,10," Doing so may result in your items being ",colors.red)
- Draw.tt(tt,5,11," lost forver ",colors.red)
- Draw.draw(term,tc,1,1,2^15,tt)
- end
- --will check if a item stack will fit into a players inventory. return true if it can
- function checkIfFits(item,amount)
- local numSlotsNeeded = math.ceil(amount/item.maxSize)
- if numSlotsNeeded > PIM.getFreeSlots() then return false else return true end
- end
- -- function to handle switching between tabs
- function updateDisplay()
- sleep(1)
- function one()
- while true do
- local event = os.pullEvent()
- if event == "updatePlayer" then
- header_current = header_sel[1]
- term.clear()
- break
- elseif event == "updateHeader" then
- break
- end
- end
- end
- function two()
- if currentPlayer == nil then os.pullEvent("updatePlayer") end
- if header_current == header_sel[1] then display_deposit()
- elseif header_current == header_sel[2] then display_withdraw()
- elseif header_current == header_sel[3] then display_selling()
- elseif header_current == header_sel[4] then display_buy()
- end
- end
- local tot =1
- while true do
- sleep(0) --todo cleanup (only there since some displays dont take in user input)
- --term.clear()
- parallel.waitForAny(one,two)
- end
- end
- --parse header input, returns the string of which tab was selected.
- function parse_header(xpos,ypos)
- if ypos == 1 then
- if xpos <13 then
- return true,header_sel[1]
- elseif xpos>13 and xpos<28 then
- return true,header_sel[2]
- elseif xpos>28 and xpos<40 then
- return true,header_sel[3]
- elseif xpos>40 then
- return true,header_sel[4]
- end
- end
- return false,nil
- end
- function draw_header(sel)
- local tc,tt = Draw.emptyScreen(term,51,3)
- Draw.tc(tc,1,1,colors.yellow,51,3)
- Draw.tc(tc,1,1,colors.green,51,1)
- Draw.tc(tc,13,1,colors.yellow,13,1)
- Draw.tc(tc,28,1,colors.yellow,28,1)
- Draw.tc(tc,40,1,colors.yellow,40,1)
- if header_sel[1] == sel then --deposit
- Draw.tc(tc,1,1,colors.lime,12,1)
- elseif header_sel[2] == sel then
- Draw.tc(tc,14,1,colors.lime,27,1)
- elseif header_sel[3] == sel then
- Draw.tc(tc,29,1,colors.lime,39,1)
- elseif header_sel[4] == sel then
- Draw.tc(tc,41,1,colors.lime,51,1)
- else
- error("wrong arg passed to draw_header, see header_sel{}",2)
- end
- Draw.tt(tt,1,1," DEPOSIT | WITHDRAW | SELLING | BUY " ,colors.black)
- if currentPlayer ~= nil then
- Draw.tt(tt,1,2,"Welcome "..currentPlayer,colors.black)
- Draw.tt(tt,1,3,money_name..": &"..Draw.getHexOf(colors.red)..player_iList[money_name],colors.black)
- end
- Draw.draw(term,tc,1,1,2^15,tt)
- end
- --if arg[1] is true then the dialog will be a yes/no dialog. Blank means just 'OK', "string" or "number" will prompt for a custom input of that type.
- function userInput(text,...)
- local screen = term
- local x1,y1 = screen.getSize()
- local t_bg,t_t = Draw.emptyScreen(screen,x1,y1)
- local bg_color = colors.white
- local fg_color = colors.lightBlue
- local b_color = colors.yellow
- local text_color = colors.white
- local xpadding = 4
- local text_start = math.floor(y1/2) -1
- local lines = {}
- if string.len(text) > x1-(2+xpadding*2) then
- local newline = ""
- local i = 1
- for word in string.gmatch(text, "%S+") do
- if string.len(newline.." "..word) > x1-10 then
- lines[i] = newline
- i=i+1
- newline = word
- else
- newline = newline.." "..word
- end
- end
- if newline ~= nil then
- lines[#lines+1] = newline
- end
- text_start = math.floor(y1/2 - #lines/2 -1)
- for i=1,#lines do
- t_t = Draw.tt(t_t,math.floor((x1-string.len(lines[i]))/2),text_start+i,lines[i],text_color)
- end
- else --one line message
- t_t = Draw.tt(t_t,math.floor((x1-string.len(text))/2),text_start,text,text_color)
- end
- t_bg = Draw.tc(t_bg,1,1,bg_color,x1,y1) --background
- t_bg = Draw.tc(t_bg,xpadding,text_start-1,fg_color,x1-xpadding,text_start+4+#lines) --forground
- if arg[1] == nil then
- t_bg = Draw.tc(t_bg,math.floor(x1/2-1),text_start+#lines+3,b_color,math.floor(x1/2+2),text_start+#lines+3)
- t_t = Draw.tt(t_t,math.floor(x1/2),text_start+#lines+3,"OK",colors.black)
- elseif arg[1] == true then
- t_bg = Draw.tc(t_bg,x1/2-9,text_start+#lines+3,b_color,x1/2-5,text_start+#lines+3)
- t_bg = Draw.tc(t_bg,x1/2+5,text_start+#lines+3,b_color,x1/2+8,text_start+#lines+3)
- t_t = Draw.tt(t_t,x1/2-8,text_start+#lines+3,"Yes",colors.black)
- t_t = Draw.tt(t_t,x1/2+6,text_start+#lines+3,"No",colors.black)
- elseif arg[1] == "string" or arg[1] == "number" then
- t_t = Draw.tt(t_t,x1/2-12,text_start+#lines+2,">",text_color)
- t_bg = Draw.tc(t_bg,x1/2-12,text_start+#lines+2,colors.black,x1/2+13,text_start+#lines+2)
- end
- Draw.drawPictureTable(screen, t_bg, 1, 1, colors.black,t_t)
- if arg[1] == "string" or arg[1] == "number" then
- while true do
- Draw.drawPictureTable(screen, t_bg, 1, 1, colors.black,t_t)
- screen.setCursorPos(x1/2-11,text_start+#lines+2)
- local input
- if arg[2] and type(arg[2]) ~= "number" then
- input = read("*")
- else
- if type(arg[2]) == "number" then
- input = getCleanInputAt(x1/2-11,text_start+#lines+2,25,tostring(arg[2]))
- else
- input = getCleanInputAt(x1/2-11,text_start+#lines+2)
- end
- end
- if arg[1] == "string" then
- if input ~= "" and tostring(input) ~= nil then
- return input
- else
- userInput("The input has to be a string")
- end
- elseif arg[1] == "number" then
- if tonumber(input) ~= nil then
- return tonumber(input)
- elseif input == "" then
- return 0
- else
- userInput("The input has to be a number")
- end
- end
- end
- else
- while true do
- local event, button1, xpos2, ypos2 = os.pullEvent()
- if arg[1] and (event == "mouse_click" or event == "key") then
- if event == "key" and button1 == 28 then
- return true
- end
- if xpos2>=x1/2-10 and xpos2<=x1/2-5 and ypos2 == text_start+#lines+3 then
- return true
- elseif xpos2>=x1/2+4 and xpos2<=x1/2+8 and ypos2 == text_start+#lines+3 then
- return false
- end
- elseif not arg[1] then
- if event =="key" then
- return true
- elseif event == "mouse_click" and xpos2>=x1/2-2 and xpos2<=x1/2+2 and ypos2 == text_start+#lines+3 then
- return true
- end
- end
- end
- end
- end
- function correctChestErrors()
- while true do
- local event = os.pullEvent("player_on")
- local last_player = currentPlayer
- while last_player == nil do
- ERR("correctChestErrors","yep, it happened. currentPlayer should not be set this quickly")
- last_player = currentPlayer
- sleep(0)
- end
- event = os.pullEvent("player_off")
- --wait for dontUpdate to change
- while dontUpdate do
- sleep(0)
- end
- local chestData = getChestData()
- if #chestData > 0 then -- leftover items in chest
- ERR("correctChestErrors", "Items in chest while dontUpdate is",dontUpdate,true)
- ERR("correctChestErrors", "Number of items in chest",#chestData,true)
- for k,v in pairs(chestData) do
- ERR("correctChestErrors", " Item Found: ",fixNames(v),true)
- end
- ERR("correctChestErrors", " Adding items to inventory",last_player,true)
- dontUpdate = true
- load_player(last_player)
- ae.suckAll(last_player)
- load_player(nil)
- dontUpdate = false
- end
- end
- end
- function print_inv()
- term.clear()
- sleep(1)
- print("printinv")
- for itemsz in tableIter(player_iList["items"]) do
- print(itemsz.name)
- end
- io.read()
- end
- function testing()
- while true do
- os.pullEvent("updatePlayer")
- if currentPlayer == nil then
- print_inv()
- else
- --print("NIL!")
- end
- sleep(0)
- end
- end
- function garbage()
- sleep(3)
- --local tabb = deepcopy(global_iList_IDs)
- load_player("NuAoA")
- term.clear()
- local tab = deepcopy(player_iList)
- for i=1,1000 do
- term.clear()
- term.setCursorPos(1,1)
- print(i)
- player_iList = deepcopy(tab)
- player_iList.name = "FakePlayer_"..i
- save_player("FakePlayer_"..i)
- end
- local tab2 = load_player("FakePlayer_999",true)
- term.clear()
- print(tab2.name)
- io.read()
- end
- function display_startup()
- local splashlogo = {
- "444444444444444444 eeeeeee eeee eeee eee eeee ";
- "444444444444444444 e e e e e e e e ";
- "44ffffffffffffff44 e eeee e e e e eee ";
- "44f0ffffffffffff44 e ee eeee e e e ";
- "44ff0fffffffffff44 e e e e e e e e ";
- "44f0ff000fffffff44 e e e e e eee eeee ";
- "44ffffffffffffff44 ";
- "44ffffffffffffff44 333 5 5 5 5 5555 333 ";
- "44ffffffffffffff44 33 5 5 5 5 5 5 33 ";
- "44ffffffffffffff44 33c 5 5 5 5 5 5 c33 ";
- "44ffffffffffffff44 3 c 5555 5 5 555 c 3 ";
- "444444444444444444 c 5 5 5 5 5 5 c ";
- "444444444444444444 c 5 5 5 5 5 5 c ";
- " 5 5 5555 5555 ";
- "";
- }
- --[[
- "8 8 8 8 8888 8888 8888 ";
- "88 8 8 8 8 8 8 8 8 8 ";
- "8 88 8 8 8888 8 8 8888 ";
- "8 8 8888 8 8 8888 8 8 ";
- "";
- }
- ]]--
- term.clear()
- Draw.draw(term, splashlogo, 2, 3, colors.black)
- while notFirstBoot do
- sleep(0.3)
- Draw.draw(term,{"44f0ffffffffffff44",""} , 2, 8, colors.black)
- sleep(0.3)
- Draw.draw(term,{"44f0ff000fffffff44",""} , 2, 8, colors.black)
- end
- while true do
- sleep(10000)
- end
- end
- function checkshit()
- while true do
- local event = os.pullEvent()
- ERR("checkshit",event)
- end
- end
- --[[
- term.clear()
- local temp_tab = modem.wrapped.callRemote(modem.interface,"getAvailableItems")
- for k,v in pairs(temp_tab) do
- print(k)
- kk = deepcopy(v)
- for i=1,100 do
- kk.dmg = i
- if modem.wrapped.callRemote(modem.interface,"extractItem",kk,ae_direction) > 0 then
- print(i)
- end
- end
- ERR("decode",textutils.serialize(v))
- end
- sleep(3)
- os.reboot()
- print("|"..modem.wrapped.callRemote(modem.interface,"canHoldNewItem").."|")
- print(modem.wrapped.callRemote(modem.interface,"getStoredItemCount"))
- print(modem.wrapped.callRemote(modem.interface,"getUnusedItemCount"))
- ]]--
- --ae.extractItem()
- --testae.extractItem()Search()
- parallel.waitForAny(display_startup,startup)
- parallel.waitForAll(updateCurrentPlayer,updateDisplay,correctChestErrors)--,garbage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement