Guest User

fn_dressUp for Dynamic Objects

a guest
Nov 14th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.93 KB | None | 0 0
  1. span class="re5"> params["_house"];
  2.  
  3. private _objects = [];
  4.  
  5. //Blacklist check
  6. if (_house getVariable ["tint_house_dressed", false] || {_house getVariable ["tint_house_blacklisted", false]} || {!(alive _house)}) exitWith {};
  7. _house setVariable ["tint_house_dressed", true];
  8.  
  9. //If house has already been initialized, then we just load the positions
  10. if (_house getVariable ["tint_house_initialized", false]) then {
  11.   {
  12.     _x params ["_type", "_pos", "_dir", "_up"];
  13.     private _obj = createSimpleObject [_type, [0,0,0], true];
  14.     _obj setVectorDirAndUp [_dir, _up];
  15.     _obj setPosWorld _pos;
  16.     _obj enableSimulation false;
  17.     _objects append [_obj];
  18.   } forEach (_house getVariable "tint_house_composition");
  19. } else {
  20. //If not, then we load and calculate compositions
  21.  
  22.   //Check whether it uses a parent class
  23.   private _class = [_house getVariable "tint_house_class"] call tint_fnc_translate;
  24.   private _compositions = tint_compNamespace getVariable [_class, [[]]];
  25.  
  26.   //Select one of the compositions to use
  27.   private _compCount = count _compositions;
  28.   private _index = 0;
  29.  
  30.   //If there is only one
  31.   if (_compCount == 1) then {
  32.     _index = 0;
  33.   } else {
  34.     _pos = getPos _house;
  35.     _index = _house getVariable ["tint_house_index", -1];
  36.    
  37.    
  38.     if (_index < 0) then {
  39.       //Choose a random, but MP consistent index based on position and seed
  40.       _index = (round((((_pos#1+_pos#2) * 10) * tint_seed)) % _compCount) max 0;
  41.     } else {
  42.       //If the composition index has been set by the mission maker, ensure it's within range
  43.       _index = (_index % (_compCount - 1));
  44.     };
  45.    
  46.   };
  47.   _house setVariable ["tint_house_index", _index];
  48.   //IMPORTANT, ARRAY IS A REFERENCE TYPE AAAAAAAAA
  49.   private _composition = +(_compositions#_index);
  50.  
  51.   //Dress up house while saving compositions
  52.   for "_i" from (count _composition - 1) to 0 step -1 do {
  53.     _cur = _composition#_i;
  54.     _cur params ["_type", "_relPos", "_relDir", "_relUp"];
  55.    
  56.     _dynamicList = ["Box_East_Wps_F","Box_IND_AmmoOrd_F"]; // <----- ADD CLASSNAMES HERE, FOR OBJECTS TO BE SPAWNED IN AS DYNAMIC OBJECTS.
  57.     _filterChecker = _dynamicList find _type;       // <----- Checks if _type is in _dynamicList
  58.  
  59.     if (_filterChecker < 0 ) then    // <----- If is NOT in _dynamicList do the normal thing.
  60.     {
  61.         private _obj = createSimpleObject [_type, [0,0,0], true];
  62.         _absDir = _house vectorModelToWorld _relDir;
  63.         _absUp = _house vectorModelToWorld _relUp;
  64.         _obj setVectorDirAndUp [_absDir, _absUp];
  65.         _cur set [2, _absDir];
  66.         _cur set [3, _absUp];
  67.        
  68.         _relPos = _relPos vectorDiff (boundingCenter _house);
  69.         _absPos = _house modelToWorldWorld _relPos;
  70.         _obj setPosWorld _abspos;
  71.         _cur set [1, _absPos];
  72.         _objects append [_obj];
  73.  
  74.         _obj enableSimulation false;
  75.  
  76.     }
  77.     else    // <----- If is in _dynamicList, Create as Dynamic Object.
  78.     {
  79.         private _obj = _type createVehicle  [0,0,0];
  80.         _absDir = _house vectorModelToWorld _relDir;
  81.         _absUp = _house vectorModelToWorld _relUp;
  82.         _obj setVectorDirAndUp [_absDir, _absUp];
  83.         _cur set [2, _absDir];
  84.         _cur set [3, _absUp];
  85.        
  86.         _relPos = _relPos vectorDiff (boundingCenter _house);
  87.         _absPos = _house modelToWorldWorld _relPos;
  88.         _obj setPosWorld _abspos;
  89.         _cur set [1, _absPos];
  90.  
  91.         _obj enableDynamicSimulation true;  // <----- Sets the Object to Dynamic
  92.  
  93.         _objects append [_obj];    
  94.     }; 
  95.   };
  96.  
  97.   //Send out calculations to other computers
  98.   [_house, _composition] remoteExecCall ["tint_fnc_updateHouse", 0];
  99. };
  100.  
  101.  
  102. private _ehd = _house addEventHandler ["dammaged", {
  103.     [{
  104.         params ["_house"];
  105.         if (!alive _house) then {
  106.             [_house] call tint_fnc_dressDown;
  107.         };
  108.     }, _this, 0.1] call cba_fnc_waitAndExecute;
  109. }];
  110. _house setVariable ["tint_house_damagedEH", _ehd];
  111. private _eh = _house addEventHandler ["killed", {params ["_house"];[_house] call tint_fnc_dressDown;}];
  112. _house setVariable ["tint_house_killedEH", _eh];
  113. _house setVariable ["tint_house_objects", _objects];
  114.  
Advertisement
Add Comment
Please, Sign In to add comment