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:

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:

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:

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:

unitsetAmmo [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
playersetAmmo[handgunWeaponplayer,10];//set player's current weapon ammo to 1 round
playersetAmmo[currentWeaponplayer,1];//if player is a gunner in a vehicle
//set his current weapon's magazine ammo to 5 rounds
(vehicleplayer)setAmmo[currentWeapon(vehicleplayer),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:

Related Posts

Frantic69

Thank you, very interesting.

ghiro

kudos, your posts are tremendously interesting KK.

I recently started playing around with Arma scripts and find your structured approach very rewarding.

I wonder if in the future you could spend a post (or two) on how you set up your development environment, the tools you normally use and the configuration steps for setting up a sandbox for developing scripts.

Do you use some kind of custom ‘unit-test’ framework that prepares the necessary context for your script to execute and cleans afterwards?
You start with the embedded debug console?
Tips like that are quite valuable in my opinion.

Keep up the good work! As a newbie I am digesting the content you share at a much lower pace then the one you produce it but I hope I can eventually catch up..

Killzone_Kid

I use ArmA 3 debug console for quick tests and thanks to more intuitive ArmA 3 editor putting something together for a more complicated test is as easy. Other than that I don’t know what to suggest.

benw

this is very useful as the community wiki doesn’t state that the command requires the addons textures.
However, I have a little question about the path for the textures. From my observation, the radar_ca.paa is actually located in a folder called ui_f_data.pbo so is there any other way to read the actual path for those addon files?

Killzone_Kid

Not sure what you’re asking. If you need paths to other images, you need to open up pbos with something like dePbo, then you can browse all assets and just copy the path to the one you want.

Johnkok

Hi KK, this tutorial for drawIcon3d has been extremely helpful to me, I used it to create some base marker text. But for some reason now it’s not working. So my question is: After the 1.22 update does the onEachFrame function still work? Sounds stupid but I cant think what else is wrong. As a test I called your exact script above and the icon only appears for a fraction of a second. I am stumped

Killzone_Kid

If you are using oneachframe elsewhere, it will overwrite previous one. Use draw3d event handler instead.

addMissionEventHandler ["Draw3d", {...yourcode here...}];

Johnkok

Killzone_Kid you nailed it again. After using that method (being very careful to check my syntax) I got my text script to run and my text to show. I am quite certain the recent update has changed how it worked as it has been working fine for weeks and then suddenly not. All my backups were affected, saves that I hadn’t touched in a long time. As a control I tried it on a completely clean mission file. Thanks again mate

Pierre MGI

Hi everyone,
Many thanks KK for all your tutorials.
I’m trying to do my own HUD. It sounds fine but… i didn’t find a way to do this kind of compass, centered on screen, with DrawIcon3D.
It seems, at first glance, choice is limited to:
- DrawIcon3D with 3D positioning (of course),
- structuredText or any static controls (on screen) but without any rotation or even mirroring text.

Any solution to rotate a centered image or text on a defined (x,y) screen position?
Hope my English is understandable.

Killzone_Kid

There are new commands on dev to rotate rscobject, but if it is image, then you can only rotate icon drawn over map control

Pierre MGI

Hi, thanks for your answer. you prevent me from wasting my time. I understand that “map”, in this case, can’t be “screen” or more exactly custom titles display. I avoid scripting in dev version because i would like to share (add-on via steam ?) for current version.