Jump to content
Sign in to follow this  
iceman77

Eject crew foreach vehicle in an array

Recommended Posts

I want the crew from every boat (in an array) to simply eject. I get type array expected object. See the bottom of my script where I highlighted the problem area.

Here's the entire code:

[Landing_List,400] Spawn {
 Private ["_Boats","_Amphibious"];
 _Center = _This Select 0;
 _Radius = _This Select 1;
 _Boats = NearestObjects [_Center, ["ship"], _Radius];
 _Amphibious = NearestObjects [_Center, ["Tank"], _Radius];

    {
        For "_i" From 0 To 1 Do
        {
            While {SurfaceIsWater GetPosATL _x} Do
            {

                 {
                    _x SetVelocity [8, 0, 0];
                       If (!SurfaceIsWater GetPosATL _x) Then
                       {
                         _x Animate ["Ramp", 1];
                         _x SetVelocity [0,0,0];
                       };

                 } ForEach _Boats; 

                                 {
                                   _x SetVelocity [3, 0, 0];
                                      If (!SurfaceIsWater GetPosATL _x) Then
                                      {
                                        _x SetVelocity [0,0,0];
                                      };

                                 } ForEach _Amphibious;


                   sleep 0.1;
            };



        }


    } Foreach _Boats + _Amphibious;

   [color=#ff0000] For "_v" From 0 To Count _Boats - 1 Do 
    {
          {
            _x Action ["Eject", Vehicle _x];
          } ForEach Crew _Boats Select _v;
    };     
[/color]
};

onMapSingleClick "player setpos _pos";

here's my rtp:

[507705,8758.51,0,"XEH: PreInit Started. v1.0.0.189. MISSINIT: missionName=HIP_TEST, worldName=Ped_Peleliu, isMultiplayer=false, isServer=true, isDedicated=false"]
[507705,8758.57,0,"XEH: PreInit Finished. CACHE DISABLED? (Disable caching with cba_disable_cache.pbo): SLX_XEH_RECOMPILE=false, CBA_COMPILE_RECOMPILE=false, CBA_FUNC_RECOMPILE=false"]
[507721,8759.22,0,"XEH: PostInit Started"]
[507721,8759.24,0,"CBA_VERSIONING: cba=1.0.0.190, cba_a2=1.0.0.8, cba_oa=1.0.0.6, "]
[507721,8759.27,0,"XEH: PostInit Finished. State: _isClient=true, _isJip=false, _isDedClient=false, _isServer=true, _isDedServer=false, _playerCheckDone=true, _sp=true, _startInitDone=true, _postInitDone=true, _mpRespawn=false, _machineType=1, _sessionId=62, _level=0, _timeOut=false, _game=1, BIS_functions=L 1-1-B:1, group=L 1-1-B, player=B 1-1-K:1 (Iceman77), _playerType="WX_USMarines_Garand_m7a1", _playerGroup=B 1-1-K"]
Error in expression <Action ["Eject", Vehicle _x];
} ForEach Crew _Boats Select _v;};             };onM>
 Error position: <Crew _Boats Select _v;}; };onM>
 Error crew: Type Array, expected Object
File C:\Users\David\Documents\ArmA 2 Other Profiles\Iceman77\missions\HIP_TEST.Ped_Peleliu\init.sqf, line 54

Share this post


Link to post
Share on other sites

You can't use crew in conjunction with an array because it needs an object. I don't see why it doesn't return an object though. Try using a hint to display what's in the _boats array. It should definitely return an object and not a string or array if you use select.

Share this post


Link to post
Share on other sites

I'm not at home so don't have access to any of my debugging tools, but I wonder if the _boats is objnul for any reason? Perhaps locality? If it's in MP, the locality of the boat might change when you eject the commander, is that a possible cause?

Share this post


Link to post
Share on other sites

Couldn't test locality but this will eject all ai (crew & cargo) and keep them out:

{
  {
     unassignVehicle _x;
     _x Action ["Eject", Vehicle _x];
     [_x] allowGetIn false;

  } ForEach crew _x;
} ForEach _Boats;

Share this post


Link to post
Share on other sites

Going back to the original I think it just need brackets in around the array but as matter pointed out they will get back in.

       } ForEach Crew (_Boats Select _v);

also using leavevehicle works without the need to lock the vehicle, it also seems a slower animation, you shouldn't use it for aircraft. As it causes the plane or heli to land.

I'd be interested to know if there's a locality issue using this command.

 {
  {
      _x leaveVehicle vehicle _x;  

  } ForEach crew _x;
} ForEach _Boats;

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Thanks for all of the helpful responses guys. :) Ahh btw, this is for a SP mission with the HIP mod. That's why the ramp animation, incase you were wondering.

Edited by Iceman77

Share this post


Link to post
Share on other sites

ah, ok. its SP. rule 1 of MP mission making. its broken, it's probably locality. :-)

Share this post


Link to post
Share on other sites

LeaveVehicle works great except it is indeed too slow for my needs. As there will be artillery pounding the beach, so, I doubt any soldier will take his time getting out of the transport.:) If he's even still alive that is when he reaches the beach. Also I don't understand why I need to lock or use allowGetIn if I'm using unassignvehicle. It's making no sense that unassignvehicle alone doesn't work for this :p. Maybe I need to make sure the leader is out first, so he doesn't tell the crew to get back in? If not I suppose I can just use the extra command(s).

Share this post


Link to post
Share on other sites

I've never found the need to use anything other than unassignVehicle and the eject action personally. The AI are not great pathfinding their way off the LCM's unfortunately because they are not ejected over the side of the boat and tend to run against the side of the lcm as they try and get off. When I did an AI landing with HIP I actually used an animation plus a little extra push with setVelocity so they ran down the ramp. I also didn't put them in the cargo positions instead used attachTo, partly because I wanted to simulate a full boat without filling all 60 of the cargo slots and partly because I could just detach them where they were, disable their reaction to danger etc and then used the animation plus setVelocity. It worked quite well as it doesn't matter if they are under fire of not, they still come running down the ramp.

Share this post


Link to post
Share on other sites

Noted. I'll give it a try your way, see if I can come up with something similar. Thanks for the tips.

Share this post


Link to post
Share on other sites
I've never found the need to use anything other than unassignVehicle and the eject action personally.

It all depends on how the vehicle is created - if it is placed in the editor you need the:

[_x] allowGetIn false;

or the crew (driver / gunner / commander ) get back in.

confirmed here, and also occurred when tested by me:

http://community.bistudio.com/wiki/unassignVehicle

Share this post


Link to post
Share on other sites

Ahh okay. They are editor created. Now it makes sense, since I usually don't create editor units. But in this case, it's the most logical thing. What doesn't make sense, is why mattar isn't in ts with me:cool:

Edited by Iceman77

Share this post


Link to post
Share on other sites
I actually used an animation plus a little extra push with setVelocity so they ran down the ramp. I also didn't put them in the cargo positions instead used attachTo, partly because I wanted to simulate a full boat without filling all 60 of the cargo slots and partly because I could just detach them where they were, disable their reaction to danger etc and then used the animation plus setVelocity. It worked quite well as it doesn't matter if they are under fire of not, they still come running down the ramp.

Cunning. Like your work. :)

Share this post


Link to post
Share on other sites
It all depends on how the vehicle is created - if it is placed in the editor you need the:

[_x] allowGetIn false;

or the crew (driver / gunner / commander ) get back in.

confirmed here, and also occurred when tested by me:

http://community.bistudio.com/wiki/unassignVehicle

Thanks for the info Mattar. :)

I tested it on a editor placed group that wasn't part of the original crew so they didn't get back in. Thinking back I guess I've mainly used it on vehicles/crew spawned via a script. Yeah so its the "if they are the original crew of the vehicle" part that's obviously critical. Good to know, thanks!

Cunning. Like your work. :)

Well I had to come up with something because watching your guys running against the inside of a boat when they are getting chopped to pieces by mg fire was not good! I'm still in two minds if the setVelocity 'push' is really needed.

Share this post


Link to post
Share on other sites

How about using doGetOut to get the people off the boat ?

Share this post


Link to post
Share on other sites

@Varanon - I'll check that out.

I condensed the script down a bit. Now I have an issue with an isKindOf condition at the bottom (in red). It will eject crew from all of the vehicles in the array and not just "ships". All of the other isKindOf conditions in the script appear to work. IE; for setVelocity. Not sure what's wrong :p

[Landing_List,400] Spawn {

 Private ["_Boats","_Amphibious"];
 _Center = _This Select 0;
 _Radius = _This Select 1;
 _LandingCraft = NearestObjects [_Center, ["ship","Tank"], _Radius];

 {
    For "_i" From 0 To 1 Do
    {
        While {SurfaceIsWater GetPosATL _x} Do
        {

             {
               [color=#0000ff] If (_x IskindOf "Ship") Then {_x SetVelocity [8, 0, 0];} Else {_x SetVelocity [3, 0, 0];};[/color] // Works fine
                If (!SurfaceIsWater GetPosATL _x) Then
                {
                  _x Animate ["Ramp", 1];
                  _x SetVelocity [0,0,0];
                };


             } ForEach _LandingCraft; 
               sleep 0.1;

         };


     };


 } Foreach _LandingCraft;

       [color=#ff0000]For "_v" From 0 To Count _LandingCraft - 1 Do 
       {
          {
            UnAssignVehicle _x;
            If (_LandingCraft Select _v IskindOf "Ship") then {_x Action ["Eject", Vehicle _x];}; [/color]//Ejects crew from every vehicle & not just "ships"[color=#ff0000]
          } ForEach Crew (_LandingCraft Select _v);
       };     [/color]

};

Edited by Iceman77

Share this post


Link to post
Share on other sites

Too many loops in there? You have 2 when you only need 1:

Remove this: For "_v" From 0 To Count _LandingCraft - 1 Do ---- the forEach is fine by itself - see example previous page.

edit:

Also is that UnassignVehicle _x in the right place - it's outside the condition so all ai may be unassigned.

edit:

here you go:

{if (_x IskindOf "Ship") then {{unassignVehicle _x; _x Action ["Eject", Vehicle _x]; [_x] allowGetIn false;} ForEach crew _x;};} ForEach _LandingCraft;

(tried the other method doGetOut and found the "original crew" jump back in with that as well (fertile meme territory that lol) as this is a beach storming scenario eject is more suitable.)

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Ignore Matter updated his post, UnassignVehicle was in the wrong place.

Share this post


Link to post
Share on other sites

Ahh yes. Mattar had just pointed that out to me in ts, about the same time I read this lol. Thanks a ton guys :bigglasses:

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  

×