Jump to content
Sign in to follow this  
johnnyboy

[Release] JBOY Fix Rooftop AI in Air after building destroyed (EH script)

Recommended Posts

Here's another byproduct of my Property of Mabunga mission.

 

Problem:  When units are on building roofs and are killed, their dead body is no longer affected by physics.  So when building is destroyed, the dead bodies are suspended in air and look dumb, and ruin immersion.

 

Solution:  Add my JBOY_AddRooftopKilledEH.sqf script to each unit placed on a rooftop.  Here's a short demonstration:

 

 

Put this code in rooftop AI unit's init:

null=[this] execvm "Scripts\JBOY_AddRooftopKilledEH.sqf" ; 
doStop this; 
this forceSpeed 0;

Note that the "doStop" and "forcespeed 0" are to keep the unit from walking off the roof.

 

Create a file in your mission directory called JBOY_AddRooftopKilledEH.sqf, and put this code in it:

// *****************************************************
// ** JBOY_AddRooftopKilledEH.sqf 
// ** by JohnnyBoy
// ** This script insures dead units on top of building will fall to ground if building destroyed.
// ** Prevents seeing dead units suspended in air which kills immersion.
// ** Start with an eventhandler:
// ** Put this in unit's init:   null=[this] execvm "Scripts\JBOY_AddRooftopKilledEH.sqf" ;
// *****************************************************
_dude = _this select 0; 
dmy = _dude addEventHandler ["killed", 
{
    _unit = _this select 0; 
    // use falling screwdriver to determine when building destroyed (i.e., screwdriver will be on roof until building destroyed, at which point it falls)
    _obj = "Land_Screwdriver_V1_F" createvehicle [0,0,0];
    //_obj setMass (getMass _obj*100);  // set mass high so less likely to fly when building blown up.
    _obj enableCollisionWith _unit;
    _pos = getposasl _unit;
    _obj setposasl [_pos select 0, _pos select 1, (_pos select 2) +.3];
    _dmy = [_unit, _obj,_pos] spawn 
    {
      _unit = _this select 0;
       _obj = _this select 1;
      _pos = _this select 2;
      sleep .3;
      _objPos = getPosASL _obj;
      _objZ = getposasl _obj select 2;
      waitUntil {sleep .1; (getposasl _obj) select 2 < _objZ -.4};
      _texture = getobjecttextures _unit select 0;
       deleteVehicle _unit;
      _unit2 = (typeOf _unit) createvehicle [0,0,0];
      _unit2 removeWeapon PrimaryWeapon _unit2;
      removeHeadgear _unit2;
      removeGoggles _unit2;
     
      _unit2 setUnitPos "DOWN";
      _unit2 setpos [_pos select 0, _pos select 1, 0];
      _unit2 setobjecttexture [0,_texture];
      sleep .2;
      _unit2 setdamage 1;   
    };
}];
  • Like 8

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×