Skip to content

Commit

Permalink
Dogtags - Fix arsenal not showing dogtag info in multiplayer (#10095)
Browse files Browse the repository at this point in the history
* Broadcast dogtag info globally so that arsenal can use it

* Broadcast changes incrementally

* Update addons/dogtags/XEH_postInit.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update addons/dogtags/functions/fnc_getDogtagItem.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Add EH only on necessary machines

---------

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
  • Loading branch information
johnb432 and PabstMirror committed Jul 4, 2024
1 parent 4d0641a commit 3745305
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 72 deletions.
2 changes: 0 additions & 2 deletions addons/dogtags/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ PREP(bloodType);
PREP(canCheckDogtag);
PREP(canTakeDogtag);
PREP(checkDogtag);
PREP(checkDogtagItem);
PREP(getDogtagData);
PREP(getDogtagItem);
PREP(sendDogtagData);
PREP(showDogtag);
PREP(ssn);
PREP(takeDogtag);
Expand Down
25 changes: 21 additions & 4 deletions addons/dogtags/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
#include "script_component.hpp"

[QGVAR(showDogtag), LINKFUNC(showDogtag)] call CBA_fnc_addEventHandler;
[QGVAR(sendDogtagData), LINKFUNC(sendDogtagData)] call CBA_fnc_addEventHandler;
[QGVAR(getDogtagItem), LINKFUNC(getDogtagItem)] call CBA_fnc_addEventHandler;
[QGVAR(addDogtagItem), LINKFUNC(addDogtagItem)] call CBA_fnc_addEventHandler;

if (hasInterface || isServer) then {
[QGVAR(broadcastDogtagInfo), {
GVAR(dogtagsData) set _this;
}] call CBA_fnc_addEventHandler;

if (isServer) then {
// Sync dogtag data from server to client
[QGVAR(requestSyncDogtagDataJIP), {
params ["_clientOwner"];

{
[QGVAR(broadcastDogtagInfo), [_x, _y], _clientOwner] call CBA_fnc_ownerEvent;
} forEach GVAR(dogtagsData);
}] call CBA_fnc_addEventHandler;
} else {
// To be here, hasInterface must be true
[QGVAR(requestSyncDogtagDataJIP), clientOwner] call CBA_fnc_serverEvent;
};
};

// Add actions and event handlers only if ace_medical is enabled
// - Adding actions via config would create a dependency
["CBA_settingsInitialized", {
Expand Down Expand Up @@ -56,8 +75,6 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
if (_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) then {
LOG("passed");
private _rightPanel = _display displayCtrl 15;
private _allDogtags = missionNamespace getVariable [QGVAR(allDogtags), []];
private _allDogtagsData = missionNamespace getVariable [QGVAR(allDogtagDatas), []];
private _cfgWeapons = configFile >> "CfgWeapons";
private _item = "";
private _dogtagData = [];
Expand All @@ -66,7 +83,7 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
_item = _rightPanel lnbData [_i, 0];

if (_item isKindOf ["ACE_dogtag", _cfgWeapons]) then {
private _name = (_allDogtagsData param [_allDogtags find _item, []]) param [0, ""];
private _name = (GVAR(dogtagsData) getOrDefault [_item, []]) param [0, ""];

// If data doesn't exist or body has no name, set name as "unknown"
if (_name == "") then {
Expand Down
8 changes: 8 additions & 0 deletions addons/dogtags/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ PREP_RECOMPILE_END;

GVAR(disabledFactions) = createHashMap;

if (hasInterface || isServer) then {
GVAR(dogtagsData) = createHashMap;

if (!isServer) exitWith {};

GVAR(idCounter) = 0;
};

ADDON = true;
4 changes: 3 additions & 1 deletion addons/dogtags/functions/fnc_addDogtagActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ private _fnc_getActions = {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");

private _action = [_x, _displayName, _picture, FUNC(checkDogtagItem), {true}, {}, _x] call EFUNC(interact_menu,createAction);
private _action = [_x, _displayName, _picture, {
[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag);
}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
};
} forEach (_player call EFUNC(common,uniqueItems));
Expand Down
22 changes: 0 additions & 22 deletions addons/dogtags/functions/fnc_checkDogtagItem.sqf

This file was deleted.

16 changes: 6 additions & 10 deletions addons/dogtags/functions/fnc_getDogtagItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ if(!isServer) exitWith {};
params ["_player", "_target"];
TRACE_2("getDogtagItem",_player,_target);

private _allDogtags = missionNamespace getVariable [QGVAR(allDogtags), []];
private _allDogtagDatas = missionNamespace getVariable [QGVAR(allDogtagDatas), []];
GVAR(idCounter) = GVAR(idCounter) + 1;

private _nextID = count _allDogtags + 1;

if (_nextID > 999) exitWith {ERROR("Ran out of IDs");};
if (GVAR(idCounter) > 999) exitWith {ERROR("Ran out of IDs");};

private _dogTagData = [_target] call FUNC(getDogTagData);
private _item = format ["ACE_dogtag_%1", _nextID];
_allDogtags pushBack _item;
_allDogtagDatas pushBack _dogTagData;
private _item = format ["ACE_dogtag_%1", GVAR(idCounter)];

missionNamespace setVariable [QGVAR(allDogtags), _allDogtags];
missionNamespace setVariable [QGVAR(allDogtagDatas), _allDogtagDatas];

[QGVAR(addDogtagItem), [_item, _dogTagData], [_player]] call CBA_fnc_targetEvent;

// Broadcast data globally, so that clients can use it where needed
[QGVAR(broadcastDogtagInfo), [_item, _dogTagData]] call CBA_fnc_globalEvent;
33 changes: 0 additions & 33 deletions addons/dogtags/functions/fnc_sendDogtagData.sqf

This file was deleted.

0 comments on commit 3745305

Please sign in to comment.