Banner Image

Module Utilities.Utils

Utilities - Derived utilities taken from the MIST framework, added helpers from the MOOSE community.

Authors:

  • Grimes : Design & Programming of the MIST framework.

Contributions:

  • FlightControl : Rework to OO framework.
  • And many more

Global(s)

Global BIGSMOKEPRESET

Global CALLSIGN

Global DCSMAP

Global FLARECOLOR

Global SMOKECOLOR

Global UTILS

Global lookup_table

#table lookup_table

Type(s)

Fields and Methods inherited from DCSMAP Description

DCSMAP.Afghanistan

DCSMAP.Caucasus

Caucasus map.

DCSMAP.Falklands

South Atlantic map.

DCSMAP.Kola

Kola map.

DCSMAP.MarianaIslands

Mariana Islands map.

DCSMAP.NTTR

Nevada Test and Training Range map.

DCSMAP.Normandy

Normandy map.

DCSMAP.PersianGulf

Persian Gulf map.

DCSMAP.Sinai

Sinai map.

DCSMAP.Syria

Syria map.

DCSMAP.TheChannel

The Channel map.

Fields and Methods inherited from FLARECOLOR Description

FLARECOLOR.Green

FLARECOLOR.Red

FLARECOLOR.White

FLARECOLOR.Yellow

Fields and Methods inherited from SMOKECOLOR Description

SMOKECOLOR.Blue

SMOKECOLOR.Green

SMOKECOLOR.Orange

SMOKECOLOR.Red

SMOKECOLOR.White

Fields and Methods inherited from UTILS Description

UTILS.AngleBetween(angle, min, max)

Checks if a given angle (heading) is between 2 other angles.

UTILS.BasicSerialize(s)

Basic serialize (porting in Slmod's "safestring" basic serialize).

UTILS.BearingToCardinal(Heading)

Heading Degrees (0-360) to Cardinal

UTILS.BeaufortScale(speed)

Beaufort scale: returns Beaufort number and wind description as a function of wind speed in m/s.

UTILS.CelsiusToFahrenheit(Celcius)

Convert temperature from Celsius to Fahrenheit.

UTILS.CheckFileExists(Path, Filename)

Function to check if a file exists.

UTILS.CheckMemory(output)

Checks the current memory usage collectgarbage("count").

UTILS.Clamp(value, min, max)

Easy to read one liner to clamp a value

UTILS.ClampAngle(value)

Clamp an angle so that it's always between 0 and 360 while still being correct

UTILS.ClockHeadingString(refHdg, tgtHdg)

Get the clock position from a relative heading

UTILS.ClockToSeconds(clock)

Convert clock time from hours, minutes and seconds to seconds.

UTILS.CombineTimeStrings(time_string_01, time_string_02)

Combines two time strings to give you a new time.

UTILS.DecimalToOctal(Number)

Convert a decimal to octal

UTILS.DeepCopy(object)

Deep copy a table.

UTILS.DisplayMissionTime(duration)

Display clock and mission time on screen as a message to all.

UTILS.DoString(s)

Executes the given string.

UTILS.EnsureTable(Object, ReturnNil)

Ensure the passed object is a table.

UTILS.FeetToMeters(feet)

UTILS.FileExists(file)

Checks if a file exists or not.

UTILS.GMTToLocalTimeDifference()

Get the time difference between GMT and local time.

UTILS.Gdump(fname)

Dumps the global table _G.

UTILS.GenerateFMFrequencies()

Function to generate valid FM frequencies in mHz for radio beacons (FM).

UTILS.GenerateLaserCodes()

Function to generate valid laser codes for JTAC.

UTILS.GenerateUHFrequencies(Start, End)

Function to generate valid UHF Frequencies in mHz (AM).

UTILS.GenerateVHFrequencies()

Function to generate valid VHF frequencies in kHz for radio beacons (FM).

UTILS.GetCallsignName(Callsign)

Get the callsign name from its enumerator value

UTILS.GetCharacters(str)

Get a table of all characters in a string.

UTILS.GetCoalitionEnemy(Coalition, Neutral)

Get the enemy coalition for a given coalition.

UTILS.GetCoalitionName(Coalition)

Get the coalition name from its numerical ID, e.g.

UTILS.GetCountPerTypeName(Group)

Function to obtain a table of typenames from the group given with the number of units of the same type in the group.

UTILS.GetDCSMap()

Returns the DCS map/theatre as optained by env.mission.theatre.

UTILS.GetDCSMissionDate()

Returns the mission date.

UTILS.GetDayOfYear(Year, Month, Day)

Get the day of the year.

UTILS.GetMagneticDeclination(map)

Returns the magnetic declination of the map.

UTILS.GetMarkID()

UTILS.GetMissionDay(Time)

Returns the day of the mission.

UTILS.GetMissionDayOfYear(Time)

Returns the current day of the year of the mission.

UTILS.GetModulationName(Modulation)

Get the modulation name from its numerical value.

UTILS.GetOSTime()

Get OS time.

UTILS.GetRandomTableElement(t, replace)

Get a random element of a table.

UTILS.GetReportingName(Typename)

Get the NATO reporting name of a unit type name

UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, Rising, Tlocal)

Get sunrise or sun set of a specific day of the year at a specific location.

UTILS.GetSunrise(Day, Month, Year, Latitude, Longitude, Rising, Tlocal)

Get sun rise of a specific day of the year at a specific location.

UTILS.GetSunset(Day, Month, Year, Latitude, Longitude, Rising, Tlocal)

Get sun set of a specific day of the year at a specific location.

UTILS.GetZoneProperties(zone_name)

Get the properties names and values of properties set up on a Zone in the Mission Editor.

UTILS.HdgDiff(h1, h2)

Calculate the difference between two "heading", i.e.

UTILS.HdgTo(a, b)

Returns the heading from one vec3 to another vec3.

UTILS.HexToRGBA(hex_string)

HexToRGBA

UTILS.IasToTas(ias, altitude, oatcorr)

Convert indicated airspeed (IAS) to true airspeed (TAS) for a given altitude above main sea level.

UTILS.IsAnyInTable(Table, Objects, Key)

Check if any object of multiple given objects is contained in a table.

UTILS.IsInRadius(InVec2, Vec2, Radius)

UTILS.IsInSphere(InVec3, Vec3, Radius)

UTILS.IsInTable(Table, Object, Key)

Check if an object is contained in a table.

UTILS.IsInstanceOf(object, className)

Function to infer instance of an object

Examples:

  • UTILS.IsInstanceOf( 'some text', 'string' ) will return true

  • UTILS.IsInstanceOf( some_function, 'function' ) will return true

  • UTILS.IsInstanceOf( 10, 'number' ) will return true

  • UTILS.IsInstanceOf( false, 'boolean' ) will return true

  • UTILS.IsInstanceOf( nil, 'nil' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', ZONE ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'ZONE' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'zone' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'BASE' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'GROUP' ) will return false

UTILS.IsLoadingDoorOpen(unit_name)

(Helicopter) Check if one loading door is open.

UTILS.KiloMetersToFeet(kilometers)

UTILS.KiloMetersToNM(kilometers)

UTILS.KiloMetersToSM(kilometers)

UTILS.KmphToKnots(knots)

UTILS.KmphToMps(kmph)

UTILS.KnotsToAltKIAS(knots, altitude)

Convert knots to altitude corrected KIAS, e.g.

UTILS.KnotsToKmph(knots)

UTILS.KnotsToMps(knots)

Convert knots to meters per second.

UTILS.LCGRandom()

Return a pseudo-random number using the LCG algorithm.

UTILS.LCGRandomSeed(seed)

Seed the LCG random number generator.

UTILS.LoadFromFile(Path, Filename)

Function to load an object from a file.

UTILS.LoadSetOfGroups(Path, Filename, Spawn, Structured, Cinematic, Effect, Density)

Load back a SET of groups from file.

UTILS.LoadSetOfOpsGroups(Path, Filename)

Load back a #OPSGROUP (ARMYGROUP) data from file for use with Ops.Brigade#BRIGADE.LoadBackAssetInPosition()

UTILS.LoadSetOfStatics(Path, Filename)

Load back a SET of statics from file.

UTILS.LoadStationaryListOfGroups(Path, Filename, Reduce, Structured, Cinematic, Effect, Density)

Load back a stationary list of groups from file.

UTILS.LoadStationaryListOfStatics(Path, Filename, Reduce, Dead, Cinematic, Effect, Density)

Load back a stationary list of statics from file.

UTILS.MGRSStringToSRSFriendly(Text, Slow)

Get a NATO abbreviated MGRS text for SRS use, optionally with prosody slow tag

UTILS.MetersToFeet(meters)

UTILS.MetersToNM(meters)

UTILS.MetersToSM(meters)

UTILS.MiphToMps(miph)

UTILS.MpsToKmph(mps)

UTILS.MpsToKnots(mps)

Convert meters per second to knots.

UTILS.MpsToMiph(mps)

Convert meters per second to miles per hour.

UTILS.NMToKiloMeters(NM)

UTILS.NMToMeters(NM)

UTILS.OctalToDecimal(Number)

Convert an octal to decimal

UTILS.OneLineSerialize(tbl)

Serialize a given table.

UTILS.PercentageChance(chance)

Easy to read one line to roll the dice on something.

UTILS.PlotRacetrack(Coordinate, Altitude, Speed, Heading, Leg, Coalition, Color, Alpha, LineType, ReadOnly)

Helper function to plot a racetrack on the F10 Map - curtesy of Buur.

UTILS.PrintTableToLog(table, indent, noprint)

Print a table to log in a nice format

UTILS.RandomGaussian(x0, sigma, xmin, xmax, imax)

Generate a Gaussian pseudo-random number.

UTILS.RandomPointInTriangle(pt1, pt2, pt3)

Given a triangle made out of 3 vector 2s, return a vec2 that is a random number in this triangle

UTILS.Randomize(value, fac, lower, upper)

Randomize a value by a certain amount.

UTILS.ReadCSV(filename)

Read csv file and convert it to a lua table.

UTILS.ReadJSON(file_path)

Easy to read one liner to read a JSON file.

UTILS.RemapValue(value, old_min, old_max, new_min, new_max)

Remap an input to a new value in a given range.

UTILS.RemoveMark(MarkID, Delay)

Remove an object (marker, circle, arrow, text, quad, ...) on the F10 map.

UTILS.ReplaceIllegalCharacters(Text, ReplaceBy)

Replace illegal characters [<>|/?*:\] in a string.

UTILS.Rotate2D(a, angle)

Rotate 3D vector in the 2D (x,z) plane.

UTILS.RotatePointAroundPivot(point, pivot, angle)

Rotates a point around another point with a given angle.

UTILS.Round(num, idp)

From http://lua-users.org/wiki/SimpleRound use negative idp for rounding ahead of decimal place, positive for rounding after decimal place

UTILS.SaveSetOfGroups(Set, Path, Filename, Structured)

Function to save the state of a set of Wrapper.Group#GROUP objects.

UTILS.SaveSetOfOpsGroups(Set, Path, Filename, Structured)

Function to save the position of a set of #OPSGROUP (ARMYGROUP) objects.

UTILS.SaveSetOfStatics(Set, Path, Filename)

Function to save the state of a set of Wrapper.Static#STATIC objects.

UTILS.SaveStationaryListOfGroups(List, Path, Filename, Structured)

Function to save the state of a list of groups found by name

UTILS.SaveStationaryListOfStatics(List, Path, Filename)

Function to save the state of a list of statics found by name

UTILS.SaveToFile(Path, Filename, Data)

Function to save an object to a file

UTILS.SecondsOfToday()

Seconds of today.

UTILS.SecondsToClock(seconds, short)

Convert time in seconds to hours, minutes and seconds.

UTILS.SecondsToMidnight()

Cound seconds until next midnight.

UTILS.ShuffleTable(t)

Shuffle a table accoring to Fisher Yeates algorithm

UTILS.SpawnFARPAndFunctionalStatics(Name, Coordinate, FARPType, Coalition, Country, CallSign, Frequency, Modulation, ADF, SpawnRadius, VehicleTemplate, Liquids, Equipment)

Spawns a new FARP of a defined type and coalition and functional statics (fuel depot, ammo storage, tent, windsock) around that FARP to make it operational.

UTILS.Split(str, sep)

Split string at separators.

UTILS.SubtractTimeStrings(time_string_01, time_string_02)

Subtracts two time string to give you a new time.

UTILS.TACANToFrequency(TACANChannel, TACANMode)

Converts a TACAN Channel/Mode couple into a frequency in Hz.

UTILS.TableLength(T)

Counts the number of elements in a table.

UTILS.TableShow(tbl, loc, indent, tableshow_tbls)

Returns table in a easy readable string representation.

UTILS.TasToIas(tas, altitude, oatcorr)

Convert true airspeed (TAS) to indicated airspeed (IAS) for a given altitude above main sea level.

UTILS.TimeBefore(start_time, time_string)

Check if the current time is before time_string.

UTILS.TimeBetween(time_string_01, time_string_02, start_time, end_time)

Checks if the current time is in between start_time and end_time

UTILS.TimeDifferenceInSeconds(start_time, end_time)

Given 2 "nice" time string, returns the difference between the two in seconds

UTILS.TimeLaterThan(start_time, time_string)

Check if the current time is later than time_string.

UTILS.TimeNow()

Get the current time in a "nice" format like 21:01:15

UTILS.ToDegree(angle)

UTILS.ToRadian(angle)

UTILS.ToStringBRAANATO(FromGrp, ToGrp)

Create a BRAA NATO call string BRAA between two GROUP objects

UTILS.UniqueName(base)

Makes a string semi-unique by attaching a random number between 0 and 1 million to it

UTILS.Vec2Add(a, b)

Calculate the total vector of two 2D vectors by adding the x,y components of each other.

UTILS.Vec2Dot(a, b)

Calculate the dot product of two 2D vectors.

UTILS.Vec2Hdg(a)

Calculate "heading" of a 2D vector in the X-Y plane.

UTILS.Vec2Norm(a)

Calculate the euclidean norm (length) of a 2D vector.

UTILS.Vec2Rotate2D(a, angle)

Rotate 2D vector in the 2D (x,z) plane.

UTILS.Vec2Substract(a, b)

Calculate the difference between two 2D vectors by substracting the x,y components from each other.

UTILS.Vec2Subtract(a, b)

Substract is not a word, don't want to rename the original function because it's been around since forever

UTILS.Vec2Translate(a, distance, angle)

Translate 2D vector in the 2D (x,z) plane.

UTILS.VecAdd(a, b)

Calculate the total vector of two 3D vectors by adding the x,y,z components of each other.

UTILS.VecAngle(a, b)

Calculate the angle between two 3D vectors.

UTILS.VecCross(a, b)

Calculate the cross product of two 3D vectors.

UTILS.VecDist2D(a, b)

Calculate the distance between two 2D vectors.

UTILS.VecDist3D(a, b)

Calculate the distance between two 3D vectors.

UTILS.VecDot(a, b)

Calculate the dot product of two vectors.

UTILS.VecHdg(a)

Calculate "heading" of a 3D vector in the X-Z plane.

UTILS.VecNorm(a)

Calculate the euclidean norm (length) of a 3D vector.

UTILS.VecSubstract(a, b)

Calculate the difference between two 3D vectors by substracting the x,y,z components from each other.

UTILS.VecSubtract(a, b)

Substract is not a word, don't want to rename the original function because it's been around since forever

UTILS.VecTranslate(a, distance, angle)

Translate 3D vector in the 2D (x,z) plane.

UTILS.WriteJSON(data, file_path)

Easy to read one liner to write a JSON file.

UTILS._MarkID

Marker index counter. Running number when marker is added.

UTILS._OneLineSerialize(tbl)

Serialize a table to a single line string.

UTILS.hPa2inHg(hPa)

Convert pressure from hecto Pascal (hPa) to inches of mercury (inHg).

UTILS.hPa2mmHg(hPa)

Convert pressure from hecto Pascal (hPa) to millimeters of mercury (mmHg).

UTILS.kg2lbs(kg)

Convert kilo gramms (kg) to pounds (lbs).

UTILS.kpairs(t, getkey, order)

Here is a customized version of pairs, which I called kpairs because it iterates over the table in a sorted order, based on a function that will determine the keys as reference first.

UTILS.lcg

UTILS.rpairs(t)

Here is a customized version of pairs, which I called rpairs because it iterates over the table in a random order.

UTILS.spairs(t, order)

Here is a customized version of pairs, which I called spairs because it iterates over the table in a sorted order.

UTILS.tostringLL(lat, lon, acc, DMS)

UTILS.tostringLLM2KData(lat, lon, acc)

UTILS.tostringMGRS(MGRS, acc)

See DCS_enum_callsigns

Field(s)

#table CALLSIGN.AH64
#table CALLSIGN.AWACS

AWACS

#table CALLSIGN.Aircraft

Aircraft

#table CALLSIGN.B1B
#table CALLSIGN.B52
#table CALLSIGN.F15E
#table CALLSIGN.F16
#table CALLSIGN.F18
#table CALLSIGN.FARP

FARP

#table CALLSIGN.JTAC

JTAC

#table CALLSIGN.Tanker

Tanker

Function(s)

DCS map as returned by env.mission.theatre.

Field(s)

#string DCSMAP.Caucasus

Caucasus map.

#string DCSMAP.Falklands

South Atlantic map.

#string DCSMAP.Kola

Kola map.

#string DCSMAP.MarianaIslands

Mariana Islands map.

#string DCSMAP.NTTR

Nevada Test and Training Range map.

#string DCSMAP.Normandy

Normandy map.

#string DCSMAP.PersianGulf

Persian Gulf map.

#string DCSMAP.Sinai

Sinai map.

#string DCSMAP.Syria

Syria map.

#string DCSMAP.TheChannel

The Channel map.

Function(s)

Field(s)

Function(s)

Field(s)

Function(s)

Utilities static class.

Field(s)

#number UTILS._MarkID

Marker index counter. Running number when marker is added.

#table UTILS.lcg

Function(s)

Checks if a given angle (heading) is between 2 other angles.

Min and max have to be given in clockwise order For example: - UTILS.AngleBetween(350, 270, 15) would return True - UTILS.AngleBetween(22, 95, 20) would return False

Defined in:

UTILS

Parameters:

#number angle

Min value to remap from

#number min

Max value to remap from

#number max

Max value to remap from

Return value:

#boolean:

Basic serialize (porting in Slmod's "safestring" basic serialize).

Defined in:

UTILS

Parameter:

#string s

Table to serialize.

Heading Degrees (0-360) to Cardinal

Defined in:

UTILS

Parameter:

#number Heading

The heading

Return value:

#string:

Cardinal, e.g. "NORTH"

Beaufort scale: returns Beaufort number and wind description as a function of wind speed in m/s.

Defined in:

UTILS

Parameter:

#number speed

Wind speed in m/s.

Return values:

#number:

Beaufort number.

#string:

Beauford wind description.

Convert temperature from Celsius to Fahrenheit.

Defined in:

UTILS

Parameter:

#number Celcius

Temperature in degrees Celsius.

Return value:

#number:

Temperature in degrees Fahrenheit.

Function to check if a file exists.

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

Return value:

#boolean:

outcome True if reading is possible, else false.

Checks the current memory usage collectgarbage("count").

Info is printed to the DCS log file. Time stamp is the current mission runtime.

Defined in:

UTILS

Parameter:

#boolean output

If true, print to DCS log file.

Return value:

#number:

Memory usage in kByte.

Easy to read one liner to clamp a value

Defined in:

UTILS

Parameters:

#number value

Input value

#number min

Minimal value that should be respected

#number max

Maximal value that should be respected

Return value:

#number:

Clamped value

Clamp an angle so that it's always between 0 and 360 while still being correct

Defined in:

UTILS

Parameter:

#number value

Input value

Return value:

#number:

Clamped value

Get the clock position from a relative heading

Defined in:

UTILS

Parameters:

#number refHdg

The heading of the reference object (such as a Wrapper.UNIT) in 0-360

#number tgtHdg

The absolute heading from the reference object to the target object/point in 0-360

Return value:

#string:

text Text in clock heading such as "4 O'CLOCK"

Usage:

Display the range and clock distance of a BTR in relation to REAPER 1-1's heading:

         myUnit = UNIT:FindByName( "REAPER 1-1" )
         myTarget = GROUP:FindByName( "BTR-1" )

         coordUnit = myUnit:GetCoordinate()
         coordTarget = myTarget:GetCoordinate()

         hdgUnit = myUnit:GetHeading()
         hdgTarget = coordUnit:HeadingTo( coordTarget )
         distTarget = coordUnit:Get3DDistance( coordTarget )

         clockString = UTILS.ClockHeadingString( hdgUnit, hdgTarget )

         -- Will show this message to REAPER 1-1 in-game: Contact BTR at 3 o'clock for 1134m!
         MESSAGE:New("Contact BTR at " .. clockString .. " for " .. distTarget  .. "m!):ToUnit( myUnit )

Convert clock time from hours, minutes and seconds to seconds.

Defined in:

UTILS

Parameter:

#string clock

String of clock time. E.g., "06:12:35" or "5:1:30+1". Format is (H)H:(M)M:((S)S)(+D) H=Hours, M=Minutes, S=Seconds, D=Days.

Return value:

#number:

Seconds. Corresponds to what you cet from timer.getAbsTime() function.

Combines two time strings to give you a new time.

For example "15:16:32" and "02:06:24" would return "17:22:56"

Defined in:

UTILS

Parameters:

#string time_string_01

Time string like "07:15:22"

#string time_string_02

Time string like "08:11:27"

Return value:

#string:

Result of the two time string combined

Convert a decimal to octal

Defined in:

UTILS

Parameter:

#number Number

the number to convert

Return value:

#number:

Octal

Deep copy a table.

See http://lua-users.org/wiki/CopyTable

Defined in:

UTILS

Parameter:

#table object

The input table.

Return value:

#table:

Copy of the input table.

Display clock and mission time on screen as a message to all.

Defined in:

UTILS

Parameter:

#number duration

Duration in seconds how long the time is displayed. Default is 5 seconds.

Executes the given string.

borrowed from Slmod

Defined in:

UTILS

Parameter:

#string s

string containing LUA code.

Return value:

#boolean:

true if successfully executed, false otherwise.

Ensure the passed object is a table.

Defined in:

UTILS

Parameters:

#table Object

The object that should be a table.

#boolean ReturnNil

If true, return #nil if Object is nil. Otherwise an empty table {} is returned.

Return value:

#table:

The object that now certainly is a table.

Defined in:

UTILS

Parameter:

feet

Checks if a file exists or not.

This requires io to be desanitized.

Defined in:

UTILS

Parameter:

#string file

File that should be checked.

Return value:

#boolean:

True if the file exists, false if the file does not exist or nil if the io module is not available and the check could not be performed.

Get the time difference between GMT and local time.

Defined in:

UTILS

Return value:

#number:

Local time difference in hours compared to GMT. E.g. Dubai is GMT+4 ==> +4 is returned.

Dumps the global table _G.

This dumps the global table G to a file in the DCS\Logs directory. This function requires you to disable script sanitization in $DCSROOT\Scripts\MissionScripting.lua to access lfs and io libraries.

Defined in:

UTILS

Parameter:

#string fname

File name.

Function to generate valid FM frequencies in mHz for radio beacons (FM).

Defined in:

UTILS

Return value:

#table:

Table of frequencies.

Function to generate valid laser codes for JTAC.

Defined in:

UTILS

Return value:

#table:

Laser Codes.

Function to generate valid UHF Frequencies in mHz (AM).

Can be between 220 and 399 mHz. 243 is auto-excluded.

Defined in:

UTILS

Parameters:

Start

(Optional) Avoid frequencies between Start and End in mHz, e.g. 244

End

(Optional) Avoid frequencies between Start and End in mHz, e.g. 320

Return value:

#table:

UHF Frequencies

Function to generate valid VHF frequencies in kHz for radio beacons (FM).

Defined in:

UTILS

Return value:

#table:

VHFrequencies

Get the callsign name from its enumerator value

Defined in:

UTILS

Parameter:

#number Callsign

The enumerator callsign.

Return value:

#string:

The callsign name or "Ghostrider".

Get a table of all characters in a string.

Defined in:

UTILS

Parameter:

#string str

Sting.

Return value:

#table:

Individual characters.

Get the enemy coalition for a given coalition.

Defined in:

UTILS

Parameters:

#number Coalition

The coalition ID.

#boolean Neutral

Include neutral as enemy.

Return value:

#table:

Enemy coalition table.

Get the coalition name from its numerical ID, e.g.

coalition.side.RED.

Defined in:

UTILS

Parameter:

#number Coalition

The coalition ID.

Return value:

#string:

The coalition name, i.e. "Neutral", "Red" or "Blue" (or "Unknown").

Function to obtain a table of typenames from the group given with the number of units of the same type in the group.

Defined in:

UTILS

Parameter:

The group to list

Return value:

#table:

Table of typnames and typename counts, e.g. {["KAMAZ Truck"]=3,["ATZ-5"]=1}

Returns the DCS map/theatre as optained by env.mission.theatre.

Defined in:

UTILS

Return value:

#string:

DCS map name.

Returns the mission date.

This is the date the mission started.

Defined in:

UTILS

Return values:

#string:

Mission date in yyyy/mm/dd format.

#number:

The year anno domini.

#number:

The month.

#number:

The day.

Get the day of the year.

Counting starts on 1st of January.

Defined in:

UTILS

Parameters:

#number Year

The year.

#number Month

The month.

#number Day

The day.

Return value:

#number:

The day of the year.

Returns the magnetic declination of the map.

Returned values for the current maps are:

  • Caucasus +6 (East), year ~ 2011
  • NTTR +12 (East), year ~ 2011
  • Normandy -10 (West), year ~ 1944
  • Persian Gulf +2 (East), year ~ 2011
  • The Cannel Map -10 (West)
  • Syria +5 (East)
  • Mariana Islands +2 (East)
  • Falklands +12 (East) - note there's a LOT of deviation across the map, as we're closer to the South Pole
  • Sinai +4.8 (East)
  • Kola +15 (East) - note there is a lot of deviation across the map (-1° to +24°), as we are close to the North pole
  • Afghanistan +3 (East) - actually +3.6 (NW) to +2.3 (SE)

Defined in:

UTILS

Parameter:

#string map

(Optional) Map for which the declination is returned. Default is from env.mission.theatre

Return value:

#number:

Declination in degrees.

get a new mark ID for markings

Defined in:

UTILS

Returns the day of the mission.

Defined in:

UTILS

Parameter:

#number Time

(Optional) Abs. time in seconds. Default now, i.e. the value return from timer.getAbsTime().

Return value:

#number:

Day of the mission. Mission starts on day 0.

Returns the current day of the year of the mission.

Defined in:

UTILS

Parameter:

#number Time

(Optional) Abs. time in seconds. Default now, i.e. the value return from timer.getAbsTime().

Return value:

#number:

Current day of year of the mission. For example, January 1st returns 0, January 2nd returns 1 etc.

Get the modulation name from its numerical value.

Defined in:

UTILS

Parameter:

#number Modulation

The modulation enumerator number. Can be either 0 or 1.

Return value:

#string:

The modulation name, i.e. "AM"=0 or "FM"=1. Anything else will return "Unknown".

Get OS time.

Needs os to be desanitized!

Defined in:

UTILS

Return value:

#number:

Os time in seconds.

Get a random element of a table.

Defined in:

UTILS

Parameters:

#table t

Table.

#boolean replace

If true, the drawn element is replaced, i.e. not deleted.

Return value:

#number:

Table element.

Get the NATO reporting name of a unit type name

Defined in:

UTILS

Parameter:

#number Typename

The type name.

Return value:

#string:

The Reporting name or "Bogey".

Get sunrise or sun set of a specific day of the year at a specific location.

Defined in:

UTILS

Parameters:

#number DayOfYear

The day of the year.

#number Latitude

Latitude.

#number Longitude

Longitude.

#boolean Rising

If true, calc sun rise, or sun set otherwise.

#number Tlocal

Local time offset in hours. E.g. +4 for a location which has GMT+4.

Return value:

#number:

Sun rise/set in seconds of the day.

Get sun rise of a specific day of the year at a specific location.

Defined in:

UTILS

Parameters:

#number Day

Day of the year.

#number Month

Month of the year.

#number Year

Year.

#number Latitude

Latitude.

#number Longitude

Longitude.

#boolean Rising

If true, calc sun rise, or sun set otherwise.

#number Tlocal

Local time offset in hours. E.g. +4 for a location which has GMT+4. Default 0.

Return value:

#number:

Sun rise in seconds of the day.

Get sun set of a specific day of the year at a specific location.

Defined in:

UTILS

Parameters:

#number Day

Day of the year.

#number Month

Month of the year.

#number Year

Year.

#number Latitude

Latitude.

#number Longitude

Longitude.

#boolean Rising

If true, calc sun rise, or sun set otherwise.

#number Tlocal

Local time offset in hours. E.g. +4 for a location which has GMT+4. Default 0.

Return value:

#number:

Sun rise in seconds of the day.

Get the properties names and values of properties set up on a Zone in the Mission Editor.

  • This doesn't work for any zones created in MOOSE

Defined in:

UTILS

Parameter:

#string zone_name

Name of the zone as set up in the Mission Editor

Return value:

#table:

with all the properties on a zone

Calculate the difference between two "heading", i.e.

angles in [0,360) deg.

Defined in:

UTILS

Parameters:

#number h1

Heading one.

#number h2

Heading two.

Return value:

#number:

Heading difference in degrees.

Returns the heading from one vec3 to another vec3.

Defined in:

UTILS

Parameters:

From vec3.

To vec3.

Return value:

#number:

Heading in degrees.

HexToRGBA

Defined in:

UTILS

Parameter:

hex_string

table

Return value:

#table:

R, G, B, A

Convert indicated airspeed (IAS) to true airspeed (TAS) for a given altitude above main sea level.

The conversion is based on the approximation that TAS is ~2% higher than IAS with every 1000 ft altitude above sea level.

Defined in:

UTILS

Parameters:

#number ias

Indicated air speed in any unit (m/s, km/h, knots, ...)

#number altitude

Altitude above main sea level in meters.

#number oatcorr

(Optional) Outside air temperature correction factor. Default 0.017.

Return value:

#number:

True airspeed in the same unit the IAS has been given.

Check if any object of multiple given objects is contained in a table.

Defined in:

UTILS

Parameters:

#table Table

The table.

#table Objects

The objects to check.

#string Key

(Optional) Key to check.

Return value:

#boolean:

Returns true if object is in table.

Test if a Vec2 is in a radius of another Vec2

Defined in:

UTILS

Parameters:

InVec2

Vec2

Radius

Test if a Vec3 is in the sphere of another Vec3

Defined in:

UTILS

Parameters:

InVec3

Vec3

Radius

Check if an object is contained in a table.

Defined in:

UTILS

Parameters:

#table Table

The table.

#table Object

The object to check.

#string Key

(Optional) Key to check. By default, the object itself is checked.

Return value:

#boolean:

Returns true if object is in table.

Function to infer instance of an object

Examples:

  • UTILS.IsInstanceOf( 'some text', 'string' ) will return true

  • UTILS.IsInstanceOf( some_function, 'function' ) will return true

  • UTILS.IsInstanceOf( 10, 'number' ) will return true

  • UTILS.IsInstanceOf( false, 'boolean' ) will return true

  • UTILS.IsInstanceOf( nil, 'nil' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', ZONE ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'ZONE' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'zone' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'BASE' ) will return true

  • UTILS.IsInstanceOf( ZONE:New( 'some zone', 'GROUP' ) will return false

Defined in:

UTILS

Parameters:

object

is the object to be evaluated

className

is the name of the class to evaluate (can be either a string or a Moose class)

Return value:

#boolean:

(Helicopter) Check if one loading door is open.

Defined in:

UTILS

Parameter:

#string unit_name

Unit name to be checked

Return value:

#boolean:

Outcome - true if a (loading door) is open, false if not, nil if none exists.

Defined in:

UTILS

Parameter:

kilometers

Defined in:

UTILS

Parameter:

kilometers

Defined in:

UTILS

Parameter:

kilometers

Defined in:

UTILS

Parameter:

knots

Defined in:

UTILS

Parameter:

kmph

Convert knots to altitude corrected KIAS, e.g.

for tankers.

Defined in:

UTILS

Parameters:

#number knots

Speed in knots.

#number altitude

Altitude in feet

Return value:

#number:

Corrected KIAS

Defined in:

UTILS

Parameter:

knots

Convert knots to meters per second.

Defined in:

UTILS

Parameter:

#number knots

Speed in knots.

Return value:

#number:

Speed in m/s.

Return a pseudo-random number using the LCG algorithm.

Defined in:

UTILS

Return value:

#number:

Random number between 0 and 1.

Seed the LCG random number generator.

Defined in:

UTILS

Parameter:

#number seed

Seed value. Default is a random number using math.random()

Function to load an object from a file.

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

Return values:

#boolean:

outcome True if reading is possible and successful, else false.

#table:

data The data read from the filesystem (table of lines of text). Each line is one single #string!

Load back a SET of groups from file.

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

#boolean Spawn

If set to false, do not re-spawn the groups loaded in location and reduce to size.

#boolean Structured

(Optional, needs Spawn=true)If true, and the data has been saved as structure before, remove the correct unit types as per the saved list.

#boolean Cinematic

(Optional, needs Structured=true) If true, place a fire/smoke effect on the dead static position.

#number Effect

(Optional for Cinematic) What effect to use. Defaults to a random effect. Smoke presets are: 1=small smoke and fire, 2=medium smoke and fire, 3=large smoke and fire, 4=huge smoke and fire, 5=small smoke, 6=medium smoke, 7=large smoke, 8=huge smoke.

#number Density

(Optional for Cinematic) What smoke density to use, can be 0 to 1. Defaults to 0.5.

Return values:

Set of GROUP objects. Returns nil when file cannot be read. Returns a table of data entries if Spawn is false: { groupname=groupname, size=size, coordinate=coordinate, template=template }

#table:

When using Cinematic: table of names of smoke and fire objects, so they can be extinguished with COORDINATE.StopBigSmokeAndFire( name )

Load back a #OPSGROUP (ARMYGROUP) data from file for use with Ops.Brigade#BRIGADE.LoadBackAssetInPosition()

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

Return value:

#table:

Returns a table of data entries: { groupname=groupname, size=size, coordinate=coordinate, template=template, structure=structure, legion=legion, alttemplate=alttemplate } Returns nil when the file cannot be read.

Load back a SET of statics from file.

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

Return value:

Set SET_STATIC containing the static objects.

Load back a stationary list of groups from file.

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

#boolean Reduce

If false, existing loaded groups will not be reduced to fit the saved number.

#boolean Structured

(Optional, needs Reduce = true) If true, and the data has been saved as structure before, remove the correct unit types as per the saved list.

#boolean Cinematic

(Optional, needs Structured = true) If true, place a fire/smoke effect on the dead static position.

#number Effect

(Optional for Cinematic) What effect to use. Defaults to a random effect. Smoke presets are: 1=small smoke and fire, 2=medium smoke and fire, 3=large smoke and fire, 4=huge smoke and fire, 5=small smoke, 6=medium smoke, 7=large smoke, 8=huge smoke.

#number Density

(Optional for Cinematic) What smoke density to use, can be 0 to 1. Defaults to 0.5.

Return values:

#table:

Table of data objects (tables) containing groupname, coordinate and group object. Returns nil when file cannot be read.

#table:

When using Cinematic: table of names of smoke and fire objects, so they can be extinguished with COORDINATE.StopBigSmokeAndFire( name )

Load back a stationary list of statics from file.

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

#boolean Reduce

If false, do not destroy the units with size=0.

#boolean Dead

(Optional, needs Reduce = true) If Dead is true, re-spawn the dead object as dead and do not just delete it.

#boolean Cinematic

(Optional, needs Dead = true) If true, place a fire/smoke effect on the dead static position.

#number Effect

(Optional for Cinematic) What effect to use. Defaults to a random effect. Smoke presets are: 1=small smoke and fire, 2=medium smoke and fire, 3=large smoke and fire, 4=huge smoke and fire, 5=small smoke, 6=medium smoke, 7=large smoke, 8=huge smoke.

#number Density

(Optional for Cinematic) What smoke density to use, can be 0 to 1. Defaults to 0.5.

Return values:

#table:

Table of data objects (tables) containing staticname, size (0=dead else 1), coordinate and the static object. Dead objects will have coordinate points {x=0,y=0,z=0}

#table:

When using Cinematic: table of names of smoke and fire objects, so they can be extinguished with COORDINATE.StopBigSmokeAndFire( name ) Returns nil when file cannot be read.

Get a NATO abbreviated MGRS text for SRS use, optionally with prosody slow tag

Defined in:

UTILS

Parameters:

#string Text

The input string, e.g. "MGRS 4Q FJ 12345 67890"

#boolean Slow

Optional - add slow tags

Return value:

#string:

Output for (Slow) spelling in SRS TTS e.g. "MGRS;4;Quebec;Foxtrot;Juliett;1;2;3;4;5;6;7;8;niner;zero;"

Defined in:

UTILS

Parameter:

meters

Defined in:

UTILS

Parameter:

meters

Defined in:

UTILS

Parameter:

meters

Defined in:

UTILS

Parameter:

miph

Defined in:

UTILS

Parameter:

mps

Convert meters per second to knots.

Defined in:

UTILS

Parameter:

#number mps

Speed in m/s.

Return value:

#number:

Speed in knots.

Convert meters per second to miles per hour.

Defined in:

UTILS

Parameter:

#number mps

Speed in m/s.

Return value:

#number:

Speed in miles per hour.

Defined in:

UTILS

Parameter:

NM

Defined in:

UTILS

Parameter:

NM

Convert an octal to decimal

Defined in:

UTILS

Parameter:

#number Number

the number to convert

Return value:

#number:

Decimal

Serialize a given table.

Defined in:

UTILS

Parameter:

#table tbl

Input table.

Return value:

#string:

Table as a string.

Easy to read one line to roll the dice on something.

1% is very unlikely to happen, 99% is very likely to happen

Defined in:

UTILS

Parameter:

#number chance

(optional) Percentage chance you want something to happen. Defaults to a random number if not given

Return value:

#boolean:

True if the dice roll was within the given percentage chance of happening

Helper function to plot a racetrack on the F10 Map - curtesy of Buur.

Defined in:

UTILS

Parameters:

#number Altitude

Altitude in feet

#number Speed

Speed in knots

#number Heading

Heading in degrees

#number Leg

Leg in NM

#number Coalition

Coalition side, e.g. coaltion.side.RED or coaltion.side.BLUE

#table Color

Color of the line in RGB, e.g. {1,0,0} for red

#number Alpha

Transparency factor, between 0.1 and 1

#number LineType

Line type to be used, line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot dash, 5=Long dash, 6=Two dash. Default 1=Solid.

#boolean ReadOnly

Print a table to log in a nice format

Defined in:

UTILS

Parameters:

#table table

The table to print

#number indent

Number of indents

#boolean noprint

Don't log but return text

Return value:

#string:

text Text created on the fly of the log output

Generate a Gaussian pseudo-random number.

Defined in:

UTILS

Parameters:

#number x0

Expectation value of distribution.

#number sigma

(Optional) Standard deviation. Default 10.

#number xmin

(Optional) Lower cut-off value.

#number xmax

(Optional) Upper cut-off value.

#number imax

(Optional) Max number of tries to get a value between xmin and xmax (if specified). Default 100.

Return value:

#number:

Gaussian random number.

Given a triangle made out of 3 vector 2s, return a vec2 that is a random number in this triangle

Defined in:

UTILS

Parameters:

DCS#Vec2 pt1

Min value to remap from

DCS#Vec2 pt2

Max value to remap from

DCS#Vec2 pt3

Max value to remap from

Return value:

Random point in triangle

Randomize a value by a certain amount.

Defined in:

UTILS

Parameters:

#number value

The value which should be randomized

#number fac

Randomization factor.

#number lower

(Optional) Lower limit of the returned value.

#number upper

(Optional) Upper limit of the returned value.

Return value:

#number:

Randomized value.

Usages:

  • UTILS.Randomize(100, 0.1) returns a value between 90 and 110, i.e. a plus/minus ten percent variation.
  • UTILS.Randomize(100, 0.5, nil, 120) returns a value between 50 and 120, i.e. a plus/minus fivty percent variation with upper bound 120.

Read csv file and convert it to a lua table.

The csv must have a header specifing the names of the columns. The column names are used as table keys.

Defined in:

UTILS

Parameter:

#string filename

File name including full path on local disk.

Return value:

#table:

The table filled with data from the csv file.

Easy to read one liner to read a JSON file.

  • json.lua exists in the DCS install Scripts folder

Defined in:

UTILS

Parameter:

#string file_path

File path

Return value:

#table:

Remap an input to a new value in a given range.

For example: - UTILS.RemapValue(20, 10, 30, 0, 200) would return 100 - 20 is 50% between 10 and 30 - 50% between 0 and 200 is 100

Defined in:

UTILS

Parameters:

#number value

Input value

#number old_min

Min value to remap from

#number old_max

Max value to remap from

#number new_min

Min value to remap to

#number new_max

Max value to remap to

Return value:

#number:

Remapped value

Remove an object (marker, circle, arrow, text, quad, ...) on the F10 map.

Defined in:

UTILS

Parameters:

#number MarkID

Unique ID of the object.

#number Delay

(Optional) Delay in seconds before the mark is removed.

Replace illegal characters [<>|/?*:\] in a string.

Defined in:

UTILS

Parameters:

#string Text

Input text.

#string ReplaceBy

Replace illegal characters by this character or string. Default underscore "_".

Return value:

#string:

The input text with illegal chars replaced.

Rotate 3D vector in the 2D (x,z) plane.

y-component (usually altitude) unchanged.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

#number angle

Rotation angle in degrees.

Return value:

Vector rotated in the (x,z) plane.

Rotates a point around another point with a given angle.

Useful if you're loading in groups or - statics but you want to rotate them all as a collection. You can get the center point of everything - and then rotate all the positions of every object around this center point.

Defined in:

UTILS

Parameters:

DCS#Vec2 point

Point that you want to rotate

DCS#Vec2 pivot

Pivot point of the rotation

#number angle

How many degrees the point should be rotated

Return value:

Rotated point

From http://lua-users.org/wiki/SimpleRound use negative idp for rounding ahead of decimal place, positive for rounding after decimal place

Defined in:

UTILS

Parameters:

num

idp

Function to save the state of a set of Wrapper.Group#GROUP objects.

Defined in:

UTILS

Parameters:

of objects to save

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

#boolean Structured

Append the data with a list of typenames in the group plus their count.

Return value:

#boolean:

outcome True if saving is successful, else false.

Usage:

We will go through the set and find the corresponding group and save the current group size and current position.
The idea is to respawn the groups **spawned during an earlier run of the mission** at the given location and reduce
the number of units in the group when reloading the data again to restart the saved mission. Note that *dead* groups
cannot be covered with this.
**Note** Do NOT use dashes or hashes in group template names (-,#)!
The data will be a simple comma separated list of groupname and size, with one header line.
The current task/waypoint/etc cannot be restored.

Function to save the position of a set of #OPSGROUP (ARMYGROUP) objects.

Defined in:

UTILS

Parameters:

of ops objects to save

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

#boolean Structured

Append the data with a list of typenames in the group plus their count.

Return value:

#boolean:

outcome True if saving is successful, else false.

Function to save the state of a set of Wrapper.Static#STATIC objects.

Defined in:

UTILS

Parameters:

of objects to save

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

Return value:

#boolean:

outcome True if saving is successful, else false.

Usage:

We will go through the set and find the corresponding static and save the current name and postion when alive.
The data will be a simple comma separated list of name and state etc, with one header line.

Function to save the state of a list of groups found by name

Defined in:

UTILS

Parameters:

#table List

Table of strings with groupnames

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

#boolean Structured

Append the data with a list of typenames in the group plus their count.

Return value:

#boolean:

outcome True if saving is successful, else false.

Usage:

We will go through the list and find the corresponding group and save the current group size (0 when dead).
These groups are supposed to be put on the map in the ME and have *not* moved (e.g. stationary SAM sites).
Position is still saved for your usage.
The idea is to reduce the number of units when reloading the data again to restart the saved mission.
The data will be a simple comma separated list of groupname and size, with one header line.

Function to save the state of a list of statics found by name

Defined in:

UTILS

Parameters:

#table List

Table of strings with statics names

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file.

Return value:

#boolean:

outcome True if saving is successful, else false.

Usage:

We will go through the list and find the corresponding static and save the current alive state as 1 (0 when dead).
Position is saved for your usage. **Note** this works on UNIT-name level.
The idea is to reduce the number of units when reloading the data again to restart the saved mission.
The data will be a simple comma separated list of name and state etc, with one header line.

Function to save an object to a file

Defined in:

UTILS

Parameters:

#string Path

The path to use. Use double backslashes \\ on Windows filesystems.

#string Filename

The name of the file. Existing file will be overwritten.

#table Data

The LUA data structure to save. This will be e.g. a table of text lines with an \n at the end of each line.

Return value:

#boolean:

outcome True if saving is possible, else false.

Seconds of today.

Defined in:

UTILS

Return value:

#number:

Seconds passed since last midnight.

Convert time in seconds to hours, minutes and seconds.

Defined in:

UTILS

Parameters:

#number seconds

Time in seconds, e.g. from timer.getAbsTime() function.

#boolean short

(Optional) If true, use short output, i.e. (HH:)MM:SS without day.

Return value:

#string:

Time in format Hours:Minutes:Seconds+Days (HH:MM:SS+D).

Cound seconds until next midnight.

Defined in:

UTILS

Return value:

#number:

Seconds to midnight.

Shuffle a table accoring to Fisher Yeates algorithm

Defined in:

UTILS

Parameter:

#table t

Table to be shuffled.

Return value:

#table:

Shuffled table.

Spawns a new FARP of a defined type and coalition and functional statics (fuel depot, ammo storage, tent, windsock) around that FARP to make it operational.

Adds vehicles from template if given. Fills the FARP warehouse with liquids and known materiels. References: DCS Forum Topic

Defined in:

UTILS

Parameters:

#string Name

Name of this FARP installation. Must be unique.

Where to spawn the FARP.

#string FARPType

Type of FARP, can be one of the known types ENUMS.FARPType.FARP, ENUMS.FARPType.INVISIBLE, ENUMS.FARPType.HELIPADSINGLE, ENUMS.FARPType.PADSINGLE. Defaults to ENUMS.FARPType.FARP.

#number Coalition

Coalition of this FARP, i.e. coalition.side.BLUE or coalition.side.RED, defaults to coalition.side.BLUE.

#number Country

Country of this FARP, defaults to country.id.USA (blue) or country.id.RUSSIA (red).

#number CallSign

Callsign of the FARP ATC, defaults to CALLSIGN.FARP.Berlin.

#number Frequency

Frequency of the FARP ATC Radio, defaults to 127.5 (MHz).

#number Modulation

Modulation of the FARP ATC Radio, defaults to radio.modulation.AM.

#number ADF

ADF Beacon (FM) Frequency in KHz, e.g. 428. If not nil, creates an VHF/FM ADF Beacon for this FARP. Requires a sound called "beacon.ogg" to be in the mission (trigger "sound to" ...)

#number SpawnRadius

Radius of the FARP, i.e. where the FARP objects will be placed in meters, not more than 150m away. Defaults to 100.

#string VehicleTemplate

template name for additional vehicles. Can be nil for no additional vehicles.

#number Liquids

Tons of fuel to be added initially to the FARP. Defaults to 10 (tons). Set to 0 for no fill.

#number Equipment

Number of equipment items per known item to be added initially to the FARP. Defaults to 10 (items). Set to 0 for no fill.

Return values:

#list<Wrapper.Static#STATIC>:

Table of spawned objects and vehicle object (if given).

#string:

ADFBeaconName Name of the ADF beacon, to be able to remove/stop it later.

Split string at separators.

C.f. split-string-in-lua.

Defined in:

UTILS

Parameters:

#string str

Sting to split.

#string sep

Separator for split.

Return value:

#table:

Split text.

Subtracts two time string to give you a new time.

For example "15:16:32" and "02:06:24" would return "13:10:08"

Defined in:

UTILS

Parameters:

#string time_string_01

Time string like "07:15:22"

#string time_string_02

Time string like "08:11:27"

Return value:

#string:

Result of the two time string subtracted

Converts a TACAN Channel/Mode couple into a frequency in Hz.

Defined in:

UTILS

Parameters:

#number TACANChannel

The TACAN channel, i.e. the 10 in "10X".

#string TACANMode

The TACAN mode, i.e. the "X" in "10X".

Return value:

#number:

Frequency in Hz or #nil if parameters are invalid.

Counts the number of elements in a table.

Defined in:

UTILS

Parameter:

#table T

Table to count

Return value:

#int:

Number of elements in the table

Returns table in a easy readable string representation.

Defined in:

UTILS

Parameters:

tbl

table to show

loc

indent

tableshow_tbls

Return value:

Human readable string representation of given table.

Convert true airspeed (TAS) to indicated airspeed (IAS) for a given altitude above main sea level.

The conversion is based on the approximation that TAS is ~2% higher than IAS with every 1000 ft altitude above sea level.

Defined in:

UTILS

Parameters:

#number tas

True air speed in any unit (m/s, km/h, knots, ...)

#number altitude

Altitude above main sea level in meters.

#number oatcorr

(Optional) Outside air temperature correction factor. Default 0.017.

Return value:

#number:

Indicated airspeed in the same unit the TAS has been given.

Check if the current time is before time_string.

Defined in:

UTILS

Parameters:

#string start_time

Time string like "07:15:22"

time_string

Return value:

#boolean:

False if later, True if before

Checks if the current time is in between start_time and end_time

Defined in:

UTILS

Parameters:

#string time_string_01

Time string like "07:15:22"

#string time_string_02

Time string like "08:11:27"

start_time

end_time

Return value:

#boolean:

True if it is, False if it's not

Given 2 "nice" time string, returns the difference between the two in seconds

Defined in:

UTILS

Parameters:

#string start_time

Time string like "07:15:22"

#string end_time

Time string like "08:11:27"

Return value:

#number:

Seconds between start_time and end_time

Check if the current time is later than time_string.

Defined in:

UTILS

Parameters:

#string start_time

Time string like "07:15:22"

time_string

Return value:

#boolean:

True if later, False if before

Get the current time in a "nice" format like 21:01:15

Defined in:

UTILS

Return value:

#string:

Returns string with the current time

Defined in:

UTILS

Parameter:

angle

Defined in:

UTILS

Parameter:

angle

Create a BRAA NATO call string BRAA between two GROUP objects

Defined in:

UTILS

Parameters:

GROUP object

GROUP object

Return value:

#string:

Formatted BRAA NATO call

Makes a string semi-unique by attaching a random number between 0 and 1 million to it

Defined in:

UTILS

Parameter:

#string base

String you want to unique-fy

Return value:

#string:

Unique string

Calculate the total vector of two 2D vectors by adding the x,y components of each other.

Defined in:

UTILS

Parameters:

Vector in 2D with x, y components.

Vector in 2D with x, y components.

Return value:

Vector c=a+b with c(i)=a(i)+b(i), i=x,y.

Calculate the dot product of two 2D vectors.

The result is a number.

Defined in:

UTILS

Parameters:

Vector in 2D with x, y components.

Vector in 2D with x, y components.

Return value:

#number:

Scalar product of the two vectors a*b.

Calculate "heading" of a 2D vector in the X-Y plane.

Defined in:

UTILS

Parameter:

Vector in 2D with x, y components.

Return value:

#number:

Heading in degrees in [0,360).

Calculate the euclidean norm (length) of a 2D vector.

Defined in:

UTILS

Parameter:

Vector in 2D with x, y components.

Return value:

#number:

Norm of the vector.

Rotate 2D vector in the 2D (x,z) plane.

Defined in:

UTILS

Parameters:

Vector in 2D with x, y components.

#number angle

Rotation angle in degrees.

Return value:

Vector rotated in the (x,y) plane.

Calculate the difference between two 2D vectors by substracting the x,y components from each other.

Defined in:

UTILS

Parameters:

Vector in 2D with x, y components.

Vector in 2D with x, y components.

Return value:

Vector c=a-b with c(i)=a(i)-b(i), i=x,y.

Substract is not a word, don't want to rename the original function because it's been around since forever

Defined in:

UTILS

Parameters:

a

b

Translate 2D vector in the 2D (x,z) plane.

Defined in:

UTILS

Parameters:

Vector in 2D with x, y components.

#number distance

The distance to translate.

#number angle

Rotation angle in degrees.

Return value:

Translated vector.

Calculate the total vector of two 3D vectors by adding the x,y,z components of each other.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

Vector in 3D with x, y, z components.

Return value:

Vector c=a+b with c(i)=a(i)+b(i), i=x,y,z.

Calculate the angle between two 3D vectors.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

Vector in 3D with x, y, z components.

Return value:

#number:

Angle alpha between and b in degrees. alpha=acos(ab)/(|a||b|), ( denotes the dot product).

Calculate the cross product of two 3D vectors.

The result is a 3D vector.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

Vector in 3D with x, y, z components.

Return value:

Vector

Calculate the distance between two 2D vectors.

Defined in:

UTILS

Parameters:

Vector in 2D with x, y components.

Vector in 2D with x, y components.

Return value:

#number:

Distance between the vectors.

Calculate the distance between two 3D vectors.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

Vector in 3D with x, y, z components.

Return value:

#number:

Distance between the vectors.

Calculate the dot product of two vectors.

The result is a number.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

Vector in 3D with x, y, z components.

Return value:

#number:

Scalar product of the two vectors a*b.

Calculate "heading" of a 3D vector in the X-Z plane.

Defined in:

UTILS

Parameter:

Vector in 3D with x, y, z components.

Return value:

#number:

Heading in degrees in [0,360).

Calculate the euclidean norm (length) of a 3D vector.

Defined in:

UTILS

Parameter:

Vector in 3D with x, y, z components.

Return value:

#number:

Norm of the vector.

Calculate the difference between two 3D vectors by substracting the x,y,z components from each other.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

Vector in 3D with x, y, z components.

Return value:

Vector c=a-b with c(i)=a(i)-b(i), i=x,y,z.

Substract is not a word, don't want to rename the original function because it's been around since forever

Defined in:

UTILS

Parameters:

a

b

Translate 3D vector in the 2D (x,z) plane.

y-component (usually altitude) unchanged.

Defined in:

UTILS

Parameters:

Vector in 3D with x, y, z components.

#number distance

The distance to translate.

#number angle

Rotation angle in degrees.

Return value:

Vector rotated in the (x,z) plane.

Easy to read one liner to write a JSON file.

Everything in @data should be serializable - json.lua exists in the DCS install Scripts folder

Defined in:

UTILS

Parameters:

#table data

table to write

#string file_path

File path

Serialize a table to a single line string.

Defined in:

UTILS

Parameter:

#table tbl

table to serialize.

Return value:

#string:

string containing serialized table.

Convert pressure from hecto Pascal (hPa) to inches of mercury (inHg).

Defined in:

UTILS

Parameter:

#number hPa

Pressure in hPa.

Return value:

#number:

Pressure in inHg.

Convert pressure from hecto Pascal (hPa) to millimeters of mercury (mmHg).

Defined in:

UTILS

Parameter:

#number hPa

Pressure in hPa.

Return value:

#number:

Pressure in mmHg.

Convert kilo gramms (kg) to pounds (lbs).

Defined in:

UTILS

Parameter:

#number kg

Mass in kg.

Return value:

#number:

Mass in lbs.

Here is a customized version of pairs, which I called kpairs because it iterates over the table in a sorted order, based on a function that will determine the keys as reference first.

Defined in:

UTILS

Parameters:

#table t

The table

#string getkey

The function to determine the keys for sorting

#string order

(Optional) The sorting function itself

Return values:

#string:

key The index key

#string:

value The value at the indexed key

Usage:

           for key,value in UTILS.kpairs(mytable, getkeyfunc) do
               -- your code here
           end

Here is a customized version of pairs, which I called rpairs because it iterates over the table in a random order.

Defined in:

UTILS

Parameter:

#table t

The table

Return values:

#string:

key The index key

#string:

value The value at the indexed key

Usage:

           for key,value in UTILS.rpairs(mytable) do
               -- your code here
           end

Here is a customized version of pairs, which I called spairs because it iterates over the table in a sorted order.

Defined in:

UTILS

Parameters:

#table t

The table

#string order

(Optional) The sorting function

Return values:

#string:

key The index key

#string:

value The value at the indexed key

Usage:

           for key,value in UTILS.spairs(mytable) do
               -- your code here
           end

acc: in DM: decimal point of minutes. In DMS: decimal point of seconds. position after the decimal of the least significant digit: So: 42.32 - acc of 2.

Defined in:

UTILS

Parameters:

lat

lon

acc

DMS

acc: in DM: decimal point of minutes. In DMS: decimal point of seconds. position after the decimal of the least significant digit: So: 42.32 - acc of 2.

Defined in:

UTILS

Parameters:

lat

lon

acc

acc- the accuracy of each easting/northing. 0, 1, 2, 3, 4, or 5.

Defined in:

UTILS

Parameters:

MGRS

acc