Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Moses
- Description:
- Allows for complex animation handling.
- Animations can be run for either a number of loops or until a certain diag_tickTime.
- A function can be defined to be executed on animation completion.
- Animations can be set as interruptable, with an animation to resume to if desired.
- Parameters:
- ARRAY -
- 0: Unit to play animation. OBJECT(Unit).
- 1: Animation. STRING(Animation)/ARRAY(ANimations, in order of play).
- 2: (OPTIONAL) Animation duration in loops or tickTime. If over 100 assumed tickTime. SCALAR(Duration)
- 3: (OPTIONAL) Function to execute on animation completion. STRING(Variable name)/CODE(Code to run).
- 4: (OPTIONAL) Set whether animation can be interrupted (W,A,S,D) or not. BOOL(Interrupt)/Array(1:Animation after interrupt)
- RETURN: Animation event handler ID. SCALAR (Event ID)
- Examples:
- //To have player repeat animation twice and die after
- [player,"animation",2,{player setDamage 1}] call MOSES_fnc_doAnimation;
- //To have player play animation for 10 seconds and be able to interrupt with no code to run after
- [player,diag_tickime +10,"",true] call MOSES_fnc_doAnimation;
- //To have player play two naimations sequentially, not be able to interrupt and run function
- [player,["anim1","anim2"],0,"fnc_afterAnim",false] call MOSES_fnc_doAnimation
- */
- if !(params[["_unit",objNull,[objNull]],["_animation",[],["",[]]]]) exitWith {};
- systemChat "Here";
- if (_animation isEqualTo []) exitWith {};
- if !(_animation isEqualType []) then {
- _animation = [_animation];
- };
- if (_animation isEqualTo [""]) exitWith {};
- private _duration = param[2,0,[0]];
- private _onComplete = param[3,"",["",{},[]]];
- private _interrupt = param[4,true,[true,[]]];
- _onComplete = call {
- if (_onComplete isEqualType "") exitWith {
- [[],"spawn",missionNamespace getVariable [_onComplete,{}]]
- };
- if (_onComplete isEqualType {}) exitWith {
- [[],"spawn",{}]
- };
- [_onComplete select 0,["spawn","call"] select (false in _onComplete),_onComplete select 1]
- };
- if !(_onComplete select 0 isEqualType []) then {
- _onComplete set [0,[_onComplete select 0]];
- };
- {_animation set [_forEachIndex,toLower _x]} forEach _animation;
- MOSES_doAnimation_animations = _animation;
- MOSES_doAnimation_duration = _duration;
- if (_duration > 100) then [{
- _duration = format["
- if (diag_tickTime >= MOSES_doAnimation_duration) then {
- _unit removeEventHandler ['AnimDone',MOSES_event_doAnimation];
- MOSES_event_doAnimation = nil;
- if (MOSES_event_doAnimationInterrupt != -1) then {
- findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
- MOSES_event_doAnimationInterrupt = -1;
- };
- %1 %2 (missionNamespace getVariable ['%3',{}])
- } else {
- _unit switchMove _animation
- };
- ",_onComplete select 0,_onComplete select 1,_onComplete select 2];
- },{
- _duration = format["
- if (MOSES_doAnimation_duration <= 1) then {
- _unit removeEventHandler ['AnimDone',MOSES_event_doAnimation];
- MOSES_event_doAnimation = nil;
- if (MOSES_event_doAnimationInterrupt != -1) then {
- findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
- MOSES_event_doAnimationInterrupt = -1;
- };
- %1 %2 (missionNamespace getVariable ['%3',{}])
- } else {
- MOSES_doAnimation_duration = MOSES_doAnimation_duration -1;
- _unit switchMove _animation;
- };
- ",_onComplete select 0,_onComplete select 1,_onComplete select 2];
- }];
- MOSES_event_doAnimation = _unit addEventHandler ["AnimDone",format["
- params[['_unit',objNull,[objNull]],['_animation','',['']]];
- if (_animation in %1) then {
- systemChat 'handled';
- if (count MOSES_doAnimation_animations > 1) then [{
- _unit switchMove (MOSES_doAnimation_animations deleteAt 0);
- if (MOSES_doAnimation_animations isEqualTo []) then {
- _unit removeEventHandler ['AnimDone',MOSES_event_doAnimation];
- MOSES_event_doAnimation = nil;
- if (MOSES_event_doAnimationInterrupt != -1) then {
- findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
- MOSES_event_doAnimationInterrupt = -1;
- };
- %2 %3 (missionNamespace getVariable ['%4',{}])
- };
- },{
- %5
- }];
- };
- ",_animation,_onComplete select 0,_onComplete select 1,_onComplete select 2,_duration]];
- _unit switchMove (MOSES_doAnimation_animations deleteAt 0);
- if (_interrupt && _unit == player) then {
- MOSES_event_doAnimationInterrupt = findDisplay 46 displayAddEventHandler ["KeyDown",{
- _moveKeys = actionKeys 'CarLeft' + actionKeys 'CarRight' + actionKeys 'MoveForward' + actionKeys 'MoveBack';
- if (_this select 1 in _moveKeys) then {
- findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
- player removeEventHandler ['AnimDone',MOSES_event_doAnimation];
- player switchMove '';
- MOSES_event_doAnimationInterrupt = -1;
- };
- }];
- };
- MOSES_event_doAnimation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement