Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. /*
  2. Author: Moses
  3. Description:
  4. Allows for complex animation handling.
  5. Animations can be run for either a number of loops or until a certain diag_tickTime.
  6. A function can be defined to be executed on animation completion.
  7. Animations can be set as interruptable, with an animation to resume to if desired.
  8. Parameters:
  9. ARRAY -
  10. 0: Unit to play animation. OBJECT(Unit).
  11. 1: Animation. STRING(Animation)/ARRAY(ANimations, in order of play).
  12. 2: (OPTIONAL) Animation duration in loops or tickTime. If over 100 assumed tickTime. SCALAR(Duration)
  13. 3: (OPTIONAL) Function to execute on animation completion. STRING(Variable name)/CODE(Code to run).
  14. 4: (OPTIONAL) Set whether animation can be interrupted (W,A,S,D) or not. BOOL(Interrupt)/Array(1:Animation after interrupt)
  15. RETURN: Animation event handler ID. SCALAR (Event ID)
  16. Examples:
  17. //To have player repeat animation twice and die after
  18. [player,"animation",2,{player setDamage 1}] call MOSES_fnc_doAnimation;
  19. //To have player play animation for 10 seconds and be able to interrupt with no code to run after
  20. [player,diag_tickime +10,"",true] call MOSES_fnc_doAnimation;
  21. //To have player play two naimations sequentially, not be able to interrupt and run function
  22. [player,["anim1","anim2"],0,"fnc_afterAnim",false] call MOSES_fnc_doAnimation
  23. */
  24.  
  25. if !(params[["_unit",objNull,[objNull]],["_animation",[],["",[]]]]) exitWith {};
  26. systemChat "Here";
  27. if (_animation isEqualTo []) exitWith {};
  28. if !(_animation isEqualType []) then {
  29. _animation = [_animation];
  30. };
  31. if (_animation isEqualTo [""]) exitWith {};
  32.  
  33. private _duration = param[2,0,[0]];
  34. private _onComplete = param[3,"",["",{},[]]];
  35. private _interrupt = param[4,true,[true,[]]];
  36.  
  37. _onComplete = call {
  38. if (_onComplete isEqualType "") exitWith {
  39. [[],"spawn",missionNamespace getVariable [_onComplete,{}]]
  40. };
  41. if (_onComplete isEqualType {}) exitWith {
  42. [[],"spawn",{}]
  43. };
  44. [_onComplete select 0,["spawn","call"] select (false in _onComplete),_onComplete select 1]
  45. };
  46. if !(_onComplete select 0 isEqualType []) then {
  47. _onComplete set [0,[_onComplete select 0]];
  48. };
  49. {_animation set [_forEachIndex,toLower _x]} forEach _animation;
  50. MOSES_doAnimation_animations = _animation;
  51. MOSES_doAnimation_duration = _duration;
  52. if (_duration > 100) then [{
  53. _duration = format["
  54. if (diag_tickTime >= MOSES_doAnimation_duration) then {
  55. _unit removeEventHandler ['AnimDone',MOSES_event_doAnimation];
  56. MOSES_event_doAnimation = nil;
  57. if (MOSES_event_doAnimationInterrupt != -1) then {
  58. findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
  59. MOSES_event_doAnimationInterrupt = -1;
  60. };
  61. %1 %2 (missionNamespace getVariable ['%3',{}])
  62. } else {
  63. _unit switchMove _animation
  64. };
  65. ",_onComplete select 0,_onComplete select 1,_onComplete select 2];
  66. },{
  67. _duration = format["
  68. if (MOSES_doAnimation_duration <= 1) then {
  69. _unit removeEventHandler ['AnimDone',MOSES_event_doAnimation];
  70. MOSES_event_doAnimation = nil;
  71. if (MOSES_event_doAnimationInterrupt != -1) then {
  72. findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
  73. MOSES_event_doAnimationInterrupt = -1;
  74. };
  75. %1 %2 (missionNamespace getVariable ['%3',{}])
  76. } else {
  77. MOSES_doAnimation_duration = MOSES_doAnimation_duration -1;
  78. _unit switchMove _animation;
  79. };
  80. ",_onComplete select 0,_onComplete select 1,_onComplete select 2];
  81. }];
  82. MOSES_event_doAnimation = _unit addEventHandler ["AnimDone",format["
  83. params[['_unit',objNull,[objNull]],['_animation','',['']]];
  84. if (_animation in %1) then {
  85. systemChat 'handled';
  86. if (count MOSES_doAnimation_animations > 1) then [{
  87. _unit switchMove (MOSES_doAnimation_animations deleteAt 0);
  88. if (MOSES_doAnimation_animations isEqualTo []) then {
  89. _unit removeEventHandler ['AnimDone',MOSES_event_doAnimation];
  90. MOSES_event_doAnimation = nil;
  91. if (MOSES_event_doAnimationInterrupt != -1) then {
  92. findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
  93. MOSES_event_doAnimationInterrupt = -1;
  94. };
  95. %2 %3 (missionNamespace getVariable ['%4',{}])
  96. };
  97. },{
  98. %5
  99. }];
  100. };
  101. ",_animation,_onComplete select 0,_onComplete select 1,_onComplete select 2,_duration]];
  102.  
  103. _unit switchMove (MOSES_doAnimation_animations deleteAt 0);
  104.  
  105. if (_interrupt && _unit == player) then {
  106. MOSES_event_doAnimationInterrupt = findDisplay 46 displayAddEventHandler ["KeyDown",{
  107. _moveKeys = actionKeys 'CarLeft' + actionKeys 'CarRight' + actionKeys 'MoveForward' + actionKeys 'MoveBack';
  108. if (_this select 1 in _moveKeys) then {
  109. findDisplay 46 displayRemoveEventHandler ['KeyDown',MOSES_event_doAnimationInterrupt];
  110. player removeEventHandler ['AnimDone',MOSES_event_doAnimation];
  111. player switchMove '';
  112. MOSES_event_doAnimationInterrupt = -1;
  113. };
  114. }];
  115. };
  116.  
  117. MOSES_event_doAnimation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement