Jump to content
Alpine_gremlin

Help with Simple MHQ Script?

Recommended Posts

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

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
	};
};

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

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
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?

  • Like 1

Share this post


Link to post
Share on other sites
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×