Alpine_gremlin 13 Posted March 7, 2021 Hi guys I`m trying to write a relatively simple MHQ script. I want it to run the loop while the MHQ is alive, but not when dead. I also have the MHQ on a respawn so I want the code to restart again when it respawns, but I`m unsue of how to do this. Can someone help me with what I have so far? if (alive mhq) then { while {alive mhq} do { if (player distance satPhone <= 3) then { player addAction ["Teleport to MHQ", {_this select 1 moveInCargo mhq}]; waitUntil {player distance satPhone > 3}; removeAllActions player; }; sleep 2; } else {waitUntil alive mhq}; }; What can I do after the waitUntil that will have the loop start again? Share this post Link to post Share on other sites
7erra 629 Posted March 8, 2021 it's not really necessary to run a while true loop here. you can use the condition of the addaction instead: player addAction ["Teleport to MHQ", {_this select 1 moveInCargo mhq}, [], 1.5, true, true, "", "alive mhq && player distance satPhone < 3"]; (note: this code has a little drawback on performance as well since the addAction's condition will be evaluated all the time. to get the best performance you could add the action to another object than the player or remove it when the mhq is killed, eg. via Killed event handler and readd on respawn) But to answer your original question: you can make an infinite loop that runs during the entire mission. keep in mind that this might not be most performant approach. while {true} do { waitUntil {alive mhq}; while {alive mhq} do { // do stuff }; }; 1 1 Share this post Link to post Share on other sites
pierremgi 4739 Posted March 8, 2021 A good respawn vehicle should pass the name of the destroyed vehicle to the "re-spawned" one. So, no need to add any loop. Share this post Link to post Share on other sites
Alpine_gremlin 13 Posted March 8, 2021 5 hours ago, pierremgi said: A good respawn vehicle should pass the name of the destroyed vehicle to the "re-spawned" one. So, no need to add any loop. That makes sense, but the script no longer works when the vehicle is destroyed the first time. I`m guessing this is because it exits the original loop after failing the alive condition once? 1 Share this post Link to post Share on other sites
pierremgi 4739 Posted March 9, 2021 18 hours ago, Alpine_gremlin said: That makes sense, but the script no longer works when the vehicle is destroyed the first time. I`m guessing this is because it exits the original loop after failing the alive condition once? You're right. But it's possible to do better. My respawn vehicle module is able to manage: names, waypoints, crew, appearance (textures/pylons), loadout (crate inventory even if backpacks contents), crew loadout, actions added on vehicle (MHQ or else)... So, not really the initial BI module. Share this post Link to post Share on other sites