Arma 3
Discover the best community content
Get the most out of Arma 3 with Steam Workshop. Find and install player-created scenarios and mods, or create your own and upload it directly to Steam.
Learn More
slawek 26 Jul, 2024 @ 12:04pm
Anti-ship explosives, have fun
I just have written a simple (?) SQF script. Works with plain vanilia Arma 3. Have fun.

// Add an "anti-ship magnetic mine" weapon to Arma 3 video game.
//
// This script make posible to use a sachel charge against floating
// patrol boats. Just add an action to menu with addAction like below:
//
// this addAction ["Place magnetic mine", "boat_magnetic_mine.sqf",
// nil, 1.5, true, true, "", "true", 4, false, "", ""];
//
// This may be done in the init field (Eden editor) or in init.sqf.
// You may use a loop to addAction to each boat in the scenario.
//
// The explosive is remotelly activated (up to 1500 meters, see below)
// or you may set timer (5 minutes). Remote activation detonate all satchels at once.
//
// By the design, only satchel charge may be used as "magnetic mine".
// You may uncoment appropariate lines to enable use demolition charge.
//
// Notice that this script use a global variable (hash map) to keep track
// planted explosives.
//
// Return true if the explosives has been succesfully deployed.
// Return false if the explosives has not been planted.
//
// This script have not been tested with the unit/group switching.
// This script have not been tested within a multiplayer environment.

params ["_target", "_caller", "_actionId", "_arguments"];

private _boat = _target;
private _player = _caller;

private _satchel = ["SatchelCharge_Remote_Mag",
"SatchelCharge_Remote_Ammo_Scripted"];
private _demo = ["DemoCharge_Remote_Mag",
"DemoCharge_Remote_Ammo_Scripted"];

private _plant_explosives = {
params ["_ammo_mag", "_ammo_scripted"];

_planted = false;
if (_ammo_mag in magazines _player) then {

// Plant the explosive. Magically change "mag" into "sripted".
//
_explosive = createVehicle [_ammo_scripted, [0,0,0], [], 0, "NONE"];
_explosive attachTo [_boat, [0,0,-3.4]];
_player removeItem _ammo_mag;
_player removeAction _actionId;

// The lazy initialization of the hash map of list of planted explosives.
// The lazy initialization of the hash map entry.
// Use a list to store info about the explosive.
//
if (isNil "global_boat_magnetic_mine_dict") then {
global_boat_magnetic_mine_dict = createHashMap;
};
private _hash = hashValue _player;
private _isMemorized = _hash in global_boat_magnetic_mine_dict;
if (not _isMemorized) then {
global_boat_magnetic_mine_dict set [_hash, []];
};
private _list = global_boat_magnetic_mine_dict get _hash;
_list pushBack _explosive;

// The time fuse logic.
//
_boat addAction [
"Set 5 minutes magnetic mine timer",
{
params ["_target", "_caller", "_actionId", "_arguments"];
_target removeAction _actionId;
_explosive = _arguments;
[_caller, _explosive] spawn {
params ["_player", "_explosive"];
private _delay_in_seconds = 5 * 60;
for "_t" from _delay_in_seconds to 1 step -1 do { // TODO ;)
if (not alive _explosive) then {
break;
};
cutText [format ["magnetic mine explosion in %1 seconds", _t], "PLAIN"];
sleep 1;
};
cutText ["", "PLAIN"];
if (alive _explosive) then {
_explosive setDamage 1; // detonate
private _hash = hashValue _player;
private _list = global_boat_magnetic_mine_dict get _hash;
_list deleteAt (_list find _explosive);
};
};
},
_explosive,
1.5, true, true, "", "true", 5, false, "", ""
];

// Remote activation logic.
//
removeAllActions _player; // @todo: removeAllActions may be hurtfull
_player addAction [
"Remote detonation of magnetic mines",
{
params ["_target", "_caller", "_actionId", "_arguments"];
private _hash = hashValue _caller;
private _list = global_boat_magnetic_mine_dict get _hash;
private _countDone = 0; // count how many explosives just exploded
{
if (alive _x) then {
private _range = 1500;
if ((_caller distance _x) <= _range) then {
_x setDamage 1; // detonate
_countDone = _countDone + 1;
};
} else {
_countDone = _countDone + 1;
};
} forEach _list;

// If all explosives exploded then there is a reason to remove
// remote detonation action/menu.
//
if (_countDone == (count _list)) then {
global_boat_magnetic_mine_dict deleteAt _hash;
_target removeAction _actionId;
};
}
];
_planted = true;
};
_planted;
};

private _planted = false;
if (not _planted) then {
_satchel call _plant_explosives;
};
// if (not _planted) then {
// _demo call _plant_explosives;
// };
Last edited by slawek; 26 Jul, 2024 @ 12:10pm