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)); init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
}; };
}; };
class Extended_PreInit_EventHandlers { class Extended_PreInit_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
}; };
}; };
class Extended_PostInit_EventHandlers { class Extended_PostInit_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));

View File

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

View File

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

View File

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

View File

@ -1,9 +1,5 @@
#include "script_component.hpp" #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 { if (hasInterface || isServer) then {
[QGVAR(broadcastDogtagInfo), { [QGVAR(broadcastDogtagInfo), {
GVAR(dogtagsData) set _this; GVAR(dogtagsData) set _this;
@ -18,69 +14,29 @@ if (hasInterface || isServer) then {
[QGVAR(broadcastDogtagInfo), [_x, _y], _clientOwner] call CBA_fnc_ownerEvent; [QGVAR(broadcastDogtagInfo), [_x, _y], _clientOwner] call CBA_fnc_ownerEvent;
} forEach GVAR(dogtagsData); } forEach GVAR(dogtagsData);
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
[QGVAR(getDogtagItem), LINKFUNC(getDogtagItem)] call CBA_fnc_addEventHandler;
} else { } else {
// To be here, hasInterface must be true // To be here, hasInterface must be true
[QGVAR(requestSyncDogtagDataJIP), clientOwner] call CBA_fnc_serverEvent; [QGVAR(requestSyncDogtagDataJIP), clientOwner] call CBA_fnc_serverEvent;
}; };
}; };
// Add actions and event handlers only if ace_medical is enabled if (hasInterface) then {
// - Adding actions via config would create a dependency // If the arsenal is loaded, show the custom names for dog tags when in the arsenal
["CBA_settingsInitialized", { if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
if !(GETEGVAR(medical,enabled,false)) exitWith {};
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);
["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), { [QEGVAR(arsenal,rightPanelFilled), {
params ["_display", "_leftPanelIDC", "_rightPanelIDC"]; params ["_display", "_leftPanelIDC", "_rightPanelIDC"];
if (_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) then { if !(_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) exitWith {};
LOG("passed");
private _rightPanel = _display displayCtrl 15; private _rightPanel = _display displayCtrl 15;
private _cfgWeapons = configFile >> "CfgWeapons"; private _cfgWeapons = configFile >> "CfgWeapons";
private _item = "";
private _dogtagData = []; TRACE_1("passed",_rightPanel);
for "_i" from 0 to (lnbSize _rightPanel select 0) - 1 do { 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 { if (_item isKindOf ["ACE_dogtag", _cfgWeapons]) then {
private _name = (GVAR(dogtagsData) getOrDefault [_item, []]) param [0, ""]; private _name = (GVAR(dogtagsData) getOrDefault [_item, []]) param [0, ""];
@ -93,12 +49,11 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
_rightPanel lnbSetText [[_i, 1], [LLSTRING(itemName), ": ", _name] joinString ""]; _rightPanel lnbSetText [[_i, 1], [LLSTRING(itemName), ": ", _name] joinString ""];
}; };
}; };
};
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
}; };
// Add context menu option // Add context menu option
[ [
"ACE_dogtag", "ACE_dogtag",
["GROUND", "CARGO", "CONTAINER"], ["GROUND", "CARGO", "CONTAINER"],
LLSTRING(checkItem), LLSTRING(checkItem),
@ -113,7 +68,52 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
false false
} }
] call CBA_fnc_addItemContextMenuOption; ] call CBA_fnc_addItemContextMenuOption;
};
// Disable dogtags for civilians // 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 {
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);
["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); "CIV_F" call FUNC(disableFactionDogtags);

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: SzwedzikPL, mharis001 * 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: * Arguments:
* 0: Player <OBJECT> * 0: Player <OBJECT>
@ -10,7 +10,7 @@
* Actions <ARRAY> * Actions <ARRAY>
* *
* Example: * Example:
* [_player] call ace_dogtags_fnc_addDogtagActions * player call ace_dogtags_fnc_addDogtagActions
* *
* Public: No * Public: No
*/ */
@ -23,14 +23,21 @@ private _fnc_getActions = {
{ {
private _config = _cfgWeapons >> _x; 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, { if (getNumber (_config >> QGVAR(tagID)) > 0) then {
[GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag); _actions pushBack [
}, {true}, {}, _x] call EFUNC(interact_menu,createAction); [
_actions pushBack [_action, [], _player]; _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)); } 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" #include "..\script_component.hpp"
/* /*
* Author: commy2 * Author: commy2
* Reports a blood type depending on the units name. * Reports a blood type depending on the unit's name.
* *
* Arguments: * Arguments:
* 0: Name of a unit <STRING> * 0: Unit name <STRING>
* *
* Return Value: * Return Value:
* A random blood type <STRING> * A random blood type <STRING>
* *
* Example: * Example:
* _bloodType = ["name"] call ace_dogtags_fnc_bloodType * "name" call ace_dogtags_fnc_bloodType
* *
* Public: No * Public: No
*/ */

View File

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

View File

@ -1,17 +1,17 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: SzwedzikPL * Author: SzwedzikPL
* Checks if dogtag can be taken. * Checks if the target's dog tag can be taken by the unit.
* *
* Arguments: * Arguments:
* 0: Player <OBJECT> * 0: Player <OBJECT>
* 1: Target <OBJECT> * 1: Target <OBJECT>
* *
* Return Value: * Return Value:
* True if dogtag can be taken <BOOL> * If dog tag can be taken <BOOL>
* *
* Example: * Example:
* _canTake = [player, unit] call ace_dogtags_fnc_canTakeDogtag * [player, cursorObject] call ace_dogtags_fnc_canTakeDogtag
* *
* Public: No * Public: No
*/ */
@ -20,7 +20,10 @@ params ["_player", "_target"];
if (isNull _target) exitWith {false}; if (isNull _target) exitWith {false};
// check if disabled for faction // Check if disabled for faction
if ((faction _target) in GVAR(disabledFactions)) exitWith {false}; 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" #include "..\script_component.hpp"
/* /*
* Author: SzwedzikPL * Author: SzwedzikPL
* Checks unit dogtag. * Checks the unit's dog tag.
* *
* Arguments: * Arguments:
* 0: Player <OBJECT> * 0: Player <OBJECT>
@ -11,17 +11,17 @@
* None * None
* *
* Example: * Example:
* [player, unit] call ace_dogtags_fnc_checkDogtag * [player, cursorObject] call ace_dogtags_fnc_checkDogtag
* *
* Public: No * Public: No
*/ */
params ["_player", "_target"]; params ["_player", "_target"];
// animation // Animation
_player call EFUNC(common,goKneeling); _player call EFUNC(common,goKneeling);
// sound // Sound
private _position = _target modelToWorldWorld (_target selectionPosition "neck"); private _position = _target modelToWorldWorld (_target selectionPosition "neck");
playSound3D [ playSound3D [
@ -34,10 +34,8 @@ playSound3D [
50 50
]; ];
// display dogtag // Display dog tag
private _doubleTags = (_target getVariable [QGVAR(dogtagTaken), objNull]) != _target; private _doubleTags = (_target getVariable [QGVAR(dogtagTaken), objNull]) != _target;
private _dogTagData = [_target] call FUNC(getDogTagData); private _dogtagData = _target call FUNC(getDogtagData);
[{ [LINKFUNC(showDogtag), [_dogtagData, _doubleTags], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;
[QGVAR(showDogtag), _this] call CBA_fnc_localEvent;
}, [_dogTagData, _doubleTags], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;

View File

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

View File

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

View File

@ -1,7 +1,8 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: SzwedzikPL * 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: * Arguments:
* 0: Player <OBJECT> * 0: Player <OBJECT>
@ -11,12 +12,12 @@
* None * None
* *
* Example: * Example:
* [player, unit] call ace_dogtags_fnc_getDogtagItem * [player, cursorObject] call ace_dogtags_fnc_getDogtagItem
* *
* Public: No * Public: No
*/ */
if(!isServer) exitWith {}; if (!isServer) exitWith {};
params ["_player", "_target"]; params ["_player", "_target"];
TRACE_2("getDogtagItem",_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 _dogTagData = [_target] call FUNC(getDogTagData);
private _item = format ["ACE_dogtag_%1", GVAR(idCounter)]; 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 // Broadcast data globally, so that clients can use it where needed
[QGVAR(broadcastDogtagInfo), [_item, _dogTagData]] call CBA_fnc_globalEvent; [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" #include "..\script_component.hpp"
/* /*
* Author: SzwedzikPL * Author: SzwedzikPL
* Shows dogtag. * Shows dog tag.
* *
* Arguments: * Arguments:
* 0: Dogtag data <ARRAY> * 0: Dog tag data <ARRAY>
* 1: Display as double tag <BOOLEAN> * 1: Display as double tag <BOOLEAN>
* *
* Return Value: * Return Value:
@ -27,8 +27,10 @@ if (_doubleTags) then {
} else { } else {
(QGVAR(tag) call BIS_fnc_rscLayer) cutRsc [QGVAR(singleTag), "PLAIN", 1, true]; (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; private _control = _display displayCtrl 1001;
_dogtagData params ["_name", "_code", "_bloodType"]; _dogtagData params ["_name", "_code", "_bloodType"];

View File

@ -1,16 +1,16 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: kymckay * Author: kymckay
* Reports a social security number generated from the units name. * Reports a social security number generated from the unit's name.
* *
* Arguments: * Arguments:
* 0: Name of a unit <STRING> * 0: Unit name <STRING>
* *
* Return Value: * Return Value:
* A random three/two/four format social security number <STRING> * A random three/two/four format social security number <STRING>
* *
* Example: * Example:
* _ssn = ["AAA"] call ace_dogtags_fnc_ssn * "name" call ace_dogtags_fnc_ssn
* *
* Public: No * Public: No
*/ */
@ -18,19 +18,20 @@
params ["_name"]; params ["_name"];
private _chars = toArray _name; private _chars = toArray _name;
private _length = count _chars;
// Warning, for strings containing non-latin characters, `_count _name` != `_count _chars` // Warning, for strings containing non-latin characters, `_count _name` != `_count _chars`
private _length = count _chars;
_chars pushBack _length; _chars pushBack _length;
_length = _length + 1; _length = _length + 1;
private _remainder = 0; 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 { for "_index" from 0 to (8 max _length) do {
private _inputChar = _chars select (_index % _length); 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; _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" #include "..\script_component.hpp"
/* /*
* Author: SzwedzikPL * Author: SzwedzikPL
* If dogtag is not already taken triggers event on server. * If the dog tag hasn't already been taken, it triggers an event on the server.
* If dogtag already taken displays info about it. * If the dog tag has already been taken, it displays info about it.
* *
* Arguments: * Arguments:
* 0: Player <OBJECT> * 0: Player <OBJECT>
@ -12,17 +12,17 @@
* None * None
* *
* Example: * Example:
* [player, unit] call ace_dogtags_fnc_takeDogtag * [player, cursorObject] call ace_dogtags_fnc_takeDogtag
* *
* Public: No * Public: No
*/ */
params ["_player", "_target"]; params ["_player", "_target"];
// animation // Animation
_player call EFUNC(common,goKneeling); _player call EFUNC(common,goKneeling);
// sound // Sound
private _position = _target modelToWorldWorld (_target selectionPosition "neck"); private _position = _target modelToWorldWorld (_target selectionPosition "neck");
playSound3D [ playSound3D [
@ -35,12 +35,11 @@ playSound3D [
50 50
]; ];
// display message // Display message
if ((_target getVariable [QGVAR(dogtagTaken), objNull]) == _target) then { if ((_target getVariable [QGVAR(dogtagTaken), objNull]) == _target) then {
[{ [EFUNC(common,displayTextStructured), [LLSTRING(dogtagAlreadyTaken), 2.5], DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;
[_this, 2.5] call EFUNC(common,displayTextStructured);
}, localize LSTRING(dogtagAlreadyTaken), DOGTAG_SHOW_DELAY] call CBA_fnc_waitAndExecute;
} else { } else {
_target setVariable [QGVAR(dogtagTaken), _target, true]; _target setVariable [QGVAR(dogtagTaken), _target, true];
[QGVAR(getDogtagItem), [_player, _target]] call CBA_fnc_serverEvent; [QGVAR(getDogtagItem), [_player, _target]] call CBA_fnc_serverEvent;
}; };