Selected Unit (?contact) Damaged
Posted: Tue Jan 18, 2022 11:17 am
Good afternoon,
Tried to get damage on a selected unit. Used the exampl from KH on
https://www.matrixgames.com/forums/tm.a ... s�
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
Tried to get damage on a selected unit. Used the exampl from KH on
https://www.matrixgames.com/forums/tm.a ... s�
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