Selected Unit (?contact) Damaged

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Parel803
Posts: 603
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Selected Unit (?contact) Damaged

Post by Parel803 »

Good afternoon,
Tried to get damage on a selected unit. Used the exampl from KH on
https://www.matrixgames.com/forums/tm.a ... s&#4900919
Thanks for that. Didn't try it on a contact yet, next on the list.

I got it working in a special action except the message. Which I wanna make a message box. Since this is made with trial&error (instead of knowledge of it all) I'm sure It can be doen better, if someone sees stuuff to change it is much appriciated.

local sUnits=ScenEdit_SelectedUnits(); --get the list.
-- compile a list of all units and contacts.
local myTempTable = {}
if(sUnits.units ~=nil) then --validate it
for k,v in pairs(sUnits.units) do
table.insert(myTempTable,{name= v.name,guid = v.guid})
end
end
if(sUnits.contacts ~=nil) then
for k,v in pairs(sUnits.contacts) do
table.insert(myTempTable,{name= v.name,guid = v.guid})
end
end
sUnits = nil; --don't need it anymore.

--now process the combined table of units and contacts.
if(#myTempTable > 0) then --if our temptable has more than 0 entries.
local u;
for k,v in pairs(myTempTable) do --loop though selected unit table
u = VP_GetUnit({guid=v.guid}); --get the unit via guid or contact guid. just used for example.
if((u ~=nil) and (u.type=='Ship')) then --only attempt for aircraft or ships.
ScenEdit_SetUnitDamage({guid=u.guid, fires=1, flood=1})
else
print("No Unit selected");
end
end
u = nil; --clear before iterate
end --end for
myTempTable = nil;

I left the notes made by KH in.
Best regards GJ
KnightHawk75
Posts: 1557
Joined: Thu Nov 15, 2018 7:24 pm

RE: Selected Unit (?contact) Damaged

Post by KnightHawk75 »

Do you want is asked per-selected-unit

or

one firelevel used for the whole selection.

See attached (tested).
Attachments
Parel803_test.zip
(1.32 KiB) Downloaded 5 times
Parel803
Posts: 603
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: Selected Unit (?contact) Damaged

Post by Parel803 »

Saw I never replied, sorry
Thank, this works great
We use it for the umpire in the MP game
regards GJ
Post Reply

Return to “Lua Legion”