Skip to content

Instantly share code, notes, and snippets.

@indig0fox
Created May 17, 2021 03:56
Show Gist options
  • Save indig0fox/5c825415ae9b287199cc39dc5bab13e3 to your computer and use it in GitHub Desktop.
Save indig0fox/5c825415ae9b287199cc39dc5bab13e3 to your computer and use it in GitHub Desktop.
management of placed expl/mines and items thrown via ACE adv throwing or vanilla Throw action
// fired EH for non-bullets
// on any projectile that's not a bullet, draw a marker that tracks its position and persists 5 seconds after it 'dies'
// smoke grenades die when smoke stops coming out. frag grenades, explosives die after explosion.
{
_x addEventHandler["Fired", {
_this spawn {
params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
_muzzleDisp = getText(configFile >> "CfgWeapons" >> _weapon >> _muzzle >> "displayName");
if (_muzzleDisp == "") then {_muzzleDisp = getText(configFile >> "CfgWeapons" >> _weapon >> "displayNameShort")};
if (_muzzleDisp == "") then {_muzzleDisp = getText(configFile >> "CfgWeapons" >> _weapon >> "displayName")};
_magDisp = getText(configFile >> "CfgMagazines" >> _magazine >> "displayNameShort");
if (_magDisp == "") then {_magDisp = getText(configFile >> "CfgMagazines" >> _magazine >> "displayName")};
if (_magDisp == "") then {_magDisp = getText(configFile >> "CfgAmmo" >> _ammo >> "displayNameShort")};
if (_magDisp == "") then {_magDisp = getText(configFile >> "CfgAmmo" >> _ammo >> "displayName")};
_ammoSimType = getText(configFile >> "CfgAmmo" >> _ammo >> "simulation");
_int = random 2000;
// "\rhsafrf\addons\rhs_weapons\gear\rhs_vog25_ca.paa"
hint parseText format["<img image='%1'/>",(getText(configfile >> "CfgMagazines" >> "rhs_vog25" >> "picture"))];
_magPic = (getText(configfile >> "CfgMagazines" >> _magazine >> "picture"));
if (_magPic == "") then {
_markerType = "mil_triangle";
_markColor = "ColorWhite";
} else {
// _magPicSplit = _magPic splitString "\\";
// _magPic = _magPicSplit # ((count _magPicSplit) -1);
// _markerType = format["magIcons\%1", _magPic];
};
hint composeText [image _magPic];
systemChat _magazine;
if (!(_ammoSimType isEqualTo "shotBullet")) then {
// non-bullet handling
_markTextLocal = format["%1 - %2", _muzzleDisp, _magDisp];
_markName = format["Projectile#%1", _int];
_markStr = format["|%1|%2|%3|%4|%5|%6|%7|%8|%9|%10",
_markName,
getPos _unit,
"selector_selectable",
"ICON",
[1, 1],
0,
"Solid",
"ColorRed",
1,
_markTextLocal
];
_markStr call BIS_fnc_stringToMarker;
_lastPos = [];
while {alive _projectile} do {
_pos = getPosATL _projectile;
_lastPos = _pos;
// systemChat str _lastPos;
_markName setMarkerPosLocal _lastPos;
};
sleep 5;
deleteMarker _markName;
};
};
}];
} forEach allUnits + vehicles;
// on any ACE explosive or mine *placement* via interaction menu, will execute the code here
["ACE_Explosives_Place", "init", {
systemChat str _this;
systemChat str (_this # 0);
systemChat str configOf (_this # 0);
systemChat str getText (configOf (_this # 0) >> "icon");
_iconPath = getText (configOf (_this # 0) >> "icon");
hint parseText format["Explosive Placed<br/>ICON:<br/><img image='%1'/>", getText(configFile >> "CfgVehicleIcons" >> _iconPath)];
}] call CBA_fnc_addClassEventHandler;
// on any remote, manual detonation (such as with a paired clacker), will execute the code here
[{
params ["_unit", "_range", "_explosive", "_fuzeTime", "_triggerItem"];
_int = random 2000;
// expl is ammo, need to find mag, and display name of mag
_explosiveMag = getText(configFile >> "CfgAmmo" >> (typeOf _explosive) >> "defaultMagazine");
_explosiveDisp = getText(configFile >> "CfgMagazines" >> _explosiveMag >> "displayName");
_triggerItemDisp = getText(configFile >> "CfgWeapons" >> _triggerItem >> "displayName");
_markTextLocal = format["%1 - %2", _triggerItemDisp, _explosiveDisp];
_markName = format["Detonation#%1", _int];
_markColor = "ColorRed";
_markerType = "waypoint";
_pos = getPos _explosive;
["fnf_ocap_handleMarker", ["CREATED", _markName, _unit, _pos, _markerType, "ICON", [1,1], 0, "Solid", "ColorRed", 1, _markTextLocal]] call CBA_fnc_localEvent;
[_markName] spawn {
params ["_markName"];
sleep 7;
// [format['["fnf_ocap_handleMarker", ["DELETED", %1]] call CBA_fnc_serverEvent;', _markName]] remoteExec ["hint", 0];
// systemChat format['["fnf_ocap_handleMarker", ["DELETED", %1]] call CBA_fnc_serverEvent;', _markName];
["fnf_ocap_handleMarker", ["DELETED", _markName]] call CBA_fnc_localEvent;
};
}] call ace_explosives_fnc_addDetonateHandler;
// track objects thrown using ACE Shift-G advanced throwing
{
trackThrows = ["ace_throwableThrown", {
_this spawn {
params["_unit", "_projectile"];
// systemChat str _this;
// limits trigger to only thrown short-fuse ACE explosives, instead of also counting chemlights/frags/smokes
// note that thrown objects outside of ACE explosives do not include a "default magazine" property in their config.
// this script will attempt to find a matching classname in CfgMagazines, as some chemlights and smokes are built this way.
// if not found, a default magazine value will be assigned (m67 frag, white smoke, green chemlight)
// systemChat str call compile "_projectile isKindOf ""ACE_SatchelCharge_Remote_Ammo_Thrown""";
// if (!(_projectile isKindOf "ACE_SatchelCharge_Remote_Ammo_Thrown")) exitWith {};
_projType = typeOf _projectile;
_projConfig = configOf _projectile;
_projName = getText(configFile >> "CfgAmmo" >> _projType >> "displayName");
systemChat format["Config name: %1", configOf _projectile];
_ammoSimType = getText(configFile >> "CfgAmmo" >> _projType >> "simulation");
systemChat format["Projectile type: %1", _ammoSimType];
_markerType = "";
_markColor = "";
_magDisp = "";
_magPic = "";
_magType = getText(_projConfig >> "defaultMagazine");
if (_magType == "") then {
_magType = configName(configfile >> "CfgMagazines" >> _projType)
};
if (!(_magType isEqualTo "")) then {
systemChat format["Mag type: %1", _magType];
_magDisp = getText(configFile >> "CfgMagazines" >> _magType >> "displayNameShort");
if (_magDisp == "") then {
_magDisp = getText(configFile >> "CfgMagazines" >> _magType >> "displayName")
};
if (_magDisp == "") then {
_magDisp = _projName;
};
_magPic = (getText(configfile >> "CfgMagazines" >> _magType >> "picture"));
hint parseText format["Projectile fired:<br/><img image='%1'/>", _magPic];
if (_magPic == "") then {
_markerType = "mil_triangle";
_markColor = "ColorRed";
} else {
_magPicSplit = _magPic splitString "\";
_magPic = _magPicSplit#((count _magPicSplit) - 1);
_markerType = format["magIcons/%1", _magPic];
_markColor = "ColorWhite";
};
} else {
_markerType = "mil_triangle";
_markColor = "ColorRed";
// set defaults based on ammo sim type, if no magazine could be matched
switch (_ammoSimType) do {
case "shotGrenade":{
_magPic = "\A3\Weapons_F\Data\UI\gear_M67_CA.paa";
_magDisp = "Frag";
};
case "shotSmokeX":{
_magPic = "\A3\Weapons_f\data\ui\gear_smokegrenade_white_ca.paa";
_magDisp = "Smoke";
};
case "shotIlluminating":{
_magPic = "\A3\Weapons_F\Data\UI\gear_flare_white_ca.paa";
_magDisp = "Flare";
};
default {
_magPic = "\A3\Weapons_F\Data\UI\gear_M67_CA.paa";
_magDisp = "Frag";
};
};
hint parseText format["Projectile fired:<br/><img image='%1'/>", _magPic];
_magPicSplit = _magPic splitString "\";
_magPic = _magPicSplit#((count _magPicSplit) - 1);
_markerType = format["magIcons/%1", _magPic];
_markColor = "ColorWhite";
};
_int = random 2000;
if (!(_ammoSimType isEqualTo "shotBullet")) then {
// non-bullet handling
_markTextLocal = format["%1", _magDisp];
_markName = format["Projectile#%1", _int];
_markStr = format["|%1|%2|%3|%4|%5|%6|%7|%8|%9|%10",
_markName,
getPos _unit,
"mil_triangle",
"ICON", [1, 1],
0,
"Solid",
"ColorRed",
1,
_markTextLocal
];
_markStr call BIS_fnc_stringToMarker;
_lastPos = [];
while {
alive _projectile
}
do {
_pos = getPosATL _projectile;
_lastPos = _pos;
// systemChat str _lastPos;
_markName setMarkerPosLocal _lastPos;
};
sleep 5;
deleteMarker _markName;
};
};
}] call CBA_fnc_addEventHandler;
}
remoteExec["call", 0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment