Advertisement
BobTheHunted

nudge.sqf

Nov 14th, 2021
1,779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.30 KB | None | 0 0
  1. // Script that enables "nudging" objects in the 3den editor for precision alignment/adjustment.  Execute script from 3den debug menu. (Ctrl + D to open) - execVM "nudge.sqf"
  2. // Select 1 or more objects in 3den and you can adjust their position(s).
  3. // Created by Rylan
  4. //
  5. //  Controls:
  6. //      Shift + Numpad 5 = Nudge "forward" (Global coordinates so it probably won't be forward for the object if it has changed rotation.)
  7. //      Shift + Numpad 1 = Nudge "left"
  8. //      Shift + Numpad 2 = Nudge "backward"
  9. //      Shift + Numpad 3 = Nudge "right"
  10. //      Ctrl + Numpad 5 or 2 = Increase or decrease the nudge increment by 0.0025 - For high precision
  11. //      Ctrl + Numpad 1 or 3 = Increase or decrease the nudge increment by 0.01 --- For lower precision
  12. //
  13. // The default value and the amount the increment can be increased or decreased can be changed by editing the first 3 variables of this script.
  14. // These variables can also be changed on the fly from the editor via the debug menu.  Simply redefine any of the variables with the values you want.
  15. //
  16. // I eventually plan on adding a way to adjust the vertical position of an object, as well as its rotation. It would also be ideal to be able to nudge along local object coordinates.
  17.  
  18.  
  19. A3EM_nudgeIncrement = 0.01; // Default nudge value
  20. A3EM_ni_inc1 = 0.0025; // ---- High precision adjustment
  21. A3EM_ni_inc2 = 0.1; // ------- Low precision adjustment
  22.  
  23. A3EM_fnc_nudgeTranslate =
  24. {
  25.     collect3DENHistory
  26.     {
  27.         private ["_keypress", "_EditorObjects"];
  28.    
  29.         _keypress = _this select 0;
  30.         _EditorObjects = get3DENSelected "object";
  31.         if (count _EditorObjects < 1) exitWith {systemChat "No object(s) selected!"};
  32.    
  33.         {
  34.             if (_keypress == "NudgeUp") then {
  35.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  36.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1) - A3EM_nudgeincrement,(_oldPos select 2)]]];
  37.             };
  38.             if (_keypress == "NudgeDown") then {
  39.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  40.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1) + A3EM_nudgeincrement,(_oldPos select 2)]]];
  41.             };
  42.             if (_keypress == "NudgeRight") then {
  43.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  44.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0) - A3EM_nudgeincrement,(_oldPos select 1),(_oldPos select 2)]]];
  45.             };
  46.             if (_keypress == "NudgeLeft") then {
  47.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  48.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0) + A3EM_nudgeincrement,(_oldPos select 1),(_oldPos select 2)]]];
  49.             };
  50.         } forEach _EditorObjects;
  51.     };
  52. };
  53.  
  54. waitUntil {!isNull (findDisplay 313)};
  55.  
  56. #include "\a3\ui_f\hpp\definedikcodes.inc"
  57.  
  58. _display = findDisplay 313;
  59. if (_display getVariable ["A3EM_eh_nudgecontrols", -1] != -1) exitWith {};
  60. _EventHandler = _display displayAddEventHandler [ "KeyDown", {
  61.     params[
  62.         "_display",
  63.         "_keyCode",
  64.         "_shft",
  65.         "_ctr",
  66.         "_alt"
  67.     ];
  68.    
  69.     call {
  70.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // up
  71.             ["NudgeUp"] call A3EM_fnc_nudgeTranslate;
  72.             true
  73.         };
  74.        
  75.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // down
  76.             ["NudgeDown"] call A3EM_fnc_nudgeTranslate;
  77.             true
  78.         };
  79.        
  80.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD3 } ) exitWith { // right
  81.             ["NudgeRight"] call A3EM_fnc_nudgeTranslate;
  82.             true
  83.         };
  84.        
  85.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD1 } ) exitWith { // left
  86.             ["NudgeLeft"] call A3EM_fnc_nudgeTranslate;
  87.             true
  88.         };
  89.        
  90.        
  91.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith {
  92.             A3EM_nudgeIncrement = A3EM_nudgeIncrement + A3EM_ni_inc1;
  93.             systemChat str A3EM_nudgeIncrement;
  94.             true
  95.         };
  96.        
  97.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith {
  98.             A3EM_nudgeIncrement = A3EM_nudgeIncrement - A3EM_ni_inc1;
  99.             systemChat str A3EM_nudgeIncrement;
  100.             true
  101.         };
  102.        
  103.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD3 } ) exitWith {
  104.             A3EM_nudgeIncrement = A3EM_nudgeIncrement + A3EM_ni_inc2;
  105.             systemChat str A3EM_nudgeIncrement;
  106.             true
  107.         };
  108.        
  109.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD1 } ) exitWith {
  110.             A3EM_nudgeIncrement = A3EM_nudgeIncrement - A3EM_ni_inc2;
  111.             systemChat str A3EM_nudgeIncrement;
  112.             true
  113.         };
  114.         false
  115.     };
  116. }];
  117. _display setVariable ["A3EM_eh_nudgecontrols", _EventHandler]
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement