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

Add naked unit bug workaround #1406

Merged
merged 21 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions addons/network/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
56 changes: 56 additions & 0 deletions addons/network/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "script_component.hpp"

ADDON = false;

// Restore loadouts lost by the naked unit bug
[QGVAR(restoreLoadout), {
params ["_unit", "_loadout"];
if (count _loadout < 7) exitWith {};

// Check if loadout got lost
private _loadoutLost = False;
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
{
(_loadout select _forEachIndex) params [["_backup", "", [""]]];
// Reject backup if it contains less information
if (_backup isEqualTo "" && !(_x isEqualTo "")) exitWith {};
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
if !(_x isEqualTo _backup) exitWith {
_loadoutLost = True;
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
};
} forEach [
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit,
uniform _unit,
vest _unit,
backpack _unit,
headgear _unit
];
Kexanone marked this conversation as resolved.
Show resolved Hide resolved

if (_loadoutLost) then {
_unit setUnitLoadout _loadout;
};
}] call CBA_fnc_addEventHandler;
Kexanone marked this conversation as resolved.
Show resolved Hide resolved

["CAManBase", "Local", {
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
params ["_unit", "_local"];
if (_local) then {
// Enable loadout restoration for units transferred to the machine
_unit setVariable [QGVAR(enableRestoreLoadout), true];
} else {
// Broadcast loadout to new owner if local was not triggered by init
if (_unit getVariable [QGVAR(enableRestoreLoadout), false]) then {
private _loadout = getUnitLoadout _unit;
[QGVAR(restoreLoadout), [_unit, _loadout], _unit] call CBA_fnc_targetEvent;
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
};
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
};
}] call CBA_fnc_addClassEventHandler;

// Enable loadout restoration for units spawned on the machine
["CAManBase", "Init", {
params ["_unit"];
if (local _unit) then {
_unit setVariable [QGVAR(enableRestoreLoadout), true];
};
commy2 marked this conversation as resolved.
Show resolved Hide resolved
}] call CBA_fnc_addClassEventHandler;

ADDON = true;
1 change: 1 addition & 0 deletions addons/network/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ class CfgPatches {
};
};

#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"