Jump to content
S3LMON

Helicopter Emergency Landing Script-How can I run code on spawned helicopters?

Recommended Posts

Hello!!

 

I would like to make a script that does not take damage for 20 seconds if it takes more than a certain amount of damage to give the spawned helicopters in the mission a chance to make an emergency landing by referring to this nice script.

https://www.armaholic.com/page.php?id=25452

But I don't know how to run code on spawned helicopters...

What I want most is to give it an emergency landing opportunity.

 

 

(Is there a better (effective) way than simply waiting for 20 seconds?)

 

Below is the code I have written now...

 

enableSaving [false,false];
[]spawn {
	while {true} do {
		_centerPosition = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition");
		Heli_List = nearestObjects [_centerPosition, ["Air"], worldSize];	


		hint str Heli_List;	

			
		{
			_damage = getDammage _x;
			if (_damage >0.85) then {
				_x setDamage 0.85;
				_x allowDamage false;
				sleep ((random 20) + 5);
				_x allowDamage true;
				_x setDamage 1;

			};
		}forEach Heli_List
	};
};

The hint message seemed to give me a way, but... I don't have too much knowledge about the script...

 

I will be very grateful for your response. 🙂

 

I have poor scripting skills so I am not sure how to achieve my goal. I am not an English speaking person.

I am not sure if my intent has been clearly communicated. (Using Google Translate)

Share this post


Link to post
Share on other sites

You're not too far. The while true loop enables you to treat all spawned things you need. Here helicopters. But you need to treat them just once.

So something like:


 

0 = [] spawn {
  private "_helos";
  while {true} do {
    sleep 2;
    _helos = vehicles select { _x isKindOf "helicopter" && isNil {_x getVariable "heloPassed"} };
    {
       _x setVariable ["heloPassed",TRUE];
       <your code for _x (as the current helicopter) here>;
    } forEach _helos;
  };
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you so much!
Thanks to you, all helicopters, whether spawned or existing, can make an emergency landing as I intended!

However, as a script beginner, there is a lot to learn.

 

 isNil {_x getVariable "heloPassed"}

 

Can you tell me what this part means?

 

Also, I'm going to go one step further and create a resuscitation function that applies to everyone.
Could you please tell me how to write a script that only runs "once" for newly created people, except for those who existed at the beginning of the mission (editor)?
I politely ask.

 

Regardless of this, I am very grateful for your help.
Not only this, I'm very good at using your various cool scripts, and I'm always grateful. 🙂

 

 

I have poor scripting skills so I am not sure how to achieve my goal. I am not an English speaking person.

I am not sure if my intent has been clearly communicated. (Using Google Translate)

Share this post


Link to post
Share on other sites

If you want to pass a code on spawned vehicles/units/objects... you need to wait for something or/and loop for a next occurrence. But you don't want to run the code multiple times, so you need to treat the spawned thing then "mark" it as treated for excluding it from the next loop. A simple way to know you have already treated the thing, is to set a variable on it, no matter the content if this variable didn't exist before. So isNil {_x getVariable "blabla"} is just a mean to check if _x had a variable ("blabla") set on it (like something personal in other word). This  isNil syntax is  mentioned in example 2 from Biki.

 

A "resuscitation function" starts with what you want exactly to do, when, for which units, in what context (SP / MP).

The reason why I created 3 modules, not only one.

In SP, you can handleDamage the player, set unconscious him when hit instead of dying, wait , set him healthy...

In SP again, you can kill some Ais and re-create them, delete corpses... not a true respawn.

In MP, all playable units are managed by editor. So simple, you can make them respawn, even heal. For other AIs, handleDamage or kill/re-create them.

The heal by AIs is subject to mods (or modules) apart.

 

Of course, you can manage a lot of things, AI "respawn", counter for "respawn", ... waves (for groups)...., but it's not a simple script. It took me months to write several modules for that.  But have a look at the forum. You'll find some reasonable codes for what you want.

Share this post


Link to post
Share on other sites

Thank you again!!

With your getVariable setVariable solution, I was able to fully implement the resuscitation function!!

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

×