Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casings - Add support for dropped magazines (40mm shell casings) #9839

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/casings/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PREP(createCasing);
PREP(createMagazine);
2 changes: 2 additions & 0 deletions addons/casings/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
if (!hasInterface || !GVAR(enabled)) exitWith {};

GVAR(cachedCasings) = createHashMap;
GVAR(cachedMagazines) = createHashMap;
GVAR(casings) = [];
["CAManBase", "FiredMan", LINKFUNC(createCasing)] call CBA_fnc_addClassEventHandler;
[QGVAR(reloaded), "Reloaded", LINKFUNC(createMagazine)] call EFUNC(common,addPlayerEH);
60 changes: 60 additions & 0 deletions addons/casings/functions/fnc_createMagazine.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "..\script_component.hpp"
/*
* Author: GabrielPearce / esteldunedain / Cyruz / diwako / PabstMirror
* Produces a casing matching the reloaded and dropped magazine
*
* Arguments:
* 0: unit - Object the event handler is assigned to <OBJECT>
* 4: Old magazine (can be nil) - <ARRAY>
*
* Return Value:
* None
*
* Example:
* [player, "", "","", ["1Rnd_HE_Grenade_shell", 0]] call ace_casings_fnc_createMagazine
*
* Public: No
*/

params ["_unit", "", "", "", "_oldMagazine"];
TRACE_2("createMagazine",_unit,_oldMagazine);

if (isNil "_oldMagazine") exitWith {};
_oldMagazine params ["_mag", "_ammo"];
if (_ammo != 0) exitWith {};

private _modelPath = GVAR(cachedMagazines) getOrDefaultCall [_mag, {
switch (true) do {
// Should cover most 40x36
case (_mag in compatibleMagazines ["arifle_Mk20_GL_F", "EGLM"]): { "A3\Weapons_F\MagazineProxies\mag_40x36_HE_1rnd.p3d" };
default { getText (configFile >> "CfgMagazines" >> _mag >> QGVAR(model)) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pull from magProxy and override with this if available?

};
}, true];

if (_modelPath isEqualTo "") exitWith {};

private _unitPos = getposASL _unit;
private _weapDir = _unit weaponDirection currentWeapon _unit;
private _ejectDir = _weapDir vectorCrossProduct [0, 0, 1];
private _pos = _unitPos
vectorAdd (_weapDir vectorMultiply (-0.5 + random 2))
vectorAdd (_ejectDir vectorMultiply (0.2 + random 2));

[
{
params ["_modelPath", "_pos"];
TRACE_2("creating magazine",_modelPath,_pos);

private _lisPos = (lineIntersectsSurfaces [_pos, _pos vectorAdd [0,0,-1e11], objNull, objNull, true, 1, "ROADWAY", "FIRE"]) #0;
private _casing = createSimpleObject [_modelPath, (_lisPos #0 vectorAdd [0,0,0.010]), false]; // global
_casing setDir (random 360);
_casing setVectorUp _lisPos #1;
private _idx = GVAR(casings) pushBack _casing;

for "_" from 0 to (_idx - GVAR(maxCasings)) do {
deleteVehicle (GVAR(casings) deleteAt 0);
};
},
[_modelPath,_pos],
0.4
] call CBA_fnc_waitAndExecute;
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ PREP(_handleRequestAllSyncedEvents);
PREP(addActionEventHandler);
PREP(addActionMenuEventHandler);
PREP(addMapMarkerCreatedEventHandler);
PREP(addPlayerEH);

PREP(removeActionEventHandler);
PREP(removeActionMenuEventHandler);
Expand Down
44 changes: 44 additions & 0 deletions addons/common/functions/fnc_addPlayerEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Adds event handler just to ace_player
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
*
* Arguments:
* 0: Key <STRING>
* 1: Event Type <STRING>
* 2: Event Code <CODE>
*
* Return Value:
* None
*
* Example:
* ["example", "FiredNear", {systemChat str _this}] call ace_common_fnc_addPlayerEH
*
* Public: Yes
*/
params [["_key", "", [""]], ["_type", "", [""]], ["_code", {}, [{}]]];

if (isNil QGVAR(playerEventsHash)) then { // init
GVAR(playerEventsHash) = createHashMap;
["unit", {
params ["_newPlayer", "_oldPlayer"];
TRACE_3("",_newPlayer,_oldPlayer,count GVAR(playerEventsHash));
{
private _var = format [QGVAR(playerEvents_%1), _x];
private _oldEH = _oldPlayer getVariable [_var, -1];
_oldPlayer removeEventHandler [_y#0, _oldEH];
_oldPlayer setVariable [_var, nil];

private _newEH = _newPlayer addEventHandler _y;
_newPlayer setVariable [_var, _newEH];
} forEach GVAR(playerEventsHash);
}, false] call CBA_fnc_addPlayerEventHandler;
};

private _event = [_type, _code];
GVAR(playerEventsHash) set [_key, _event];

if (isNull ACE_player) exitWith {};
private _var = format [QGVAR(playerEvents_%1), _key];
private _newEH = ACE_player addEventHandler _event;
ACE_player setVariable [_var, _newEH];