// Define variables
boobyTrappedBackpacks = []; // Array to store all booby-trapped backpacks
// Function to set the booby trap on a backpack
setBoobyTrapBackpack = {
// Check if the player has an explosive charge
if (!("DemoCharge_Remote_Mag" in magazines player)) exitWith {
hint "You need an explosive charge to set a booby trap!";
};
// Check if the player is wearing a backpack
if (backpack player == "") exitWith {
hint "You must be wearing a backpack to set a booby trap!";
};
// Start the 5-second setup timer with visible countdown
for "_i" from 5 to 0 step -1 do {
hint format ["Setting booby trap on your backpack... %1 seconds", _i];
sleep 1;
};
// Remove the explosive charge from the player's inventory
player removeItem "DemoCharge_Remote_Mag"; // Replace with the appropriate explosive classname
// Create a unique ID for the booby trap
_trapID = format ["boobyTrap_%1", count boobyTrappedBackpacks];
// Store the booby trap details in the array
_trapDetails = [backpack player, _trapID, player]; // Store the player as the owner
boobyTrappedBackpacks pushBack _trapDetails;
// Hint to inform the player
hint format ["Booby trap (%1) has been set on your backpack! Place it in a vehicle, drop it, or give it to an AI unit, then use the detonate action.", _trapID];
// Add action to manually detonate the booby trap
player addAction [
format ["Detonate Booby Trap (%1)", _trapID], // Action text
{
params ["_target", "_caller", "_actionID", "_arguments"];
_arguments params ["_backpackClass", "_trapID", "_owner"];
// Find the booby trap in the array
_trapIndex = boobyTrappedBackpacks findIf {_x select 1 == _trapID};
if (_trapIndex != -1) then {
_trapDetails = boobyTrappedBackpacks select _trapIndex;
_trapDetails params ["_backpackClass", "_trapID", "_owner"];
// Find the backpack in the world
_backpack = objNull;
{
// Check if the backpack is being carried by a unit
if (backpack _x == _backpackClass) exitWith {
_backpack = _x;
};
// Check if the backpack is in a vehicle's inventory
if (_backpackClass in backpackCargo _x) exitWith {
_backpack = _x;
};
} forEach (vehicles + allUnits);
// If the backpack is not found in a unit or vehicle, check if it's on the ground
if (isNull _backpack) then {
{
if (typeOf _x == _backpackClass) exitWith {
_backpack = _x;
};
} forEach (allMissionObjects "WeaponHolder");
};
// Check if the backpack is valid
if (!isNull _backpack) then {
// Ensure the backpack or its container is simulated globally
if (_backpack isKindOf "WeaponHolder") then {
_backpack setPosWorld (getPosWorld _backpack); // Force global position update
} else {
if (!isNull objectParent _backpack) then {
(objectParent _backpack) setPosWorld (getPosWorld (objectParent _backpack)); // Force global position update for the vehicle
};
};
// Get the global position of the backpack
_backpackPos = getPosWorld _backpack;
// Create an explosion at the backpack's global position
_explosion = "Bo_GBU12_LGB" createVehicle _backpackPos;
// Damage nearby units and vehicles
{
_x setDamage 1; // Set damage to 100%
} forEach (_backpack nearEntities ["CAManBase", 10]); // Damage units within 10 meters
{
_x setDamage 1; // Set damage to 100%
} forEach (_backpack nearEntities ["AllVehicles", 10]); // Damage vehicles within 10 meters
// Explosion hint
hint format ["Booby trap (%1) has exploded!", _trapID];
} else {
hint "No backpack found to detonate!";
};
// Remove the booby trap from the array
boobyTrappedBackpacks deleteAt _trapIndex;
// Remove the detonate action
player removeAction _actionID;
} else {
hint "No active booby trap to detonate!";
};
},
[backpack player, _trapID, player], // Arguments
1.5, // Priority
true, // Show in action menu
true, // Hide on use
"", // Shortcut
"true", // Condition (always show)
5 // Radius (optional)
];
};
// Add action to set the booby trap on the player's backpack
player addAction ["Set Booby Trap on Backpack", { [] spawn setBoobyTrapBackpack; }];
// Add an event handler to detect when the player acquires explosives
player addEventHandler ["Take", {
params ["_unit", "_container", "_item"];
if (_item == "DemoCharge_Remote_Mag") then {
hint "You now have explosives! You can set a booby trap on your backpack.";
};
}];