1
0

fnc_impulseApply.sqf 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. _vehicle = _this;
  2. //systemChat "apply";
  3. private _impulse_state = _vehicle getvariable ["impulsorStatus", 0];
  4. private _target_speed = 0;
  5. private _max_change = 0;
  6. private _accelerate = True;
  7. private _decelerate = True;
  8. private _stage_message = "";
  9. switch (_impulse_state) do
  10. {
  11. case -1:
  12. {
  13. _target_speed = 100;
  14. _max_change = 10;
  15. _accelerate = False;
  16. _stage_message = format["%1 kph", _target_speed];
  17. };
  18. case 0:
  19. {
  20. _target_speed = 0;
  21. _max_change = 0;
  22. _accelerate = False;
  23. _decelerate = False;
  24. _stage_message = "neutral";
  25. };
  26. case 1:
  27. {
  28. _target_speed = 400;
  29. _max_change = 10;
  30. _decelerate = False;
  31. _stage_message = format["%1 kph", _target_speed];
  32. };
  33. case 2:
  34. {
  35. _target_speed = 600;
  36. _max_change = 30;
  37. _stage_message = format["%1 kph", _target_speed];
  38. };
  39. default
  40. {
  41. hint "ERROR";
  42. };
  43. };
  44. _titlehintimpulsor = "<t color='#253f5c' size='2' shadow='1' shadowColor='#000000' align='center'>IMPULSOR</t>";
  45. _texthintimpulsor = format ["<br /><t color='#ffffff' size='1.4' shadow='1' shadowColor='#000000' align='center'>Stage %1 - %2</t>", _impulse_state, _stage_message];
  46. hint parseText (_titlehintimpulsor+_texthintimpulsor);
  47. if (!_accelerate && !_decelerate) exitWith{};
  48. while {_vehicle getVariable ['impulsorStatus', 0] isEqualTo _impulse_state && alive _vehicle} do
  49. {
  50. private _movement = velocity _vehicle;
  51. private _velocity = speed _vehicle;
  52. private _diff = _target_speed - _velocity;
  53. private _change = 0;
  54. if (abs _diff < _max_change) then {
  55. _change = _diff;
  56. } else {
  57. if (_diff < 0) then {
  58. _change = -_max_change;
  59. } else {
  60. _change = _max_change;
  61. };
  62. };
  63. if (_change > 0 && !_accelerate) then {
  64. _change = 0;
  65. };
  66. if (_change < 0 && !_decelerate) then {
  67. _change = 0;
  68. };
  69. // systemChat format ["%1 - %2 - %3 - %4 - %5", str _velocity, str _target_speed, str _diff, str _max_change, str _change];
  70. if (_change != 0) then {
  71. private _direction = vectorDir _vehicle;
  72. _vehicle setVelocity [
  73. (_movement select 0) + (_direction select 0) * _change,
  74. (_movement select 1) + (_direction select 1) * _change,
  75. (_movement select 2) + (_direction select 2) * _change
  76. ];
  77. };
  78. sleep 0.5;
  79. };