From 7345cf91cf254d35bf1f0578bd4000f7dc0461d8 Mon Sep 17 00:00:00 2001 From: Thomas Kooi Date: Sat, 17 Jan 2015 13:54:44 +0100 Subject: [PATCH] Minor code clean up --- addons/common/functions/fnc_carriedByObj.sqf | 6 +-- .../fnc_getAllDefinedSetVariables.sqf | 5 ++- addons/common/functions/fnc_getDeathAnim.sqf | 39 +++++++++-------- .../functions/fnc_resetAllDefaults_f.sqf | 42 +++++++------------ .../common/functions/fnc_setCaptiveSwitch.sqf | 11 +---- 5 files changed, 42 insertions(+), 61 deletions(-) diff --git a/addons/common/functions/fnc_carriedByObj.sqf b/addons/common/functions/fnc_carriedByObj.sqf index d946d0decc..139a449c77 100644 --- a/addons/common/functions/fnc_carriedByObj.sqf +++ b/addons/common/functions/fnc_carriedByObj.sqf @@ -10,8 +10,4 @@ #include "script_component.hpp" -private ["_unit","_to"]; -_to = _this select 0; -_unit = _this select 1; - -([_to] call FUNC(getCarriedBy) == [_unit] call FUNC(getCarriedBy)); \ No newline at end of file +([(_this select 0)] call FUNC(getCarriedBy) == [(_this select 1)] call FUNC(getCarriedBy)); \ No newline at end of file diff --git a/addons/common/functions/fnc_getAllDefinedSetVariables.sqf b/addons/common/functions/fnc_getAllDefinedSetVariables.sqf index a2027270f0..eb9e77f2da 100644 --- a/addons/common/functions/fnc_getAllDefinedSetVariables.sqf +++ b/addons/common/functions/fnc_getAllDefinedSetVariables.sqf @@ -12,9 +12,10 @@ private ["_object", "_return", "_val", "_category"]; _object = _this select 0; _category = if (count _this > 1) then { _this select 1 } else { "" }; -if (isnil QGVAR(OBJECT_VARIABLES_STORAGE)) then { - GVAR(OBJECT_VARIABLES_STORAGE) = []; +if (isnil QGVAR(OBJECT_VARIABLES_STORAGE)) exitwith { + []; }; + _return = []; { _val = _object getvariable (_x select 0); diff --git a/addons/common/functions/fnc_getDeathAnim.sqf b/addons/common/functions/fnc_getDeathAnim.sqf index 9394e65438..64439cebfe 100644 --- a/addons/common/functions/fnc_getDeathAnim.sqf +++ b/addons/common/functions/fnc_getDeathAnim.sqf @@ -11,23 +11,28 @@ private ["_unit", "_curAnim", "_animation", "_cfg","_unitAnimation", "_animationState"]; _unit = _this select 0; -_animation = ""; -_animationState = (animationState _unit); -_unitAnimation = (configFile >> "CfgMovesMaleSdr" >> "States" >> _animationState); -if (isText (_unitAnimation >> "actions")) then { - if ((vehicle _unit) != _unit) then { - _cfg = (configFile >> "CfgMovesMaleSdr" >> "States" >> _animationState); - if (isArray (_cfg >> "interpolateTo")) then { - _animation = getArray (_cfg >> "interpolateTo") select 0; - }; - } else { - _cfg = (configFile >> "CfgMovesBasic" >> "Actions" >> (getText (_unitAnimation >> "actions")) >> "die"); - if (isText _cfg) then { - _animation = getText _cfg; + +if (vehicle _unit != _unit) exitwith { + _animation = ""; + _animationState = (animationState _unit); + _unitAnimation = (configFile >> "CfgMovesMaleSdr" >> "States" >> _animationState); + if (isText (_unitAnimation >> "actions")) then { + if ((vehicle _unit) != _unit) then { + _cfg = (configFile >> "CfgMovesMaleSdr" >> "States" >> _animationState); + if (isArray (_cfg >> "interpolateTo")) then { + _animation = getArray (_cfg >> "interpolateTo") select 0; + }; + } else { + _cfg = (configFile >> "CfgMovesBasic" >> "Actions" >> (getText (_unitAnimation >> "actions")) >> "die"); + if (isText _cfg) then { + _animation = getText _cfg; + }; }; }; + if (isnil "_animation") then { + _animation = ""; + }; + _animation; }; -if (isnil "_animation") then { - _animation = ""; -}; -_animation \ No newline at end of file + +"Unconscious"; diff --git a/addons/common/functions/fnc_resetAllDefaults_f.sqf b/addons/common/functions/fnc_resetAllDefaults_f.sqf index 5d3fcdc00e..3cdd746cd0 100644 --- a/addons/common/functions/fnc_resetAllDefaults_f.sqf +++ b/addons/common/functions/fnc_resetAllDefaults_f.sqf @@ -11,17 +11,7 @@ #include "script_component.hpp" private ["_unit","_oldUnit","_sets"]; -_unit = [_this, 0, objNull, [objNull]] call BIS_fnc_param; -_oldUnit = [_this, 1, objNull, [objNull]] call BIS_fnc_param; - -//_unit setvariable[QGVAR(unconscious_non_captive_f),nil]; -if (missionNamespace getvariable [QGVAR(unconscious_non_captive_f),false]) then { - _unit setCaptive false; - missionNamespace setvariable[QGVAR(unconscious_non_captive_f),nil]; - [format["Detected unit as a non captive but in captive state. RESETTING"]] call FUNC(debug); -} else { - [format["didn't trigger but unit is: %1 - %2", captive _unit, (missionNamespace getvariable [QGVAR(unconscious_non_captive_f),false])]] call FUNC(debug); -}; +_unit = _this select 0; _unit setvariable [QGVAR(isDead),nil,true]; _unit setvariable [QGVAR(stateUnconscious), nil, true]; @@ -31,23 +21,19 @@ if (isPlayer _unit) then { [false] call FUNC(disableKeyInput_f); [false] call EFUNC(GUI,effectBlackOut); [player, -1] call FUNC(limitSpeed); - if (isnil QGVAR(DISABLE_USER_INPUT_COLLECTION_F)) then { - GVAR(DISABLE_USER_INPUT_COLLECTION_F) = []; + + if !(isnil QGVAR(DISABLE_USER_INPUT_COLLECTION_F)) then { + // clear all disable user input + { + [_X, false] call FUNC(disableUserInput_f); + }foreach GVAR(DISABLE_USER_INPUT_COLLECTION_F); }; - { - [_X, false] call FUNC(disableUserInput_f); - }foreach GVAR(DISABLE_USER_INPUT_COLLECTION_F); -}; -_sets = [_unit] call FUNC(getAllDefinedSetVariables); -[format["defaults for %1 : %2",_unit,_sets]] call FUNC(debug); -if ((count _sets) > 0) then { - { - if (!(_x select 4)) then { - _unit setvariable [(_x select 0),nil,_x select 3]; - [format["RESETTING: %1",[(_x select 0),_unit, _x select 1, (_unit getvariable (_x select 0))]]] call FUNC(debug); - }; - }foreach _sets; -} else { - ["No defaults have been set"] call FUNC(debug); }; + +{ + if (!(_x select 4)) then { + _unit setvariable [(_x select 0),nil,_x select 3]; + }; +}foreach ([_unit] call FUNC(getAllDefinedSetVariables)); + [[_unit],"resetToDefaults"] call FUNC(raiseScriptedEvent_f); \ No newline at end of file diff --git a/addons/common/functions/fnc_setCaptiveSwitch.sqf b/addons/common/functions/fnc_setCaptiveSwitch.sqf index e6056b4332..ec45007e8b 100644 --- a/addons/common/functions/fnc_setCaptiveSwitch.sqf +++ b/addons/common/functions/fnc_setCaptiveSwitch.sqf @@ -20,20 +20,13 @@ if (_setCaptive) then { if (captive _unit) then { _captiveSwitch = false; } else { - if (player == _unit) then { - missionNamespace setvariable[QGVAR(unconscious_non_captive_f),true]; - }; _unit setCaptive true; - [format["USED SETCAPTIVE",_unit]] call FUNC(debug); }; } else { - if (alive _unit) then { + if (captive _unit) then { _unit setCaptive false; - if (!isnil QGVAR(unconscious_non_captive_f)) then { - missionNamespace setvariable[QGVAR(unconscious_non_captive_f),nil]; - }; } else { - _unit setCaptive false; + _captiveSwitch = false; }; };