Jump to content

LUA : Show crate capacity


tonyenkiducx

Recommended Posts

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 by tonyenkiducx
Copied old code by mistake!
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...