Jump to content
johnnyboy

[Release] JBOY Move Collection of Objects script

Recommended Posts

Here's another byproduct of my Property of Mabunga mission.   This script will move a collection of objects you defined in Eden Editor from one position to another.  Its useful when you define a complex collection of items for a base, camp, buiding interior etc., that you want to dyanmically move to another location.  Here's a short demonstration:

 

 

After you have defined a set of objects, choose one to be the "source object".  Then at a different location, create another object of the same type to be the "target object".  You can orient that "target object" differently than the source object.  I put the following line of code in my init.sqf to move the objects from source location to target location:

dummy = [ammoHouse, ammoHouse2, 10] execVM "Scripts\JBOY_MoveNearObjects.sqf";

The parameters are:  [sourceObject, targetObject, RadiusToLookForObjectstoMove]

 

Create a script file named JBOY_MoveNearObjects.sqf in your mission directory, and put this code in that file:

//////////////////////////////////////////////////////////
// JBOY_MoveNearObjects.sqf 
// By: johnnyboy
// dummy = [ammoHouse, ammoHouse2, 10] execVM "Scripts\JBOY_MoveNearObjects.sqf";
//////////////////////////////////////////////////////////

_houseFrom = _this select 0;
_houseTo = _this select 1;
_radius = _this select 2;

_fromDir = getdir _houseFrom;
_toDir = getdir _houseTo;

_houseTo setdir _fromDir;

_pos = getposasl _houseTo;

_zOffset = 0;
if ((getpos _houseFrom select 2) > (getpos _houseTo select 2)) then 
{
   _zOffset = abs((getpos _houseFrom select 2) - (getpos _houseTo select 2)) *-1;
} else {
   _zOffset = abs((getpos _houseFrom select 2) - (getpos _houseTo select 2));
};

// Load all objects within radius into an array
_objs = []; 
{
    if ((   str typeof _x find "Land_" > -1 
         or str typeof _x find "Box_" > -1 
         or str typeof _x find "I_" > -1 
         or str typeof _x find "O_" > -1 
         or str typeof _x find "B_" > -1) 
         and !(_x == _houseFrom)) then {
        _objs pushBack _x;
    };
} forEach nearestObjects [_houseFrom, [], _radius];
{
    _x enableSimulation false;
    _wtmPos =  _houseFrom worldToModel (_x modelToWorld [0,0,0]);
    _x attachTo [_houseFrom, _wtmPos];
 } foreach _objs;
deleteVehicle _houseTo;
_houseFrom setDir _toDir;
sleep .1;
_houseFrom setposasl _pos;
sleep 1;
{detach _x; sleep .2; _x setdamage 0;} foreach _objs;
sleep 1;
{_x enablesimulation true; _x setdamage 0;} foreach _objs;
sleep 1;

/*
// stack some ammo boxes after they've been moved and physics has settled.
// If I try to pre-stack them, and have this script move them, the physics tends
// to make them fall over, so you have a jumbled mess of ammo crates.
// So I only put one ammo crate down in editor, and Move script moves that ammocrate
// then 10 seconds later below code stacks more objects on top of the named ammo crates (without falling over!).
sleep 10;
dummy = [ammo1, 2] execVM "Scripts\JBOY_StackObjects.sqf";
dummy = [ammo1a, 2] execVM "Scripts\JBOY_StackObjects.sqf";
dummy = [ammo2, 3] execVM "Scripts\JBOY_StackObjects.sqf";
dummy = [ammo3, 2] execVM "Scripts\JBOY_StackObjects.sqf";
dummy = [ammo4, 3] execVM "Scripts\JBOY_StackObjects.sqf";
dummy = [roofBox1, 1] execVM "Scripts\JBOY_StackObjects.sqf";
dummy = [roofBox2, 1] execVM "Scripts\JBOY_StackObjects.sqf";
*/

Warning:  NearObjects finds insects and other strange objects you don't want to move, so this code is currently hardcoded to move soldiers, houses, and ammo boxes via code snippet below.  You may need to modify this part of the code so it finds other types of objects you want it to move:

    if ((   str typeof _x find "Land_" > -1 
         or str typeof _x find "Box_" > -1 
         or str typeof _x find "I_" > -1 
         or str typeof _x find "O_" > -1 
         or str typeof _x find "B_" > -1) 
         and !(_x == _houseFrom)) then {
        _objs pushBack _x;
    };
  • Like 5

Share this post


Link to post
Share on other sites

Pretty genius! I've been using a much simpler beginner's concept of this to setposworld mission assets to specific start points randomly selected from an initial array, in my init.sqf. Just like with your shack, it's a random experience each time, but each choice is specified in a way that purely random position generators can't do perfectly (even with as many parameters like Zenophon's framework for position functions). I specifically placed a bunch of vehicles in tiny residential garages or similarly tight quarters, for instance.

This is pretty cool b/c it's a composition version of that setpos hack in lieu of imprecise random spawning. Is there no easy way to directly get the positioning of the objects relative to the source shack, then rotate everything around a common point to the target shack's orientation before/during setpos translation to the target shack? I'm suspecting that's the case, since you went with this route.

  • Like 1

Share this post


Link to post
Share on other sites

Hi dakaodo.  True random positioning is always cool too, but my precise approach guarantees the object is oriented in the best direction for each of the chosen settings.  There is a place for both approaches I think.

 

 

Is there no easy way to directly get the positioning of the objects relative to the source shack, then rotate everything around a common point to the target shack's orientation before/during setpos translation to the target shack? I'm suspecting that's the case, since you went with this route.

I'm not sure I understand your question.  By attaching all the objects to the source shack before moving it, you gurantee all the relative positions without having to record them in an array, and you can setdir the shack once its at the target location in any direction and attached objects keep their relative position to moved shack. 

  • Like 1

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

×