Havok66 1 Posted June 1, 2016 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
kylania 568 Posted June 1, 2016 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
Havok66 1 Posted June 2, 2016 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
bad benson 1733 Posted June 2, 2016 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
R3vo 2654 Posted June 2, 2016 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
Lala14 135 Posted June 3, 2016 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