player2_dz

p2_inspectLoop.sqf

Aug 29th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.38 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. Player2's Inspect Item Script
  3. Version: 1.0
  4. ---------------------------------------------------------------------------*/
  5.  
  6. /*--Configuration Options----------------------------------------------------
  7. ---------------------------------------------------------------------------*/
  8.  
  9. //enable/disable this script (you could do it here or just remove its execVM, up to you m8)
  10. P2_INSPECT_ENABLE = true;
  11. //distance at which items can be inspected (default: 2.75)
  12. P2_INSPECT_DISTANCE = 2.75;
  13.  
  14. /*--End of Configuration Options---------------------------------------------
  15. ---------------------------------------------------------------------------*/
  16.  
  17. /*--Start of Script----------------------------------------------------------
  18. ---------------------------------------------------------------------------*/
  19.  
  20. //set up global vars
  21. INSPECT_ITEM_ACTIONS = [];
  22.  
  23. //ensure user didnt fuck up the config
  24. if (isNil 'P2_INSPECT_DISTANCE') then { P2_INSPECT_DISTANCE = 2.75; };
  25. if (isNil 'P2_INSPECT_ENABLE') then { P2_INSPECT_ENABLE = true; };
  26.  
  27. //  make sure key function exists / hasnt been renamed by exile mod team
  28. //declare these
  29. private["_timeSlept","_errorMsg","_quit"];
  30. //initialise these
  31. _timeSlept  = 0;
  32. _errorMsg   = "P2_INSPECT: Error - ExileMod has removed or renamed the key function 'ExileClient_gui_itemDetails_show'";
  33. _quit       = false;
  34.  
  35. waitUntil{
  36.     //wait 10 seconds per check
  37.     uiSleep 10;
  38.     //add to total time waited so far
  39.     _timeSlept = _timeSlept + 10;
  40.     //wait up to 30 seconds for function to be defined
  41.     if (_timeSlept > 30) exitWith {
  42.         //30 second limit reached, function isnt gonna be found bruh
  43.         _quit = true;
  44.     };
  45.  
  46.     //if function exists, continue
  47.     !isNil 'ExileClient_gui_itemDetails_show';
  48. };
  49.  
  50. //output error messages before quitting
  51. if (_quit) exitWith {
  52.     systemChat(_errorMsg);
  53.     diag_log(_errorMsg);
  54. };
  55.  
  56. //start loop
  57. while {P2_INSPECT_ENABLE} do {
  58.     //declare this here instead of down there because it is used in both scopes
  59.     private["_nearObjects"];
  60.  
  61.     //get near objects (P2_INSPECT_DISTANCE meters)
  62.     _nearObjects = player nearObjects P2_INSPECT_DISTANCE;
  63.  
  64.     //wait a moment so we retrieve the objects properly (script would only fail without this on super slow systems surrounded by items)
  65.     sleep 0.01;
  66.  
  67.     //for all nearby objects found
  68.     {
  69.         //declare our private vars for this scope
  70.         private ["_obj", "_mags", "_weps", "_bags", "_items", "_full"];
  71.  
  72.         //store current object
  73.         _obj = _x;
  74.  
  75.         //if object not the player themselves
  76.         if (player != _obj && ((vehicle player) != _obj) && !isNull _obj && (typeOf _obj == "GroundWeaponHolder")) then {
  77.  
  78.             //get object contents
  79.             _mags  = getMagazineCargo   _obj;
  80.             _weps  = getWeaponCargo     _obj;
  81.             _bags  = getBackpackCargo   _obj;
  82.             _items = getItemCargo       _obj;
  83.  
  84.             //we only want the classnames, not the amount of items there are, so we select 0
  85.             _mags  = _mags  select 0;
  86.             _weps  = _weps  select 0;
  87.             _bags  = _bags  select 0;
  88.             _items = _items select 0;
  89.  
  90.             //combine object contents into 1 array
  91.             _full = []; _full = _mags + _weps + _bags + _items;
  92.  
  93.             //if there are items in the object
  94.             if (count _full > 0) then {
  95.  
  96.                 //for all things inside the object
  97.                 {
  98.                     //declare our privates for this scope
  99.                     private ["_itemClassName", "_configName", "_itemDispName", "_inspectActionText", "_inspectAction"];
  100.  
  101.                     //store classname
  102.                     _itemClassName = _x;
  103.  
  104.                     //retrieve configname
  105.                     _configName = _itemClassName call ExileClient_util_gear_getConfigNameByClassName;
  106.  
  107.                     //retrieve item display name
  108.                     _itemDispName = getText (configFile >> _configName >> _itemClassName >> "displayname");
  109.  
  110.                     //Create inspect text
  111.                     _inspectActionText = ("Inspect " + _itemDispName);
  112.  
  113.                     //Add scroll action
  114.                     _inspectAction = player addAction [
  115.                         _inspectActionText, //scroll text
  116.                         //code that gets run when action is clicked
  117.                         {
  118.                             //needed since we're calling a dialog script
  119.                             disableSerialization;
  120.                             //use input vars (see below) to call up the item detail menu
  121.                             [_this select 3 select 0, _this select 3 select 1] call ExileClient_gui_itemDetails_show;
  122.                             //ensure that while the menu is open that the consume/construct/inspect buttons cannot be clicked
  123.                             [] spawn {
  124.                                 disableSerialization;
  125.                                 //while dialog is open
  126.                                 while {(str(uiNameSpace getVariable ["RscExileItemDetailsDialog", displayNull]) != "No display")} do {
  127.                                     _dialog = uiNameSpace getVariable ["RscExileItemDetailsDialog", displayNull];
  128.                                     (_dialog displayCtrl 1300) ctrlEnable false; //disable consume button
  129.                                     (_dialog displayCtrl 1301) ctrlEnable false; //disable inspect button
  130.                                     (_dialog displayCtrl 1303) ctrlEnable false; //disable construct button
  131.                                 };
  132.                             };
  133.                         },
  134.                         //vars parsed to code (see above)
  135.                         [_configName, _itemClassName],
  136.                         //priority (lower the number the lower priority)
  137.                         0,
  138.                         //show text in center screen
  139.                         false,
  140.                         //hide on use?
  141.                         false
  142.                     ];
  143.  
  144.                     //add action to our array of all inspect actions
  145.                     INSPECT_ITEM_ACTIONS set [count INSPECT_ITEM_ACTIONS, _inspectAction];
  146.  
  147.                 } count _full;
  148.  
  149.                 //wait until player is no longer near the object or the object is null
  150.                 waitUntil {
  151.                     //lonely private var is lonely
  152.                     private["_dist"];
  153.                     //hold up a moment, we dont want to run this every 0.00001 seconds now do we?
  154.                     uiSleep 0.1;
  155.                     //if undefined it should default to this and assume the items gone and exit
  156.                     _dist = P2_INSPECT_DISTANCE + 1;
  157.                     //if item not found, it is null
  158.                     if (isNil '_obj') then { _obj = objNull; };
  159.                     //if item not null, check distance from it
  160.                     if (!isNull _obj) then {
  161.                         _dist = player distance _obj;
  162.                     //if item is null, then set distance to > P2_INSPECT_DISTANCE so it exits
  163.                     } else {
  164.                         _dist = P2_INSPECT_DISTANCE + 1;
  165.                     };
  166.                     //if item distance > P2_INSPECT_DISTANCE, then exit, otherwise keep loopin'
  167.                     (_dist > P2_INSPECT_DISTANCE)
  168.                 };
  169.  
  170.                 //remove all actions now that player has moved away from object
  171.                 { player removeAction _x } count INSPECT_ITEM_ACTIONS;
  172.                 INSPECT_ITEM_ACTIONS = [];
  173.             };
  174.         };
  175.     } count _nearObjects;
  176.  
  177.     //wait a moment before checking nearby objects again - using uiSleep as we're not waiting for code to process
  178.     uiSleep 0.667;
  179. }; //byPlayer2
Advertisement
Add Comment
Please, Sign In to add comment