ArmA 3 has already more than 1400 commands. While 1200 or so of them are ArmA 2, new commands are often not documented well enough. I think I should start including my findings in blog posts for future reference. So today it will be about distanceSqr, linearConversion, difficulty, setAmmo and drawIcon3D.

## distanceSqr

As you know in order to calculate distance between 2 points in 3 dimensional world you need to:

`distance = sqrt ((x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2)`

This is what the result will be if you use normal distance command. distanceSqr does not have square root operation, so it is useless for measuring actual distances but pretty useful if you want to just compare distances:

`distanceSquared = (x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2`

Because it it has 1 less mathematical operation it is faster than distance and can be used to optimise scripts. However in my experiments the difference in speed appeared to be insignificant, nevertheless there is a difference. Usage:

distanceSquaredObjectOrPositionOrLocation distanceSqr ObjectOrPositionOrLocation;

## linearConversion

This command allows you to define two separate ranges, then take a value from one range and find its proportional value from another range. Complicated? Lets look at simple practical application. You have 390 apples in a box. You picked up 20 apples and what to know what percentage is it in relation to all the apples. You can do it the usual way:

_percentage = 20 * 100 / 390;

Or you can use linearConversion:

_percentage = linearConversion [0,390,20,0,100,false];

The result will be the same: 5.12821. This command might be useful for all sorts of conversions including resizing, however it is quite a bit slower than a couple of math commands that would do the same thing. Usage:

R2Value = linearConversion [R1Start, R1End, R1Value, R2Start, R2EndallowClipping];

• R1Start (number) : range 1 start
• R1End (number) : range 1 end
• R1Value (number) : range 1 value (can be outside of the range)
• R2Start (number) : range 2 start
• R2End (number) : range 2 end
• allowClipping (boolean) : if true, output is always within range 2

You can specify R1Value outside of the range 1, this will obviously force R2Value to appear outside of the range 2. If allowClipping is set to true then the result that should be outside of the range 2 will be clipped:

linearConversion [0,390,-3,0,100,false]; //-0.769231 linearConversion [0,390,-3,0,100,true]; //0 linearConversion [0,390,400,0,100,false]; //102.564 linearConversion [0,390,400,0,100,true]; //100

## difficulty

This command simply gives you the index of selected difficulty as it appears in CfgDifficulties. By default there are 4 difficulty classes: Recruit, Regular, Veteran and Mercenary (displayName “Elite”). I’ve added 1 more difficulty and called it Insane.

When selected “Insane”, the difficulty command returned 4. If “Regular” is selected the result is 0. Usage:

difficultyIndex = difficulty;

## setAmmo

This command will set custom ammo count in the currently loaded magazine of the specified weapon. The wiki page at the time of writing contains incorrect information. Usage:

unit setAmmo [TypeOfWeapon, ammoCountInWeaponMagazine];

If you try to set more ammo than the magazine can hold, it will be clipped at default magazine capacity. Some examples:

//set player's handgun ammo to 10 rounds player setAmmo [handgunWeapon player, 10]; //set player's current weapon ammo to 1 round player setAmmo [currentWeapon player, 1]; //if player is a gunner in a vehicle //set his current weapon's magazine ammo to 5 rounds (vehicle player) setAmmo [currentWeapon (vehicle player), 5];

## drawIcon3D

This command allows you to display an image with a text underneath this image on your screen in 3D world. Pretty useful for tagging players and objectives. The trick with this command however is that icon it creates exists only for a fraction of a second. So if you want continuity or to even see the result, you have to call this command at least for every frame. Usage:

drawIcon3D [imgPath, color, pos3D, imgW, imgH, imgDir, text, effect, textSize, textFont];

• imgPath (string) : path to image :  ”\path\image.paa” (seems to want AddOn textures)
• color (array) : color for image and text : [r, g, b, a]
• pos3D (array) : icon position in 3D world : [x, y, z]
• imgW (number) : width of image relative to icon : 1 – fit with icon
• imgH (number) : height of image relative to icon : 1 – fit with icon
• imgDir (number) : image rotation angle : 0 – 360, 0 – no rotation
• text (string) : text to appear underneath the image : “some text”
• effect (number) : effect : 0 – plain, 1 – add shadow, 2 – add stroke
• textSize (number) : text size relative to HUD size : 0.03 – normal size
• textFont (string) : text font : “PuristaLight”

To display dynamic semi transparent image of compass bearing above player head in blue:

Use the following code:

onEachFrame { private "_private"; _playerPos = getPosATL player; drawIcon3D [ "\a3\ui_f\data\IGUI\Cfg\Radar\radar_ca.paa", [0,0,1,0.5], [_playerPos select 0,_playerPos select 1,2.3], 5, 5, direction player, "COMPASS", 0, 0.03, "PuristaMedium" ]; };

Enjoy,
KK