Lua Condition- If Destroyed In A Area

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Posts: 327
Joined: Thu Mar 26, 2015 2:09 pm

Lua Condition- If Destroyed In A Area

Post by butch4343 »

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?



Posts: 1847
Joined: Wed Dec 27, 2017 12:59 pm

RE: Lua Condition- If Destroyed In A Area

Post by BDukes »

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

Don't call it a comeback...
Posts: 1582
Joined: Thu Nov 15, 2018 7:24 pm

RE: Lua Condition- If Destroyed In A Area

Post by KnightHawk75 »

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

Code: Select all

 --change function names or all to locals to suit your desires, globals presented here.
 --global funcs on scene load.
 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;
     return false;
 function gKH.SceneGlobals.QualifiyBackfireDestruction(u,airbasename)
   if ((u ~= nil) and u.base ~=nil) and gKH.Unit:isAircraftAirborne(u) == false and"AirBase" and == airbasename  then return true;
   else return false;
 -- end global startup functions

Code: Select all

 --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( .. ' destroyed at qualified airbase.');
Post Reply

Return to “Lua Legion”