Jump to content
Sign in to follow this  
carlostex

Respawn an aircraft as flyable?

Recommended Posts

How can i set the special condition of a unit so when a plane or chopper respawns in the air it starts flying and does not fall into the ground?

I can't seem to find any answers for this.

Share this post


Link to post
Share on other sites

dont use createVehicle for aircrafts start flying spawns, use BIS_fnc_spawnVehicle

this will spawn a a10 and make it flying at start with pilot:

// (random 360) is the direction it wil spawn towards, 0 for north 180 for south etc..
myplane = [getMarkerPos "anymarkername", (random 360), "A10_US_EP1", west] call BIS_fnc_spawnVehicle;

if you have a desired height you wish to force the spawn in replace getMArkerPos "anymarkername" with:

// that will force 250 height over the marker named ....
[getMarkerPos "anymarkername" select 0,getMarkerPos "anymarkername" select 1,250]

As PvPSCene mentioned you can use setVelocity with using createvehicle, this because that command will spawn it stopped but at specified height so it will fall to the ground, setVelocity will give it a push to get it flying, still needs to start engines completely etc so not recomended at all for planes unless very high or using script to hold it up until able to itself.

Stick with spawnVehicle and remember to have a function module placed on map.

Edited by Demonized

Share this post


Link to post
Share on other sites

Demonized BIS_fnc_spawnvehicle is awesome! How can i name that unit that has been spawned?

Share this post


Link to post
Share on other sites

_sv =[............] call BIS_fnc_spawnVehicle;

// Name the vehicle and group.

_vehicle = _sv select 0; // vehicle spawned.

_vehiclegrp = _sv select 2; // group of vehicle.

Share this post


Link to post
Share on other sites

Well i created a plane.sqf with this:

_a10 = [[getMarkerPos "ui" select 0,getMarkerPos "ui" select 1,50], 180, "A10_US_EP1", west] call BIS_fnc_spawnVehicle;

_vehicle = _a10 select 0; // vehicle spawned.

_vehiclegrp = _a10 select 2; // group of vehicle.

I have a radio bravo trigger with this to spawn the vehicle:

null = execVM "plane.sqf";

I also have a radio alpha trigger with this:

a10 setdamage 1

Radio Bravo works great but radio alpha doens't maybe because it is not setting that unit's name.

Sorry i don't quite understand variables.

Also i have a script that creates several waypoints for a spawned unit, how can i make the unit do what the script orders after it spawns?

---------- Post added at 11:48 AM ---------- Previous post was at 11:37 AM ----------

Sorry demonized i forgot to tell:

A10 =_vehicle;

After this it worked.

Anyway can you help me with the waypoint script?

---------- Post added at 12:08 PM ---------- Previous post was at 11:48 AM ----------

lol i got it.

Share this post


Link to post
Share on other sites

Hey demonized this is strange. How come i forgot to put the functions module in the editor and it still worked?

It shouldn't work without the functions module right?

Now i'm confused!

---------- Post added at 09:40 AM ---------- Previous post was at 09:29 AM ----------

BTW with your help i created this plane.sqf script:

_sv = this spawn { waitUntil { if !(alive _this) exitWith {}; if (fuel _this < 0.25) then { _this setFuel 1 }; false } };

_sv = [[getMarkerPos "helo_spawn" select 0,getMarkerPos "helo_spawn" select 1,50], 180, "Mi24_P", east] call BIS_fnc_spawnVehicle;

_sv execVM "hunters.sqf";

_vehicle = _sv select 0; // vehicle spawned.

_vehiclegrp = _sv select 2; // group of vehicle.

helo1 = _vehicle;

sleep 10;

if (true) exitWith {};

OK now how can i create a variable that will set the number of respawns, or in other words, make the chopper only respawn a certain number of times like it had a lives counter?

Share this post


Link to post
Share on other sites

amount of "lives"

// create a new plane after first is dead _x amount of times.
_respawns = 5;  // this is wmount of "lives" a plane has.

while {_respawns != 0} do {
// _sv = this spawn { waitUntil { if !(alive _this) exitWith {}; if (fuel _this < 0.25) then { _this setFuel 1 }; false } };  // not sure what you need this line for as this is nothing in a script.
_sv = [[getMarkerPos "helo_spawn" select 0,getMarkerPos "helo_spawn" select 1,50], 180, "Mi24_P", east] call BIS_fnc_spawnVehicle;
_sv execVM "hunters.sqf";

_vehicle = _sv select 0; // vehicle spawned.
_vehiclegrp = _sv select 2; // group of vehicle.

//helo1 = _vehicle;  // this line i removed as its not needed, you can do format combined with text command to create global names if needed.

waitUntil { !alive _vehicle OR !canMove _vehicle };  // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
_respawns = _respawns + 1;  // _x amount respawns is now +1 and will create the plane again in exact same way as first one.
   sleep 60;  // this is how long after vehicle is dead before it will respawn.
};

if you want to delete the wreck to tidy up, you can add this after sleep line after waituntil:

[_vehicle] spawn {
  _vehicle = _this select 0;
  _timer = 60;  // this is how long after vehicle is dead or cannot move it will be deleted, here is 60 seconds.
  sleep _timer;
  deleteVehicle _vehicle;
};

Share this post


Link to post
Share on other sites
// _sv = this spawn { waitUntil { if !(alive _this) exitWith {}; if (fuel _this < 0.25) then { _this setFuel 1 }; false } }; // not sure what you need this line for as this is nothing in a script.

Yeah this piece of code was worng but now i fixed it. It just guarantees the spawned vehicle does not run out of fuel.

Anyway thanks a lot Demonized. I really want to learn how to script and your help has been clearing up some things on my mind although i still have a loooooong way to go.

---------- Post added at 09:00 AM ---------- Previous post was at 08:56 AM ----------

I made the script for my gaming community so it is like this currently:

//Air_Vehicle_Respawn
//=WB=Tex


_airvehicle = [[getMarkerPos "helo_spawn" select 0,getMarkerPos "helo_spawn" select 1,50], (random 360), "MI24_P", east] call BIS_fnc_spawnVehicle; 
_airvehicle execVM "hunters.sqf";

_vehicle = _airvehicle select 0; // vehicle spawned.
_vehiclegrp = _airvehicle select 2; // group of vehicle. 

helo1 = _vehicle;

nul = _vehicle spawn { waitUntil { if !(alive helo1) exitWith {}; if (fuel helo1 < 0.1) then { helo1 setFuel 1 }; false } };

sleep 10;

if (true) exitWith {};

Now i'm just gonna add what you gave me!

Share this post


Link to post
Share on other sites

Demonized seems that the lives thing is not working. It keeps spawning vehicles without an end. Tried with just your code and seems lives are infinite.

Share this post


Link to post
Share on other sites

this line was wrong

_respawns = _respawns + 1;

that should be

_respawns = _respawns - 1;

i added more lives instead of taking them away, lack of sleep i guess :)

Share this post


Link to post
Share on other sites

no problems!!!! i'm still trying to learn.

There is something i don't understand. Can you explain me what does the select command do?

Share this post


Link to post
Share on other sites

select does exatly that:

it chooses from any array - [] this is a array, it can contain anything. numbers, objects variables etc.

items in array is arranged from 1st ( select 0) to last whatever (select some number)

_surprise = ["apple", "oranges", "monkey_poo"] select 2:

_surprise will return "monkey_poo", wich is the last in array and when you count from 0 on 1st you get 2 on 3rd object.

you can also define the array and select from that:

_myArray = ["apple", "oranges", "monkey_poo",5];

_surprise = _myArray select 0; // will return "apple"

_surprise = _myArray select 3; // will return 5

Share this post


Link to post
Share on other sites

Yeah but how do you know how the array is organized if you didn't define it?

~in the code you gave me?:

_vehicle = _sv select 0; // vehicle spawned.

_vehiclegrp = _sv select 2; // group of vehicle.

how do you know select 0 will refer to vehicle name and select 2 is group of the vehicle?

Share this post


Link to post
Share on other sites

Thanks! So it depends on the return value of the used command from what i understood.

Currently the script is working great like this:

//Vehicle_Respawn
//Created by =WB=Tex 
//Most of the code by Demonized

// create a new plane after first is dead _x amount of times.
_respawns = 5;  // this is amount of "lives" a plane has.

while {_respawns != 0} do {
   _sv = [[getMarkerPos "helo_spawn" select 0,getMarkerPos "helo_spawn" select 1,10], 0, "Mi24_P", east] call BIS_fnc_spawnVehicle;
   _sv execVM "hunters.sqf";

   _vehicle = _sv select 0; // vehicle spawned.
   _vehiclegrp = _sv select 2; // group of vehicle.

   helo1 = _vehicle;  // might erase this but still need it as don't know how to do better

  _vehicle spawn { waitUntil { if !(alive helo1) exitWith {}; if (fuel helo1 < 0.1) then { helo1 setfuel 1}; false } }; // this allows for the vehicle to never have fuel shortage
  _vehicle lock true;

  waitUntil { !alive _vehicle OR !canMove _vehicle };  // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
  _respawns = _respawns - 1;  // _x amount respawns is now +1 and will create the plane again in exact same way as first one.
  sleep 60;  // this is how long after vehicle is dead before it will respawn.

  [_vehicle] spawn {
  _vehicle = _this select 0;
  _timer = 60;  // this is how long after vehicle is dead or cannot move it will be deleted, here is 60 seconds.
  sleep _timer;
  deleteVehicle _vehicle;
};  

};  

I would love to get a next step on this which would make the script awesome which would be making it work on the init line of a vehicle and if that particular vehicle was destroyed it would then spawn same type of vehicle and the same side as well.

I tried using :

_type = typeOf _sv

_side = (side _sv)

And then setting the variables before calling the function like this:

_sv = [[getMarkerPos "helo_spawn" select 0,getMarkerPos "helo_spawn" select 1,10], 0, _type, _side] call BIS_fnc_spawnVehicle;

but of course silly me this didn't work and returned an error i think mainly because i didn't initialised the variables properly.

Share this post


Link to post
Share on other sites

dont open until you have given up or dont want to spend more time in figuring it out ;)

this you can use on any vehicle with any marker unlimited amount of times, but the name heli1 will be overwritten each time if you keep it in.

//Vehicle_Respawn
//Created by =WB=Tex 
//Most of the code by Demonized
// put in init line of any vehicle: _null = [this, "anymarker_name"] execVM "script_name.sqf"
// create a new plane after first is dead _x amount of times.
_respawns = 5;  // this is amount of "lives" a plane has.
_veh = _this select 0;  // this is the vehicle that runs the script.
_spawnPoint = _this select 1;  // this is the marker where you want it to spawn at.
_vehicleType = typeOf _veh;  // get the type of vehicle.
_side = side (driver _veh);  // get side of driver.

while {_respawns != 0} do {
_sv = [[getMarkerPos _spawnPoint select 0,getMarkerPos _spawnPoint select 1,10], 0, _vehicleType, _side] call BIS_fnc_spawnVehicle;
_sv execVM "hunters.sqf";  // if this is not working put it after you have named vehicle and group and use _vehicle or _vehiclegrp instead of _sv. 

_vehicle = _sv select 0; // vehicle spawned.
_vehiclegrp = _sv select 2; // group of vehicle.

helo1 = _vehicle;  // if not needed for a editor placed trigger or something else, just delete this line, it has no effect inside this script, exept for giving vehicle a global name.

_fuelchk = [_vehicle] spawn {
	if (isServer) then {
		_vehicle = _this select 0;
		waitUntil { if !(alive _vehicle) exitWith {}; if (fuel _vehicle < 0.1) then { _vehicle setfuel 1}; false }; // this allows for the vehicle to never have fuel shortage
	};
};
_vehicle lock true;

waitUntil { !alive _vehicle OR !canMove _vehicle };  // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
_respawns = _respawns - 1;  // _x amount respawns is now -1 and will create the plane again in exact same way as first one.
sleep 60;  // this is how long after vehicle is dead before it will respawn.

[_vehicle] spawn {
	if (isServer) then {
		_vehicle = _this select 0;
		_timer = 60;  // this is how long after vehicle is dead or cannot move it will be deleted, here is 60 seconds.
		sleep _timer;
		deleteVehicle _vehicle;
	};
};  
};

Edited by Demonized
removed an extra }

Share this post


Link to post
Share on other sites

My god! Script is looping like hell, freezes the game!! Shouldn't the script be waiting for the death of the editor placed unit for it to begin? It keeps spawning without stopping and the game freezes.

---------- Post added at 12:02 PM ---------- Previous post was at 11:38 AM ----------

Found this:

//Vehicle_Respawn
//Created by =WB=Tex 
//Most of the code by Demonized
// put in init line of any vehicle: _null = [this, "anymarker_name"] execVM "script_name.sqf"
// create a new plane after first is dead _x amount of times.
_respawns = 5;  // this is amount of "lives" a plane has.
_veh = _this select 0;  // this is the vehicle that runs the script.
_spawnPoint = _this select 1;  // this is the marker where you want it to spawn at.
_vehicleType = typeOf _veh;  // get the type of vehicle.
_side = side (driver _veh);  // get side of driver.

while {_respawns != 0} do {
   _sv = [[getMarkerPos _spawnPoint select 0,getMarkerPos _spawnPoint select 1,10], 0, _vehicleType, _side] call BIS_fnc_spawnVehicle;
   _sv execVM "hunters.sqf";  // if this is not working put it after you have named vehicle and group and use _vehicle or _vehiclegrp instead of _sv. 

   _vehicle = _sv select 0; // vehicle spawned.
   _vehiclegrp = _sv select 2; // group of vehicle.

   helo1 = _vehicle;  // if not needed for a editor placed trigger or something else, just delete this line, it has no effect inside this script, exept for giving vehicle a global name.

   _fuelchk = [_vehicle] spawn {
       if (isServer) then {
           _vehicle = _this select 0;
           waitUntil { if !(alive _vehicle) exitWith {}; if (fuel _vehicle < 0.1) then { _vehicle setfuel 1}; false } }; // this allows for the vehicle to never have fuel shortage
       };
   [color=Red]}; // if i delete this line script stops looping and respawns 1 vehicle immediately[/color] [color=Red]only, if i desroy them script stops respawning[/color]
   _vehicle lock true;

   waitUntil { !alive _vehicle OR !canMove _vehicle };  // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
   _respawns = _respawns - 1;  // _x amount respawns is now -1 and will create the plane again in exact same way as first one.
   sleep 60;  // this is how long after vehicle is dead before it will respawn.

   [_vehicle] spawn {
       if (isServer) then {
           _vehicle = _this select 0;
           _timer = 60;  // this is how long after vehicle is dead or cannot move it will be deleted, here is 60 seconds.
           sleep _timer;
           deleteVehicle _vehicle;
       };
   };  
};  

Share this post


Link to post
Share on other sites
work on the init line of a vehicle and if that particular vehicle was destroyed it would then spawn same type of vehicle and the same side as well.
???????????

---------- Post added at 01:06 PM ---------- Previous post was at 01:05 PM ----------

ah ok.. maybe im tired as well lol

Share this post


Link to post
Share on other sites

Demonized i have to thank you a lot. I finished the script finally! I had to correct some of the code and add a few things as well. Currently is working great like this:

//Vehicle_Respawn by =WB=Tex
//Concept and code adaptation by =WB=Tex 
//Most of the code by Demonized
// put in init line of any vehicle: _null = [this, "markername", number of lives, time until respawn] execVM "script_name.sqf" 
// create a new plane after first is dead _x amount of times.

_veh = _this select 0; 			// this is the vehicle that runs the script.
_spawnpos = _this select 1; 		// this is the marker where you want it to spawn at. 
_respawns = _this select 2;	 	// this is where you get the number of lives (respawns) of the unit.
_delay = _this select 3; 		// this gets the time until a new unit respawns and other is deleted;
_vehicleType = typeOf _veh;  		// gets the type of vehicle.
_side = side (driver _veh);		// gets the side of vehicle. 

waitUntil {!alive _veh OR !canMove _veh};  // wait until the placed unit in the editor is destroyed or disabled.
sleep _delay;			// delayed timer defined in the initialization
deleteVehicle _veh;			// deletes the placed editor unit.

while {_respawns != 0} do {
   _sv = [[getMarkerPos _spawnpos select 0,getMarkerPos _spawnpos select 1, 0], (random 360), _vehicleType, _side] call BIS_fnc_spawnVehicle;  // creates a new unit regarding it hasn't ran out of lives.
   _sv execVM "hunters.sqf";											               // external script execution.	

  _vehicle = _sv select 0; 		// vehicle spawned
  _vehiclegrp = _sv select 2;		//vehicle spawned group

  //helo1= _vehicle; // just for testing purposes when using triggers.

  _fuelchk = [_vehicle] spawn {
       if (isServer) then {
           _vehicle = _this select 0;
           waitUntil { if !(alive _vehicle) exitWith {}; if (fuel _vehicle < 0.1) then { _vehicle setfuel 1}; false }; // this allows for the vehicle to never have fuel shortage
       };
   }; 

  waitUntil { !alive _vehicle OR !canMove _vehicle }; 							 // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
  _respawns = _respawns - 1; 									 // _x amount respawns is now -1 and will create the plane again in exact same way as first one.
  sleep _delay;  										// this is how long after vehicle is dead before it will respawn.

  [_vehicle] spawn {
  _vehicle = _this select 0;
  sleep 360;
  deleteVehicle _vehicle;									
};  

};

Share this post


Link to post
Share on other sites

this is what I've been searching the forums for, but it doesn't work because of this line:

_sv execVM "hunters.sqf";

What is this hunters.sqf all the posters assume is in place?

~Z~

Share this post


Link to post
Share on other sites

just like to add that this thread is so damn useful in so many damn ways. thanks to all contributors. wish this and similar would be collated for future use somewhere.

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  

×