fnc_impulseApply_LE.sqf 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = 200;
  29. _max_change = 10;
  30. _decelerate = False;
  31. _stage_message = format["%1 kph", _target_speed];
  32. };
  33. case 2:
  34. {
  35. _target_speed = 400;
  36. _max_change = 20;
  37. _stage_message = format["%1 kph", _target_speed];
  38. };
  39. case 3:
  40. {
  41. _target_speed = 700;
  42. _max_change = 30;
  43. _stage_message = format["%1 kph", _target_speed];
  44. };
  45. default
  46. {
  47. hint "ERROR";
  48. };
  49. };
  50. _titlehintimpulsor = "<t color='#253f5c' size='2' shadow='1' shadowColor='#000000' align='center'>IMPULSOR</t>";
  51. _texthintimpulsor = format ["<br /><t color='#ffffff' size='1.4' shadow='1' shadowColor='#000000' align='center'>Stage %1 - %2</t>", _impulse_state, _stage_message];
  52. hint parseText (_titlehintimpulsor+_texthintimpulsor);
  53. if (!_accelerate && !_decelerate) exitWith{};
  54. while {_vehicle getVariable ['impulsorStatus', 0] isEqualTo _impulse_state && alive _vehicle} do
  55. {
  56. private _movement = velocity _vehicle;
  57. private _velocity = speed _vehicle;
  58. private _diff = _target_speed - _velocity;
  59. private _change = 0;
  60. if (abs _diff < _max_change) then {
  61. _change = _diff;
  62. } else {
  63. if (_diff < 0) then {
  64. _change = -_max_change;
  65. } else {
  66. _change = _max_change;
  67. };
  68. };
  69. if (_change > 0 && !_accelerate) then {
  70. _change = 0;
  71. };
  72. if (_change < 0 && !_decelerate) then {
  73. _change = 0;
  74. };
  75. // systemChat format ["%1 - %2 - %3 - %4 - %5", str _velocity, str _target_speed, str _diff, str _max_change, str _change];
  76. if (_change != 0) then {
  77. private _direction = vectorDir _vehicle;
  78. _vehicle setVelocity [
  79. (_movement select 0) + (_direction select 0) * _change,
  80. (_movement select 1) + (_direction select 1) * _change,
  81. (_movement select 2) + (_direction select 2) * _change
  82. ];
  83. };
  84. sleep 0.5;
  85. };