Jump to content
Sign in to follow this  
wickedstigma

Simple Artillery Strike v1.0

Recommended Posts

Hi everyone! This is a Simple Artillery Strike script I made to help myself and some others to have basic idea of a custom artillery strike, or just to add a simple artillery script to your missions.

This script is preset do the following:

Fire: D30 122mm HE

Place: artilleryTarget Marker

Delay: 5 seconds between each round

Height: 500 meters

Amount: 10

Spread: 50 meters

How to use it?

1) Create a marker called artilleryTarget and place it anywhere on the map

2) Make a radio activated trigger and write the following code in the On Act. box:

hint "Left click on map to send coordinates"; onMapSingleClick """artilleryTarget"" setMarkerPos _pos; 

[""ARTY_Sh_122_HE"",""artilleryTarget"",5,500,10,50]execVM ""artillery.sqf""; onMapSingleClick """";";

3)Copy the following code to notepad and save it as artillery.sqf

/*
 ------------------------------|
 Simple Artillery Strike v1.1  |
 ------------------------------|
 By:wickedStigma               |
 ------------------------------|
 June 9, 2010                  |
 ------------------------------|
 Special Thanks to: ST_Dux	|
 ------------------------------|
*/

//Link: http://forums.bistudio.com/showthread.php?p=1646466

//INTRUCTIONS:
//Write the following code on a radio activated trigger
//hint "Left click on map to send coordinates"; onMapSingleClick """artilleryTarget"" setMarkerPos _pos; 

[""ARTY_Sh_122_HE"",""artilleryTarget"",5,500,10,50]execVM ""artillery.sqf""; onMapSingleClick """";";


//Script Start

//Declare Variables and gets data from the array

_ammo      = _this select 0;
_bombsite1 = _this select 1;
_delay     = _this select 2;
_height    = _this select 3;
_amount    = _this select 4;
_spread    = _this select 5;
_y         = 0;

//Delays the script for the amount of time stored in _delay

sleep _delay;

// Loops the amount of times stored in _amount

for [{_x = 0}, {_x <= _amount}, {_x = _x + 1}] 

do 

{
	//Creates the slected ARTY_Sh_122_HE at 300 meters
	_artilleryStrike = _ammo createVehicle [(getMarkerPos _bombsite1 select 0) + (_y - 10),( getMarkerPos _bombsite1 select 1) + 

(_y - 			10), _height];

	//Creates a ramndom number from 0 up to the value assigned to _spread
	_y = round(random _spread);

	//Delays the code for the selected amount of time
	sleep _delay;
};



4) Enjoy! :yay:

----------------------------------------------------------------------------------------

IMPORTANT!

You can change different things in the code to suite your needs. To do this just change the values on the array before the execVM.

[""ammo"",""target"",delay,height,amount,spread] execVM

Feel free to ask any question and if someone knows how to handle variables through the OnMapSingleClick, please PM me. I just want to be able to put an array of the settings of your artillery, (ammo, height, number of rounds, etc.), through the activation trigger.

Edited by wickedstigma
New Version

Share this post


Link to post
Share on other sites

You can pass arguments to the script in the array preceding "execVM." Instead of having to go back into the script each time you wish to change a variable, simply pass those variable as arguments in the script call and have the script retrieve them via the special local variable, "_this".

e.g.:

Script Call:
["argument1","argument2",42] execVM "myScript.sqf"

Script:
_arg1 = _this select 0; // first element in passed array,string  "argument1";
_arg2 = _this select 1; // second element in passed array, string "argument2";
_arg3 = _this select 2; // third element in passed array, number 42;

// you can now use these local variables in your script, and when they are changed in the script call, they will be changed for the script

Share this post


Link to post
Share on other sites
You can pass arguments to the script in the array preceding "execVM." Instead of having to go back into the script each time you wish to change a variable, simply pass those variable as arguments in the script call and have the script retrieve them via the special local variable, "_this".

e.g.:

Script Call:
["argument1","argument2",42] execVM "myScript.sqf"

Script:
_arg1 = _this select 0; // first element in passed array,string  "argument1";
_arg2 = _this select 1; // second element in passed array, string "argument2";
_arg3 = _this select 2; // third element in passed array, number 42;

// you can now use these local variables in your script, and when they are changed in the script call, they will be changed for the script

Yeah, I know that is the way, but when I'm using the OnMapSingleClick command and put arguments in the array before the execVM it keeps saying " ; Missing" and there isn't any semi colon missing. I made this same code without the OnMapSingleClick first just create a simulation of an artillery strike on a small mission and it worked perfectly, but when I added the OnMapSingleClick i had to change the code a bit becuase of this error.

---------- Post added at 12:58 PM ---------- Previous post was at 12:57 PM ----------

wickedstigma Nice work!

Thanks man! Much appreciated.

Share this post


Link to post
Share on other sites

There's no reason for argument passing not to work with onMapSingleClick. My guess is that you forgot to double up your quotes somewhere. Paste the onMapSingleClick line that's not working right, and I'll tell you why.

Share this post


Link to post
Share on other sites
There's no reason for argument passing not to work with onMapSingleClick. My guess is that you forgot to double up your quotes somewhere. Paste the onMapSingleClick line that's not working right, and I'll tell you why.

Here it is, it doesnt work when I put it like this:

hint "Left click on map to send coordinates"; onMapSingleClick """artilleryTarget"" setMarkerPos _pos; ["ARTY_Sh_122_HE","atilleryTarget",5,500,10,50]execVM ""artillery.sqf""; onMapSingleClick """";";

Edited by wickedstigma
Correcting spelling

Share this post


Link to post
Share on other sites
["ARTY_Sh_122_HE","atilleryTarget",5,500,10,50]

As I guessed, you forgot to double up these quotes, which you need to do because they are strings within a string. Just add another " to the bold parts, and all should be fine.

Share this post


Link to post
Share on other sites
As I guessed, you forgot to double up these quotes, which you need to do because they are strings within a string. Just add another " to the bold parts, and all should be fine.

Ok, Ill try it and post back in a few minutes. Thanks.

---------- Post added at 02:41 PM ---------- Previous post was at 02:00 PM ----------

Yes! It worked as you said, the problem where the extra quotes. Thanks for your help. I was trying also to work something out with the spawning of the artillery shells, but I couldn't find anything.

1) You know when you spawn the shell it comes down flat, not down like its supposed to be if they where fired from a mortar or whatever.

2) I was trying to make the code shorter by elminiating the following red parts in the code:

_artilleryStrike = _ammo createVehicle [(getMarkerPos _bombsite1 select 0) [color="Red"]+ (_y - 10)[/color],( getMarkerPos _bombsite1 select 1) [color="Red"]+ 

(_y - 10)[/color], _height];

and change it to something like this:

bomb = someGroup createUnit ["_ammo", [0,0,1], [],[color="Red"] [b]_spread[/b][/color], "CAN_COLLIDE"];

[color="Red"][b]Red[/b][/color] = [i]Placement Radius of the object[/i]

But it crashes when I do it.

Share this post


Link to post
Share on other sites

My bad, I use createVehicle, and it crashed first becuase I was using the "FLY" argument, now Im using the "CAN_COLLIDE" argument and its not crashing, even though everything works but the artillery doesn't spawn. I used this code:

_artilleryStrike = createVehicle ["_ammo", [(getMarkerPos "artilleryTarget") select 0, (getMarkerPos "artilleryTarget") select 1, _height], [], _spread, 

"CAN_COLLIDE"];

I even took the quotes on _ammo to see if it worked and it didn't.

Share this post


Link to post
Share on other sites

Well, _ammo should definitely not have quotes around it, as it is a variable. Putting it in quotes makes the command think that there is a class type in the game called "_ammo" that it needs to create rather than being pointed toward the string that is contained within the _ammo variable.

Other than that, nothing appears wrong with that line. It should be working.

Share this post


Link to post
Share on other sites

To make it look a little more realistic you need to vector the bomb to vertical and give it some speed as it's far to slow.

_vel You will need to specify velocity -200 doesn't look to bad for most ammo types.

I'm not sure how this works with multipe strikes.

_artilleryStrike setvectorup [0,9,0.1];


_artilleryStrike setVelocity [0,0,_vel];

Edited by F2k Sel

Share this post


Link to post
Share on other sites
"CAN_COLLIDE" creates the vehicle exactly where asked, not checking if others objects can cross its 3D model.

I'd just use "NONE". Makes things simple! :D

A couple of other things which might help:

  1. When creating the artillery, the line '_y = round(random _spread);' is placed after the first shell is created, meaning that the first shell will always hit -10m (X) and -10m (Y) from where the player clicked the map, disregarding the spread.
  2. (From what I know) The kind of For loop you're using is only really useful when changing the step. You can do the same with the type of For loop below, but it looks a bit nicer if you're doing something simple.

Try:

//Loops the amount of times stored in _amount

for "_x" from 1 to _amount do {
//Creates a ramndom number from 0 up to the value assigned to _spread
_y = round(random _spread);

//Creates the slected ARTY_Sh_122_HE at 300 meters
_artilleryStrike = _ammo createVehicle [(getMarkerPos _bombsite1 select 0) + (_y - 10),( getMarkerPos _bombsite1 select 1) + (_y - 10), _height];

//Delays the code for the selected amount of time
sleep _delay;
};

Share this post


Link to post
Share on other sites
To make it look a little more realistic you need to vector the bomb to vertical and give it some speed as it's far to slow.

_vel You will need to specify velocity -200 doesn't look to bad for most ammo types.

I'm not sure how this works with multipe strikes.

_artilleryStrike setvectorup [0,9,0.1];


_artilleryStrike setVelocity [0,0,_vel];

Ok, first of all thanks for helping. Now the codes worked, but the setVectorUp worked only at low level, like 10 meters above the ground, when I spawn it 100 for example it comes down on an angle instead of the being completely vertical.

---------- Post added at 05:56 PM ---------- Previous post was at 05:48 PM ----------

I'd just use "NONE". Makes things simple! :D

A couple of other things which might help:

  1. When creating the artillery, the line '_y = round(random _spread);' is placed after the first shell is created, meaning that the first shell will always hit -10m (X) and -10m (Y) from where the player clicked the map, disregarding the spread.
  2. (From what I know) The kind of For loop you're using is only really useful when changing the step. You can do the same with the type of For loop below, but it looks a bit nicer if you're doing something simple.

Try:

//Loops the amount of times stored in _amount

for "_x" from 1 to _amount do {
//Creates a ramndom number from 0 up to the value assigned to _spread
_y = round(random _spread);

//Creates the slected ARTY_Sh_122_HE at 300 meters
_artilleryStrike = _ammo createVehicle [(getMarkerPos _bombsite1 select 0) + (_y - 10),( getMarkerPos _bombsite1 select 1) + (_y - 10), _height];

//Delays the code for the selected amount of time
sleep _delay;
};

I see. but the -10 meters are just there to make negative values for the random numbers from 1 to 10 of the spread radius. this could be replaced with the other code I wanted to implement since the placement radius will take care of the negative and positive values. About the loop, I didn't know you could use a For loop like that here, I'm just taking the structure of the loops from a sqf guide I found on the net.

Share this post


Link to post
Share on other sites

Ahh ok I see.

Well, in terms of the placement radius, (you probably already know) if you use createVehicle Array, you can specify the placement radius. So, changes highlighted in red, you could do something like:

[color="red"]//Set the position of our target
_roundPos = [getMarkerPos _bombsite1 select 0, getMarkerPos _bombsite1 select 1, _height];[/color]

//Loops the amount of times stored in _amount

for "_x" from 1 to _amount do {
//Creates a ramndom number from 0 up to the value assigned to _spread
_y = round(random _spread);

//Creates the slected ARTY_Sh_122_HE at 300 meters
[color="Red"]_artilleryStrike = createVehicle [_ammo, _roundPos, [], _spread, "NONE"];[/color]

//Delays the code for the selected amount of time
sleep _delay;
};

Using the in-built placement radius saves you having to generate random positions.

Also, using F2k Sel's code, I think that to put something upside-down you have to use this setVectorUp [0.001, 0.001, -1];.

Also, through some quick testing, the terminal velocity of "ARTY_Sh_105_HE" is 160.645 m/s. So, I'd make sure to keep your _vel value to that number, otherwise it will just speed up / slow down to that speed during flight.

So, we could do:

//Set our velocity
_vel = 160.645;

//Set the position of our target
_roundPos = [getMarkerPos _bombsite1 select 0, getMarkerPos _bombsite1 select 1, _height];

//Loops the amount of times stored in _amount

for "_x" from 1 to _amount do {

//Creates the slected ARTY_Sh_122_HE at 300 meters
_artilleryStrike = createVehicle [_ammo, _roundPos, [], _spread, "NONE"];
_artilleryStrike setVectorUp [0.001, 0.001, -1];
_artilleryStrike setVelocity [0, 0, -_vel];

//Delays the code for the selected amount of time
sleep _delay;
};

We could also tailor the height (seeing as it's now sped up), to match the velocity and time required.

This way, you'll be defining '_initDelay' as the amount of time before the first shell arrives, and then deciding on the height to keep the velocity of the shell the same.

Using the formula Distance = Speed x Time, we could do:

_height = ((_vel * _initDelay) / 2);

Make sure to make _vel a positive number. It just simplifies things.

So, say we want the delay to be 30 seconds before first impact, and then 5 seconds in-between each round:

//Set our velocity and requested delay
_vel = 160.645;
_initDelay = 30;
_roundDelay = 5;

//Calculate our height
_height = ((_vel * _initDelay) / 2);

//Set the position of our target
_roundPos = [getMarkerPos _bombsite1 select 0, getMarkerPos _bombsite1 select 1, _height];

//Loops the amount of times stored in _amount
for "_x" from 1 to _amount do {

//Creates the slected ARTY_Sh_122_HE at 300 meters
_artilleryStrike = createVehicle [_ammo, _roundPos, [], _spread, "NONE"];
_artilleryStrike setVectorUp [0.001, 0.001, -1];
_artilleryStrike setVelocity [0, 0, -_vel];

//Delays the code for the selected amount of time
sleep _roundDelay;

};

Hope I helped some.

Edited by Fuzzy Bandit
Adding bits of code / ideas...

Share this post


Link to post
Share on other sites

I see, Ill try it later, I have to go out now will be back in a couple of hours to try the code.

Share this post


Link to post
Share on other sites

I checked the bomb vector and it works correctly at my end, using the art shell you don't need the velocity command as they seem fast enough. Bombs fall too slowly and need some extra speed.

Share this post


Link to post
Share on other sites

Hi! I keep trying to use the setVectorUp and it still seems to work @ low altitude, but when I spawn again at lets say 100 meters they keep coming down on an angle. I had to play with the values to make it appear perfectly straight. Ill try it again and will post back.

Share this post


Link to post
Share on other sites

I can't really work out why, are you using vector after spawning.

If you use the "Bo_GBU12_LGB" it drops slowly at an angle but I can drop it form 1500 meters using the vector command and get it to within a couple of meters of dead centre of the target.

I've tested with "ARTY_Sh_122_HE" and it's just the same, to test it I froze it mid flight as otherwise it's hard to see.

Fuzzy has also used a vector in the updated script above, now if that works for him it doesn't for me it's still flat.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
I can't really work out why, are you using vector after spawning.

If you use the "Bo_GBU12_LGB" it drops slowly at an angle but I can drop it form 1500 meters using the vector command and get it to within a couple of meters of dead centre of the target.

I've tested with "ARTY_Sh_122_HE" and it's just the same, to test it I froze it mid flight as otherwise it's hard to see.

Fuzzy has also used a vector in the updated script above, now if that works for him it doesn't for me it's still flat.

Finally, I never saw the error, every time I tried I copy/paste the cod, but now it worked perfectly @ any distance, I tried with the Mk82 since I don't know how to freeze the damn thing in mid air. I will be glad if you post the code to do that. Thanks again for your coop.

---------- Post added at 11:46 PM ---------- Previous post was at 10:47 PM ----------

@Fuzzy Bandit i also replaced the old for loop and the old way I spawned the mortars for the one that let me use the radius of placement as the _spread. Next task is to change the how the code manages the arguments with the Swtch Case structure you gave me. This thing is getting better with all of these.

Edited by wickedstigma

Share this post


Link to post
Share on other sites

I found out that freezing it had an odd effect that messes up the vectoring anyway.

If you spawn the bomb 100 meters for eg and then vector it you can use the attachto command to attach it to an object.

_bomb attachto [player,[0,2,2]] pust the bomb 2 meters in front and 2 meters high so you can see it.The problem is that doing this will make it always appear to be flat.

However if you place the attachto command before the vectoring it works and you can check the orientation of the vector.

So it is of some use for things that fly too fast to see properly.

Warning the bomb is still live so don't knock it.

.

Share this post


Link to post
Share on other sites

I do believe that bombs such as the GBU-12 and Mk82 naturally don't fall straight down - they start accelerating in the X and Z axis as well.

Artillery Shells don't do that for me, and using the vector below I can turn any object directly up-side-down. Tanks, shells, people, boats, anything.

this setVectorUp [0.001, 0.001, -1];

Share this post


Link to post
Share on other sites

Upside down yes that works but the shells need to be turned through 90deg not 180deg.

Share this post


Link to post
Share on other sites

It doesn't matter which way they are initially pointing.

From the biki:

player setVectorUp [0,1,0]
  If the player is facing 0 degrees (north), then this will do NOTHING.
  If the player is facing 90 degrees (east), then this will make him bank 90 degrees to his left.

Share this post


Link to post
Share on other sites

I get that but that's not what I'm talking about, the shell is a cylinder and tuning it upside down still has it lying on it's side but now it's the other side.

A car upside down is still lying flat, it needs to point nose down for a bomb as they are spawned flat.

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  

×