Whoahoohoodilly! I’ve got another donation, this time from a fellow by the name of Nazar. If it keeps on going like this, I’m quitting my day job! :)Спасибо Вам большое, Назар! Now. I’ve already made an introduction post on how to create scripted charges in Arma 3. Today I would like to expand on it a little bit and I’m going to show you how to destroy static objects on the map in a way that they remain JIP compatible. By static, I mean objects that are pre-placed in map editor.

So what is the problem? Let’s take trees for example. If you destroy a tree it falls down. Pretty cool. However destroying tree is not enough, it actually matters how you destroy it, because if you just kill it with tree setDamage 1, any player Joining In Progress (i.e. after the tree fell down) will see the tree standing up. Even if you, yourself, drop to the lobby and back, you would see the tree standing up again, while all other players that witnessed tree falling will see this tree on the ground.

Needless to say this is not acceptable from gameplay point of view. So how do you script this into a reliable functionality? The obvious way would be to add trees killed by a script into JIP array, so that you can just run {_x setDamage 1} forEach trees_in_JIP_array for every joining player. Simple enough, but not optimal. You see, setDamage is global command, this means that every joining player will make a global damage broadcast call for every tree in JIP array. If there are 100 trees in the array and 50 players on the server, that is 5000 packets sent. Red chain alert!

Actually this may not cause red chain on its own, however, all things considered, you wouldn’t really want to add to the network traffic unless it is absolutely necessary. On the other hand, if you mow a tree with a tank, it will become JIP compatible and will stay on the ground for everyone. So what do you do, you are not just going to throw tanks at the trees, are you? Are you? Well, why the hell not? I have to confess, I did just that to begin. Then I switched to cars, quad bikes… Finally I found what I was looking for:

Land_CargoBox_V1_F

A PhysX enabled cargo box! While as it is, the box is pretty light and bounces off trees, making it a “little bit” heavier with setMass command did the trick. And because knocking trees down is built in functionality, it naturally syncs for JIP players on the engine level without hassle. To make it part of C4 explosion, all I needed to do was to make it fly in all directions from the epicentre of explosion, while making box indestructible at that too. To limit the range, the boxes need to be deleted pretty soon after they are created.

The added benefits of this method is that you can also knock fences and lamp posts if C4 goes off near them. The functionality that should already exist in Arma 3 in the core. In fact, thinking about it, each explosion could have a rapidly expanding PhysX bubble, which would start losing mass the bigger it is. Any objects that can be knocked down will be knocked down when they come in touch with the bubble, subject to bubble’s mass at the time. Sounds like a pretty simple solution to me that can add to great realism. No need to even mess with existing JIP array as it all works already.

I’ve made my workaround to be compatible with dedicated server only. Why? I create boxes on the server as local objects so they do not get transferred over network. In the following video I made boxes global so that you could actually see what is going on on the server:

Below is the code I used for my experiments. Add it to init.sqf if you want. It will place C4 on the ground where you’re looking at. I actually had too much fun blowing up things left right and centre testing it, so here is the code for you to play too:

if (isDedicated) then { "BOOM" addPublicVariableEventHandler { _c4 = _this select 1 select 0; _c4pos = _this select 1 select 1; for "_dir" from 0 to 359 step 45 do { 0 = [_dir, _c4pos] spawn { _dir = _this select 0; _f = "Land_CargoBox_V1_F" createVehicleLocal [0,0,0]; _f setMass 999999; _f allowDamage false; _f setDir _dir; _f setPosASL (_this select 1); _f setVelocity [cos _dir * 5, sin _dir * 5, 5]; sleep 0.5; deleteVehicle _f; }; }; _c4 setDamage 1; }; } else { KK_fnc_makeC4 = { player addAction ["Put C4", { _c4pos = screenToWorld [0.5,0.5]; player playActionNow "PutDown"; sleep 0.5; _c4 = createVehicle [ "DemoCharge_Remote_Ammo_Scripted", _c4pos, [], 0, "CAN_COLLIDE" ]; player removeAction (_this select 2); player addAction ["GO BOOM!", { BOOM = _this select 3; publicVariableServer "BOOM"; player removeAction (_this select 2); call KK_fnc_makeC4; }, [_c4, getPosASL _c4]]; }]; }; call KK_fnc_makeC4; };

Enjoy,
KK

UPDATE: Scripted damage to trees and static buildings (Visitor placed) is now JIP compatible. While this is great news, I think I still prefer throwing boxes at trees to simulate shock wave :)