Advertisement
MGT

ExileClient_action_execute.sqf

MGT
May 22nd, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. private["_actionName", "_parameters", "_progress", "_actionConfig", "_duration", "_durationFunction", "_failChance", "_animation", "_animationType", "_conditionFunction", "_abortInCombatMode", "_startTime", "_sleepDuration", "_failAt", "_errorMessage", "_keyDownHandle", "_mouseButtonDownHandle", "_display", "_label", "_progressBarBackground", "_progressBarMaxSize", "_progressBar", "_function", "_progressBarColor"];
  2. disableSerialization;
  3. if (ExileClientActionDelayShown) exitWith { false };
  4. ExileClientActionDelayShown = true;
  5. ExileClientActionDelayAbort = false;
  6. _actionName = _this select 0;
  7. _parameters = _this select 1;
  8. _progress = 0;
  9. _actionConfig = missionconfigFile >> "CfgExileDelayedActions" >> _actionName;
  10. _duration = getNumber (_actionConfig >> "duration");
  11. _durationFunction = getText (_actionConfig >> "durationFunction");
  12. _failChance = getNumber (_actionConfig >> "failChance");
  13. _animation = getText (_actionConfig >> "animation");
  14. _animationType = getText (_actionConfig >> "animationType");
  15. _conditionFunction = getText (_actionConfig >> "conditionFunction");
  16. _abortInCombatMode = (getText (_actionConfig >> "abortInCombatMode")) isEqualTo 1;
  17. _startTime = diag_tickTime;
  18. _sleepDuration = _duration / 100;
  19. _failAt = diag_tickTime + 99999;
  20. _errorMessage = "";
  21. if !(_conditionFunction isEqualTo "") then
  22. {
  23. _errorMessage = _parameters call (missionNameSpace getVariable [_conditionFunction,{}]);
  24. };
  25. if !(_errorMessage isEqualTo "") exitWith
  26. {
  27. ExileClientActionDelayShown = false;
  28. ["ErrorTitleAndText", ["Whoops!", _errorMessage]] call ExileClient_gui_toaster_addTemplateToast;
  29. };
  30. if !(_durationFunction isEqualTo "") then
  31. {
  32. _duration = _parameters call (missionNameSpace getVariable [_durationFunction,{}]);
  33. };
  34. if ((floor (random 100)) < _failChance) then
  35. {
  36. _failAt = _startTime + _duration * (0.5 + (random 0.5));
  37. };
  38. ("ExileActionProgressLayer" call BIS_fnc_rscLayer) cutRsc ["RscExileActionProgress", "PLAIN", 1, false];
  39. _keyDownHandle = (findDisplay 46) displayAddEventHandler ["KeyDown","_this call ExileClient_action_event_onKeyDown"];
  40. _mouseButtonDownHandle = (findDisplay 46) displayAddEventHandler ["MouseButtonDown","_this call ExileClient_action_event_onMouseButtonDown"];
  41. _display = uiNamespace getVariable "RscExileActionProgress";
  42. _label = _display displayCtrl 4002;
  43. _label ctrlSetText "0%";
  44. _progressBarBackground = _display displayCtrl 4001;
  45. _progressBarMaxSize = ctrlPosition _progressBarBackground;
  46. _progressBar = _display displayCtrl 4000;
  47. _progressBar ctrlSetPosition [_progressBarMaxSize select 0, _progressBarMaxSize select 1, 0, _progressBarMaxSize select 3];
  48. _progressBar ctrlSetBackgroundColor [0, 0.78, 0.93, 1];
  49. _progressBar ctrlCommit 0;
  50. _progressBar ctrlSetPosition _progressBarMaxSize;
  51. _progressBar ctrlCommit _duration;
  52. if !(_animation isEqualTo "") then
  53. {
  54. if (_animationType isEqualTo "switchMove") then
  55. {
  56. player switchMove _animation;
  57. ["switchMoveRequest", [netId player, _animation]] call ExileClient_system_network_send;
  58. }
  59. else
  60. {
  61. player playMoveNow _animation;
  62. };
  63. };
  64. try
  65. {
  66. while {_progress < 1} do
  67. {
  68. if (diag_tickTime >= _failAt) then
  69. {
  70. throw 1;
  71. };
  72. if (ExileClientActionDelayAbort) then
  73. {
  74. throw 2;
  75. };
  76. if (ExileClientPlayerIsInCombat) then
  77. {
  78. if (_abortInCombatMode) then
  79. {
  80. throw 2;
  81. };
  82. };
  83. if !(alive player) then
  84. {
  85. throw 2;
  86. };
  87. uiSleep _sleepDuration;
  88. _progress = ((diag_tickTime - _startTime) / _duration) min 1;
  89. _label ctrlSetText format["%1%2", round (_progress * 100), "%"];
  90. };
  91. _errorMessage = "";
  92. if !(_conditionFunction isEqualTo "") then
  93. {
  94. _errorMessage = _parameters call (missionNameSpace getVariable [_conditionFunction,{}]);
  95. };
  96. if !(_errorMessage isEqualTo "") exitWith
  97. {
  98. ["ErrorTitleAndText", ["Whoops!", _errorMessage]] call ExileClient_gui_toaster_addTemplateToast;
  99. throw 2;
  100. };
  101. throw 0;
  102. }
  103. catch
  104. {
  105. _function = "";
  106. _progressBarColor = [];
  107. switch (_exception) do
  108. {
  109. case 0:
  110. {
  111. _function = getText (_actionConfig >> "completedFunction");
  112. _progressBarColor = [0.7, 0.93, 0, 1];
  113. };
  114. case 2:
  115. {
  116. _function = getText (_actionConfig >> "abortedFunction");
  117. _progressBarColor = [0.82, 0.82, 0.82, 1];
  118. };
  119. case 1:
  120. {
  121. _function = getText (_actionConfig >> "failedFunction");
  122. _progressBarColor = [0.91, 0, 0, 1];
  123. };
  124. };
  125. _progressBar ctrlSetBackgroundColor _progressBarColor;
  126. if !(_function isEqualTo "") then
  127. {
  128. _parameters call (missionNameSpace getVariable [_function,{}]);
  129. };
  130. if !(_animation isEqualTo "") then
  131. {
  132. player switchMove "";
  133. ["switchMoveRequest", [netId player, ""]] call ExileClient_system_network_send;
  134. };
  135. _progressBar ctrlSetPosition _progressBarMaxSize;
  136. _progressBar ctrlCommit 0;
  137. };
  138. ("ExileActionProgressLayer" call BIS_fnc_rscLayer) cutFadeOut 2;
  139. (findDisplay 46) displayRemoveEventHandler ["KeyDown", _keyDownHandle];
  140. (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", _mouseButtonDownHandle];
  141. ExileClientActionDelayShown = false;
  142. ExileClientActionDelayAbort = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement