Dogtags - Code cleanup (#10097)

* Clean up dogtags

* Only allow taking of dogtags if unit has space

* Fixed upper case T

* Stop throwing error

* Reverted to case insensitive method of checking

* Remove unused files

* More cleanup & fixes

- Better check for taking dog tags until 2.18 comes
- Changed parent condition from `canTakeDogtag` to `canCheckDogtag`
- Register EH only where necessary

* Update CfgEventHandlers.hpp

* More header cleanup
This commit is contained in:
johnb432 2024-07-20 08:29:17 +02:00 committed by GitHub
parent 05ab1bbe99
commit 5d133bd793
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 173 additions and 184 deletions

View File

@ -3,11 +3,13 @@ class Extended_PreStart_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));

View File

@ -4,7 +4,7 @@ class CfgVehicles {
class ACE_Actions {
class ACE_Dogtag {
displayName = CSTRING(itemName);
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeDogtag));
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canCheckDogtag));
statement = "";
exceptions[] = {"isNotSwimming", "isNotInside"};
showDisabled = 0;

View File

@ -16,8 +16,8 @@ class CfgWeapons {
author = ECSTRING(common,ACETeam);
scope = 0;
displayName = CSTRING(itemName);
model = QUOTE(PATHTOF(data\ace_dogtag.p3d));
picture = QUOTE(PATHTOF(data\dogtagSingle.paa));
model = QPATHTOF(data\ace_dogtag.p3d);
picture = QPATHTOF(data\dogtagSingle.paa);
class ItemInfo: CBA_MiscItem_ItemInfo {
mass = 0; //too small to for 1 ?
};

View File

@ -1,13 +1,11 @@
PREP(addDogtagActions);
PREP(addDogtagItem);
PREP(bloodType);
PREP(canCheckDogtag);
PREP(canTakeDogtag);
PREP(checkDogtag);
PREP(disableFactionDogtags);
PREP(getDogtagData);
PREP(getDogtagItem);
PREP(showDogtag);
PREP(ssn);
PREP(takeDogtag);
PREP(disableFactionDogtags);

View File

@ -1,9 +1,5 @@
#include "script_component.hpp"
[QGVAR(showDogtag), LINKFUNC(showDogtag)] 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;
@ -18,69 +14,29 @@ if (hasInterface || isServer) then {
[QGVAR(broadcastDogtagInfo), [_x, _y], _clientOwner] call CBA_fnc_ownerEvent;
} forEach GVAR(dogtagsData);
}] call CBA_fnc_addEventHandler;
[QGVAR(getDogtagItem), LINKFUNC(getDogtagItem)] 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", {
if !(GETEGVAR(medical,enabled,false)) exitWith {};
if (hasInterface) then {
// If the arsenal is loaded, show the custom names for dog tags when in the arsenal
if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
[QEGVAR(arsenal,rightPanelFilled), {
params ["_display", "_leftPanelIDC", "_rightPanelIDC"];
if (hasInterface) then {
private _checkTagAction = [
"ACE_CheckDogtag",
format ["%1: %2", localize LSTRING(itemName), localize LSTRING(checkDogtag)],
QPATHTOF(data\dogtag_icon_ca.paa),
{[_player,_target] call FUNC(checkDogtag)},
{!isNil {_target getVariable QGVAR(dogtagData)}}
] call EFUNC(interact_menu,createAction);
if !(_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) exitWith {};
["ACE_bodyBagObject", 0, ["ACE_MainActions"], _checkTagAction, true] call EFUNC(interact_menu,addActionToClass);
private _takeTagAction = [
"ACE_TakeDogtag",
format ["%1: %2", localize LSTRING(itemName), localize LSTRING(takeDogtag)],
QPATHTOF(data\dogtag_icon_ca.paa),
{[_player,_target] call FUNC(takeDogtag)},
{(!isNil {_target getVariable QGVAR(dogtagData)}) && {((_target getVariable [QGVAR(dogtagTaken), objNull]) != _target)}}
] call EFUNC(interact_menu,createAction);
["ACE_bodyBagObject", 0, ["ACE_MainActions"], _takeTagAction, true] call EFUNC(interact_menu,addActionToClass);
};
if (isServer) then {
["ace_placedInBodyBag", {
params ["_target", "_bodyBag", "_isGrave"];
if (_isGrave) exitWith {};
TRACE_2("ace_placedInBodyBag eh",_target,_bodyBag);
private _dogTagData = [_target] call FUNC(getDogtagData);
_bodyBag setVariable [QGVAR(dogtagData), _dogTagData, true];
if ((_target getVariable [QGVAR(dogtagTaken), objNull]) == _target) then {
_bodyBag setVariable [QGVAR(dogtagTaken), _bodyBag, true];
};
}] call CBA_fnc_addEventHandler;
};
}] call CBA_fnc_addEventHandler;
// If the arsenal is loaded, show the custom names for dog tags when in the arsenal
if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
[QEGVAR(arsenal,rightPanelFilled), {
params ["_display", "_leftPanelIDC", "_rightPanelIDC"];
if (_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) then {
LOG("passed");
private _rightPanel = _display displayCtrl 15;
private _cfgWeapons = configFile >> "CfgWeapons";
private _item = "";
private _dogtagData = [];
TRACE_1("passed",_rightPanel);
for "_i" from 0 to (lnbSize _rightPanel select 0) - 1 do {
_item = _rightPanel lnbData [_i, 0];
private _item = _rightPanel lnbData [_i, 0];
if (_item isKindOf ["ACE_dogtag", _cfgWeapons]) then {
private _name = (GVAR(dogtagsData) getOrDefault [_item, []]) param [0, ""];
@ -93,27 +49,71 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
_rightPanel lnbSetText [[_i, 1], [LLSTRING(itemName), ": ", _name] joinString ""];
};
};
};
}] call CBA_fnc_addEventHandler;
}] call CBA_fnc_addEventHandler;
};
// Add context menu option
[
"ACE_dogtag",
["GROUND", "CARGO", "CONTAINER"],
LLSTRING(checkItem),
nil,
QPATHTOF(data\dogtag_icon_ca.paa),
[
{true},
{true}
],
{
[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag);
false
}
] call CBA_fnc_addItemContextMenuOption;
};
// Add context menu option
[
"ACE_dogtag",
["GROUND", "CARGO", "CONTAINER"],
LLSTRING(checkItem),
nil,
QPATHTOF(data\dogtag_icon_ca.paa),
[
{true},
{true}
],
{
[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag);
// Add actions and event handlers only if ace_medical is enabled
// - Adding actions via config would create a dependency
["CBA_settingsInitialized", {
if !(GETEGVAR(medical,enabled,false)) exitWith {};
false
}
] call CBA_fnc_addItemContextMenuOption;
if (hasInterface) then {
private _checkTagAction = [
"ACE_CheckDogtag",
format ["%1: %2", LLSTRING(itemName), LLSTRING(checkDogtag)],
QPATHTOF(data\dogtag_icon_ca.paa),
{[_player, _target] call FUNC(checkDogtag)},
{!isNil {_target getVariable QGVAR(dogtagData)}}
] call EFUNC(interact_menu,createAction);
// Disable dogtags for civilians
["ACE_bodyBagObject", 0, ["ACE_MainActions"], _checkTagAction, true] call EFUNC(interact_menu,addActionToClass);
private _takeTagAction = [
"ACE_TakeDogtag",
format ["%1: %2", LLSTRING(itemName), LLSTRING(takeDogtag)],
QPATHTOF(data\dogtag_icon_ca.paa),
{[_player, _target] call FUNC(takeDogtag)},
{(!isNil {_target getVariable QGVAR(dogtagData)}) && {((_target getVariable [QGVAR(dogtagTaken), objNull]) != _target)}}
] call EFUNC(interact_menu,createAction);
["ACE_bodyBagObject", 0, ["ACE_MainActions"], _takeTagAction, true] call EFUNC(interact_menu,addActionToClass);
};
if (isServer) then {
["ace_placedInBodyBag", {
params ["_target", "_bodyBag", "_isGrave"];
if (_isGrave) exitWith {};
TRACE_2("ace_placedInBodyBag eh",_target,_bodyBag);
private _dogtagData = _target call FUNC(getDogtagData);
_bodyBag setVariable [QGVAR(dogtagData), _dogtagData, true];
if ((_target getVariable [QGVAR(dogtagTaken), objNull]) == _target) then {
_bodyBag setVariable [QGVAR(dogtagTaken), _bodyBag, true];
};
}] call CBA_fnc_addEventHandler;
};
}] call CBA_fnc_addEventHandler;
// Disable dog tags for civilians
"CIV_F" call FUNC(disableFactionDogtags);

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL, mharis001
* Returns children actions for checking dogtags in player's inventory.
* Returns children actions for checking dog tags in the player's inventory.
*
* Arguments:
* 0: Player <OBJECT>
@ -10,7 +10,7 @@
* Actions <ARRAY>
*
* Example:
* [_player] call ace_dogtags_fnc_addDogtagActions
* player call ace_dogtags_fnc_addDogtagActions
*
* Public: No
*/
@ -23,14 +23,21 @@ private _fnc_getActions = {
{
private _config = _cfgWeapons >> _x;
if (getNumber (_config >> QGVAR(tagID)) > 0) then {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");
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];
if (getNumber (_config >> QGVAR(tagID)) > 0) then {
_actions pushBack [
[
_x,
getText (_config >> "displayName"),
getText (_config >> "picture"),
{[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag)},
{true},
{},
_x
] call EFUNC(interact_menu,createAction),
[],
_player
];
};
} forEach (_player call EFUNC(common,uniqueItems));

View File

@ -1,38 +0,0 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* Adds dogtag item to unit (triggered by server).
*
* Arguments:
* 0: Item class <STRING>
* 1: Dogtag data <ARRAY>
*
* Return Value:
* None
*
* Example:
* ["itemClass", ["name", "610-27-5955", "A POS"]] call ace_dogtags_fnc_addDogtagItem
*
* Public: No
*/
params ["_item", "_dogtagData"];
if (_item == "") exitWith {};
// Verify that the unit has inventory space, otherwise drop the dogtag on the ground
[ace_player, _item, true] call CBA_fnc_addItem;
_dogtagData params ["_name"];
// If data doesn't exist or body has no name, set name as "unknown"
if (_name == "") then {
_name = LELSTRING(common,unknown);
};
private _displayText = format [localize LSTRING(takeDogtagSuccess), _name];
// display message
[{
[_this, 2.5] call EFUNC(common,displayTextStructured);
}, _displayText, DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;

View File

@ -1,16 +1,16 @@
#include "..\script_component.hpp"
/*
* Author: commy2
* Reports a blood type depending on the units name.
* Reports a blood type depending on the unit's name.
*
* Arguments:
* 0: Name of a unit <STRING>
* 0: Unit name <STRING>
*
* Return Value:
* A random blood type <STRING>
*
* Example:
* _bloodType = ["name"] call ace_dogtags_fnc_bloodType
* "name" call ace_dogtags_fnc_bloodType
*
* Public: No
*/

View File

@ -1,26 +1,26 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* Checks if dogtag can be checked.
* Checks if the target's dog tag can be checked by the unit.
*
* Arguments:
* 0: Player <OBJECT>
* 0: Player (not used) <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* True if dogtag can be checked <BOOL>
* If dog tag can be checked <BOOL>
*
* Example:
* _canCheck = [player, unit] call ace_dogtags_fnc_canCheckDogtag
* [player, cursorObject] call ace_dogtags_fnc_canCheckDogtag
*
* Public: No
*/
params ["_player", "_target"];
params ["", "_target"];
if (isNull _target) exitWith {false};
// check if disabled for faction
// Check if disabled for faction
if ((faction _target) in GVAR(disabledFactions)) exitWith {false};
!(_target call EFUNC(common,isAwake))

View File

@ -1,17 +1,17 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* Checks if dogtag can be taken.
* Checks if the target's dog tag can be taken by the unit.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* True if dogtag can be taken <BOOL>
* If dog tag can be taken <BOOL>
*
* Example:
* _canTake = [player, unit] call ace_dogtags_fnc_canTakeDogtag
* [player, cursorObject] call ace_dogtags_fnc_canTakeDogtag
*
* Public: No
*/
@ -20,7 +20,10 @@ params ["_player", "_target"];
if (isNull _target) exitWith {false};
// check if disabled for faction
// Check if disabled for faction
if ((faction _target) in GVAR(disabledFactions)) exitWith {false};
!(_target call EFUNC(common,isAwake)) && {_player canAdd ["ACE_dogtag_1", 1/*, true*/]} // Todo: Uncomment in 2.18
// CBA_fnc_canAddItem doesn't account for mass 0 items and unit not having any containers
!(_target call EFUNC(common,isAwake)) && {(uniform _player + vest _player + backpack _player) != ""} && {[_player, "ACE_dogtag_1"] call CBA_fnc_canAddItem}
// Todo: Use code below in 2.18
// _player canAdd ["ACE_dogtag_1", 1, true]

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* Checks unit dogtag.
* Checks the unit's dog tag.
*
* Arguments:
* 0: Player <OBJECT>
@ -11,17 +11,17 @@
* None
*
* Example:
* [player, unit] call ace_dogtags_fnc_checkDogtag
* [player, cursorObject] call ace_dogtags_fnc_checkDogtag
*
* Public: No
*/
params ["_player", "_target"];
// animation
// Animation
_player call EFUNC(common,goKneeling);
// sound
// Sound
private _position = _target modelToWorldWorld (_target selectionPosition "neck");
playSound3D [
@ -34,10 +34,8 @@ playSound3D [
50
];
// display dogtag
// Display dog tag
private _doubleTags = (_target getVariable [QGVAR(dogtagTaken), objNull]) != _target;
private _dogTagData = [_target] call FUNC(getDogTagData);
private _dogtagData = _target call FUNC(getDogtagData);
[{
[QGVAR(showDogtag), _this] call CBA_fnc_localEvent;
}, [_dogTagData, _doubleTags], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;
[LINKFUNC(showDogtag), [_dogtagData, _doubleTags], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: commy2
* Disable this faction from using dogtags.
* Disables this faction from using dog tags.
*
* Arguments:
* 0: Faction <STRING>

View File

@ -1,19 +1,19 @@
#include "..\script_component.hpp"
/*
* Author: esteldunedain
* Get unit dogtag data.
* Gets unit's dog tag data.
*
* Arguments:
* 0: Target <OBJECT>
*
* Return Value:
* Dogtag Data <ARRAY>
* Dog tag Data <ARRAY>
* 0: Name <STRING>
* 1: SSN <STRING>
* 2: Blood Type <STRING>
*
* Example:
* _dogtagData = [unit, player] call ace_dogtags_fnc_getDogtagData
* player call ace_dogtags_fnc_getDogtagData
*
* Public: No
*/
@ -21,17 +21,20 @@
params ["_target"];
// Check if the data was already created
private _dogTagData = _target getVariable QGVAR(dogtagData);
if (!isNil "_dogTagData") exitWith {_dogTagData};
private _dogtagData = _target getVariable QGVAR(dogtagData);
if (!isNil "_dogtagData") exitWith {_dogtagData};
// Create dog tag data once for the unit: nickname, code (eg. 135-13-900) and blood type
private _targetName = [_target, false, true] call EFUNC(common,getName);
private _dogTagData = [
private _dogtagData = [
_targetName,
_targetName call FUNC(ssn),
_targetName call FUNC(bloodType)
];
// Store it
_target setVariable [QGVAR(dogtagData), _dogTagData, true];
_dogTagData
_target setVariable [QGVAR(dogtagData), _dogtagData, true];
_dogtagData

View File

@ -1,7 +1,8 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* Server: creates new dogtag item and send it to client.
* Server: Creates a new dog tag item and sends it to client.
* It broacasts the dog tag info to all machines with interfaces.
*
* Arguments:
* 0: Player <OBJECT>
@ -11,12 +12,12 @@
* None
*
* Example:
* [player, unit] call ace_dogtags_fnc_getDogtagItem
* [player, cursorObject] call ace_dogtags_fnc_getDogtagItem
*
* Public: No
*/
if(!isServer) exitWith {};
if (!isServer) exitWith {};
params ["_player", "_target"];
TRACE_2("getDogtagItem",_player,_target);
@ -28,7 +29,20 @@ if (GVAR(idCounter) > 999) exitWith {ERROR("Ran out of IDs");};
private _dogTagData = [_target] call FUNC(getDogTagData);
private _item = format ["ACE_dogtag_%1", GVAR(idCounter)];
[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;
// Dog tags have no mass, so no need to check if it can fit in container, but check if unit has an inventory at all
[_player, _item, true] call CBA_fnc_addItem;
_name = _dogtagData param [0, ""];
// If data doesn't exist or body has no name, set name as "unknown"
if (_name == "") then {
_name = LELSTRING(common,unknown);
};
// Display message
[{
[QEGVAR(common,displayTextStructured), [_this select 0, 2.5], _this select 1] call CBA_fnc_targetEvent;
}, [format [LLSTRING(takeDogtagSuccess), _name], _player], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;

View File

@ -1,10 +1,10 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* Shows dogtag.
* Shows dog tag.
*
* Arguments:
* 0: Dogtag data <ARRAY>
* 0: Dog tag data <ARRAY>
* 1: Display as double tag <BOOLEAN>
*
* Return Value:
@ -27,8 +27,10 @@ if (_doubleTags) then {
} else {
(QGVAR(tag) call BIS_fnc_rscLayer) cutRsc [QGVAR(singleTag), "PLAIN", 1, true];
};
private _display = uiNamespace getvariable [QGVAR(tag), displayNull];
if(isNull _display) exitWith {};
private _display = uiNamespace getVariable [QGVAR(tag), displayNull];
if (isNull _display) exitWith {};
private _control = _display displayCtrl 1001;
_dogtagData params ["_name", "_code", "_bloodType"];

View File

@ -1,16 +1,16 @@
#include "..\script_component.hpp"
/*
* Author: kymckay
* Reports a social security number generated from the units name.
* Reports a social security number generated from the unit's name.
*
* Arguments:
* 0: Name of a unit <STRING>
* 0: Unit name <STRING>
*
* Return Value:
* A random three/two/four format social security number <STRING>
*
* Example:
* _ssn = ["AAA"] call ace_dogtags_fnc_ssn
* "name" call ace_dogtags_fnc_ssn
*
* Public: No
*/
@ -18,19 +18,20 @@
params ["_name"];
private _chars = toArray _name;
private _length = count _chars;
// Warning, for strings containing non-latin characters, `_count _name` != `_count _chars`
private _length = count _chars;
_chars pushBack _length;
_length = _length + 1;
private _remainder = 0;
private _nums = [0,0,0,0,0,0,0,0,0];
private _nums = [0, 0, 0, 0, 0, 0, 0, 0, 0];
for "_index" from 0 to (8 max _length) do {
private _inputChar = _chars select (_index % _length);
_nums set [(_index % 9), ((_nums select (_index % 9)) + _inputChar + _remainder) % 10];
_nums set [_index % 9, ((_nums select (_index % 9)) + _inputChar + _remainder) % 10];
_remainder = (_inputChar + _remainder) % 256;
};
([_nums select [0,3],_nums select [3,2], _nums select [5,4]] apply { _x joinString "" }) joinString "-"
([_nums select [0, 3], _nums select [3, 2], _nums select [5, 4]] apply { _x joinString "" }) joinString "-"

View File

@ -1,8 +1,8 @@
#include "..\script_component.hpp"
/*
* Author: SzwedzikPL
* If dogtag is not already taken triggers event on server.
* If dogtag already taken displays info about it.
* If the dog tag hasn't already been taken, it triggers an event on the server.
* If the dog tag has already been taken, it displays info about it.
*
* Arguments:
* 0: Player <OBJECT>
@ -12,17 +12,17 @@
* None
*
* Example:
* [player, unit] call ace_dogtags_fnc_takeDogtag
* [player, cursorObject] call ace_dogtags_fnc_takeDogtag
*
* Public: No
*/
params ["_player", "_target"];
// animation
// Animation
_player call EFUNC(common,goKneeling);
// sound
// Sound
private _position = _target modelToWorldWorld (_target selectionPosition "neck");
playSound3D [
@ -35,12 +35,11 @@ playSound3D [
50
];
// display message
// Display message
if ((_target getVariable [QGVAR(dogtagTaken), objNull]) == _target) then {
[{
[_this, 2.5] call EFUNC(common,displayTextStructured);
}, localize LSTRING(dogtagAlreadyTaken), DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;
[EFUNC(common,displayTextStructured), [LLSTRING(dogtagAlreadyTaken), 2.5], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;
} else {
_target setVariable [QGVAR(dogtagTaken), _target, true];
[QGVAR(getDogtagItem), [_player, _target]] call CBA_fnc_serverEvent;
};