-
Notifications
You must be signed in to change notification settings - Fork 10
/
main_board
1 lines (1 loc) · 25.7 KB
/
main_board
1
{"slots":{"0":{"name":"CORE","type":{"events":[],"methods":[]}},"1":{"name":"SCREEN_A","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"system.print(\"KICKSTART\")\nrefresh_in_sec = 8 --export\nunit.setTimer(\"refresh\", refresh_in_sec)\nunit.stopTimer(\"kickstart\")\nreload()","filter":{"args":[{"value":"kickstart"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"0"},{"code":"--system.print(\"RELOAD\")\nreload()","filter":{"args":[{"value":"refresh"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"1"},{"code":"-- FACTORY HUD v1.9 by carmo\n-- Any questions please contact carmo#1590 on discord\n-- THIS CODE NEEDS TO BE PLACED ON A MAIN BOARD AND DISPLAY SCREEN.\n\n-----------------\n-- SYSTEM VARS --\n-----------------\nlocal version = 1.9\n\n---------------\n-- USER VARS --\n---------------\nlocal ContainerLCapacity = 153600 --export\nlocal ContainerMCapacity = 64000 --export\nlocal ContainerSCapacity = 9600 --export\nlocal ContainerXSCapacity = 1200 --export\nlocal Percentage_RED = 10 --export\nlocal Percentage_GREEN = 60 --export\nlocal UseContainerHubs = false --export\nlocal UseDoors = false --export\nlocal DoorUsers = {'user1', 'user2', 'user3'}\n-- username array like {'user1', 'user2', 'CaseSensitive'}\nlocal showHudWidget = false --export\n\n-----------------\n-- USER CONFIG --\n-----------------\n-- LIST OF ORE/PURES:\n-- \"HEMATITE\",\"IRON\",\"BAUXITE\",\"ALUMINIUM\",\"COAL\",\"CARBON\",\"QUARTZ\",\"SILICON\"\n-- \"LIMESTONE\",\"CALCIUM\",\"MALACHITE\",\"COPPER\",\"NATRON\",\"SODIUM\",\"CHROMITE\",\"CHROMIUM\",\"ACANTHITE\"\n-- \"SILVER\",\"PYRITE\",\"SULFUR\",\"PETALITE\",\"LITHIUM\",\"GARNIERITE\",\"NICKEL\",\"GOLDNUGGETS\",\"GOLD\"\n-- \"CRYOLITE\",\"FLUORINE\",\"COBALTITE\",\"COBALT\",\"KOLBECKITE\",\"SCANDIUM\",\"RHODONITE\",\"MANGANESE\"\n-- \"COLUMBITE\",\"NIOBIUM\",\"VANADINITE\",\"VANADIUM\",\"ILMENITE\",\"TITANIUM\"\n-- EXTRA MATERIALS TO USE: \"OXYGEN\", \"HYDROGEN\", \"WARPCELL\"\n-- On this next arrays you will place witch order you like\n-- Read always left to right, then next line.\n-- YOU CAN SET \"EMPTY\" if you need a blank space\n\nlocal SCREENA = {\"HEMATITE\", \"IRON\", \"BAUXITE\", \"ALUMINIUM\", \"COAL\", \"CARBON\", \"QUARTZ\", \"SILICON\", \"LIMESTONE\", \"CALCIUM\",\n \"MALACHITE\", \"COPPER\", \"NATRON\", \"SODIUM\", \"CHROMITE\", \"CHROMIUM\", \"ACANTHITE\", \"SILVER\", \"PYRITE\", \"SULFUR\"}\n\nlocal SCREENB = {\"PETALITE\", \"LITHIUM\", \"GARNIERITE\", \"NICKEL\", \"GOLDNUGGETS\", \"GOLD\", \"CRYOLITE\", \"FLUORINE\",\n \"COBALTITE\", \"COBALT\", \"KOLBECKITE\", \"SCANDIUM\", \"RHODONITE\", \"MANGANESE\", \"COLUMBITE\", \"NIOBIUM\", \"VANADINITE\",\n \"VANADIUM\", \"ILMENITE\", \"TITANIUM\"}\n\n-------------------------\n-- AUXILIARY FUNCTIONS --\n-------------------------\nfunction roundint(x)\n return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)\nend\n\nfunction round(value)\n local x = math.abs(value)\n if math.type(x) == \"float\" then\n return utils.round(x, 0.1)\n else\n return x\n end\nend\n\nfunction split(s, sep)\n local fields = {}\n local sep = sep or \" \"\n local pattern = string.format(\"([^%s]+)\", sep)\n string.gsub(s, pattern, function(c)fields[#fields + 1] = c end)\n return fields\nend\n\nlocal function hasValue(s)\n if s == nil or s == '' then return \"empty\"\n else return s end\nend\n\nfunction print_r(arr, indentLevel)\n local str = \"\"\n local indentStr = \"#\"\n \n if (indentLevel == nil) then\n system.print(print_r(arr, 0))\n return\n end\n \n for i = 0, indentLevel do\n indentStr = indentStr .. \"\\t\"\n end\n \n for index, value in pairs(arr) do\n if type(value) == \"table\" then\n str = str .. indentStr .. index .. \": \\n\" .. print_r(value, (indentLevel + 1))\n else\n str = str .. indentStr .. index .. \": \" .. value .. \"\\n\"\n end\n end\n return str\nend\n\nfunction arraylength(T)\n local count = 0\n if T == nil then return 0\n else\n for _ in pairs(T) do count = count + 1 end\n return count\n end\nend\n\nfunction getFromArray(array, position)\n u = \"\"\n for i, j in pairs(array) do u = j[position] end\n --print_r(array)\n return u\nend\n\n----------------\n-- CORE STUFF --\n----------------\ncore = nil\ndbank = nil\nfor slot_name, slot in pairs(unit) do\n if\n type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getElementClass\n then\n if slot.getElementClass():lower():find(\"coreunit\") then\n core = slot\n elseif\n slot.getElementClass():lower():find(\"databank\") then\n dbank = slot\n end\n end\nend\n\ncontainersIdList = {}\nif core ~= nil then\n local elementsIdList = core.getElementIdList()\n for _, id in pairs(elementsIdList) do\n local elementType = core.getElementTypeById(id):lower()\n if elementType:find(\"container\") then\n local name = core.getElementNameById(id)\n if string.match(name, \"CH_\") or string.match(name, \"C_\") then\n local temp = split(name, \"_\")\n local tq = string.match(temp[2], \"%d+\")\n --system.print([[\"ID: \"]] .. id .. [[\", TEMP1: \"]] .. temp[1] .. [[\", TEMP 2,1: \"]] .. hasValue(tq) .. [[\", TEMP 2,2: \"]] .. string.sub(temp[2], -1) .. [[\", TEMP3: \"]] .. temp[3] .. [[\", TEMP4: \"]] .. hasValue(temp[4]))\n table.insert(containersIdList, {id, temp[1], string.match(temp[2], \"%d+\"), string.sub(temp[2], -1), temp[3], hasValue(temp[4])})\n --1: id, 2: type, 3: containercount, 4: containersize, 5: material, 6: description\n end\n end\n end\nend\n\nfunction checkDB()\n dbVersion = dbank.getFloatValue(\"version\")\n if dbVersion == nil then return nil\n elseif dbVersion < version then return \"upgrade\"\n else return \"noupgrade\" end\nend\n\nfunction saveDB()\n dbank.setIntValue(\"dummy\", 1)\n dbank.setFloatValue(\"version\", version)\n dbank.setIntValue(\"ContainerLCapacity\", ContainerLCapacity)\n dbank.setIntValue(\"ContainerMCapacity\", ContainerMCapacity)\n dbank.setIntValue(\"ContainerSCapacity\", ContainerSCapacity)\n dbank.setIntValue(\"ContainerXSCapacity\", ContainerXSCapacity)\n dbank.setIntValue(\"Percentage_RED\", Percentage_RED)\n dbank.setIntValue(\"Percentage_GREEN\", Percentage_GREEN)\n if UseContainerHubs then\n dbank.setIntValue(\"UseContainerHubs\", 1)\n else\n dbank.setIntValue(\"UseContainerHubs\", 0)\n end\n if UseDoors then\n dbank.setIntValue(\"UseDoors\", 1)\n else\n dbank.setIntValue(\"UseDoors\", 0)\n end\n if showHudWidget then\n dbank.setIntValue(\"showHudWidget\", 1)\n else\n dbank.setIntValue(\"showHudWidget\", 0)\n end\nend\n\nfunction readDB()\n if dbank.getIntValue(\"dummy\") == 1 then\n ContainerLCapacity = dbank.getIntValue(\"ContainerLCapacity\")\n ContainerMCapacity = dbank.getIntValue(\"ContainerMCapacity\")\n ContainerSCapacity = dbank.getIntValue(\"ContainerSCapacity\")\n ContainerXSCapacity = dbank.getIntValue(\"ContainerXSCapacity\")\n Percentage_RED = dbank.getIntValue(\"Percentage_RED\")\n Percentage_GREEN = dbank.getIntValue(\"Percentage_GREEN\")\n \n if dbank.getIntValue(\"UseContainerHubs\") == 1 then\n UseContainerHubs = true\n else\n UseContainerHubs = false\n end\n if dbank.getIntValue(\"UseDoors\") == 1 then\n UseDoors = true\n else\n UseDoors = false\n end\n if dbank.getIntValue(\"showHudWidget\") == 1 then\n showHudWidget = true\n else\n showHudWidget = false\n end\n end\nend\n\nfunction goDB()\n if dbank ~= nil then\n system.print(\"DATABANK FOUND\")\n system.print(\"SCRIPT LOAD OK. CHECKING DB VERSION\")\n \n if checkDB() == nil then\n system.print(\"UPGRADE DETECTED. FIRST RUN? LOADING KICKSTART\")\n unit.setTimer(\"kickstart\", 1)\n elseif checkDB() == \"upgrade\" then\n readDB()\n system.print(\"UPGRADE DETECTED. USER CONFIG LOADED. LOADING KICKSTART\")\n unit.setTimer(\"kickstart\", 1)\n else\n readDB()\n system.print(\"NO UPGRADE NEEDED. SAME VERSION. LOADING KICKSTART\")\n unit.setTimer(\"kickstart\", 1)\n end\n else\n system.print(\"NO DATABANK FOUND. LOADING KICKSTART\")\n unit.setTimer(\"kickstart\", 1)\n end\nend\n----------\n-- HTML --\n----------\nlocal html_css\nif UseContainerHubs then\n html_css = [[\n <style> \n .table {background-color:none; height:99vh; margin:auto; padding:0; position:relative; width:98vw} \n .column_1_2 {background-color:none; position:absolute; left:20px; height:100%; width:45vw} \n .column_2_2 {background-color:none; position:absolute; right:0; height:100%; width:45vw} \n .row {background-color:none; height:9.8vh; border:0px grey solid; padding-left:35%; width:99%} \n .rowinfo {background-color:none; height:9.8vh; width:99%; text-align: center; font-size: 1.4vw;font-weigh:300; padding-top:6px}\n .name {background-color:none; padding-left:0px; line-height:5vh; font-size: 4vh; display:inline-block; width:70%}\n .progressbar {background-color:green; position:relative; float:right; bottom:2px; min-height:1vh; height:1vh; right:0; min-width:1vw}\n .daysavailable {width:100%; background-color:none; position:relative; float:left; text-align:right; bottom:2px; height:2vh;font-size:12px}\n .percentage {background-color:none; font-size: 5vh; line-height: 5vh; width:8.5vw; top: 0; right: 0; text-align:right; display:inline-block} \n .desc {font-size:1.5vw; background-color: none; width: 98%; display: inline-block;}\n .info {font-size:1.5vw; background-color: none; width: 30%; display: inline-block; right: 5px; position: absolute; text-align: right;}\n </style>\n ]]\n\nelse html_css = [[ \n <style> \n .table {background-color:none; height:99vh; margin:auto; padding:0; position:relative; width:50vw; display:inline-block} \n .column_1_2 {background-color:none; position:absolute; height:100%; width:25vw} \n .column_2_2 {background-color:none; position:absolute; right:0; height:100%; width:25vw}\n .row {background-color:none; height:9.8vh; width:99%; padding: 0 8px} \n .rowinfo {background-color:none; height:9.8vh; width:99%; text-align: center; font-size: 1.4vw;font-weigh:300; padding-top:6px}\n .name {background-color:none; padding-left:0px; line-height:5vh; font-size: 3vh; display:inline-block; width:64%} \n .progressbar {background-color:green; position:relative; float:right; bottom:2px; min-height:1vh; height:1vh; right:0; min-width:1vw}\n .daysavailable {width:100%; background-color:none; position:relative; float:left; text-align:right; bottom:2px; height:2vh;font-size:12px}\n .percentage {background-color:none; font-size: 4vh; line-height: 5vh; width:36%; top: 0; right: 0px; text-align:right; display:inline-block; padding:0}\n .desc {font-size:1.2vw; background-color: none; width: 98%; display: inline-block;}\n .info {font-size:1.2vw; background-color: none; width: 50%; display: inline-block; right: 10px; position: absolute; text-align: right;}\n </style> \n ]]\n\nend\n\ncss_loading = [[\n <style> \n .wrapper{background-color:none;color:white;font-size:2vw;}\n .valign > div{border:dotted 1px white;padding:20px 20px;}\n .wrapper {position: absolute;width: 100%;height: 100%;}\n .valign {width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;}\n </style>\n]]\n\nlocal material_readout_top = [[<div class=\"table\"><div class=\"column_1_2\">]]\n\nfunction material_readout_cell(name)\n x = {}\n --system.print(\"NAME: \"..hasValue(name))\n if name == nil then\n html = [[<div class=\"row\"><div class=\"name\"></div><div class=\"percentage\"></div><div class=\"progressbar\" style=\"width:0%; background-color:pink\"> </div></div>]]\n else\n --system.print(name)\n x = getMaterial(name)\n --system.print(\"ENTRA 1\")\n if next(x) == nil then\n --system.print(\"array vazio\")\n html = [[<div class=\"rowinfo\">PLEASE CONNECT<br>]] .. name .. [[</div>]]\n else\n percentage = getFromArray(x, 9)\n description = getFromArray(x, 6)\n if description == \"empty\" then description = \"\" end\n quantity = getFromArray(x, 8)\n totalcontainerqtdinlitre = getFromArray(x, 10)\n --print_r(x)\n --system.print(\"MATERIAL: \"..name..\" | %: \"..percentage)\n html = [[<div class=\"row\"><div class=\"name\">]] .. _G[name][1] .. [[</div><div class=\"percentage\">]] .. percentage .. [[%</div><div class=\"progressbar\" style=\"width:]] .. percentage .. [[%; background-color:]] .. progresscolor(percentage) .. [[\"> </div>\n <div class=\"desc\">]]\n .. description .. [[</div><div class=\"info\">]] .. litreParse(quantity, totalcontainerqtdinlitre) .. [[</div></div>]]\n --system.print(progresscolor(percentage))\n end\n end\n return html\nend\n\nlocal material_readout_middle = [[</div><div class=\"column_2_2\">]]\nlocal material_readout_bottom = [[</div></div>]]\n\nfunction progresscolor(percentage)\n if tonumber(percentage) then\n color = \"\"\n if (percentage <= Percentage_RED) then\n color = \"red\"\n elseif (percentage > Percentage_RED) and (percentage < Percentage_GREEN) then\n color = \"yellow\"\n else\n color = \"green\"\n end\n return color\n else\n return \"pink\"\n end\nend\n\nfunction litreParse(litre, total)\n size = \"\"\n if total < 1000 then\n size = \"L\"\n elseif total < 1000000 then\n total = total / 1000\n size = \"kL\"\n else\n total = total / 1000000\n size = \"kt\"\n end\n \n if litre < 1000 then return string.format(\"%.1f\", litre) .. \"/\" .. string.format(\"%.1f\", total) .. size\n elseif litre < 1000000 then\n litre = litre / 1000\n return string.format(\"%.1f\", litre) .. \"/\" .. string.format(\"%.1f\", total) .. size\n else\n litre = litre / 10000\n total = total / 1000\n return string.format(\"%.1f\", litre) .. \"/\" .. string.format(\"%.1f\", total) .. size\n end\nend\n\n--------------------\n-- MATERIAL STUFF --\n--------------------\n-- VARIABLE = {Name that will be displayed on screen, unit mass, unit volume if exists}\nfunction createMaterials()\n -- T1\n HEMATITE = {\"Hematite\", 5.04}\n IRON = {\"Iron\", 7.85}\n BAUXITE = {\"Bauxite\", 1.2811}\n ALUMINIUM = {\"Aluminium\", 2.7}\n QUARTZ = {\"Quartz\", 2.65}\n SILICON = {\"Silicon\", 2.33}\n COAL = {\"Coal\", 1.35}\n CARBON = {\"Carbon\", 2.27}\n -- T2\n LIMESTONE = {\"Limestone\", 2.711}\n CALCIUM = {\"Calcium\", 1.55}\n MALACHITE = {\"Malachite\", 4}\n COPPER = {\"Copper\", 8.96}\n NATRON = {\"Natron\", 1.55}\n SODIUM = {\"Sodium\", 0.97}\n CHROMITE = {\"Chromite\", 4.54}\n CHROMIUM = {\"Chromium\", 7.19}\n -- T3\n PYRITE = {\"Pyrite\", 5.01}\n SULFUR = {\"Sulfur\", 1.82}\n PETALITE = {\"Petalite\", 2.41}\n LITHIUM = {\"Lithium\", 0.53}\n ACANTHITE = {\"Acanthite\", 7.2}\n SILVER = {\"Silver\", 10.49}\n GARNIERITE = {\"Garnierite\", 2.6}\n NICKEL = {\"Nickel\", 8.91}\n -- T4\n GOLDNUGGETS = {\"Gold Nuggets\", 19.3}\n GOLD = {\"Gold\", 19.3}\n CRYOLITE = {\"Cryolite\", 2.95}\n FLUORINE = {\"Fluorine\", 1.7}\n COBALTITE = {\"Cobaltite\", 6.33}\n COBALT = {\"Cobalt\", 8.9}\n KOLBECKITE = {\"Kolbeckite\", 2.37}\n SCANDIUM = {\"Scandium\", 2.98}\n -- T5\n RHODONITE = {\"Rhodonite\", 3.76}\n MANGANESE = {\"Manganese\", 7.21}\n COLUMBITE = {\"Columbite\", 5.38}\n NIOBIUM = {\"Niobium\", 8.57}\n VANADINITE = {\"Vanadinite\", 6.95}\n VANADIUM = {\"Vanadium\", 6}\n ILMENITE = {\"Ilmenite\", 4.55}\n TITANIUM = {\"Titanium\", 4.51}\n -- OTHER\n OXYGEN = {\"Oxygen\", 1}\n HYDROGEN = {\"Hydrogen\", 0.07}\n WARPCELL = {\"Warpcell\", 100}\n -- STUFF\n AILERONM = {\"Aileron M\", 3410, 1238.4}\nend\n\nfunction getQuantity(material, materialmass)\n quantity = nil\n quantity = roundint(materialmass / (_G[material][2]))\n return quantity\nend\n\nfunction createMaterialArray(material)\n arrayX = {}\n for i, j in pairs(containersIdList) do\n if j[5] == material then\n if j[2] == \"CH\" or j[2] == \"C\" and j[6] == \"empty\" then\n --system.print(\"id: \"..j[1]..\", type: \"..j[2]..\", quantity: \"..j[3]..\", size: \"..j[4]..\", material: \"..j[5]..\", description: \"..j[6])\n table.insert(arrayX, {j[1], j[2], j[3], j[4], j[5], j[6]})\n end\n end\n end\n return arrayX\nend\n\nfunction getContainerCapacity(size)\n capacity = 0\n if size == \"L\" then capacity = ContainerLCapacity\n elseif size == \"M\" then capacity = ContainerMCapacity\n elseif size == \"S\" then capacity = ContainerSCapacity\n elseif size == \"XS\" then capacity = ContainerXSCapacity\n else\n capacity = 0\n end\n return capacity\nend\n\nfunction getContainerMass(size)\n mass = 0\n if size == \"L\" then mass = 14842.7\n elseif size == \"M\" then mass = 7421.35\n elseif size == \"S\" then mass = 1281.31\n elseif size == \"XS\" then mass = 229.09\n else\n mass = 0\n end\n return mass\nend\n\nfunction calculateMaterial(arrayx)\n containermass = 0\n percentage = 0\n arrayY = {}\n for i, j in pairs(arrayx) do\n if j[2] == \"CH\" then\n \n containermass = core.getElementMassById(j[1]) - 55.8 -- 55.8 is the hub mass\n if containermass > 0 then\n quantity = getQuantity(j[5], containermass)\n \n if _G[j[5]][3] ~= nil then\n percentage = containerPercentage(quantity * _G[j[5]][3], getContainerCapacity(j[4]) * j[3])\n else\n percentage = containerPercentage(quantity, getContainerCapacity(j[4]) * j[3])\n end\n \n totalcontainerquantityinlitre = getContainerCapacity(j[4]) * j[3]\n --system.print(\"ore: \"..j[5]..\" | QTD: \"..quantity..\" | %: \"..percentage)\n table.insert(arrayY, {j[1], j[2], j[3], j[4], j[5], j[6], containermass, quantity, percentage, totalcontainerquantityinlitre})\n else\n --system.print(\"MATERIAL: \"..j[5]..\" | EMPTY\")\n end\n --system.print(\"FODASSE ore: \"..j[5]..\" | id: \"..j[1]..\" | massa: \"..hubmass)\n elseif j[2] == \"C\" then\n \n --system.print(\"nome é: \"..j[4] ..\"size é: \" .. core.getElementMassById(j[1]) .. \" e o container vazio: \" .. getContainerMass(j[4]))\n containermass = core.getElementMassById(j[1]) - getContainerMass(j[4])\n \n if containermass > 0 then\n quantity = getQuantity(j[5], containermass)\n \n if _G[j[5]][3] ~= nil then\n percentage = containerPercentage(quantity * _G[j[5]][3], getContainerCapacity(j[4]))\n quantity = quantity * _G[j[5]][3]\n else\n percentage = containerPercentage(quantity, getContainerCapacity(j[4]))\n end\n \n totalcontainerquantityinlitre = getContainerCapacity(j[4])\n \n table.insert(arrayY, {j[1], j[2], j[3], j[4], j[5], j[6], containermass, quantity, percentage, totalcontainerquantityinlitre})\n else\n end\n end\n end\n --1: id, 2: type, 3: containercount, 4: containersize, 5: material, 6: description, 7: mass, 8: quantity, 9: percentage, 10: totalcontainerquantityinlitre\n --system.print(\"o size do array é: \" .. arraylength(arrayY))\n if arraylength(arrayY) > 1 then\n --system.print(\"o array é do material: \".. getFromArray(arrayY, 5))\n arrayZ = {}\n v1 = 999999999\n v2 = \"C\"\n v3 = 0\n v4 = \"SUM\"\n v5 = \"\"\n v6 = \"\"\n v7 = 0\n v8 = 0\n v9 = 0\n v10 = 0\n for i, j in pairs(arrayY) do\n v5 = j[5]\n v7 = v7 + getContainerCapacity(j[4])\n v8 = v8 + j[8]\n --system.print(\"v8: \"..v8)\n v10 = v10 + j[10]\n end\n v9 = containerPercentage(v8, v7)\n table.insert(arrayZ, {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10})\n end\n \n if arraylength(arrayZ) > 0 then return arrayZ\n else return arrayY end\nend\n\nfunction containerPercentage(materialqtd, containercapacity)\n if materialqtd ~= nil then\n local x = materialqtd * 100 / containercapacity\n local y = math.floor(x + .5)\n if y - x < 0.05 then\n return roundint(x)\n else\n return round(x)\n end\n else\n return 666\n end\nend\n\nfunction getMaterial(material)\n step1 = {}\n step2 = {}\n arrayZ = nil\n -- STEP 1\n -- create array with list of CH or C that contain specific material\n step1 = createMaterialArray(material)\n \n -- STEP 2\n -- calculate mass, quantity, percentage\n step2 = calculateMaterial(step1)\n \n -- RETURN FULL ARRAY\n --print_r(step2)\n return step2\nend\n\n----------------\n-- HTML STUFF --\n----------------\nfunction create_material_readout_screen_A()\n html = html_css .. material_readout_top\n for i = 1, 20 do if (i % 2 ~= 0) then html = html .. material_readout_cell(SCREENA[i]) end end\n html = html .. material_readout_middle\n for i = 1, 20 do if (i % 2 == 0) then html = html .. material_readout_cell(SCREENA[i]) end end\n html = html .. material_readout_bottom\n if not UseContainerHubs then\n html = html .. material_readout_top\n for i = 1, 20 do if (i % 2 ~= 0) then html = html .. material_readout_cell(SCREENB[i]) end end\n html = html .. material_readout_middle\n for i = 1, 20 do if (i % 2 == 0) then html = html .. material_readout_cell(SCREENB[i]) end end\n html = html .. material_readout_bottom\n end\n return html\nend\n\nfunction create_material_readout_screen_B()\n html = html_css .. material_readout_top\n for i = 1, 20 do if (i % 2 ~= 0) then html = html .. material_readout_cell(SCREENB[i]) end end\n html = html .. material_readout_middle\n for i = 1, 20 do if (i % 2 == 0) then html = html .. material_readout_cell(SCREENB[i]) end end\n html = html .. material_readout_bottom\n return html\nend\n\nfunction clearSCREEN()\n -- CLEAR SCREENS\n SCREEN_A.clear()\n if SCREEN_B ~= nil then SCREEN_B.clear() end\nend\n\nfunction reload()\n clearSCREEN()\n \n -- SCREEN A\n html = [[<div style=\"width:100vw\"><div style=\"margin-top: 10px;padding: 0px;width: 100vw;display: inline-block;\">]] .. create_material_readout_screen_A() .. [[</div></div>]]\n SCREEN_A.setHTML(html)\n \n -- SCREEN B\n if SCREEN_B ~= nil then\n html = [[<div style=\"width:100vw\"><div style=\"margin-top:10px;padding:0px;width:100vw;display:inline-block;\">]] .. create_material_readout_screen_B() .. [[</div></div>]]\n SCREEN_B.setHTML(html)\n end\nend\n\nfunction warmup()\n system.print(\"WARMUP\")\n \n -- SCREEN A\n html = css_loading .. [[<div class=\"wrapper\"><div class=\"valign\"><div>LOADING</div></div></div>]]\n SCREEN_A.setHTML(html)\n \n -- LOAD SCREEN B LOADING\n if SCREEN_B ~= nil then SCREEN_B.setHTML(html) end\nend\n\nfunction door()\n local playerId = unit.getMasterPlayerId()\n local playerName = system.getPlayerName(playerId)\n local t = doorUsers -- username array like {'user1', 'user2', 'CaseSensitive'}\n local function has_value(tab, val)\n for index, value in ipairs(tab) do\n if value == val then\n return true\n end\n end\n return false\n end\n --system.print(\"Hello \" .. playerName .. \" : \" .. playerId .. \"!\")\n if has_value(t, playerName) then\n if DOOR1 ~= nil then DOOR1.activate() end\n if DOOR2 ~= nil then DOOR2.activate() end\n --someSCREEN.setCenteredText(\"WELCOME\" .. playerName)\n else\n system.print('PERMISSION DENIED')\n end\nend\n\n-- STARTUP FACTORY\nwarmup()\ncreateMaterials()\ngoDB()\n\nif not showHudWidget then unit.hide() end\nif UseDoors then door() end","filter":{"args":[],"signature":"start()","slotKey":"-2"},"key":"2"},{"code":"SCREEN_A.clear()\nif SCREEN_B ~= nil then SCREEN_B.clear() end\n\nif DOOR1 ~= nil then\nif DOOR1.getState() == 1 then \n if DOOR1 ~= nil then DOOR1.deactivate() end\n if DOOR2 ~= nil then DOOR2.deactivate() end\n SCREEN_A.clear() \n if SCREEN_B ~= nil then SCREEN_B_celar() end\nend\nend\n\nif dbank ~= nil then \n system.print(\"USER CONFIG SAVED. BYE\")\n saveDB()\nend","filter":{"args":[],"signature":"stop()","slotKey":"-2"},"key":"3"}],"methods":[],"events":[]}