Jump to content
HereIsJones

Deleting simple objects

Recommended Posts

Hi, I have a problem deleting simple objects.

 

I spawn a number of simple and "normal" objects in a 150m radius using this code:

//simple object
_thisObject = createSimpleObject [_thisClass, _thisPos, true];

//normal object
_thisObject = createVehicle [_thisClass, _thisPos, [], 0, "CAN_COLLIDE"];

But when I try to delete those objects with this code, it only deletes the "normal" objects:

{deleteVehicle _x} forEach nearestObjects [_centerPos, ["all"], 150];

It turns out, nearestObjects only locates the "normal" objects, not the simple objects spawned in with createSimpleObject.

 

The wiki says that simple objects can be deleted with deleteVehicle, but how do I get a handle on a group of them within a specific radius in order to use that command? Is there some equivalent to nearestObjects for simple objects?

Share this post


Link to post
Share on other sites

Maybe add them to an array as you create them, so you can reference them later? Obviously adds another layer of complexity on both ends.

  • Thanks 1

Share this post


Link to post
Share on other sites

I actually have an array, but I tried testing this with:

if (typeof _x == "Land_WoodenCounter_01_F") then {deleteVehicle _x};

That will delete "normal" objects, including objects that are hand-placed in the editor, but it doesn't recognize simple objects.

 

I don't know of another way to use an array to get a handle on a group of objects. Wouldn't you need to create an individual pointer or variable name for each object?

Share this post


Link to post
Share on other sites
4 minutes ago, HereIsJones said:

Wouldn't you need to create an individual pointer or variable name for each object?

 

Not necessarily? I think? It should be enough to check the array for elements within your desired area.

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

I guess my question is, how do you use an array element to point to a simple object?  Here's my array:

_compSimple =
[
      ["Land_CncBarrier_stripes_F",[11068,8464.88,0],[[0,1,0],[0,0,1]]],
      ["Land_WoodenCounter_01_F",[11077.9,8467.94,0],[[0.1793,0.983794,0],[0,0,1]]],
      ["Land_PaperBox_01_small_ransacked_brown_F",[11079.4,8466.79,0],[[0.792886,-0.609371,0],[0,0,1]]],
      ["Land_FoodSacks_01_small_brown_F",[11077.3,8470.54,0.815598],[[0.998695,-0.0510703,0],[0,0,1]]],
      ["Land_FoodSack_01_full_brown_F",[11077.3,8469.66,0.814713],[[0.984472,0.175543,0],[0,0,1]]],
      ["Land_LiquidDispenser_01_F",[11078.5,8467.7,0.960007],[[-0.0663435,-0.997797,0],[0,0,1]]],
      ["Land_MarketShelter_F",[11077.4,8474.25,0.479996],[[1,-4.37114e-008,0],[0,0,1]]]
];

I have a class name, position and rotational data in it. What code would you use to grab the actual object with this, seeing that nearestObjects and TypeOf don't work? I suppose it would have to use the class name, but I don't know what the command would be.

 

EDIT: isKindOf doesn't work either. It deletes the "normal" object but not the simple object.

Share this post


Link to post
Share on other sites

Works! Let it be known that nearObjects is the only way to get a handle on simple objects, and also that sarogahtyp is a dang genius.

 

EDIT: Also, it turns out that nearObjects will pick up every object including triggers, so adjust your code accordingly.

  • Like 1

Share this post


Link to post
Share on other sites

I guess the angle I was taking was more along the lines of:

{
  if (_x in _array && (_x distance _center < 150)) then {deleteVehicle _x}
} forEach _array;

But my understanding was that you just wanted to delete ALL simple objects in your array within an area.

Like this:

nul = [] spawn {
    _array = [];
    for "_i" from 0 to 9999 do 
    { 
        _obj = createSimpleObject ["A3\Structures_F\Civ\Ancient\AncientPillar_F.p3d",[0,0,0]]; 
        _pos = [["center"],[]] call BIS_fnc_randomPos;
        _obj setPosATL _pos;
      _array pushback _obj;
    };

    sleep 5;

    _center = getMarkerPos "center";

    {
        if (_x in _array && (_x distance _center < 150)) then {deleteVehicle _x}
    } forEach _array;
};

nu06x5h.jpg

 

Of course, nearObjects is far more elegant.

  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, Harzach said:

I guess the angle I was taking was more along the lines of:


{
  if (_x in _array && (_x distance _center < 150)) then {deleteVehicle _x}
} forEach _array;

 

 

Ah, ok I get it now. I had an array of class names, but you created an array of objects at the point of object creation. That would have worked as well.

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

×