Guest User

Untitled

a guest
Aug 25th, 2024
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 2.12 KB | None | 0 0
  1. /*
  2.     Author: Grok 2, Optimized
  3.  
  4.     Description:
  5.         Calculates the size of an object based on its bounding box or defaults to a known size if not calculable.
  6.  
  7.     Parameters:
  8.         0: OBJECT or STRING - Either the object itself or its class name.
  9.  
  10.     Returns:
  11.         NUMBER - The largest dimension of the object, or a default size if not calculable.
  12.  
  13.     Example:
  14.         _size = ["B_supplyCrate_F"] call PatrolOps_fnc_getObjectSize;
  15.         // or with an object
  16.         _size = [player] call PatrolOps_fnc_getObjectSize;
  17. */
  18.  
  19. params [["_object", objNull, [objNull, ""]]];
  20.  
  21. // If a string (class name) is provided, we'll attempt to create a temporary object for measurement
  22. if (_object isEqualType "") then {
  23.     // Create a temporary object for size calculation
  24.     private _tempObject = createVehicle [_object, [0,0,0], [], 0, "CAN_COLLIDE"];
  25.     private _boundingBox = boundingBoxReal _tempObject;
  26.     deleteVehicle _tempObject; // Clean up temporary object
  27.    
  28.     if (count _boundingBox != 2) exitWith { 2 }; // Default size if bounding box can't be determined
  29.  
  30.     // Extract the dimensions from the bounding box
  31.     private _length = (_boundingBox select 1 select 0) - (_boundingBox select 0 select 0);
  32.     private _width = (_boundingBox select 1 select 1) - (_boundingBox select 0 select 1);
  33.     private _height = (_boundingBox select 1 select 2) - (_boundingBox select 0 select 2);
  34.  
  35.     // Return the largest dimension
  36.     [_length, _width, _height] call BIS_fnc_greatestNum;
  37. } else {
  38.     // For objects, proceed as before
  39.     private _boundingBox = boundingBoxReal _object;
  40.    
  41.     if (count _boundingBox != 2) exitWith { 2 }; // Default size if bounding box can't be determined
  42.  
  43.     // Extract the dimensions from the bounding box
  44.     private _length = (_boundingBox select 1 select 0) - (_boundingBox select 0 select 0);
  45.     private _width = (_boundingBox select 1 select 1) - (_boundingBox select 0 select 1);
  46.     private _height = (_boundingBox select 1 select 2) - (_boundingBox select 0 select 2);
  47.  
  48.     // Return the largest dimension
  49.     [_length, _width, _height] call BIS_fnc_greatestNum;
  50. };
Advertisement
Add Comment
Please, Sign In to add comment