Suggested script fix for ship's with more than 1k elements #25
FairfieldTekLLC
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
--[[
Damage Report 3.31
A LUA script for Dual Universe
]]
YourShipsName = "Enter here" --export Enter your ship name here if you want it displayed instead of the ship's ID. YOU NEED TO LEAVE THE QUOTATION MARKS.
SkillRepairToolEfficiency = 0 --export Enter (0-5) your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Efficiency"
SkillRepairToolOptimization = 0 --export Enter your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Optimization"
StatAtmosphericFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED ATMOSPHERIC FUEL TANKS (from the builders talent "Piloting -> Atmospheric Flight Technician -> Atmospheric Fuel-Tank Handling")
StatSpaceFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL SPACE TANKS (from the builders talent "Piloting -> Atmospheric Engine Technician -> Space Fuel-Tank Handling")
StatRocketFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL ROCKET TANKS (from the builders talent "Piloting -> Rocket Scientist -> Rocket Booster Fuel Tank Handling")
StatContainerOptimization = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL TANKS "from the builders talent Mining and Inventory -> Stock Control -> Container Optimization"
StatFuelTankOptimization = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL TANKS "from the builders talent Mining and Inventory -> Stock Control -> Fuel Tank Optimization"
ShowWelcomeMessage = true --export Do you want the welcome message on the start screen with your name?
DisallowKeyPresses = false --export Need your keys for other scripts/huds and want to prevent Damage Report keypresses to be processed? Then check this. (Usability of the HUD mode will be small.)
AddSummertimeHour = false --export: Is summertime currently enabled in your location? (Adds one hour.)
ElementsPerPass = 1000
ElementsPerPassLastPosition = 0
damagedElements = {};
brokenElements = {};
healthyElements = {};
UpdateDataInterval = 1.0
HighlightBlinkingInterval = 0.5
ColorPrimary = "FF6700"
ColorSecondary = "FFFFFF"
ColorTertiary = "000000"
ColorHealthy = "00FF00"
ColorWarning = "FFFF00"
ColorCritical = "FF0000"
ColorBackground = "000000"
ColorBackgroundPattern = "4F4F4F"
ColorFuelAtmospheric = "004444"
ColorFuelSpace = "444400"
ColorFuelRocket = "440044"
VERSION = 3.31
DebugMode = false
DebugRenderClickareas = true
DBData = {}
core = nil
db = nil
screens = {}
dscreens = {}
Warnings = {}
screenModes = {
["flight"] = {id = "flight"},
["damage"] = {id = "damage"},
["damageoutline"] = {id = "damageoutline"},
["fuel"] = {id = "fuel"},
["cargo"] = {id = "cargo"},
["agg"] = {id = "agg"},
["map"] = {id = "map"},
["time"] = {id = "time", activetoggle = "true"},
["settings1"] = {id = "settings1"},
["startup"] = {id = "startup"}
}
backgroundModes = {"deathstar", "capsule", "rain", "signal", "hexagon", "diagonal", "diamond", "plus", "dots"}
BackgroundMode = "deathstar"
BackgroundSelected = 1
BackgroundModeOpacity = 0.25
SaveVars = {
"dscreens",
"ColorPrimary",
"ColorSecondary",
"ColorTertiary",
"ColorHealthy",
"ColorWarning",
"ColorCritical",
"ColorBackground",
"ColorBackgroundPattern",
"ColorFuelAtmospheric",
"ColorFuelSpace",
"ColorFuelRocket",
"ScrapTier",
"HUDMode",
"SimulationMode",
"DMGOStretch",
"HUDShiftU",
"HUDShiftV",
"colorIDIndex",
"colorIDTable",
"BackgroundMode",
"BackgroundSelected",
"BackgroundModeOpacity"
}
HUDMode = false
HUDShiftU = 0
HUDShiftV = 0
hudSelectedIndex = 0
hudStartIndex = 1
hudArrowSticker = {}
highlightOn = false
highlightID = 0
highlightX = 0
highlightY = 0
highlightZ = 0
SimulationMode = false
OkayCenterMessage = "All systems nominal."
CurrentDamagedPage = 1
CurrentBrokenPage = 1
DamagePageSize = 12
ScrapTier = 1
totalScraps = 0
ScrapTierRepairTimes = {10, 50, 250, 1250}
coreWorldOffset = 0
totalShipHP = 0
formerTotalShipHP = -1
totalShipMaxHP = 0
totalShipIntegrity = 100
elementsId = {}
elementsIdList = {}
damagedElements = {}
brokenElements = {}
rE = {}
healthyElements = {}
typeElements = {}
ElementCounter = 0
UseMyElementNames = true
dmgoElements = {}
DMGOMaxElements = 250
DMGOStretch = false
ShipXmin = 99999999
ShipXmax = -99999999
ShipYmin = 99999999
ShipYmax = -99999999
ShipZmin = 99999999
ShipZmax = -99999999
totalShipMass = 0
formerTotalShipMass = -1
formerTime = -1
FuelAtmosphericTanks = {}
FuelSpaceTanks = {}
FuelRocketTanks = {}
FuelAtmosphericTotal = 0
FuelSpaceTotal = 0
FuelRocketTotal = 0
FuelAtmosphericCurrent = 0
FuelSpaceTotalCurrent = 0
FuelRocketTotalCurrent = 0
formerFuelAtmosphericTotal = -1
formerFuelSpaceTotal = -1
formerFuelRocketTotal = -1
hexTable = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
colorIDIndex = 1
colorIDTable = {
[1] = {id = "ColorPrimary", desc = "Main HUD Color", basec = "FF6700", newc = "FF6700"},
[2] = {id = "ColorSecondary", desc = "Secondary HUD Color", basec = "FFFFFF", newc = "FFFFFF"},
[3] = {id = "ColorTertiary", desc = "Tertiary HUD Color", basec = "000000", newc = "000000"},
[4] = {id = "ColorHealthy", desc = "Color code for Healthy/Okay", basec = "00FF00", newc = "00FF00"},
[5] = {id = "ColorWarning", desc = "Color code for Damaged/Warning", basec = "FFFF00", newc = "FFFF00"},
[6] = {id = "ColorCritical", desc = "Color code for Broken/Critical", basec = "FF0000", newc = "FF0000"},
[7] = {id = "ColorBackground", desc = "Background Color", basec = "000000", newc = "000000"},
[8] = {id = "ColorBackgroundPattern", desc = "Background Pattern Color", basec = "4F4F4F", newc = "4F4F4F"},
[9] = {id = "ColorFuelAtmospheric", desc = "Color for Atmo Fuel/Elements", basec = "004444", newc = "004444"},
[10] = {id = "ColorFuelSpace", desc = "Color for Space Fuel/Elements", basec = "444400", newc = "444400"},
[11] = {id = "ColorFuelRocket", desc = "Color for Rocket Fuel/Elements", basec = "440044", newc = "440044"}
}
function InitiateSlots()
for a, b in pairs(unit) do
if type(b) == "table" and type(b.export) == "table" and b.getElementClass then
local c = b.getElementClass():lower()
if c:find("coreunit") then
core = b
local d = core.getMaxHitPoints()
if d > 10000 then
coreWorldOffset = 128
elseif d > 1000 then
coreWorldOffset = 64
elseif d > 150 then
coreWorldOffset = 32
else
coreWorldOffset = 16
end
elseif c == "databankunit" then
db = b
elseif c == "screenunit" then
local e = "startup"
screens[#screens + 1] = {
element = b,
id = b.getId(),
mode = e,
submode = "",
ClickAreas = {},
refresh = true,
active = false,
fuelA = true,
fuelS = true,
fuelR = true,
fuelIndex = 1
}
end
end
end
end
function LoadFromDatabank()
if db == nil then
return
else
for f, g in pairs(SaveVars) do
if db.hasKey(g) then
local h = json.decode(db.getStringValue(g))
if h ~= nil then
if
g == "YourShipsName" or g == "AddSummertimeHour" or g == "UpdateDataInterval" or
g == "HighlightBlinkingInterval" or
g == "SkillRepairToolEfficiency" or
g == "SkillRepairToolOptimization" or
g == "SkillAtmosphericFuelEfficiency" or
g == "SkillSpaceFuelEfficiency" or
g == "SkillRocketFuelEfficiency" or
g == "StatAtmosphericFuelTankHandling" or
g == "StatSpaceFuelTankHandling" or
g == "StatRocketFuelTankHandling"
then
else
_G[g] = h
end
end
end
end
for i, j in ipairs(screens) do
for k, l in ipairs(dscreens) do
if screens[i].id == dscreens[k].id then
screens[i].mode = dscreens[k].mode
screens[i].submode = dscreens[k].submode
screens[i].active = dscreens[k].active
screens[i].refresh = true
screens[i].fuelA = dscreens[k].fuelA
screens[i].fuelS = dscreens[k].fuelS
screens[i].fuelR = dscreens[k].fuelR
screens[i].fuelIndex = dscreens[k].fuelIndex
end
end
end
end
end
function SaveToDatabank()
if db == nil then
return
else
dscreens = {}
for i, m in ipairs(screens) do
dscreens[i] = {}
dscreens[i].id = m.id
dscreens[i].mode = m.mode
dscreens[i].submode = m.submode
dscreens[i].active = m.active
dscreens[i].fuelA = m.fuelA
dscreens[i].fuelS = m.fuelS
dscreens[i].fuelR = m.fuelR
dscreens[i].fuelIndex = m.fuelIndex
end
db.clear()
for f, g in pairs(SaveVars) do
db.setStringValue(g, json.encode(_G[g]))
end
end
end
function InitiateScreens()
if screens ~= nil and #screens > 0 then
for i = 1, #screens, 1 do
screens[i] = CreateClickAreasForScreen(screens[i])
end
end
end
function UpdateTypeData()
FuelAtmosphericTanks = {}
FuelSpaceTanks = {}
FuelRocketTanks = {}
FuelAtmosphericTotal = 0
FuelAtmosphericCurrent = 0
FuelSpaceTotal = 0
FuelSpaceCurrent = 0
FuelRocketCurrent = 0
FuelRocketTotal = 0
local n = 4
local o = 6
local p = 0.8
if StatContainerOptimization > 0 then
n = n - 0.05 * StatContainerOptimization * n
o = o - 0.05 * StatContainerOptimization * o
p = p - 0.05 * StatContainerOptimization * p
end
if StatFuelTankOptimization > 0 then
n = n - 0.05 * StatFuelTankOptimization * n
o = o - 0.05 * StatFuelTankOptimization * o
p = p - 0.05 * StatFuelTankOptimization * p
end
for i, q in ipairs(typeElements) do
local r = core.getElementNameById(q) or ""
local s = core.getElementTypeById(q) or ""
local t = core.getElementPositionById(q) or 0
local u = core.getElementHitPointsById(q) or 0
local v = core.getElementMaxHitPointsById(q) or 0
local w = core.getElementMassById(q) or 0
local x = ""
local y = 0
local z = 0
local A = 0
local B = 0
if s == "Atmospheric Fuel Tank" then
if v > 10000 then
x = "L"
z = 5480
y = 12800
elseif v > 1300 then
x = "M"
z = 988.67
y = 1600
elseif v > 150 then
x = "S"
z = 182.67
y = 400
else
x = "XS"
z = 35.03
y = 100
end
if StatAtmosphericFuelTankHandling > 0 then
y = 0.2 * StatAtmosphericFuelTankHandling * y + y
end
A = w - z
if A <= 10 then
A = 0
end
B = string.format("%.0f", A / n)
cPercent = string.format("%.1f", math.floor(100 / y * tonumber(B)))
table.insert(
FuelAtmosphericTanks,
{
type = 1,
id = q,
name = r,
maxhp = v,
hp = GetHPforElement(q),
pos = t,
size = x,
mass = z,
vol = y,
cvol = B,
percent = cPercent
}
)
if u > 0 then
FuelAtmosphericCurrent = FuelAtmosphericCurrent + B
end
FuelAtmosphericTotal = FuelAtmosphericTotal + y
elseif s == "Space Fuel Tank" then
if v > 10000 then
x = "L"
z = 5480
y = 12800
elseif v > 1300 then
x = "M"
z = 988.67
y = 1600
else
x = "S"
z = 182.67
y = 400
end
if StatSpaceFuelTankHandling > 0 then
y = 0.2 * StatSpaceFuelTankHandling * y + y
end
A = w - z
if A <= 10 then
A = 0
end
B = string.format("%.0f", A / o)
cPercent = string.format("%.1f", 100 / y * tonumber(B))
table.insert(
FuelSpaceTanks,
{
type = 2,
id = q,
name = r,
maxhp = v,
hp = GetHPforElement(q),
pos = t,
size = x,
mass = z,
vol = y,
cvol = B,
percent = cPercent
}
)
if u > 0 then
FuelSpaceCurrent = FuelSpaceCurrent + B
end
FuelSpaceTotal = FuelSpaceTotal + y
elseif s == "Rocket Fuel Tank" then
if v > 65000 then
x = "L"
z = 25740
y = 50000
elseif v > 6000 then
x = "M"
z = 4720
y = 6400
elseif v > 700 then
x = "S"
z = 886.72
y = 800
else
x = "XS"
z = 173.42
y = 400
end
if StatRocketFuelTankHandling > 0 then
y = 0.1 * StatRocketFuelTankHandling * y + y
end
A = w - z
if A <= 10 then
A = 0
end
B = string.format("%.0f", A / p)
cPercent = string.format("%.1f", 100 / y * tonumber(B))
table.insert(
FuelRocketTanks,
{
type = 3,
id = q,
name = r,
maxhp = v,
hp = GetHPforElement(q),
pos = t,
size = x,
mass = z,
vol = y,
cvol = B,
percent = cPercent
}
)
if u > 0 then
FuelRocketCurrent = FuelRocketCurrent + B
end
FuelRocketTotal = FuelRocketTotal + y
end
end
if FuelAtmosphericCurrent ~= formerFuelAtmosphericCurrent then
SetRefresh("fuel")
formerFuelAtmosphericCurrent = FuelAtmosphericCurrent
end
if FuelSpaceCurrent ~= formerFuelSpaceCurrent then
SetRefresh("fuel")
formerFuelSpaceCurrent = FuelSpaceCurrent
end
if FuelRocketCurrent ~= formerFuelRocketCurrent then
SetRefresh("fuel")
formerFuelRocketCurrent = FuelRocketCurrent
end
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function clearTable(t)
for k in pairs (t) do
t [k] = nil
end
end
StillFetching = false;
function UpdateDamageData(C)
C = C or false
if SimulationActive == true then
return
end
local formerTotalShipHP = totalShipHP
totalShipHP = 0
totalShipMaxHP = 0
totalShipIntegrity = 100
end
function GetHPforElement(q)
for i, j in ipairs(brokenElements) do
if j.id == q then
return 0
end
end
for i, j in ipairs(damagedElements) do
if j.id == q then
return j.hp
end
end
for i, j in ipairs(healthyElements) do
if j.id == q then
return j.maxhp
end
end
end
function UpdateClickArea(G, H, I)
for i, m in ipairs(screens) do
for J, j in pairs(screens[i].ClickAreas) do
if j.id == G and j.mode == I then
screens[i].ClickAreas[J] = H
end
end
end
end
function AddClickArea(I, H)
for i, m in ipairs(screens) do
if screens[i].mode == I then
table.insert(screens[i].ClickAreas, H)
end
end
end
function startswith(text, prefix)
return text:find(prefix, 1, true) == 1
end
function AddClickAreaForScreenID(K, H)
for i, m in ipairs(screens) do
if screens[i].id == K then
table.insert(screens[i].ClickAreas, H)
end
end
end
function DisableClickArea(G, I)
UpdateClickArea(G, {id = G, mode = I, x1 = -1, x2 = -1, y1 = -1, y2 = -1})
end
function SetRefresh(I, L)
I = I or "all"
L = L or "all"
if screens ~= nil and #screens > 0 then
for i = 1, #screens, 1 do
if screens[i].mode == I or I == "all" then
if screens[i].submode == L or L == "all" then
screens[i].refresh = true
end
end
end
end
end
function WipeClickAreasForScreen(m)
m.ClickAreas = {}
return m
end
function CreateBaseClickAreas(m)
table.insert(m.ClickAreas, {mode = "all", id = "ToggleHudMode", x1 = 1537, x2 = 1728, y1 = 1015, y2 = 1075})
table.insert(
m.ClickAreas,
{mode = "all", id = "ButtonPress", param = "damage", x1 = 193, x2 = 384, y1 = 1015, y2 = 1075}
)
table.insert(
m.ClickAreas,
{mode = "all", id = "ButtonPress", param = "damageoutline", x1 = 385, x2 = 576, y1 = 1015, y2 = 1075}
)
table.insert(
m.ClickAreas,
{mode = "all", id = "ButtonPress", param = "fuel", x1 = 577, x2 = 768, y1 = 1015, y2 = 1075}
)
table.insert(
m.ClickAreas,
{mode = "all", id = "ButtonPress", param = "time", x1 = 0, x2 = 192, y1 = 1015, y2 = 1075}
)
table.insert(
m.ClickAreas,
{mode = "all", id = "ButtonPress", param = "settings1", x1 = 1729, x2 = 1920, y1 = 1015, y2 = 1075}
)
return m
end
function CreateClickAreasForScreen(m)
if m == nil then
return {}
end
if m.mode == "flight" then
elseif m.mode == "damage" then
table.insert(m.ClickAreas, {mode = "damage", id = "ToggleElementLabel", x1 = 70, x2 = 425, y1 = 325, y2 = 355})
table.insert(
m.ClickAreas,
{mode = "damage", id = "ToggleElementLabel2", x1 = 980, x2 = 1400, y1 = 325, y2 = 355}
)
elseif m.mode == "damageoutline" then
table.insert(
m.ClickAreas,
{mode = "damageoutline", id = "DMGOChangeView", param = "top", x1 = 60, x2 = 439, y1 = 150, y2 = 200}
)
table.insert(
m.ClickAreas,
{mode = "damageoutline", id = "DMGOChangeView", param = "side", x1 = 440, x2 = 824, y1 = 150, y2 = 200}
)
table.insert(
m.ClickAreas,
{mode = "damageoutline", id = "DMGOChangeView", param = "front", x1 = 825, x2 = 1215, y1 = 150, y2 = 200}
)
table.insert(
m.ClickAreas,
{mode = "damageoutline", id = "DMGOChangeStretch", x1 = 1530, x2 = 1580, y1 = 150, y2 = 200}
)
elseif m.mode == "fuel" then
elseif m.mode == "cargo" then
elseif m.mode == "agg" then
elseif m.mode == "map" then
elseif m.mode == "time" then
elseif m.mode == "settings1" then
table.insert(m.ClickAreas, {mode = "settings1", id = "ToggleBackground", x1 = 75, x2 = 860, y1 = 170, y2 = 215})
table.insert(
m.ClickAreas,
{mode = "settings1", id = "PreviousBackground", x1 = 75, x2 = 460, y1 = 235, y2 = 285}
)
table.insert(m.ClickAreas, {mode = "settings1", id = "NextBackground", x1 = 480, x2 = 860, y1 = 235, y2 = 285})
table.insert(m.ClickAreas, {mode = "settings1", id = "DecreaseOpacity", x1 = 75, x2 = 460, y1 = 300, y2 = 350})
table.insert(m.ClickAreas, {mode = "settings1", id = "IncreaseOpacity", x1 = 480, x2 = 860, y1 = 300, y2 = 350})
table.insert(m.ClickAreas, {mode = "settings1", id = "ResetColors", x1 = 75, x2 = 860, y1 = 370, y2 = 415})
table.insert(m.ClickAreas, {mode = "settings1", id = "PreviousColorID", x1 = 90, x2 = 140, y1 = 500, y2 = 550})
table.insert(m.ClickAreas, {mode = "settings1", id = "NextColorID", x1 = 795, x2 = 845, y1 = 500, y2 = 550})
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosUp", param = "1", x1 = 210, x2 = 290, y1 = 655, y2 = 700}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosUp", param = "2", x1 = 300, x2 = 380, y1 = 655, y2 = 700}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosUp", param = "3", x1 = 385, x2 = 465, y1 = 655, y2 = 700}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosUp", param = "4", x1 = 470, x2 = 550, y1 = 655, y2 = 700}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosUp", param = "5", x1 = 560, x2 = 640, y1 = 655, y2 = 700}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosUp", param = "6", x1 = 645, x2 = 725, y1 = 655, y2 = 700}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosDown", param = "1", x1 = 210, x2 = 290, y1 = 740, y2 = 780}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosDown", param = "2", x1 = 300, x2 = 380, y1 = 740, y2 = 780}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosDown", param = "3", x1 = 385, x2 = 465, y1 = 740, y2 = 780}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosDown", param = "4", x1 = 470, x2 = 550, y1 = 740, y2 = 780}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosDown", param = "5", x1 = 560, x2 = 640, y1 = 740, y2 = 780}
)
table.insert(
m.ClickAreas,
{mode = "settings1", id = "ColorPosDown", param = "6", x1 = 645, x2 = 725, y1 = 740, y2 = 780}
)
table.insert(m.ClickAreas, {mode = "settings1", id = "ResetPosColor", x1 = 160, x2 = 340, y1 = 885, y2 = 935})
table.insert(m.ClickAreas, {mode = "settings1", id = "ApplyPosColor", x1 = 355, x2 = 780, y1 = 885, y2 = 935})
elseif m.mode == "startup" then
end
m = CreateBaseClickAreas(m)
return m
end
function CheckClick(M, N, O)
M = M * 1920
N = N * 1120
O = O or ""
HitPayload = {}
if screens ~= nil and #screens > 0 then
for i = 1, #screens, 1 do
if
screens[i].active == true and screens[i].element.getMouseX() ~= -1 and
screens[i].element.getMouseY() ~= -1
then
if O == "" then
for J, j in pairs(screens[i].ClickAreas) do
if j ~= nil and M >= j.x1 and M <= j.x2 and N >= j.y1 and N <= j.y2 then
O = j.id
HitPayload = j
break
end
end
end
if O == "ButtonPress" then
if screens[i].mode == HitPayload.param then
screens[i].mode = "startup"
else
screens[i].mode = HitPayload.param
end
if screens[i].mode == "damageoutline" then
if screens[i].submode == "" then
screens[i].submode = "top"
end
end
screens[i].refresh = true
screens[i].ClickAreas = {}
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "ToggleBackground" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if BackgroundMode == "" then
BackgroundSelected = 1
BackgroundMode = backgroundModes[BackgroundSelected]
else
BackgroundSelected = 1
BackgroundMode = ""
end
for J, m in pairs(screens) do
screens[J].refresh = true
end
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "PreviousBackground" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if BackgroundMode == "" then
BackgroundSelected = 1
BackgroundMode = backgroundModes[BackgroundSelected]
else
if BackgroundSelected <= 1 then
BackgroundSelected = #backgroundModes
else
BackgroundSelected = BackgroundSelected - 1
end
BackgroundMode = backgroundModes[BackgroundSelected]
end
for J, m in pairs(screens) do
screens[J].refresh = true
end
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "NextBackground" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if BackgroundMode == "" then
BackgroundSelected = 1
BackgroundMode = backgroundModes[BackgroundSelected]
else
if BackgroundSelected >= #backgroundModes then
BackgroundSelected = 1
else
BackgroundSelected = BackgroundSelected + 1
end
BackgroundMode = backgroundModes[BackgroundSelected]
end
for J, m in pairs(screens) do
screens[J].refresh = true
end
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "DecreaseOpacity" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if BackgroundModeOpacity > 0.1 then
BackgroundModeOpacity = BackgroundModeOpacity - 0.05
for J, m in pairs(screens) do
screens[J].refresh = true
end
SaveToDatabank()
SetRefresh()
RenderScreens()
end
elseif O == "IncreaseOpacity" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if BackgroundModeOpacity < 1.0 then
BackgroundModeOpacity = BackgroundModeOpacity + 0.05
for J, m in pairs(screens) do
screens[J].refresh = true
end
SaveToDatabank()
SetRefresh()
RenderScreens()
end
elseif O == "ResetColors" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
db.clear()
ColorPrimary = "FF6700"
ColorSecondary = "FFFFFF"
ColorTertiary = "000000"
ColorHealthy = "00FF00"
ColorWarning = "FFFF00"
ColorCritical = "FF0000"
ColorBackground = "000000"
ColorBackgroundPattern = "4f4f4f"
ColorFuelAtmospheric = "004444"
ColorFuelSpace = "444400"
ColorFuelRocket = "440044"
BackgroundMode = "deathstar"
BackgroundSelected = 1
BackgroundModeOpacity = 0.25
colorIDTable = {
[1] = {id = "ColorPrimary", desc = "Main HUD Color", basec = "FF6700", newc = "FF6700"},
[2] = {id = "ColorSecondary", desc = "Secondary HUD Color", basec = "FFFFFF", newc = "FFFFFF"},
[3] = {id = "ColorTertiary", desc = "Tertiary HUD Color", basec = "000000", newc = "000000"},
[4] = {
id = "ColorHealthy",
desc = "Color code for Healthy/Okay",
basec = "00FF00",
newc = "00FF00"
},
[5] = {
id = "ColorWarning",
desc = "Color code for Damaged/Warning",
basec = "FFFF00",
newc = "FFFF00"
},
[6] = {
id = "ColorCritical",
desc = "Color code for Broken/Critical",
basec = "FF0000",
newc = "FF0000"
},
[7] = {id = "ColorBackground", desc = "Background Color", basec = "000000", newc = "000000"},
[8] = {
id = "ColorBackgroundPattern",
desc = "Background Pattern Color",
basec = "4F4F4F",
newc = "4F4F4F"
},
[9] = {
id = "ColorFuelAtmospheric",
desc = "Color for Atmo Fuel/Elements",
basec = "004444",
newc = "004444"
},
[10] = {
id = "ColorFuelSpace",
desc = "Color for Space Fuel/Elements",
basec = "444400",
newc = "444400"
},
[11] = {
id = "ColorFuelRocket",
desc = "Color for Rocket Fuel/Elements",
basec = "440044",
newc = "440044"
}
}
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "PreviousColorID" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
colorIDIndex = colorIDIndex - 1
if colorIDIndex < 1 then
colorIDIndex = #colorIDTable
end
SaveToDatabank()
SetRefresh("settings1")
RenderScreens("settings1")
elseif O == "NextColorID" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
colorIDIndex = colorIDIndex + 1
if colorIDIndex > #colorIDTable then
colorIDIndex = 1
end
SaveToDatabank()
SetRefresh("settings1")
RenderScreens("settings1")
elseif O == "ColorPosUp" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
local P =
tonumber(string.sub(colorIDTable[colorIDIndex].newc, HitPayload.param, HitPayload.param), 16)
P = P + 1
if P > 15 then
P = 0
end
colorIDTable[colorIDIndex].newc =
replace_char(HitPayload.param, colorIDTable[colorIDIndex].newc, hexTable[P + 1])
SaveToDatabank()
SetRefresh("settings1")
RenderScreens("settings1")
elseif O == "ColorPosDown" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
local P =
tonumber(string.sub(colorIDTable[colorIDIndex].newc, HitPayload.param, HitPayload.param), 16)
P = P - 1
if P < 0 then
P = 15
end
colorIDTable[colorIDIndex].newc =
replace_char(HitPayload.param, colorIDTable[colorIDIndex].newc, hexTable[P + 1])
SaveToDatabank()
SetRefresh("settings1")
RenderScreens("settings1")
elseif O == "ResetPosColor" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
colorIDTable[colorIDIndex].newc = colorIDTable[colorIDIndex].basec
_G[colorIDTable[colorIDIndex].id] = colorIDTable[colorIDIndex].basec
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "ApplyPosColor" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
_G[colorIDTable[colorIDIndex].id] = colorIDTable[colorIDIndex].newc
SaveToDatabank()
SetRefresh()
RenderScreens()
elseif O == "DamagedPageDown" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
CurrentDamagedPage = CurrentDamagedPage + 1
if CurrentDamagedPage > math.ceil(#damagedElements / DamagePageSize) then
CurrentDamagedPage = math.ceil(#damagedElements / DamagePageSize)
end
HudDeselectElement()
SaveToDatabank()
SetRefresh("damage")
RenderScreens("damage")
elseif O == "DamagedPageUp" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
CurrentDamagedPage = CurrentDamagedPage - 1
if CurrentDamagedPage < 1 then
CurrentDamagedPage = 1
end
HudDeselectElement()
SaveToDatabank()
SetRefresh("damage")
RenderScreens("damage")
elseif O == "BrokenPageDown" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
CurrentBrokenPage = CurrentBrokenPage + 1
if CurrentBrokenPage > math.ceil(#brokenElements / DamagePageSize) then
CurrentBrokenPage = math.ceil(#brokenElements / DamagePageSize)
end
HudDeselectElement()
SaveToDatabank()
SetRefresh("damage")
RenderScreens("damage")
elseif O == "BrokenPageUp" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
CurrentBrokenPage = CurrentBrokenPage - 1
if CurrentBrokenPage < 1 then
CurrentBrokenPage = 1
end
HudDeselectElement()
SaveToDatabank()
SetRefresh("damage")
RenderScreens("damage")
elseif O == "DMGOChangeView" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
screens[i].submode = HitPayload.param
UpdateViewDamageoutline(screens[i])
SaveToDatabank()
SetRefresh("damageoutline", screens[i].submode)
RenderScreens("damageoutline", screens[i].submode)
elseif O == "DMGOChangeStretch" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if DMGOStretch == true then
DMGOStretch = false
else
DMGOStretch = true
end
UpdateViewDamageoutline(screens[i])
SaveToDatabank()
SetRefresh("damageoutline")
RenderScreens("damageoutline")
elseif
O == "ToggleDisplayAtmosphere" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all")
then
if screens[i].fuelA == true then
screens[i].fuelA = false
else
screens[i].fuelA = true
end
screens[i].fuelIndex = 1
SaveToDatabank()
SetRefresh("fuel")
RenderScreens("fuel")
elseif O == "ToggleDisplaySpace" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if screens[i].fuelS == true then
screens[i].fuelS = false
else
screens[i].fuelS = true
end
screens[i].fuelIndex = 1
SaveToDatabank()
SetRefresh("fuel")
RenderScreens("fuel")
elseif O == "ToggleDisplayRocket" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if screens[i].fuelR == true then
screens[i].fuelR = false
else
screens[i].fuelR = true
end
screens[i].fuelIndex = 1
SaveToDatabank()
SetRefresh("fuel")
RenderScreens("fuel")
elseif O == "DecreaseFuelIndex" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
screens[i].fuelIndex = screens[i].fuelIndex - 1
if screens[i].fuelIndex < 1 then
screens[i].fuelIndex = 1
end
SaveToDatabank()
SetRefresh("fuel")
RenderScreens("fuel")
elseif O == "IncreaseFuelIndex" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
screens[i].fuelIndex = screens[i].fuelIndex + 1
SaveToDatabank()
SetRefresh("fuel")
RenderScreens("fuel")
elseif O == "ToggleHudMode" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
if HUDMode == true then
HUDMode = false
forceDamageRedraw = true
HudDeselectElement()
SaveToDatabank()
SetRefresh()
RenderScreens()
else
HUDMode = true
forceDamageRedraw = true
HudDeselectElement()
SaveToDatabank()
SetRefresh()
RenderScreens()
end
elseif O == "ToggleSimulation" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then
CurrentDamagedPage = 1
CurrentBrokenPage = 1
if SimulationMode == true then
SimulationMode = false
SimulationActive = false
UpdateDamageData()
UpdateTypeData()
forceDamageRedraw = true
HudDeselectElement()
SetRefresh("damage")
SetRefresh("damageoutline")
SetRefresh("settings1")
SetRefresh("fuel")
SaveToDatabank()
RenderScreens()
else
SimulationMode = true
SimulationActive = false
UpdateDamageData()
UpdateTypeData()
forceDamageRedraw = true
HudDeselectElement()
SetRefresh("damage")
SetRefresh("damageoutline")
SetRefresh("settings1")
SetRefresh("fuel")
SaveToDatabank()
RenderScreens()
end
elseif
(O == "ToggleElementLabel" or O == "ToggleElementLabel2") and
(HitPayload.mode == screens[i].mode or HitPayload.mode == "all")
then
if UseMyElementNames == true then
UseMyElementNames = false
SetRefresh("damage")
RenderScreens("damage")
else
UseMyElementNames = true
SetRefresh("damage")
RenderScreens("damage")
end
elseif
(O == "SwitchScrapTier" or O == "SwitchScrapTier2") and
(HitPayload.mode == screens[i].mode or HitPayload.mode == "all")
then
ScrapTier = ScrapTier + 1
if ScrapTier > 4 then
ScrapTier = 1
end
SetRefresh("damage")
RenderScreens("damage")
end
end
end
end
end
function GetContentFlight()
local Q = ""
Q = Q .. GetHeader("Flight Data Report") .. [[
end
function GetContentDamage()
local Q = ""
if SimulationMode == true then
Q = Q .. GetHeader("Damage Report (Simulated damage)") .. [[]]
else
Q = Q .. GetHeader("Damage Report") .. [[]]
end
Q = Q .. GetContentDamageScreen()
return Q
end
function GetContentDamageoutline(m)
UpdateDataDamageoutline()
UpdateViewDamageoutline(m)
local Q = ""
Q =
Q ..
GetHeader("Damage Ship Outline Report") ..
GetDamageoutlineShip() ..
[[]]
if m.submode == "top" then
Q =
Q ..
[[
Top View
Side View
Front View
]]
elseif m.submode == "side" then
Q =
Q ..
[[
Top View
Side View
Front View
]]
elseif m.submode == "front" then
Q =
Q ..
[[
Top View
Side View
Front View
]]
else
end
Q = Q .. [[]] .. #dmgoElements .. [[ of ]] .. ElementCounter .. [[ shown]]
Q = Q .. [[]]
if DMGOStretch == true then
Q = Q .. [[]]
end
Q = Q .. [[Stretch both axis]]
return Q
end
function GetContentFuel(m)
if #FuelAtmosphericTanks < 1 and #FuelSpaceTanks < 1 and #FuelRocketTanks < 1 then
return ""
end
local R = 0
local Q = ""
local S = {}
FuelDisplay = {m.fuelA, m.fuelS, m.fuelR}
if FuelDisplay[1] == true and #FuelAtmosphericTanks > 0 then
table.insert(S, "Atmospheric")
R = R + 1
end
if FuelDisplay[2] == true and #FuelSpaceTanks > 0 then
table.insert(S, "Space")
R = R + 1
end
if FuelDisplay[3] == true and #FuelRocketTanks > 0 then
table.insert(S, "Rocket")
R = R + 1
end
Q =
Q ..
GetHeader("Fuel Report (" .. table.concat(S, ", ") .. ")") ..
[[
<style>
.fuele{fill:#]] ..
ColorBackground ..
[[;}
.fuela{fill:#]] ..
ColorFuelAtmospheric ..
[[;fill-opacity:1;}
.fuels{fill:#]] ..
ColorFuelSpace ..
[[;fill-opacity:1;}
.fuelr{fill:#]] ..
ColorFuelRocket ..
[[;fill-opacity:1;}
end
function GetContentCargo()
local Q = ""
Q = Q .. GetHeader("Cargo Report") .. [[
end
function GetContentAGG()
local Q = ""
Q = Q .. GetHeader("Anti-Grav Control") .. [[
end
function GetContentMap()
local Q = ""
Q = Q .. GetHeader("Map Overview") .. [[
end
function GetContentTime()
local Q = ""
Q = Q .. GetHeader("Time") .. epochTime()
Q =
Q ..
[[
<rect x=0 y=13 width=4 height=5 fill=#]] ..
ColorPrimary ..
[[>
<rect x=10 y=13 width=4 height=5 fill=#]] ..
ColorPrimary ..
[[>
<rect x=20 y=13 width=4 height=5 fill=#]] ..
ColorPrimary ..
[[>
]]
return Q
end
function GetContentSettings1()
local Q = ""
Q = Q .. GetHeader("Settings") .. [[]]
if BackgroundMode == "" then
Q = Q .. [[Activate background]]
else
Q =
Q ..
[[Deactivate background (']] ..
BackgroundMode .. [[', ]] .. string.format("%.0f", BackgroundModeOpacity * 100) .. [[%)]]
end
Q =
Q ..
[[
Previous background
Next background
end
function GetContentStartup()
local Q = ""
Q = Q .. GetElementLogo(812, 380, "f", "f", "f")
if YourShipsName == "Enter here" then
Q =
Q ..
[[Spaceship ID ]] ..
ShipID ..
[[]]
else
Q =
Q ..
[[]] ..
YourShipsName ..
[[]]
end
if ShowWelcomeMessage == true then
Q = Q .. [[Greetings, Commander ]] .. PlayerName .. [[.]]
end
if #Warnings > 0 then
Q = Q .. [[Warning: ]] .. table.concat(Warnings, " ") .. [[]]
end
Q =
Q ..
[[Damage Report v]] ..
VERSION .. [[, by DorianGray - Discord: Dorian Gray#2623.]]
return Q
end
function RenderScreen(m, a0)
if a0 == nil then
PrintConsole("ERROR: contentToRender is nil.")
unit.exit()
end
CreateClickAreasForScreen(m)
local Q = ""
Q =
Q ..
[[
<style>
body{
background-color: #]] ..
ColorBackground ..
[[; ]] ..
GetContentBackground(BackgroundMode) ..
[[
}
.screen { width: 1920px; height: 1120px; }
.main { width: 1920px; height: 1040px; }
.menu { width: 1920px; height: 70px; stroke: #]] ..
ColorPrimary ..
[[; stroke-width: 3; }
end
function RenderScreens(a2, a3)
a2 = a2 or "all"
a3 = a3 or "all"
if screens ~= nil and #screens > 0 then
local a4 = ""
local a5 = ""
local a6 = ""
local a7 = ""
local a8 = ""
local a9 = ""
local aa = ""
local ab = ""
local ac = ""
local ad = ""
local ae = ""
local af = ""
for J, m in pairs(screens) do
if m.refresh == true then
local a0 = ""
if m.mode == "flight" and (a2 == "flight" or a2 == "all") then
if a4 == "" then
a4 = GetContentFlight()
end
a0 = a4
elseif m.mode == "damage" and (a2 == "damage" or a2 == "all") then
if a5 == "" then
a5 = GetContentDamage()
end
a0 = a5
elseif m.mode == "damageoutline" and (a2 == "damageoutline" or a2 == "all") then
if m.submode == "" then
m.submode = "top"
screens[J].submode = "top"
end
if m.submode == "top" and (a3 == "top" or a3 == "all") then
if a6 == "" then
a6 = GetContentDamageoutline(m)
end
a0 = a6
end
if m.submode == "side" and (a3 == "side" or a3 == "all") then
if a7 == "" then
a7 = GetContentDamageoutline(m)
end
a0 = a7
end
if m.submode == "front" and (a3 == "front" or a3 == "all") then
if a8 == "" then
a8 = GetContentDamageoutline(m)
end
a0 = a8
end
elseif m.mode == "fuel" and (a2 == "fuel" or a2 == "all") then
m = WipeClickAreasForScreen(screens[J])
a0 = GetContentFuel(m)
elseif m.mode == "cargo" and (a2 == "cargo" or a2 == "all") then
if aa == "" then
aa = GetContentCargo()
end
a0 = aa
elseif m.mode == "agg" and (a2 == "agg" or a2 == "all") then
if ab == "" then
ab = GetContentAGG()
end
a0 = ab
elseif m.mode == "map" and (a2 == "map" or a2 == "all") then
if ac == "" then
ac = GetContentMap()
end
a0 = ac
elseif m.mode == "time" and (a2 == "time" or a2 == "all") then
if ad == "" then
ad = GetContentTime()
end
a0 = ad
elseif m.mode == "settings1" and (a2 == "settings1" or a2 == "all") then
if ae == "" then
ae = GetContentSettings1()
end
a0 = ae
elseif m.mode == "startup" and (a2 == "startup" or a2 == "all") then
if af == "" then
af = GetContentStartup()
end
a0 = af
else
a0 = "Invalid screen mode. ('" .. m.mode .. "')"
end
if a0 ~= "" then
RenderScreen(m, a0)
else
DrawCenteredText("ERROR: No contentToRender delivered for " .. m.mode)
PrintConsole("ERROR: No contentToRender delivered for " .. m.mode)
unit.exit()
end
screens[J].refresh = false
end
end
end
if HUDMode == true then
system.setScreen(GetContentDamageHUDOutput())
system.showScreen(1)
else
system.showScreen(0)
end
end
function OnTickData(C)
end
function OnTickData1(C)
totalShipMass = core.getConstructMass();
if formerTotalShipMass ~= totalShipMass then
--UpdateDamageData(true)
UpdateTypeData()
SetRefresh()
formerTotalShipMass = totalShipMass
else
--UpdateDamageData(C)
UpdateTypeData()
end
end
unit.hide()
ClearConsole()
PrintConsole("DAMAGE REPORT v" .. VERSION .. " STARTED", true)
InitiateSlots()
LoadFromDatabank()
SwitchScreens("on")
InitiateScreens()
if core == nil then
PrintConsole("ERROR: Connect the core to the programming board.")
unit.exit()
else
OperatorID = unit.getMasterPlayerId()
OperatorData = database.getPlayer(OperatorID)
PlayerName = OperatorData["name"]
ShipID = core.getConstructId()
end
if db == nil then
table.insert(Warnings, "No databank connected, won't save/load settings.")
end
if YourShipsName == "Enter here" then
table.insert(Warnings, "No ship name set in LUA settings.")
end
if
SkillRepairToolEfficiency == 0 and SkillRepairToolOptimization == 0 and StatFuelTankOptimization == 0 and
StatContainerOptimization == 0 and
StatAtmosphericFuelTankHandling == 0 and
StatSpaceFuelTankHandling == 0 and
StatRocketFuelTankHandling == 0
then
table.insert(Warnings, "No talents/stats set in LUA settings.")
end
if
SkillRepairToolEfficiency < 0 or SkillRepairToolOptimization < 0 or StatFuelTankOptimization < 0 or
StatContainerOptimization < 0 or
StatAtmosphericFuelTankHandling < 0 or
StatSpaceFuelTankHandling < 0 or
StatRocketFuelTankHandling < 0 or
SkillRepairToolEfficiency > 5 or
SkillRepairToolOptimization > 5 or
StatFuelTankOptimization > 5 or
StatContainerOptimization > 5 or
StatAtmosphericFuelTankHandling > 5 or
StatSpaceFuelTankHandling > 5 or
StatRocketFuelTankHandling > 5
then
PrintConsole(
"ERROR: Talents/stats can only range from 0 to 5. Please set correctly in LUA settings and reactivate script."
)
unit.exit()
end
if screens == nil or #screens == 0 then
HUDMode = true
PrintConsole("Warning: No screens connected. Entering HUD mode only.")
end
OnTickData(true)
unit.setTimer("UpdateData", UpdateDataInterval)
unit.setTimer("UpdateHighlight", HighlightBlinkingInterval)
Beta Was this translation helpful? Give feedback.
All reactions