Add Mission name to Unit Name

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
morphin
Posts: 723
Joined: Fri Apr 26, 2002 6:51 pm
Location: Switzerland

Add Mission name to Unit Name

Post 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
morphin
Posts: 723
Joined: Fri Apr 26, 2002 6:51 pm
Location: Switzerland

Re: Add Mission name to Unit Name

Post 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 :D
Post Reply

Return to “Lua Legion”