Jump to content
Sign in to follow this  
Havok66

Returning vehicle to original position if unoccupied

Recommended Posts

I'm trying to return a vehicle to its original position if it's unoccupied for 60 seconds. This is my code in the vehicle's init field but it doesn't move the vehicle after waiting 2+ minutes. I do know the variable orig_pos is properly stored and working.

orig_pos = (getPosATL this);

while {true} do 
{
	if ({alive _x} count crew this == 0) then {this setPosATL orig_pos} else {};
	sleep 60;
};

I'm no doubt making some dumb mistake and any help would be greatly appreciated. Thanks!

Share this post


Link to post
Share on other sites

Can't sleep in the init field.  Put sleep/waitUntil type code in a script and run the script from the init.  Or just use the built in vehicle respawn system using modules.

Share this post


Link to post
Share on other sites

Or just use the built in vehicle respawn system using modules.

Got this module to work out the way I wanted. Thanks!

Share this post


Link to post
Share on other sites

you could also spawn the code if you want it all inside the init line.

[this,(getPosATL this)] spawn
{
   params ["_veh", "_pos"];
   while {true} do 
   {
	if ({alive _x} count crew _veh == 0) then {_veh setPosATL _pos} else {};
	sleep 60;
   };
};

Share this post


Link to post
Share on other sites

Bad idea to use a while loop when there is a respawn module with this built-in function ;)

Share this post


Link to post
Share on other sites

maybe this may be better.

null = [this,(getPosVisual this)] spawn {
    _this params [["_veh",objNull],["_pos",[0,0,0]]];
   if (isNull _veh) exitWith {};
    _veh setVariable ["org_position",_pos,true];
    while {alive _veh} do 
    {
      if ({alive _x} count crew _veh == 0) then { 
        private "_timeStarted";
        _timeStarted = time + 60;
        waitUntil {sleep 0.01; ((time >= _timeStarted) && ({alive _x} count crew _veh == 0))};
        if ({alive _x} count crew _veh == 0) then { 
          _veh setPos (_veh getVariable "org_position");
        };
      };
      sleep 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
Sign in to follow this  

×