Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 10.75 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #define COLOR_GREEN "#(argb,8,8,3)color(0,1,0,0.3,ca)"
  2. #define COLOR_RED       "#(argb,8,8,3)color(1,0,0,0.3,ca)"
  3. #define COLOR_GRAY      "#(argb,8,8,3)color(0,0,0,0.3,ca)"
  4.  
  5. ////////////////////////////////
  6.  
  7. if (isnil {_this getvariable "MSO_cnstrct_radius"}) then {
  8.         if (isnil {_this getvariable "MSO_cnstrct_supplies"}) then {
  9.                 _this setvariable ["MSO_cnstrct_supplies",500,true];
  10.         };
  11.         if (isnil {_this getvariable "MSO_cnstrct_radius"}) then {
  12.                 _this setvariable ["MSO_cnstrct_radius",20];
  13.         };
  14.         if (isnil {_this getvariable "MSO_cnstrct_buildings"}) then {
  15.                 _this setvariable ["MSO_cnstrct_buildings",[]];
  16.         };
  17.  
  18.         //List of items, fixed for OA
  19.         if (isnil {_this getvariable "MSO_cnstrct_categories"}) then {
  20.                 _this setvariable ["MSO_cnstrct_categories",["Barriers","Sandbags","HESCO","Bunkers","Trenches","Netting","Misc"]];
  21.         };
  22.         if (isnil {_this getvariable "MSO_cnstrct_items"}) then {
  23.                 _this setvariable ["MSO_cnstrct_items",[
  24.                         ["Fort_RazorWire","Barriers",200],
  25.                         ["Hedgehog_EP1","Barriers",200],
  26.                         ["Land_fort_bagfence_long","Sandbags",100],
  27.                         ["Land_fort_bagfence_round","Sandbags",300],
  28.                         ["Land_HBarrier1","HESCO",70],
  29.                         ["Land_HBarrier3","HESCO",200],
  30.                         ["Land_HBarrier5","HESCO",300],
  31.                         ["Land_HBarrier_large","HESCO",800],
  32.                         ["Land_fortified_nest_small_EP1","Bunkers",800],
  33.                         ["Land_fortified_nest_big_EP1","Bunkers",1800],
  34.                         ["Land_Fort_Watchtower_EP1","Bunkers",2000],
  35.                         ["Fort_EnvelopeSmall_EP1","Trenches",0],
  36.                         ["Fort_EnvelopeBig_EP1","Trenches",0],
  37.                         ["Land_CamoNetVar_NATO_EP1","Netting",500],
  38.                         ["Land_CamoNetB_NATO_EP1","Netting",900],
  39.                         ["Land_CamoNet_NATO_EP1","Netting",400],
  40.                         ["CampEast_EP1","Misc",1200],
  41.                         ["MASH_EP1","Misc",1500],
  42.                         ["Land_GuardShed","Misc",800],
  43.                         ["Land_Antenna","Misc",500],
  44.                         ["Misc_cargo_cont_net1","Misc",1000],
  45.                         ["Misc_cargo_cont_net2","Misc",3000],
  46.                         ["Misc_cargo_cont_net3","Misc",7000]
  47.                 ]];
  48.         };
  49.         _this setvariable ["MSO_cnstrct_usenvg",false];
  50. };
  51.  
  52. ////////////////////////////////
  53.  
  54. if (isnil "MSO_cnstrct_fnc_create") then {
  55.         MSO_cnstrct_fnc_create = {
  56.                 if ((MSO_cnstrct_preview getvariable "MSO_cnstrct_color") != COLOR_GREEN) exitwith {};
  57.                 private ["_class"];
  58.                 _class = MSO_cnstrct_preview getvariable "MSO_cnstrct_type";
  59.                 {
  60.                         if ((_x select 0) == _class) exitwith {
  61.                                 private ["_supplies"];
  62.                                 _supplies = MSO_cnstrct_center getvariable "MSO_cnstrct_supplies";
  63.                                 if (_supplies - (_x select 2) >= 0) then {
  64.                                         MSO_cnstrct_center setvariable ["MSO_cnstrct_supplies", _supplies - (_x select 2)];
  65.                                         private ["_direction","_position","_object"];
  66.                                         _direction = getdir MSO_cnstrct_preview;
  67.                                         _position = screentoworld [0.5,0.5];
  68.                                         _object = createvehicle [_class,_position,[],0,"NONE"];
  69.                                         _object setdir _direction;
  70.                                         _object setpos _position;
  71.                                         [MSO_cnstrct_center,"MSO_cnstrct_buildings",_object,true] call bis_fnc_variablespaceadd;
  72.                                 };
  73.                                 deletevehicle MSO_cnstrct_preview;
  74.                         };
  75.                 } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_items");
  76.         };
  77.         MSO_cnstrct_fnc_handler = {
  78.                 private ["_terminate"];
  79.                 _terminate = false;
  80.  
  81.                 private ["_keyscancel","_keysnvg","_keyssell"];
  82.                 _keyscancel     = (actionKeys "MenuBack") + [1];
  83.                 _keysnvg = actionKeys "NightVision";
  84.                 _keyssell = actionKeys "Compass";
  85.                
  86.                 private ["_key","_shift","_ctrl","_alt"];
  87.                 _key = _this select 1;
  88.                 if (count _this > 5) then {
  89.                         //mouse
  90.                         //_shift = _this select 4;
  91.                         _ctrl = _this select 5;
  92.                         //_alt = _this select 6;
  93.                 } else {
  94.                         //keyboard
  95.                         //_shift = _this select 2;
  96.                         _ctrl = _this select 3;
  97.                         //_alt = _this select 4;
  98.                 };
  99.                 if !(isnil {MSO_cnstrct_center getvariable "MSO_cnstrct_busy"}) exitwith {
  100.                         sleep 0.2;
  101.                         MSO_cnstrct_center setvariable ["MSO_cnstrct_busy",nil];
  102.                 };
  103.                 MSO_cnstrct_center setvariable ["MSO_cnstrct_busy",true];              
  104.                
  105.                 ////////////////////////////////
  106.                 if ((_key == 0) and (not isnull MSO_cnstrct_preview) and (not _ctrl)) then {
  107.                         [] call MSO_cnstrct_fnc_create;
  108.                         [] call MSO_cnstrct_fnc_refresh;
  109.                 } else {
  110.                         if (_key in _keyscancel) then {
  111.                                 switch (tolower(typename MSO_cnstrct_params)) do {
  112.                                         case "scalar" : {
  113.                                                 [] call MSO_cnstrct_fnc_refresh;
  114.                                         };
  115.                                         case "string" : {
  116.                                                 deletevehicle MSO_cnstrct_preview;
  117.                                                
  118.                                         };
  119.                                         default {
  120.                                                 if (not isnull MSO_cnstrct_preview) then {
  121.                                                         [] call MSO_cnstrct_fnc_refresh;
  122.                                                         deletevehicle MSO_cnstrct_preview;
  123.                                                 } else {
  124.                                                         _terminate = true;
  125.                                                 };
  126.                                         };
  127.                                 };
  128.                         };
  129.                         if (_key in _keyssell) then {
  130.                                 [] call MSO_cnstrct_fnc_sell;
  131.                         };
  132.                         if (_key in _keysnvg) then {
  133.                                 if (player hasweapon "NVGoggles") then {
  134.                                         private ["_bool"];
  135.                                         _bool = not (MSO_cnstrct_center getvariable "MSO_cnstrct_usenvg");
  136.                                         MSO_cnstrct_center setvariable ["MSO_cnstrct_usenvg",_bool];
  137.                                         camusenvg _bool;
  138.                                 };
  139.                         };
  140.                 };
  141.                 if (_terminate) then {
  142.                         if (not isnull MSO_cnstrct_preview) then {
  143.                                 deletevehicle MSO_cnstrct_preview;
  144.                         };
  145.                         MSO_cnstrct_center = nil;
  146.                         MSO_cnstrct_preview = nil;
  147.                 };
  148.         };
  149.         MSO_cnstrct_fnc_refresh = {
  150.                 MSO_cnstrct_params = false;
  151.                 showcommandingmenu "";
  152.                 showcommandingmenu "#USER:MSO_cnstrct_menu_0";
  153.         };
  154.         MSO_cnstrct_fnc_sell = {
  155.                 private ["_position","_object"];
  156.                 _position = screentoworld [0.5,0.5];
  157.                 _object = _position nearestobject "all";
  158.                 if (isnull _object) exitwith {};
  159.                 if (_object distance _position > 7) exitwith {};
  160.                 private ["_type"];
  161.                 _type = typeof _object;
  162.                 {
  163.                         if ((_x select 0) == _type) exitwith {
  164.                                 MSO_cnstrct_center setvariable ["MSO_cnstrct_supplies", (MSO_cnstrct_center getvariable "MSO_cnstrct_supplies") + (_x select 2)];
  165.                                 [MSO_cnstrct_center,"MSO_cnstrct_buildings",_object,true] call bis_fnc_variablespaceremove;
  166.                                 deletevehicle _object;
  167.                         };
  168.                 } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_items");
  169.         };
  170.         MSO_cnstrct_fnc_update = {
  171.                 private ["_supplies"];
  172.                 _supplies = MSO_cnstrct_center getvariable "MSO_cnstrct_supplies";
  173.                 ((uinamespace getvariable "BIS_CONTROL_CAM_DISPLAY") displayctrl 112224) ctrlsetstructuredtext (parsetext format["<t color='#ddffdd' size='2.2'>S%1</t>",_supplies]);
  174.                 switch (tolower(typename MSO_cnstrct_params)) do {
  175.                         case "scalar" : {
  176.                                 //open menu
  177.                                 private ["_i"];
  178.                                 _i = 0;
  179.                                 {
  180.                                         private ["_category"];
  181.                                         _category = _x;
  182.                                         if (_i == MSO_cnstrct_params) exitwith {
  183.                                                 private ["_types","_names","_enabled"];
  184.                                                 _types = []; _names = []; _enabled = [];
  185.                                                 {
  186.                                                         if (_category == (_x select 1)) then {
  187.                                                                 private ["_type","_cost"];
  188.                                                                 _type = _x select 0;
  189.                                                                 _cost = _x select 2;
  190.                                                                 _types = _types + [_type];
  191.                                                                 _names = _names + [(gettext (configfile >> "CfgVehicles" >> _type >> "displayName")) + format ["        %1", _cost]];
  192.                                                                 _enabled = _enabled + [if (_supplies - _cost >= 0) then {1} else {0}];
  193.                                                         };
  194.                                                 } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_items");
  195.                                                 [[_category,true],"MSO_cnstrct_menu2",[_types,_names,_enabled],"","MSO_cnstrct_params = '%1'; showcommandingmenu ''"] call BIS_fnc_createmenu;
  196.                                         };
  197.                                         _i = _i + 1;
  198.                                 } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_categories");
  199.                                 showcommandingmenu "#USER:MSO_cnstrct_menu2_0";
  200.                         };
  201.                         case "string" : {
  202.                                 //create preview
  203.                                 private ["_class","_position"];
  204.                                 _class = MSO_cnstrct_params;
  205.                                 MSO_cnstrct_params = false;
  206.                                 showcommandingmenu "";
  207.                                 if (_class == "") exitwith {};
  208.                                 _position = screentoworld [0.5,0.5];
  209.                                 if (_position distance MSO_cnstrct_center > (MSO_cnstrct_center getvariable "MSO_cnstrct_radius")) exitwith {};
  210.                                 private ["_camera","_ghost"];
  211.                                 _camera = MSO_cnstrct_center getvariable "MSO_cnstrct_camera";
  212.                                 _ghost = gettext (configfile >> "CfgVehicles" >> _class >> "ghostpreview");
  213.                                 if (_ghost == "") then {_ghost = _class};
  214.                                 MSO_cnstrct_preview = _ghost createvehiclelocal _position;
  215.                                 MSO_cnstrct_preview setvariable ["MSO_cnstrct_type",_class];
  216.                                 MSO_cnstrct_preview setobjecttexture [0,COLOR_GRAY];
  217.                                 _camera camsettarget MSO_cnstrct_preview;
  218.                                 _camera camcommit 0;
  219.                                 while {not isnull MSO_cnstrct_preview} do {
  220.                                         private ["_color","_position"];
  221.                                         _position = getpos MSO_cnstrct_preview;
  222.                                         _color = if (count (_position isflatempty [(sizeof _class) / 4,0,0.8,(sizeof _class),0,false,MSO_cnstrct_preview]) > 0) then {COLOR_GREEN} else {COLOR_GRAY};
  223.                                         MSO_cnstrct_preview setobjecttexture [0,_color];
  224.                                         if (_position distance MSO_cnstrct_center > (MSO_cnstrct_center getvariable "MSO_cnstrct_radius")) exitwith {
  225.                                                 deletevehicle MSO_cnstrct_preview;
  226.                                                 [] call MSO_cnstrct_fnc_refresh;
  227.                                         };
  228.                                         MSO_cnstrct_preview setvariable ["MSO_cnstrct_color",_color];
  229.                                         sleep 0.2;
  230.                                 };
  231.                         };
  232.                         default {
  233.                                 [] call MSO_cnstrct_fnc_refresh;
  234.                         };
  235.                 };
  236.         };
  237. };
  238.  
  239. ////////////////////////////////
  240.  
  241. disableserialization;
  242.  
  243. private ["_position","_viewdistance"];
  244. _position = getpos _this;
  245. _viewdistance = viewdistance;
  246. setviewdistance ((_this getvariable "MSO_cnstrct_radius") max 50);
  247.  
  248. _camera = "camconstruct" camcreate [_position select 0, _position select 1, 5];
  249. _camera cameraeffect ["internal","back"];
  250. _camera campreparefov 0.900;
  251. _camera campreparefocus [-1,-1];
  252. _camera camcommitprepared 0;
  253. cameraeffectenablehud true;
  254. _camera camConstuctionSetParams ([_position] + [_this getvariable "MSO_cnstrct_radius",10]);
  255. BIS_CONTROL_CAM = _camera;
  256.  
  257. showcinemaborder false;
  258. 1122 cutrsc ["constructioninterface","plain"];
  259.  
  260. ////////////////////////////////
  261.  
  262. MSO_cnstrct_center = _this;
  263. MSO_cnstrct_params = "";
  264. MSO_cnstrct_preview = objnull;
  265. MSO_cnstrct_center setvariable ["MSO_cnstrct_camera",_camera];
  266. MSO_cnstrct_center setvariable ["MSO_cnstrct_usenvg",false];
  267.  
  268. ////////////////////////////////
  269.  
  270. private ["_display"];
  271. _display = findDisplay 46;
  272.  
  273. private ["_keydown","_keyup","_mousedown"];
  274. _keydown = _display displayaddeventhandler ["KeyDown","0 = _this spawn MSO_cnstrct_fnc_handler;"];
  275. _keyup = _display displayaddeventhandler ["KeyUp","0 = _this spawn MSO_cnstrct_fnc_handler;"];
  276. _mousedown = _display displayaddeventhandler ["MouseButtonDown","0 = _this spawn MSO_cnstrct_fnc_handler;"];
  277.  
  278. ////////////////////////////////
  279.  
  280. [["Categories",true],"MSO_cnstrct_menu",_this getvariable "MSO_cnstrct_categories","","MSO_cnstrct_params = %2"] call BIS_fnc_createmenu;
  281. [] call MSO_cnstrct_fnc_refresh;
  282.        
  283. ////////////////////////////////
  284.  
  285. while {not isnil "MSO_cnstrct_center"} do {
  286.         [] call MSO_cnstrct_fnc_update;
  287.         sleep 0.2;
  288. };
  289.  
  290. ////////////////////////////////
  291.  
  292. _camera cameraeffect ["terminate","back"];
  293. camdestroy _camera;
  294. 1122 cuttext ["","plain"];
  295. BIS_CONTROL_CAM = nil;
  296. showcommandingmenu "";
  297.  
  298. setviewdistance _viewdistance;
  299.  
  300. _display displayremoveeventhandler ["KeyDown",_keydown];
  301. _display displayremoveeventhandler ["KeyUp",_keyup];
  302. _display displayremoveeventhandler ["MouseButtonDown",_mousedown];