Advertisement
Guest User

Untitled

a guest
May 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 9.28 KB | None | 0 0
  1. scriptName "3Dmarkers.sqf";
  2. /*
  3.     author - BrotherhoodOfHam
  4.    
  5.     version: 1.1
  6.    
  7.     description:
  8.         Shows all user placed map markers as icons on the screen, icons can be toggled on and off by pressing Y.
  9.         MUST be executed on mission start in order to work correctly.
  10.    
  11.     Examples of usage:
  12.    
  13.         init.sqf -
  14.             nul = [] execVM "3Dmarkers.sqf";
  15.        
  16.         or
  17.        
  18.         description.ext -
  19.             class params
  20.             {
  21.                 class marker3D
  22.                 {
  23.                     title = "3D markers";
  24.                     values[] = {0,1};
  25.                     texts[] = {$STR_DISABLED,$STR_ENABLED};
  26.                     default = 1;
  27.                     isGlobal = 1;
  28.                     file = "3Dmarkers.sqf";
  29.                 };
  30.             };
  31.        
  32.     known issues:
  33.         - needs to be run on mission start to work properly - causes issues with detecting which radio channel is selected otherwise.
  34.        
  35.     Todo:
  36.         - Optimize draw3D loop for 3d markers
  37.         - Add support for markers to fade or shrink with distance
  38. */
  39.  
  40. #include "\a3\editor_f\data\scripts\dikCodes.h"
  41.  
  42. //for debugging
  43. //#define DEBUG_MODE
  44.  
  45. if (!hasInterface) exitWith {};
  46. if (([_this, 0, 1, [1]] call BIS_fnc_param) == 0) exitWith {};
  47.  
  48. ///////////////////////////////////////////////////////////////editable parameters//////////////////////////////////////////////////////////////////////
  49.  
  50. BH_fnc_mkr3D_toggleKey = DIK_Y; //replace with whatever key you want to use for showing/hiding 3D markers in game. DIK code macros are provided.
  51. BH_fnc_mkr3D_JIPsync = true; //sync markers in global and side chat for JIP players
  52.  
  53. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  54.  
  55. waitUntil {!isNull player};
  56.  
  57. with uiNamespace do
  58. {
  59.     BH_fnc_mkr3D_logGrp_global = [];
  60.     BH_fnc_mkr3D_logGrp = [];
  61.  
  62.     BH_fnc_mkr3D_logGrp_west= [];
  63.     BH_fnc_mkr3D_logGrp_east= [];
  64.     BH_fnc_mkr3D_logGrp_ind = [];
  65.     BH_fnc_mkr3D_logGrp_civ = [];
  66.  
  67.     BH_fnc_mkr3D_logGrp_dir = [];
  68.     BH_fnc_mkr3D_logGrp_veh = [];
  69.     BH_fnc_mkr3D_logGrp_grp = [];
  70.     BH_fnc_mkr3D_logGrp_com = [];
  71. };
  72.  
  73.  
  74.  
  75. BH_fnc_mkr3D = {
  76.     if (isDedicated) exitWith {};
  77.    
  78.     if (isNull player) then  //&& (items player find ["G_Tactical_Clear","G_Tactical_Black"] >0)]
  79.     {
  80.         waitUntil {!isNull player};
  81.         waitUntil {!isNull ([] call BIS_fnc_displayMission)};
  82.     };
  83.    
  84.        
  85.     private ["_path", "_pos", "_text", "_markers", "_marker", "_cfg", "_colour", "_index", "_name", "_type", "_grp", "_array", "_data"];
  86.    
  87.     _marker = _this select 0;
  88.    
  89.     if (getMarkerColor _marker == "") exitWith {};
  90.    
  91.     _path = getText (configfile >> "cfgMarkers" >> (markerType _marker) >> "icon");
  92.    
  93.     _pos = getMarkerPos _marker;
  94.    
  95.     #ifdef DEBUG_MODE
  96.         hint parseText format ["<t align = 'center'>3D MARKERS:</t><br/><t align = 'left'>Name: %1<br/>Channel: %2<br/></t>", _marker, (uiNamespace getVariable ["VON_curSelChannel", "error"])];
  97.     #endif
  98.    
  99.     _cfg = configFile >> "cfgMarkers";
  100.    
  101.     _colour = getArray (configfile >> "cfgMarkerColors" >> getMarkerColor _marker >> "color");
  102.    
  103.     if (count _colour == 0) then {_colour = [1,1,1,1]};
  104.    
  105.     {
  106.         if (typeName _x == typeName "") then
  107.         {
  108.             _colour set [_foreachindex, call compile _x];
  109.         };
  110.     } forEach _colour;
  111.    
  112.     _text = markerText _marker;
  113.    
  114.     _logic = "logic" createVehicleLocal _pos;
  115.    
  116.     _data = [] call BH_fnc_mkr3D_VON;
  117.     _grp = _data select 1;
  118.     _type = _data select 2;
  119.    
  120.     _array = uiNamespace getVariable _grp;
  121.    
  122.     _index = count _array;
  123.     _array set [_index, _logic];
  124.    
  125.     uiNamespace setVariable [_grp, _array];
  126.    
  127.     _name = format ["BH_mkr3D_log_%1_%2", _type, _index];
  128.    
  129.     _logic setVehicleVarName _name;
  130.     uiNamespace setVariable [_name, _logic];
  131.    
  132.     _code = format ['uiNamespace getVariable %1', str _name];
  133.    
  134.     _logic setVariable
  135.     [
  136.         "BH_UserMkr_EH",
  137.         addMissionEventhandler
  138.         [
  139.             "draw3D",
  140.             compile format
  141.             [
  142.                 '
  143.                     if (count (toArray (getMarkerColor %5)) > 0) then
  144.                     {
  145.                         if (uiNamespace getVariable ["BH_fnc_mkr3D_show", true]) then
  146.                         {
  147.                             drawIcon3D
  148.                             [
  149.                                 %1,
  150.                                 %2,
  151.                                 %3,
  152.                                 1,
  153.                                 1,
  154.                                 0,
  155.                                 %4,
  156.                                 0,
  157.                                 0.05
  158.                             ];
  159.                         };
  160.                     }
  161.                     else
  162.                     {
  163.                         _obj = %6;
  164.                        
  165.                         if (isNull _obj) exitWith {};
  166.                        
  167.                         _type = (_obj getVariable "BH_UserMkr_Array");
  168.                         _array = uiNamespace getVariable _type;
  169.                        
  170.                         _index = _array find _obj;
  171.                         _array set [_index, objNull];
  172.                        
  173.                         uiNamespace setVariable [_type, _array];
  174.                        
  175.                         removeMissionEventhandler ["draw3D", _obj getVariable "BH_UserMkr_EH"];
  176.                         deleteVehicle _obj;
  177.                     };
  178.                 ',
  179.                 str _path,
  180.                 _colour,
  181.                 _pos,
  182.                 str _text,
  183.                 str _marker,
  184.                 _code
  185.             ]
  186.         ]
  187.     ];
  188.    
  189.     _logic setVariable
  190.     [
  191.         "BH_UserMkr_ID",
  192.         _marker
  193.     ];
  194.    
  195.     _logic setVariable
  196.     [
  197.         "BH_UserMkr_Array",
  198.         _grp
  199.     ];
  200. };
  201.  
  202. BH_fnc_mkr3D_VON =
  203. {
  204.     private ["_r"];
  205.    
  206.     if (isDedicated) exitWith {};
  207.    
  208.     _r = switch (uiNamespace getVariable ['VON_curSelChannel', '']) do
  209.     {
  210.         case localize "str_channel_global" : {[true, "BH_fnc_mkr3D_logGrp_global", 0]};
  211.         case localize "str_channel_side" :
  212.         {
  213.             [
  214.                 side player,
  215.                 switch (side player) do
  216.                 {
  217.                     case west: {"BH_fnc_mkr3D_logGrp_west"};
  218.                     case east: {"BH_fnc_mkr3D_logGrp_east"};
  219.                     case resistance: {"BH_fnc_mkr3D_logGrp_ind"};
  220.                     case civilian: {"BH_fnc_mkr3D_logGrp_civ"};
  221.                 },
  222.                 1
  223.             ]
  224.         };
  225.         case localize "str_channel_command" : {[player, "BH_fnc_mkr3D_logGrp_com", 2]};
  226.         case localize "str_channel_group" : {[group player, "BH_fnc_mkr3D_logGrp_grp", 3]};
  227.         case localize "str_channel_vehicle" : {[crew vehicle player, "BH_fnc_mkr3D_logGrp_veh", 4]};
  228.         case localize "str_channel_direct" : {[player, "BH_fnc_mkr3D_logGrp_dir", 5]};
  229.         default {[player, "BH_fnc_mkr3D_logGrp_dir", 5]};
  230.     };
  231.    
  232.     _r
  233. };
  234.  
  235. disableSerialization;
  236.  
  237. waitUntil {!isNull ([] call BIS_fnc_displayMission)};
  238.  
  239. uiNamespace setVariable ["VON_curSelChannel", (localize "str_channel_group")];
  240. uiNamespace setVariable ["BH_fnc_mkr3D_show", true];
  241.  
  242. _map = (findDisplay 12) displayCtrl 51;
  243.  
  244. addMissionEventhandler
  245. [
  246.     "draw3D",
  247.     {
  248.         if (!isNull (findDisplay 63)) then
  249.         {
  250.             _text = ctrlText ((findDisplay 63) displayCtrl 101);
  251.            
  252.             uiNamespace setVariable ["VON_curSelChannel", _text];
  253.            
  254.             #ifdef DEBUG_MODE
  255.             hintSilent _text;
  256.             #endif
  257.         };
  258.     }
  259. ];
  260.  
  261. ([] call BIS_fnc_displayMission) displayAddEventhandler
  262. [
  263.     "keydown",
  264.     {
  265.         _key = _this select 1;
  266.        
  267.         switch (true) do
  268.         {
  269.             case (_key == BH_fnc_mkr3D_toggleKey):  //default DIK_Y (0x15)
  270.             {
  271.                 _toggle = !(uiNamespace getVariable "BH_fnc_mkr3D_show");
  272.                 uiNamespace setVariable ["BH_fnc_mkr3D_show", _toggle];
  273.                
  274.                 _layer = "BH_marker3D_indic" call BIS_fnc_rscLayer;
  275.                 _layer cutRsc ["RscDynamicText", "PLAIN"];
  276.                
  277.                 _ctrl = (uiNamespace getVariable "BIS_dynamicText") displayCtrl 9999;
  278.                
  279.                 _ctrl ctrlSetPosition
  280.                 [
  281.                     0.4 * safezoneW + safezoneX,
  282.                     0.05 * safezoneH + safezoneY,
  283.                     0.2 * safezoneW,
  284.                     0.05 * safezoneH
  285.                 ];
  286.                
  287.                 _ctrl ctrlCommit 0;
  288.                
  289.                 _format = if (_toggle) then {"on"} else {"off"};
  290.                
  291.                 _text = format
  292.                 [
  293.                     "<t align = 'center' shadow = '0' size = '0.7'>3D markers: %1</t>",
  294.                     _format
  295.                 ];
  296.                
  297.                 _ctrl ctrlSetStructuredText parseText _text;
  298.                 _ctrl ctrlSetFade 1;
  299.                 _ctrl ctrlCommit 2;
  300.             };
  301.         };
  302.        
  303.         false
  304.     }
  305. ];
  306.  
  307. _map ctrlAddEventHandler
  308. [
  309.     "MouseButtonDblClick",
  310.     {
  311.         _this spawn
  312.         {
  313.             disableSerialization;
  314.            
  315.             waitUntil {!isNull (findDisplay 54)}; //RscDisplayInsertMarker
  316.             _display = findDisplay 54;
  317.            
  318.             _display displayAddEventhandler
  319.             [
  320.                 "unload",
  321.                 {
  322.                     disableSerialization;
  323.                    
  324.                     _display = _this select 0;
  325.                     //_map = (findDisplay 12) displayCtrl 51;
  326.                     _path = ctrlText (_display displayCtrl 102);
  327.                    
  328.                     if ((_this select 1) == 1) then
  329.                     {
  330.                         nul = [allMapMarkers, _path, _display] spawn
  331.                         {
  332.                             private ["_target", "_persistent"];
  333.                            
  334.                             _target = ([] call BH_fnc_mkr3D_VON) select 0;
  335.                             _persistent = false;
  336.                            
  337.                             //JIP persistence
  338.                             if (BH_fnc_mkr3D_JIPsync) then
  339.                             {
  340.                                 _persistent = switch (typeName _target) do
  341.                                 {
  342.                                     case (typeName true): {true};
  343.                                     case (typeName sideLogic): {true};
  344.                                     default {false};
  345.                                 };
  346.                             };
  347.                            
  348.                             [
  349.                                 [
  350.                                     [(allMapMarkers - (_this select 0)) select 0],
  351.                                     {
  352.                                         if (!hasInterface) exitWith {};
  353.                                        
  354.                                         waitUntil {missionNamespace getVariable ["3Dmarkers_intialized", false]};
  355.                                        
  356.                                         _this spawn BH_fnc_mkr3D;
  357.                                     }
  358.                                 ],
  359.                                 "BIS_fnc_spawn",
  360.                                 _target,
  361.                                 _persistent,
  362.                                 false
  363.                             ] spawn BIS_fnc_MP;
  364.                         };
  365.                     };
  366.                 }
  367.             ]
  368.         };
  369.        
  370.         false
  371.     }
  372. ];
  373.  
  374. {
  375.     (ctrlParent _map) displayAddEventhandler
  376.     [
  377.         _x,
  378.         {
  379.             if (!isNull (findDisplay 63)) then
  380.             {
  381.                 _text = ctrlText ((findDisplay 63) displayCtrl 101);
  382.                
  383.                 uiNamespace setVariable ["VON_curSelChannel", _text];
  384.                
  385.                 #ifdef DEBUG_MODE
  386.                 hintSilent _text;
  387.                 #endif
  388.             };
  389.         }
  390.     ];
  391. } forEach ["mouseMoving", "mouseHolding"];
  392.  
  393.  
  394.  
  395. if (isNull (findDisplay 602)) then
  396. {
  397.     _goggles = goggles player;
  398.     if (player alive && _goggles in ["G_Tactical_Clear","G_Tactical_Black"]) then
  399.     {
  400.         missionNamespace setVariable ["3Dmarkers_intialized", true];
  401.     }
  402.     else
  403.     {
  404.         missionNamespace setVariable ["3Dmarkers_intialized", false];  
  405.     };
  406. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement