This specifics of the facility may matter, but have you tried imparting damage or destroyed status on what you want disabled or impacted (be that a sensor, mount, or other component), or alternatively (harder with aircraft in the air) remove all quantity of weapons you don't want firing till you otherwise set it back.
So for a simple example lets say you have a Single Unit Airfield and a M777 or Ceasar and you wanted to disable any aircraft launching due to temporary weather or whatever, and you wanted to disable the m777 or Ceasar from firing temporarily without wanting to track ammo and not caring about existing operational status. We'll further assume one doesn't care if there is destruction to any aircraft\boats that are technically presently hosted on runway or rap at the moment of execution, though this warning would apply more to hangers and parking spaces etc(not in the example) but you have been warned.
Code: Select all
---// function to set ALL or first matching components matching a name-contains string:find() pattern to a specified operational status.
---@param u CMO__UnitWrapper - The unit wrapper to operate upon.
---@param thecompname string - the string.find() pattern to search the component name for containing.
---@param thestatus string - the operational status string code 'none','destroyed','light' or 'heavy'
---@param firstonly? boolean - optional (required if log param will be specified as well) defaults to false, controls of only first-match search is done.
---@param log boolean - defaults to false, true to enable successful operation logging.
---@return boolean - true if no errors, false upon at least 1 error even if somoe successes.
local function SetComponentStatusByNameContains(u,thecompname,thestatus,firstonly,log)
if u==nil or thecompname == nil or thestatus==nil then print('invalid params. unit wrapper,component name, and string status required.'); return false; end
if (firstonly == nil) or type(firstonly) ~='boolean' then firstonly=false; end
if log==nil then log=false; end
local retval1,retval2,eflag = false,nil,true;
for _,v in ipairs(u.components) do
retval1,retval2=false,nil;
if v.comp_name:find(thecompname) ~= nil then --user can use string.find special indicators if needbe.
retval1,retval2 = pcall(ScenEdit_SetUnitDamage,{guid=u.guid, components={{v.comp_guid,thestatus}}});
if retval1 == false then --log error
print('failed to set operation status to ' ..tostring(thestatus).. ' on component: ' .. tostring(v.comp_name)); eflag=false;
elseif log then
print(tostring(v.comp_name) .. ' set to ' .. thestatus);
end
if firstonly then break; end
end
end
return eflag
end
---// function to set ALL or first matching mounts matching a name-contains string:find() pattern to a specified operational status.
---@param u CMO__UnitWrapper - The unit wrapper to operate upon.
---@param themountname string - the string.find() pattern to search the component name for containing.
---@param thestatus string - the operational status string code 'none','destroyed','light' or 'heavy'
---@param firstonly? boolean - optional (required if log param will be specified as well) defaults to false, controls of only first-match search is done.
---@param log? boolean - optional defaults to false, true to enable successful operation logging.
---@return boolean - true if no errors, false upon at least 1 error even if somoe successes.
local function SetMountStatusByNameContains(u,themountname,thestatus,firstonly,log)
if u==nil or themountname == nil or thestatus==nil then print('invalid params. unit wrapper, mount name, and status string required.'); return false; end
if (firstonly == nil) or type(firstonly) ~='boolean' then firstonly=false; end
if log==nil then log =false; end
local retval1,retval2,egflag= false,nil,true;
for _,v in ipairs(u.mounts) do
retval1,retval2=false,nil;
if v.mount_name:find(themountname) ~= nil then --user can use string.find special indicators if needbe.
retval1,retval2 = pcall(ScenEdit_SetUnitDamage,{guid=u.guid, components={{v.mount_guid,thestatus}}});
if retval1 == false then --log error
print('failed to set operational status to '.. tostring(thestatus) .. ' on mount: ' .. tostring(v.mount_name)); eflag=false;
elseif log then
print(tostring(v.mount_name) .. ' set to ' .. thestatus);
end
if firstonly then break; end
end
end
return eflag
end
--usage example:
local sua = ScenEdit_GetUnit({guid='4FH7PU-0HMIGRLV5HQ8V',name="Blue_SUA_1"}); --replace with whatever unit
local art = ScenEdit_GetUnit({guid='4FH7PU-0HMIGRLV5HQES',name='#2401 155mm/52 Caesar'}); --replace with whatever unit
SetComponentStatusByNameContains(sua,'Runway','destroyed',nil,true); -- as of db490 should cover all runway\runway-taxiway\and raps.
SetMountStatusByNameContains(art,'155mm/','destroyed'); -- example covering most 155mm entries, like caesar\m777\m109 etc.
-- check DamageCtrl screen for said units here you will see destroyed status without rest of unit destroyed...
SetComponentStatusByNameContains(sua,'Runway','none',false,true) ;
SetMountStatusByNameContains(art,'155mm/','none');
-- check DamageCtrl screen for said units here you will see operational status restored...
print('done');
-- This is just a very simple example. It does not take into account a full solution,
-- that say tracks the state of said component\mount\sensor before hand, keeps that state data, and then returns
-- the state to what it was at the time of disabling nor does it cover the saving of that global state.
-- It just a simple how do you change the values example. Also it does not try to completely maximize speed of execution\compare.
Hope that hopes, and if you are wonder why the two functions when technically in the above case you could just use components version to do the mounts, the primary is there will be less to unnecessarily check with 'mounts' version then all components, hence better performance.