Jump to content
DoobieDoobieDoo

Help needed spawning an aircraft that patrols an area

Recommended Posts

Hi

 

First of all, thanks to Something Something Games!

 

I am a scripting noob. I spent many months getting simple things to work, and built a couple of mp scenarios, but have had some difficulty with ai aircrew.

For more than one iteration of an event, I am using a trigger to spawn vehicles.

 

I can get one aircaft, with pilot, that spawns, but then turns and flies in a straight line to map coords 0000

I can make it produce two pairs, four separate ones, but they all do the same thing.

 

It is supposed to spawn an aircraft when triggered and the aircrew are supposed to then patrol around a marker.

 

Can anyone explain where I am going wrong? My guess is I lack understanding of the link between the spawned group (plane + pilot) and the pilot.

Line 5 is the issue, which I have put in bold for clarity ( not in the trigger!).

I need to instruct something to patrol that area (around m1,  an object name), I keep getting lots of waypoint creation errors when i run it, or undeclared variables.

Is there another scripting function that I should use instead of BIS_fnc_taskPatrol ?

 

0= [] spawn {
_spawnLocation = [m1, 1000, (RANDOM 360)] call BIS_fnc_relPos;
_airCraft = [_spawnLocation, 180, "O_Plane_Fighter_02_F",  ] call BIS_fnc_spawnvehicle;
_planePilot = _airCraft select 0;
??? [group _planePilot, getPos m1, 1000] call BIS_fnc_taskPatrol;
};

 

Any help appreciated!

Share this post


Link to post
Share on other sites

Well, i have it working, but it returns lots of errors when I run it in the editor. Maybe they will clear up online (lol)

The patrol command i guessed should be commanding the group _planePilot.

 

It seems that it instructs the object instead - how weird !!

Once I realised that it said "_grp is returned expected object" because it is backwards, it was easier to understand !

The waypoints BIS_fnc_taskPatrol generates are attached to the object (sync) it seems, rather than the group leader's init .

 

0= [] spawn {
_spawnLocation = [m1, 1000, (RANDOM 360)] call BIS_fnc_relPos;
_airCraft = [_spawnLocation, 180, "O_Plane_Fighter_02_F", EAST] call BIS_fnc_spawnVehicle;
_planePilot = _airCraft select 2;
_planePilot = [group airCraft, getPos m1, 1000] call BIS_fnc_taskPatrol;
};

 

If anyone knows how to make this more elegant, please chip in!

Share this post


Link to post
Share on other sites

Here's an untested version that is hopefully explained through comments:

 

<yourTag>_fnc_spawnAndPatrol = {
	// take the plane type as parameter, default to O_Plane_Fighter_02_F
	// second parameter is the patrol center point, default to [0,0,0]
	// third parameter is the distance from patrol center point, default to 1000 meter
	params [["_type", "O_Plane_Fighter_02_F"], ["_pos", [0,0,0]], ["_dist", 1000]];

	// use getPos instead of BIS_fnc_relPos to save some CPU cycles
	private _spawnLocation = _pos getPos [_dist, random 360];
	// spawn in 500 meter height
	_spawnLocation = [_spawnLocation select 0, _spawnLocation select 1, 500];
	// spawn flying plane at _spawnLocation, facing towards _pos
	private _planeInfo = [_spawnLocation, _spawnLocation getDir _pos, "O_Plane_Fighter_02_F", EAST] call BIS_fnc_spawnVehicle;

	// order plane to patrol _dist meter around _pos - almost certainly a too small area
	private _grp = _planeInfo select 2;
	[_grp, _pos, _dist] call BIS_fnc_taskPatrol;

	// return the new spawned plane object
	_planeInfo select 0;
};

["O_Plane_Fighter_02_F", getPos m1, 1000] call <yourTag>_fnc_spawnAndPatrol;

Replace <yourTag> with a handle for your own person and purpose, e.g. Doo_planeFight. Also place this code in Init.sqf and not an init box to make it easier to change later on.

Share this post


Link to post
Share on other sites

You can also get the pilot/driver if you have the vehicle.

systemChat format ["> %1", (driver _airCraft)]; // This applies to both vehicles and aircraft

But as @TeTeT said, you can pass the group to the taskPatrol function, which it asks for.

Quote

Syntax:

[group,position,distance,area blacklist] call BIS_fnc_taskPatrol

Parameters:

group - the group to which to assign the waypoints (Group)

position - the position on which to base the patrol (Array)

distance - the maximum distance between waypoints (Number)

area blacklist - (optional) blacklist of areas (Array)

Return Value:

Success Flag (Boolean)

 

Share this post


Link to post
Share on other sites

Also be aware that 1000m for the task patrol function is extremely small for any aircraft, better use 10000 so the aircraft doesn't do constant turns.

 

Cheers

Share this post


Link to post
Share on other sites

Thanks all ... I am guessing that the comment " - almost certainly too small an area" refers to something you percieve as incorrect in my code, as GOM suspected.

 

Unfortunately as you know, ARMA does not let us see very far in game.

 

Thanks for all your help! I will take a good look at them later tonight :)

Share this post


Link to post
Share on other sites
On 1/24/2018 at 7:55 PM, Grumpy Old Man said:

 

Aircraft are always rendered with the terrain view distance, which doesn't impact fps too much.

Try it.

 

Cheers

 

Apologies, I had better explain that more thoroughly ... so, I go to test - play as character, step into trigger, see aircraft :¬)

 

Obviously once I know it's working it will be different -  they will be patrolling 4 - 12km from their markers

 

Sorry for any confusion :f:

Share this post


Link to post
Share on other sites

Sorry I didn't read this post before.

You could proceed as BI for their CAS support module. If virtual, no problem, you spawn your aircraft (for BI, on module) just before ordering a waypoint.

For any player in the supporting aircraft, the module just add a task, the player manages the flight of course.

For AI real CAS bomber, BI module disables the simulation of the aircraft, then enable it when requested. On the other end, the flight back is not very sexy, attempting for land somewhere. Why not... you can hack this to make the aircraft returning at home position with fuel/simulation management. Home can be out of the map.

 

Btw, it seems to me I'm the only guy on forum using bis_fnc_spawnGroup (even for one unit). I don't know why. It's handy for any further waypoint and you can extract the crew data anyway.

 

Share this post


Link to post
Share on other sites
On 1/29/2018 at 1:44 AM, pierremgi said:

 using bis_fnc_spawnGroup (even for one unit). I don't know why. It's handy for any further waypoint and you can extract the crew data anyway.

 

 

I guess it is the same as BIS_fnc_spawnVehicle but for infantry?

 

or are you saying I can use BIS_fnc_spawnGroup to spawn an aircraft and pilot, or something else?

Share this post


Link to post
Share on other sites

As far as any single/grouped unit(s), or manned vehicle(s) are groups, you can spawn what group you want. From a single civilian beggar to an armored joint squad and more. Place an aircraft class and you will have the aircraft with its standard crew. Place two aircraft + several infantry + a tank + a ship, and you will have all this manned stuff.

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

×