Let’s talk little bit about commands in Arma 3, or precisely 1,500+ of them. Just the other day we were discussing this with my friend SaMatra that we should compile the top 10 most useless commands in Arma list for a laugh. BTW if you have some ideas about that leave it in the comment section :).
Having lots of commands is a double edged sword. On one hand the more the better as you have more access to Arma insides, on the other hand it becomes problematic to remember what does what and let’s face it, going by command name alone in many cases is pretty misleading. Then there is this thing called backwards compatibility where you cannot remove commands because someone might have used them and it would brake their work. You can only either expand existing syntax or add new commands all together. I personally would prefer the 1st method. In fact I think I’m going to propose here a syntax change for one of the commands dealing with storage containers.
I made a blog post awhile ago on how to find a centre of mass offset of a vehicle because while there was setCenterOfMass command, the getCenterOfMass was missing. Not anymore! It is good to see that BIS are listening and doing something about it. The rudimentary commands like for example getFOV to simply return Field Of View value of the client or even vehicleLights to tell you if a vehicle has its lights turned on are absolutely essential, yet somehow missing.
Another such command would be the one that provides the ability to put a magazine in a crate with predefined amount of ammo. You just cannot simply fill a crate with mags with different ammo count. The addMagazine command will let you do that but only when adding mag to unit’s inventory. This command has started taking global arguments recently, i.e. you can use it on the server to add mags with custom ammo count to any client. It’s a start. So the easiest way would probably be to expand this command to work with containers too. Or maybe add the 3rd param to addMagazineCargoGlobal command indicating how much ammo the mag should have when added?
I hope this gets sorted soon, and I have faith in awesome japapatramtara, BIS dev who is doing all inventory magic. In the mean time I took upon myself a challenge to do so in the current state of the game. It is ugly and it is funny but it works! In the video below you can see I’ve added 4 mags to 300 crates and each time the mags added had different ammo count. The visible ascending civilians? This can be optimised further, but I wanted to leave it as is to demonstrate the principle.
The way it is done here is that a civilian unit is created and it receives 1 magazine with custom ammo count because we can with addMagazine. Then the unit is forced to drop the mag into container with action “PutMagazine”. Because you cannot indicate which mag exactly the unit should drop, you can only do one mag at a time. Sounds simple? Wait until you try this in practice.
The unit will only place mag in the end of its animation. If you try to do anything to disrupt the animation, it will refuse to place the mag. The unit has to be next to the crate. The greater the distance between the crate and the unit the more unreliable this becomes. So you cannot just spawn unit elsewhere and make it remote fill the crate. But you can move the crate to the unit, make it fill it and then move the crate back. I will let you think of the logistics of it, because all I was interested was a concept. I suppose it can be used as it is if you are only filling crates at server start. Hopefully someone from BIS sees how awkward it could be to do a simple thing and gives us a dedicated command.
Here is the main function that does the filling:
And here is a snippet I used on the video to stress test it:
The function must be ‘spawned’ obviously as we use suspension and if you fill several crates, the loop MUST be ‘spawned’ too. It works in MP and if you run it on the server the unit will appear standing up, but that is ok, because it is lying on the server and this just speeds up crate filling a bit. So from the video it took 12 seconds to fill 300 crates with 4 mags each, roughly 100 mags a second. Of course this could be slower if you are trying to fill a single crate.
Another word of warning. The script takes container object as well as an array of mags to fill. It is easy with crate or a car cargo space, but if you want to use WeaponHolder you should be aware that if you do not put anything inside WeaponHolder immediately after it is created it will get automatically deleted. It takes some time for the unit to put 1st item into the storage container, so the newly created WeaponHolder will most likely get deleted beforehand. If deleted, the unit will create default WeaponHolder, but “Put” event handler will not fire in this case so it won’t work. Just make sure WeaponHolder is not empty when you pass it to the function.
Enjoy,
KK
EDIT: There is new command added recently hideObjectGlobal which can be used to hide _bob. However if you’re going to use it, there are few things you need to know. Command can only be executed on the server, so the crate filling script will have to run server side. If you spawn too many crates at once, some of the hideObjectGlobal _bob; effects will fail together with some crate filling. It could be ideal though if you want to spawn custom filled crates in small numbers.
EDIT: Forget about using human unit or hiding. I’ve just discovered it is possible to use Logic, a virtual unit class, as a base for modifying ammo count. The thing is you cannot addMagzine to Logic out of the box, because it simply hasn’t got where to store it. If you addUniform to Logic, for example, you can addMagazine then. So I have modified the original function a little bit to accommodate Logic and it is backward compatible. This is the resulting code (I am leaving the original code too in case someone is interested in history :). Oh, and don’t forget you must spawn or execVM this function):
EDIT: Well, well, well, and here we have it, ladies and gents, japapatramtara did it again!
box addMagazineAmmoCargo [magazine, quantity, ammocount] (currently on 1.29 DEV)