Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.71 KB | None | 0 0
  1. /*-----------------------------------------------------------*/
  2. // Created by Raymix
  3. // Last update - August 21 2014
  4. /*-----------------------------------------------------------*/
  5.  
  6. private ["_object","_objectSnapGizmo","_objColorActive","_objColorInactive","_classname","_whitelist","_points","_radius","_cfg","_cnt","_pos","_findWhitelisted","_nearbyObject","_posNearby","_selectedAction","_newPos","_pointsNearby","_onWater","_waterBase"];
  7. //Args
  8. snapActionState = _this select 3 select 0;
  9. _object = _this select 3 select 1;
  10. _classname = _this select 3 select 2;
  11. _objectHelper = _this select 3 select 3;
  12. _selectedAction = _this select 3 select 4;
  13.  
  14. //Snap config file
  15. _cfg = (missionConfigFile >> "SnapBuilding" >> _classname);
  16. _whitelist = getArray (_cfg >> "snapTo");
  17. _points = getArray (_cfg >> "points");
  18. _radius = getNumber (_cfg >> "radius");
  19.  
  20. //colors
  21. _objColorActive = "#(argb,8,8,3)color(0,0.92,0.06,1,ca)";
  22. _objColorInactive = "#(argb,8,8,3)color(0.04,0.84,0.92,0.3,ca)";
  23.  
  24.  
  25. fnc_snapActionCleanup = {
  26.     private ["_s1","_s2","_s3","_cnt"];
  27.     _s1 = _this select 0;
  28.     _s2 = _this select 1;
  29.     _s3 = _this select 2;
  30.     player removeAction s_player_toggleSnap; s_player_toggleSnap = -1;
  31.     player removeAction s_player_toggleSnapSelect; s_player_toggleSnapSelect = -1;
  32.     if (count s_player_toggleSnapSelectPoint != 0) then {{player removeAction _x;} count s_player_toggleSnapSelectPoint; s_player_toggleSnapSelectPoint=[]; snapActions = -1;};
  33.     if (_s1 > 0) then {
  34.         s_player_toggleSnap = player addaction [format[("<t color=""#ffffff"">" + ("Snap: %1") +"</t>"),snapActionState],"custom\snap_pro\snap_build.sqf",[snapActionState,_object,_classname,_objectHelper],10,false,true];
  35.     };
  36.     if (_s2 > 0) then {
  37.         s_player_toggleSnapSelect = player addaction [format[("<t color=""#ffffff"">" + ("Snap Point: %1") +"</t>"),snapActionStateSelect],"custom\snap_pro\snap_build.sqf",[snapActionStateSelect,_object,_classname,_objectHelper],9,false,true];
  38.     };
  39.     if (_s3 > 0) then {
  40.         s_player_toggleSnapSelectPoint=[];
  41.         _cnt = 0;
  42.         {snapActions = player addaction [format[("<t color=""#ffffff"">" + ("%1)Select: %2") +"</t>"),_cnt,_x select 3],"custom\snap_pro\snap_build.sqf",["Selected",_object,_classname,_objectHelper,_cnt],8,false,false];
  43.         s_player_toggleSnapSelectPoint set [count s_player_toggleSnapSelectPoint,snapActions];
  44.         _cnt = _cnt+1;
  45.     }count _points;
  46.     };
  47. };
  48.  
  49. fnc_initSnapPoints = {
  50.     snapGizmos = [];
  51.     {
  52.         _objectSnapGizmo = "Sign_sphere10cm_EP1" createVehicleLocal [0,0,0];
  53.         _objectSnapGizmo setobjecttexture [0,_objColorInactive];
  54.         _objectSnapGizmo attachTo [_object,[_x select 0,_x select 1,_x select 2]];
  55.         snapGizmos set [count snapGizmos,_objectSnapGizmo];
  56.     } count _points;
  57. };
  58.  
  59. fnc_initSnapPointsNearby = {
  60.     _pos = [_object] call FNC_GetPos;
  61.     _findWhitelisted = []; _pointsNearby = [];
  62.     _findWhitelisted = nearestObjects [_pos,_whitelist,(_radius + DZE_snapExtraRange)]-[_object];
  63.     snapGizmosNearby = []; 
  64.     {  
  65.         _nearbyObject = _x;
  66.         _pointsNearby = getArray (missionConfigFile >> "SnapBuilding" >> (typeOf _x) >> "points");
  67.         {
  68.             _objectSnapGizmo = "Sign_sphere10cm_EP1" createVehicleLocal [0,0,0];
  69.             _objectSnapGizmo setobjecttexture [0,_objColorInactive];
  70.             _objectSnapGizmo setDir (_nearbyObject getVariable["memDir",0]);
  71.             _posNearby = _nearbyObject modelToWorld [_x select 0,_x select 1,_x select 2];
  72.             if (surfaceIsWater _posNearby) then {
  73.                 _objectSnapGizmo setPosASL [(_posNearby) select 0,(_posNearby) select 1,(getPosASL _nearbyObject select 2) + (_x select 2)];
  74.             } else {
  75.                 _objectSnapGizmo setPosATL _posNearby;
  76.             };
  77.             snapGizmosNearby set [count snapGizmosNearby,_objectSnapGizmo];
  78.         } count _pointsNearby;
  79.     } forEach _findWhitelisted;
  80. };
  81.  
  82. fnc_initSnapPointsCleanup = {
  83.     {detach _x;deleteVehicle _x;}count snapGizmos;snapGizmos=[];
  84.     {detach _x;deleteVehicle _x;}count snapGizmosNearby;snapGizmosNearby=[];
  85.     snapActionState = "OFF";
  86. };
  87.  
  88. fnc_snapDistanceCheck = {
  89.     while {snapActionState != "OFF"} do {
  90.     private ["_distClosestPointFound","_distCheck","_distClosest","_distClosestPoint","_testXPos","_testXDir","_distClosestPointFoundPos","_distClosestPointFoundDir","_distClosestAttached","_distCheckAttached","_distClosestAttachedFoundPos"];
  91.     _distClosestPointFound = objNull; _distCheck = 0; _distClosest = 10; _distClosestPoint = objNull; _testXPos = []; _distClosestPointFoundPos =[]; _distClosestPointFoundDir = 0;
  92.         {  
  93.             if (_x !=_distClosestPointFound) then {_x setobjecttexture [0,_objColorInactive];};
  94.             _testXPos = [_x] call FNC_GetPos;
  95.             _distCheck = _objectHelper distance _testXPos;
  96.             _distClosestPoint = _x;
  97.                 if (_distCheck < _distClosest) then {
  98.                     _distClosest = _distCheck;
  99.                     _distClosestPointFound setobjecttexture [0,_objColorInactive];
  100.                     _distClosestPointFound = _x;
  101.                     _distClosestPointFound setobjecttexture [0,_objColorActive];
  102.                 };
  103.         } count snapGizmosNearby;  
  104.        
  105.         if (!isNull _distClosestPointFound) then {
  106.             if (snapActionStateSelect == "Manual") then {
  107.                 if (helperDetach) then {
  108.                     _onWater = surfaceIsWater position _distClosestPointFound;
  109.                     _distClosestPointFoundDir = getDir _distClosestPointFound;
  110.                     if (_onWater) then {
  111.                         _distClosestPointFoundPos = getPosASL _distClosestPointFound;
  112.                         _objectHelper setPosASL _distClosestPointFoundPos;
  113.                     } else {
  114.                         _distClosestPointFoundPos = getPosATL _distClosestPointFound;
  115.                         _objectHelper setPosATL _distClosestPointFoundPos;
  116.                     };
  117.                     DZE_memDir = _distClosestPointFoundDir;
  118.                     [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  119.                     waitUntil {sleep 0.1; !helperDetach};
  120.                 };
  121.             } else {
  122.                 _distClosestAttached = objNull; _distCheckAttached = 0; _distClosest = 10; _distClosestAttachedFoundPos = [];
  123.                 {
  124.                     if (_x !=_distClosestAttached) then {_x setobjecttexture [0,_objColorInactive];};
  125.                     _testXPos = [_x] call FNC_GetPos;
  126.                     _distCheckAttached = _distClosestPointFound distance _testXPos;
  127.                     _distClosestPoint = _x;
  128.                         if (_distCheckAttached < _distClosest) then {
  129.                             _distClosest = _distCheckAttached;
  130.                             _distClosestAttached setobjecttexture [0,_objColorInactive];
  131.                             _distClosestAttached = _x;
  132.                             _distClosestAttached setobjecttexture [0,_objColorActive];
  133.                         };
  134.                 } count snapGizmos;
  135.            
  136.                 if (helperDetach) then {
  137.                     _distClosestPointFoundDir = getDir _distClosestPointFound;
  138.                     _onWater = surfaceIsWater position _distClosestPointFound;
  139.                     if (_onWater) then {
  140.                         _distClosestPointFoundPos = getPosASL _distClosestPointFound;
  141.                         _distClosestAttachedFoundPos = getPosASL _distClosestAttached;
  142.                         detach _object;
  143.                         _objectHelper setPosASL _distClosestAttachedFoundPos;
  144.                         _object attachTo [_objectHelper];
  145.                         _objectHelper setPosASL _distClosestPointFoundPos;
  146.                     } else {
  147.                         _distClosestPointFoundPos = getPosATL _distClosestPointFound;
  148.                         _distClosestAttachedFoundPos = getPosATL _distClosestAttached;
  149.                         detach _object;
  150.                         _objectHelper setPosATL _distClosestAttachedFoundPos;
  151.                         _object attachTo [_objectHelper];
  152.                         _objectHelper setPosATL _distClosestPointFoundPos;
  153.                     };
  154.                     DZE_memDir = _distClosestPointFoundDir;
  155.                     [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  156.                     waitUntil {sleep 0.1; !helperDetach};
  157.                 };
  158.             };
  159.         };
  160.         sleep 0.1;
  161.     };
  162. };
  163.  
  164. fnc_initSnapTutorial = {
  165. /*
  166.     Shows help dialog for player ONCE per log in, explaining controls.
  167.     Add snapTutorial = false; to your init.sqf to disable this tutorial completely.
  168.     You can also add this bool to the end of this function to only show tutorial once per player login (not recommended)
  169. */
  170.     private ["_bldTxtSwitch","_bldTxtEnable","_bldTxtClrO","_bldTxtClrC","_bldTxtClrW","_bldTxtClrR","_bldTxtClrG","_bldTxtSz","_bldTxtSzT","_bldTxtShdw","_bldTxtAlgnL","_bldTxtUndrln","_bldTxtBold","_bldTxtFinal","_bldTxtStringTitle","_bldTxtStringSD","_bldTxtStringSE","_bldTxtStringSA","_bldTxtStringSM","_bldTxtStringPG","_bldTxtStringAPG","_bldTxtStringCPG","_bldTxtStringQE","_bldTxtStringQEF","_bldTxtStringFD","_bldTxtStringFS"];
  171.         if (isNil "snapTutorial") then {
  172.             _bldTxtSwitch = _this select 0;
  173.             _bldTxtEnable = _this select 1;
  174.             _bldTxtClrO = "color='#ff8800'"; //orange
  175.             _bldTxtClrC = "color='#17DBEC'"; //cyan
  176.             _bldTxtClrW = "color='#ffffff'"; //white
  177.             _bldTxtClrR = "color='#fd0a05'"; //red
  178.             _bldTxtClrG = "color='#11ef00'"; //green
  179.             _bldTxtSz = "size='0.76'"; //Title font size
  180.             _bldTxtSzT = "size='0.4'"; //Text font size
  181.             _bldTxtShdw = "shadow='1'"; //Font shadow
  182.             _bldTxtAlgnL = "align='left'"; //Text align left
  183.             _bldTxtUndrln = "underline='true'";
  184.             _bldTxtBold = "font='Zeppelin33'"; //Bold text
  185.             _bldTxtFinal = "";
  186.            
  187.             //Delete on init
  188.             800 cutRsc ["Default", "PLAIN"];
  189.             sleep 0.1;
  190.            
  191.             //Init Tutorial text
  192.             if (_bldTxtEnable) then {
  193.                 _bldTxtStringTitle = format ["<t %1%2%3%4>Snap Building <t %5%6%7>Pro 1.4</t></t><br />",_bldTxtClrO,_bldTxtSz,_bldTxtShdw,_bldTxtAlgnL,_bldTxtClrW,_bldTxtUndrln,_bldTxtBold];
  194.                 _bldTxtStringSD = format["<t %1%4%5%6>[Snap]<t %2> Disabled:</t> <t %3>use action menu to enable.</t></t><br /><br />",_bldTxtClrC,_bldTxtClrR,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  195.                 _bldTxtStringSE = format["<t %1%4%5%6>[Snap]<t %2> Enabled:</t> <t %3>use action menu to disable.</t></t><br /><br />",_bldTxtClrC,_bldTxtClrG,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  196.                 _bldTxtStringSA = format["<t %1%3%4%5>[Snap Point]<t %2> AUTOMATIC: Automatic snap point detection.</t></t><br /><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  197.                 _bldTxtStringSM = format["<t %1%3%4%5>[Snap Point]<t %2> MANUAL: Select your preferred snap point.</t></t><br /><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  198.                 _bldTxtStringPG = format["<t %1%3%4%5>[PgUP / PgDOWN]<t %2>: Adjust height of object by 10cm</t></t><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  199.                 _bldTxtStringAPG = format["<t %1%3%4%5>[Alt]+[PgUP / PgDOWN]<t %2>: Adjust height of object by 1m</t></t><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  200.                 _bldTxtStringCPG = format["<t %1%3%4%5>[Ctrl]+[PgUP / PgDOWN]<t %2>: Adjust height of object by 1cm</t></t><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  201.                 _bldTxtStringQE = format["<t %1%3%4%5>[Q / E]<t %2>: Rotate object 180 degrees while holding.</t></t><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  202.                 _bldTxtStringQEF = format["<t %1%3%4%5>[Q / E]<t %2>: Rotate object 45 degrees while dropped or snapped.</t></t><br /><br />",_bldTxtClrC,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  203.                 _bldTxtStringFD = format["<t %1%3%4%5>[F]<t %2>: Drop / Pick up object.</t></t><br />",_bldTxtClrO,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  204.                 _bldTxtStringFS = format["<t %1%3%4%5>[F]<t %2>: Snap /Pick up object.</t></t><br />",_bldTxtClrO,_bldTxtClrW,_bldTxtSzT,_bldTxtShdw,_bldTxtAlgnL];
  205.                 switch (_bldTxtSwitch) do {
  206.                     case "init": {
  207.                         _bldTxtFinal = _bldTxtStringTitle + _bldTxtStringSD + _bldTxtStringPG + _bldTxtStringAPG + _bldTxtStringCPG + _bldTxtStringQE + _bldTxtStringQEF + _bldTxtStringFD;
  208.                     };
  209.                     case "OnAuto": {
  210.                         _bldTxtFinal = _bldTxtStringTitle + _bldTxtStringSE + _bldTxtStringSA + _bldTxtStringPG + _bldTxtStringAPG + _bldTxtStringCPG + _bldTxtStringQE + _bldTxtStringQEF + _bldTxtStringFS;
  211.                     };
  212.                     case "manual": {
  213.                         _bldTxtFinal = _bldTxtStringTitle + _bldTxtStringSE + _bldTxtStringSM + _bldTxtStringPG + _bldTxtStringAPG + _bldTxtStringCPG + _bldTxtStringQE + _bldTxtStringQEF + _bldTxtStringFS;
  214.                     };
  215.                 };
  216.  
  217.                 [
  218.                     _bldTxtFinal, //structured text
  219.                     0.73 * safezoneW + safezoneX, //number - x
  220.                     0.65 * safezoneH + safezoneY, //number - y
  221.                     30, //number - duration
  222.                     1, // number - fade in time
  223.                     0, // number - delta y
  224.                     800 //number - layer ID
  225.                 ] spawn bis_fnc_dynamicText;
  226.             };
  227.         }; 
  228. };
  229.  
  230. switch (snapActionState) do {
  231.     case "Init": {
  232.         ["init",true] call fnc_initSnapTutorial;
  233.         snapActionState = "OFF";
  234.         [1,0,0] call fnc_snapActionCleanup;
  235.         [] spawn {
  236.         while {true} do {
  237.             if(!DZE_ActionInProgress || DZE_cancelBuilding) exitWith {call fnc_initSnapPointsCleanup;[0,0,0] call fnc_snapActionCleanup; ["",false] call fnc_initSnapTutorial; snapActionState = "OFF";};
  238.             sleep 2;
  239.             };
  240.         };
  241.     };
  242.     case "OFF": {
  243.         ["OnAuto",true] call fnc_initSnapTutorial;
  244.         snapActionState = "ON"; snapActionStateSelect = "Auto";
  245.         [1,1,0] call fnc_snapActionCleanup;
  246.         call fnc_initSnapPoints;
  247.         call fnc_initSnapPointsNearby;
  248.         sleep 0.25;
  249.         call fnc_snapDistanceCheck;
  250.     };
  251.    
  252.     case "ON": {
  253.         ["init",true] call fnc_initSnapTutorial;
  254.         snapActionState = "OFF";
  255.         [1,0,0] call fnc_snapActionCleanup;
  256.         call fnc_initSnapPointsCleanup;
  257.     };
  258.    
  259.     case "Auto": {
  260.         ["manual",true] call fnc_initSnapTutorial;
  261.         snapActionState = "ON";snapActionStateSelect = "Manual";
  262.         [1,1,1] call fnc_snapActionCleanup;
  263.     };
  264.    
  265.     case "Manual": {
  266.         ["OnAuto",true] call fnc_initSnapTutorial;
  267.         snapActionState = "ON";snapActionStateSelect = "Auto";
  268.         [1,1,0] call fnc_snapActionCleanup;
  269.     };
  270.    
  271.     case "Selected": { _cnt = 0; _newPos = [];
  272. {  
  273.     _x setobjecttexture [0,_objColorInactive];
  274.     if (_cnt == _selectedAction) then {
  275.         _newPos = [(getPosATL _x select 0),(getPosATL _x select 1),(getPosATL _x select 2)];
  276.         detach _object;
  277.         detach _objectHelper;
  278.         _objectHelper setDir (getDir _object);
  279.         _objectHelper setPosATL _newPos;
  280.         _object attachTo [_objectHelper];
  281.         _x setobjecttexture [0,_objColorActive];
  282.         if (!helperDetach) then {_objectHelper attachTo [player]; _objectHelper setDir ((getDir _objectHelper)-(getDir player));};
  283.        
  284.         [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  285.        
  286.     };
  287.     _cnt = _cnt+1;
  288. }count snapGizmos;
  289.     };
  290. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement