Skip to content

Instantly share code, notes, and snippets.

@Freddo3000
Created November 13, 2020 18:07
Show Gist options
  • Save Freddo3000/94f7805eb9aaeb540b7a7b3363609445 to your computer and use it in GitHub Desktop.
Save Freddo3000/94f7805eb9aaeb540b7a7b3363609445 to your computer and use it in GitHub Desktop.
Road IED script
// Initializes scripted IEDs
// Author: Freddo
// #define DEBUG
params ["_mines", ["_detonateRadius", 5], ["_ownedSide", east]];
private _statemachine = [_mines, true] call CBA_statemachine_fnc_create;
_statemachine setVariable ["FRD_ownedSide", _ownedSide];
_statemachine setVariable ["FRD_radius", _detonateRadius];
[_statemachine, {}, {}, {}, "init"] call CBA_statemachine_fnc_addState;
[_statemachine, {}, {
_this setDamage 1;
}, {}, "detonate"] call CBA_statemachine_fnc_addState;
[_statemachine, "init", "detonate", {
#ifdef DEBUG
systemChat str _this;
#endif
private _ownedSide = _stateMachine getVariable "FRD_ownedSide";
private _radius = _stateMachine getVariable "FRD_radius";
private _entitiesMen = _this nearEntities ["CAManBase", _radius];
if (_entitiesMen findIf {
!(stance _x in ["PRONE", "", "UNDEFINED"]) &&
[_ownedSide, side _x] call BIS_fnc_sideIsEnemy
} != -1) exitWith {true};
private _entitiesVehicles = _this nearEntities ["LandVehicle", _radius * 1.5];
if (_entitiesVehicles findIf {
isEngineOn _x &&
[_ownedSide, side _x] call BIS_fnc_sideIsEnemy
} != -1) exitWith {true};
false
}] call CBA_statemachine_fnc_addtransition;
#ifdef DEBUG
_stateMachine spawn {
sleep 0.1;
private _output = [_this, true, true] call CBA_statemachine_fnc_toString;
copyToClipboard _output;
hintC _output;
};
#endif
// Spawns IEDs near roads within defined areas
// Author: Freddo
// #define DEBUG
params ["_whitelistAreas", "_blacklistAreas", "_amount", ["_ownerSide", east]];
_whitelistAreas = _whitelistAreas apply {_x call BIS_fnc_getArea};
_blacklistAreas = _blacklistAreas apply {_x call BIS_fnc_getArea};
private _roadSegments = [];
{
private _area = _x;
_x params ["_center", "_a", "_b"/*, "_angle", "_isRectangle", "_height"*/];
_roadSegments append ((_center nearRoads (_a max _b)) inAreaArray _area);
} forEach _whitelistAreas;
_roadSegments = _roadSegments arrayIntersect _roadSegments;
#ifdef DEBUG
{
private _marker = createMarker [format ["debug_roadSegment_%1", _forEachIndex], _x];
_marker setMarkerType "mil_dot";
_marker setMarkerSize [0.5, 0.5];
if ((_blacklistAreas findIf {(getMarkerPos _marker) inArea _x}) == -1) then {
_marker setMarkerColor "ColorRed";
} else {
// segment in blacklist area
_marker setMarkerColor "ColorOrange";
};
} forEach _roadSegments;
#endif
_roadSegments = _roadSegments select {
private _segment = _x;
(_blacklistAreas findIf {_segment inArea _x}) == -1
};
private _mines = [];
{
private _mineType = selectRandom [
"ACE_IEDLandBig_Command_Ammo",
"ACE_IEDLandSmall_Command_Ammo",
"ACE_IEDUrbanBig_Command_Ammo",
"ACE_IEDUrbanSmall_Command_Ammo"
];
(getRoadInfo _x) params ["", "_width"];
private _mine = createVehicle [_mineType, _x, [], _width, "NONE"];
_ownerSide revealMine _mine;
#ifdef DEBUG
private _marker = createMarker [format ["debug_IED_%1", _forEachIndex], _mine];
_marker setMarkerType "mil_warning";
_marker setMarkerSize [0.5, 0.5];
_marker setMarkerColor "ColorRed";
#endif
_mines pushBack _mine;
} forEach ((_roadSegments call BIS_fnc_arrayShuffle) select [0, _amount]);
_mines
FRD_fnc_spawnIEDs = compileFinal preprocessFileLineNumbers "fn_spawnIEDs.sqf";
FRD_fnc_initIEDs = compileFinal preprocessFileLineNumbers "fn_initIEDs.sqf";
if (isServer) then {
private _mines = [
[trigger1,trigger2,triggerN], // Whitelist areas to place mines in
[trigger3,trigger4, triggerX], // Blacklist areas where no mines will be placed
east // Owner side to which the mines will be revealed
] call FRD_fnc_spawnIEDs;
[
_mines, // Mine objects
5, // Detonation radius. Increased by 50% for vehicles
east // Owned side which will not detonate the mines
] call FRD_fnc_initIEDs;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment