It appears I am spamming the forum
I have a problem. I've been sitting at it for the last few days and am stumped. The API reference does not help much, but the wiki mentions that adding mutliple units at runtime should be possible - at the 'postRunFn' stage. Brilliant for my use case. So I wrote this code:
local maxVariants = 20
while i < maxVariants do
local MuVariantRecord = api.type.MultipleUnit.new() -- creating a variant
MuVariantRecord.name = muRecord.name -- giving it a name
MuVariantRecord.vehicles = {} -- create the vehicles array
for _, vehicle in ipairs( muRecord.vehicles ) do
-- this does not work --
-- MuVariantRecord.vehicles:insert(
-- i
-- , { name = string.gsub( FormSavePath( vehicle.name ), "^/res/models/model/", "" )
-- , forward = vehicle.forward
-- }
-- )
end
api.res.multipleUnitRep.add( muRecord.fileName, MuVariantRecord, true ) -- add MU
i = i + 1
end
Alles anzeigen
What I am trying to do is to take an existing MU and add several variants of it using different models. The problem I am facing is that I don't know how to add stuff ot the vehicles array. So far I tried to use the 'table.insert', use an index starting from 1 or from 0 and even regular c++ code.
I gather that I should use some sort of an api call for the engine to allocate the memory for the MU component for me. But I dumped the api and api.type arrays and did not find any relevant function. Scouring the game provided scripts gave me nothing. What am I missing?
EDIT: the creation of the vehicle array does not seem to change anything.