Lua Condition- If Destroyed In A Area (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


butch4343 -> Lua Condition- If Destroyed In A Area (5/22/2021 3:26:49 PM)

Hi folks

I was wondering if its possible to set a condition of where a unit is destroyed, I have some Backfires that are participating in a carrier strike, I want the player to score if they are destroyed on their airfield rather than in the air.

I have had a look and wondered if theres a way to set a condition whereby the scoring is only allowed if the unit is within XYZ?

I have looked at the LUA script

local u = side:unitsInArea({Area = { 'RP-5094', 'RP-5095', 'RP-5096', 'RP-5097'}, TargetFilter = { TargetType = 'Aircraft'} })

But I dont think that would work TBH because its to do with side contacts, I think what I need is something that references where the unit is if that makes sense?


Or alternatively another easier way to score it, I did consider just having the player score for damaging the Large Parking Spot that only bombers can be parked on but then they would score damaging empty parking stands.

Anyone any thoughts?

Regards

Butch








BDukes -> RE: Lua Condition- If Destroyed In A Area (5/22/2021 3:47:27 PM)

Hmm. Maybe a conditional based on the aircraft's altitude?

Mike




KnightHawk75 -> RE: Lua Condition- If Destroyed In A Area (5/22/2021 9:45:21 PM)

Butch sadly when destroyed a unit no longer has a location, this is flaw in my opinion but it is what it is atm, well technically it has a location - 0 lat and 0 lon, indicating it's dead, so while I have some inside-polygon checking code you could use it will not work here, nor may :inArea after unit has been destroyed. It does however maintain it's past 'base' and 'group' during the event execution though, so if it's a member of a air-base group or otherwise hosted by a facility you could check if it's the base\group\unit in question you want to compare against.
In the following example the airbase is a typical grouped airbase called "Some Airbase" and the unit was in a facility with-in that group.

So you can set an event based on a Unit Destroyed trigger for Blackfire's side (we'll call it Red), aircraft, bomber,tu-22m etc and tie an action (or condition) to something like following

--change function names or all to locals to suit your desires, globals presented here.
--global funcs on scene load.
gKH={};gKH.Unit={};gKH.SceneGlobals={};
function gKH.Unit:isAircraftAirborne(u)
    if ((u.condition_v == "Airborne") or u.condition_v == "RTB") or u.condition_V == "Landing_PreTouchdown" or
     u.condition_v == "ManoeuveringToRefuel" or u.condition_v == "Refuelling" or u.condition_v == "OffloadingFuel" or 
     u.condition_v == "DeployingDippingSonar" or u.condition_v == "EmergencyLanding" or  u.condition_v == "BVRAttack" or 
     u.condition_v == "BVRCrank" or u.condition_v == "Dogfight" or u.condition_v == "BVRDrag" or u.condition_v == "TransferringCargo" then
      return true;
    end
    return false;
end

function gKH.SceneGlobals.QualifiyBackfireDestruction(u,airbasename)
  if ((u ~= nil) and u.base ~=nil) and gKH.Unit:isAircraftAirborne(u) == false and 
    u.base.group.type=="AirBase" and u.base.group.name == airbasename  then return true;
  else return false;
  end
end
-- end global startup functions
--Placed in some action script for the event or convert for use in a 'condition'.
local u = ScenEdit_UnitX();
if gKH.SceneGlobals.QualifiyBackfireDestruction(u,"Some Airbase") == true then
    ScenEdit_SetScore("Blue",ScenEdit_GetScore("Blue") + 50,'Backfire unit ' .. tostring(u.name) .. ' destroyed at qualified airbase.');
end




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.546875