tonyenkiducx Posted September 20, 2020 Share Posted September 20, 2020 (edited) A little script I knocked up to show the capacity of attached crates. There are 2 parameters to set, the name of the resource you are monitoring in the crates, and a unit mass(KG/L). You will need a screen attached called "Screen", or change the relevant part in the script. Containers don't need a specific name. This is my first time coding LUA, or in DU, so any improvements I can make, please let me know. objectMassPerLitre = 2.7 --export containerContentsName = "Aluminium" --export local containerArray = {} local containerCount = 0 for key, value in pairs(unit) do if type(value) == "table" and type(value.export) == "table" then if value.getSelfMass then containerCount = containerCount + 1 containerArray[containerCount] = value end end end local containerMassContentsCount = 0 local totalVolume = 0 for i= 1, containerCount do containerMassContentsCount = containerMassContentsCount + containerArray[i].getItemsMass() if containerArray[i].getSelfMass() == 1281.31 then totalVolume = totalVolume + 8000 elseif containerArray[i].getSelfMass() == 229.09 then totalVolume = totalVolume + 1000 elseif containerArray[i].getSelfMass() == 7421.35 then totalVolume = totalVolume + 64000 elseif containerArray[i].getSelfMass() == 14842.7 then totalVolume = totalVolume + 128000 end end local totalContentsVolume = math.floor(containerMassContentsCount / objectMassPerLitre) local message = containerCount .." containers of ".. containerContentsName .. " <br> " .. totalContentsVolume .."<emp>L</emp> used of ".. totalVolume .. "<emp>L</emp> total space" if oreDisplay == nil then oreDisplay = Screen.addContent(2,50,message) else Screen.resetContent(oreDisplay, message) end Edited September 20, 2020 by tonyenkiducx Copied old code by mistake! Link to comment Share on other sites More sharing options...
Bobylein Posted September 23, 2020 Share Posted September 23, 2020 edit: I am stupid and misunderstood what you script is supposed to do. Thanks for sharing anyway! Link to comment Share on other sites More sharing options...
Velase85 Posted September 23, 2020 Share Posted September 23, 2020 Did you do this thru a programing board? or just edit the LUA script on a control seat/core? Link to comment Share on other sites More sharing options...
CoyoteNZ Posted September 28, 2020 Share Posted September 28, 2020 How do you get it to refresh? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now