diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index dbc7e39f48..91f496916a 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -241,6 +241,7 @@ PREP(fixCrateContent); PREP(globalEvent); PREP(_handleNetEvent); PREP(addEventHandler); +PREP(objectEvent); PREP(targetEvent); PREP(serverEvent); PREP(localEvent); diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 8bda027d1f..58e674dd8d 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -149,6 +149,9 @@ if (isServer) then { ["setSpeaker", {(_this select 0) setSpeaker (_this select 1)}] call FUNC(addEventhandler); ["selectLeader", {(_this select 0) selectLeader (_this select 1)}] call FUNC(addEventHandler); ["setVelocity", {(_this select 0) setVelocity (_this select 1)}] call FUNC(addEventHandler); +["playMove", {(_this select 0) playMove (_this select 1)}] call FUNC(addEventHandler); +["playMoveNow", {(_this select 0) playMoveNow (_this select 1)}] call FUNC(addEventHandler); +["switchMove", {(_this select 0) switchMove (_this select 1)}] call FUNC(addEventHandler); if (isServer) then { ["hideObjectGlobal", {(_this select 0) hideObjectGlobal (_this select 1)}] call FUNC(addEventHandler); diff --git a/addons/common/functions/fnc_doAnimation.sqf b/addons/common/functions/fnc_doAnimation.sqf index 42d59f0b72..bfd50b08b8 100644 --- a/addons/common/functions/fnc_doAnimation.sqf +++ b/addons/common/functions/fnc_doAnimation.sqf @@ -1,6 +1,5 @@ /* * Author: commy2 - * * Execute an animation. This is used to not break things like the unconsciousness animation. * * Arguments: @@ -10,15 +9,20 @@ * 0 = PlayMove * 1 = PlayMoveNow * 2 = SwitchMove (no transitional animation, doesn't overwrite priority 1) + * 3: Force overwritting unconscious (default: false) * * Return Value: * None * + * Example: + * [player, "AmovPercMstpSnonWnonDnon_exerciseKata", 1] call ace_common_fnc_doAnimation + * * Public: Yes */ #include "script_component.hpp" params ["_unit", "_animation", ["_priority", 0], ["_force", false]]; +TRACE_4("params",_unit,_animation,_priority,_force); // don't overwrite more important animations if (_unit getVariable ["ACE_isUnconscious", false] && {(_animation != "Unconscious")} && {!_force}) exitWith {}; @@ -33,36 +37,38 @@ if (_animation == "") then { //if (_animation == animationState _unit) exitWith {}; +TRACE_2("",local _unit,vehicle _unit); switch (_priority) do { case 0: { if (_unit == vehicle _unit) then { - [_unit, format ["{_this playMove '%1'}", _animation], _unit] call FUNC(execRemoteFnc); + ["playMove", _unit, [_unit, _animation]] call FUNC(objectEvent); } else { // Execute on all machines. PlayMove and PlayMoveNow are bugged: They have no global effects when executed on remote machines inside vehicles. - [_unit, format ["{_this playMove '%1'}", _animation]] call FUNC(execRemoteFnc); + ["playMove", [_unit, _animation]] call FUNC(globalEvent); }; }; case 1: { if (_unit == vehicle _unit) then { - [_unit, format ["{_this playMoveNow '%1'}", _animation], _unit] call FUNC(execRemoteFnc); + ["playMoveNow", _unit, [_unit, _animation]] call FUNC(objectEvent); } else { - // Execute on all machines. PlayMove and PlayMoveNow are bugged: They have no global effects when executed on remote machines inside vehicles. - [_unit, format ["{_this playMoveNow '%1'}", _animation]] call FUNC(execRemoteFnc); + // Execute on all machines. PlayMove and PlayMoveNow are bugged: They have no global effects when executed on remote machines inside vehicles. + ["playMoveNow", [_unit, _animation]] call FUNC(globalEvent); }; }; case 2: { // try playMoveNow first if (_unit == vehicle _unit) then { - [_unit, format ["{_this playMoveNow '%1'}", _animation], _unit] call FUNC(execRemoteFnc); + ["playMoveNow", _unit, [_unit, _animation]] call FUNC(objectEvent); } else { - // Execute on all machines. PlayMove and PlayMoveNow are bugged: They have no global effects when executed on remote machines inside vehicles. - [_unit, format ["{_this playMoveNow '%1'}", _animation]] call FUNC(execRemoteFnc); + // Execute on all machines. PlayMove and PlayMoveNow are bugged: They have no global effects when executed on remote machines inside vehicles. + ["playMoveNow", [_unit, _animation]] call FUNC(globalEvent); }; // if animation doesn't respond, do switchMove if (animationState _unit != _animation) then { + TRACE_1("did not respond to playMoveNow",animationState _unit); // Execute on all machines. SwitchMove has local effects. - [_unit, format ["{_this switchMove '%1'}", _animation]] call FUNC(execRemoteFnc); + ["switchMove", [_unit, _animation]] call FUNC(globalEvent); }; }; default {}; diff --git a/addons/common/functions/fnc_objectEvent.sqf b/addons/common/functions/fnc_objectEvent.sqf new file mode 100644 index 0000000000..2015ad77dc --- /dev/null +++ b/addons/common/functions/fnc_objectEvent.sqf @@ -0,0 +1,34 @@ +/* + * Author: PabstMirror + * Execute an event where object is local. + * If local there is no network traffic/delay (Unlike targetEvent) + * + * Arguments: + * 0: Event name (STRING) + * 1: Event target + * 2: Event args + * + * Return Value: + * None + * + * Example: + * ["doThing", vehicle player, []] call ace_common_fnc_objectEvent + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_eventName", "_eventTarget", "_eventArgs"]; + +#ifdef DEBUG_EVENTS + ACE_LOGINFO_2("* Object Event: %1 - %2",_eventName,_eventTarget); + ACE_LOGINFO_1(" args=%1",_eventArgs); +#endif + +if (local _eventTarget) then { + [_eventName, _eventArgs] call FUNC(localEvent); +} else { + _this call FUNC(targetEvent); +}; + +nil