Jump to content
GamersFortitude

Ai dropping a bomb on each waypoint while on patrol

Recommended Posts

Hi all, Im looking into modifying a file for my arma 3 wasteland server where it has a hostile plane patrol going around the map, based on random waypoints, which are set as towns.

 

What im wanting to do is make the plane drop a bomb when its for example 50m away from the town. Having found examples of code and using the wiki i came up with this, but unfortunately i get the following error

 

(_bomb is defined further up in the file)

	private _bombspace = _vehicle distance2D currentWaypoint;
	
	if (_bombspace < 49) then {
		_bomb = "LIB_MG81_Ju87" createVehicle ((getpos _vehicle) vectorAdd [0,0,-1]); 
		_bomb setDir getDir _vehicle;
		_bomb setVelocityModelSpace [0,50,0];}	
	else {
		waitUntil _bombspace = 50;
	};

Here's the error. What am i missing?



21:43:08   Error position: <;

if (_bombspace < 49) then {

_bomb = ">

21:43:08   Error Invalid number in expression

21:43:08 File mpmissions\__cur_mp.malden\server\missions\sideMissions\mission_HostilePlane.sqf..., line 126

Line 126 is this

	private _bombspace = _vehicle distance2D currentWaypoint;

Thanks to anyone than can help

Share this post


Link to post
Share on other sites

Always follow the syntax from BIKI:

 

private _bombspace = _vehicle distance2D waypointPosition currentWaypoint group _vehicle;

That said, I don't know if you edited or scripted the waypoints but you need to check this distance regularly, not just once.

usually you can add a code like waitUntil { sleep 0.1; _vehicle distance2D waypointPosition currentWaypoint group _vehicle < 50}; depending on where you are coding. The local variable _vehicle must be defined and the distance to the current waypoint must be consistent (waypoint not yet completed).

 

  • Like 1

Share this post


Link to post
Share on other sites

Another option. 

Have aircraft flying around.

Create a trigger. When the trigger fires have an aircraft bomb or an aircraft missile, to explode at a given location or explode at a random location nearby.

 

To the player:  Enemy aircraft is flying around and drops a bomb.

.

 

Share this post


Link to post
Share on other sites

Ok so what I've done is basically create triggers at set distances away from towns with a predetermined flightpath for a, at this stage, C47 Skytrain . Yet to add in another mod which will give me a B17.

After a few hours of fiddling with a code, I managed to get 4 bombs dropping with a interval of 1 second or so, between impacts.

if isServer then {_bomb = "Bomb_03_F" createVehicle ((getpos plane1) vectorAdd [0,0,-1]); _bomb setDir getDir plane1; _bomb setVelocityModelSpace [0,40,-10];}; 
if isServer then {_bomb2 = "Bomb_03_F" createVehicle ((getpos plane1) vectorAdd [0,0,-1]); _bomb2 setDir getDir plane1; _bomb2 setVelocityModelSpace [0,30,-15];}; 
if isServer then {_bomb3 = "Bomb_03_F" createVehicle ((getpos plane1) vectorAdd [0,0,-1]); _bomb3 setDir getDir plane1; _bomb3 setVelocityModelSpace [0,20,-20];}; 
if isServer then {_bomb4 = "Bomb_03_F" createVehicle ((getpos plane1) vectorAdd [0,0,-1]); _bomb4 setDir getDir plane1; _bomb4 setVelocityModelSpace [0,10,-25];};

Originally used the MK82 bomb but just went with the the one above.

I tried putting 'sleep 1;' into each line just before the next bomb dropped, in order to get a uniform drop, but i get a syntax error..

Checking to see how it's used didnt seem to help, as I still got the error.

 

Now seeing that Sleep is used in conjunction with Spawn, would it be more efficient to create a script which gets called on each trigger ?

Share this post


Link to post
Share on other sites
Posted (edited)

@GamersFortitude,
This does what the script above is supposed to do,

Spoiler

plane1 spawn {
	if !isServer exitWith {};
	private _arr= [0, 50, 0];
	for "_i" from 0 to 3 do {
		_arr= [0, (_arr select 1)-10, (_arr select 2)+ -5];
		private _bomb = "Bomb_03_F" createVehicle ((getpos _this) vectorAdd [0,0,-1]);
		_bomb setDir getDir _this;
		_bomb setVelocityModelSpace _arr;
		sleep 1
	}
};

 

However I'm not sure that's exactly what you want it to do.

As a function it can work repeatedly but mostly for visual effect (there's no aim),

Spoiler

bomb_target= {		params ["_caller", "_target", "_area"];
	if !isServer exitWith {};
	waitUntil {sleep 1;
		if !(_caller distance _target < _area) then {false} else {
			for "_i" from 0 to 3 do {
				private _bomb = "Bomb_03_F" createVehicle ((getpos _caller) vectorAdd [0,0,-1]);
				_bomb setDir getDir _caller;
				_bomb setVelocityModelSpace [0, 50, -5];
				sleep 1
			};
			true
		}
	}
};

[plane_1, player, 500] spawn bomb_target

 


Have fun!

Edited by wogz187
added function
  • Like 2

Share this post


Link to post
Share on other sites

That's perfect! thank you very much Wogz, Works like a charm. Out of curiosity thou, what defines the bomb count to be dropped? eg if i wanted to make it 8 etc

Share this post


Link to post
Share on other sites
19 minutes ago, GamersFortitude said:

what defines the bomb count to be dropped? eg if i wanted to make it 8 etc

 

this line repeats the loop 4 time (0, 1, 2, 3):

 

for "_i" from 0 to 3 do {

changing 3 to 7 will do it 8 times.

  • Like 1

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

×