Page 1 of 1
Add Mission name to Unit Name
Posted: Sun Aug 13, 2023 2:03 pm
by morphin
Hi
I would like to put in front of the unit name the mission name (Players Side, for all units that have a mission assigned).
Is there a easy way to do it with Lua?
Thank's for any help and hints
Andy
Re: Add Mission name to Unit Name
Posted: Mon Aug 14, 2023 9:47 am
by morphin
Ok
I have this code made:
local a = VP_GetSide({Side ="NATO"})
local units = {}
for i = 1, #a.units do --loop thru units and push them into the table
table.insert(units, a.units)
end --closes loop
for i = 1, #units do --loop thru table of units
local myUnit = ScenEdit_GetUnit( {guid= units.guid})
if myUnit.type =="Aircraft" and myUnit.mission ~= nil then
if not string.find(myUnit.name,myUnit.mission.name:gsub("%s+", ""),1,true) then
print(myUnit.mission.name:gsub("%s+", "").." "..myUnit.name)
ScenEdit_SetUnit({guid=units.guid,newname=myUnit.mission.name:gsub("%s+", "").." "..myUnit.name})
end
end
end --closes loop
seems to work 