Jump to content
Sign in to follow this  
CaptainBravo

Simple questions about a random mortar script

Recommended Posts

Hi everyone,

I have a couple of simple questions about a random mortar script.

a) How do I add sound to it so every time it fires a sound file is played.

b) How do I call the script from a trigger I havetried a variation execVM and others with no luck.

Script:

// ///////////////////////////////////////////////////////////////

// 1. Center place an object ot gamelogic where you want the explosions.

// 2. Choose the size of the area in metere.

// 3. Select how many explosions you require

// 4. Select the maximum delay between explosions in seconds.

// 5. minimum delay is 0.5 secs and can be changed in the script.

// 6. If the two // are removed from the "Grenadebase" line a more visible marke is left on the ground.

// 7."HelicopterExploSmall" "HelicopterExploBig" "SmallSecondary"

_pos = _this select 0;

_area = _this select 1;

_rounds = _this select 2;

_del = _this select 3;

_height = 0;// increase this if you want the items to fall from the sky.

_ammo = "grenade";// Ammo can be changed for larger effects.

for [{_i = 0},{_i < _rounds},{_i = _i + 1}] do

{

_newpos = GetPos _pos;

_posX = _newpos select 0;

_posY = _newpos select 1;

_bomb = _ammo createVehicle[(_posX + random _area)-_area/2, (_posY + random _area)-_area/2,_height];

// _bomb = "GrenadeBase" createVehicle [(getpos _bomb select 0),(getpos _bomb select 1),-10];

sleep (random _del)+0.5;// minimum delay 0.5, adjust for best results.

};

Thanks for your help in advance.

Share this post


Link to post
Share on other sites

Perhaps I should rephrase the question .. has anyone got a random mortars/explosions script to work with the whizing sound. So a sound is played before explosion??

The above script works but have not been able to get a sound to work with it.

Share this post


Link to post
Share on other sites

Hi...I had a quick play with this and I will try to help. A little quick demo is here.

You need the whizz sound you want to use in .ogg format. Audacity can help you convert a .wav file to .ogg if you don't already have one.

Create a folder in your mission folder called sounds...put the sound file in there.

Create a description.ext in your mission folder and add this to it.

decription.ext

class CfgSounds
{
sounds[]= {mortarwhizz};

class mortarwhizz
{
	name = "mortarwhizz";
	sound[] = {\sounds\mortarwhizz.ogg, 1, 1.0};
	titles[] = {};
};

};

Below I have inserted the line needed to play the sound....and increased the height for the round so that the sound gets time to play before impact. I simply chose 50m. Using playsound the sound will not be directional...this may or may not be a problem for you.

yourscript.sqf

// ///////////////////////////////////////////////////////////////
// 1. Center place an object ot gamelogic where you want the explosions.
// 2. Choose the size of the area in metere.
// 3. Select how many explosions you require
// 4. Select the maximum delay between explosions in seconds.
// 5. minimum delay is 0.5 secs and can be changed in the script.
// 6. If the two // are removed from the "Grenadebase" line a more visible marke is left on the ground.
// 7."HelicopterExploSmall" "HelicopterExploBig" "SmallSecondary"

_pos = _this select 0;
_area = _this select 1;
_rounds = _this select 2;
_del = _this select 3;

_height = [b]50[/b];// increase this if you want the items to fall from the sky.
_ammo = "grenade";// Ammo can be changed for larger effects.

for [{_i = 0},{_i < _rounds},{_i = _i + 1}] do {
_newpos = GetPos _pos;
_posX = _newpos select 0;
_posY = _newpos select 1;
_bomb = _ammo createVehicle[(_posX + random _area)-_area/2, (_posY + random _area)-_area/2,_height];
[b]playsound "mortarwhizz";[/b]
// _bomb = "GrenadeBase" createVehicle [(getpos _bomb select 0),(getpos _bomb select 1),-10];
sleep (random _del)+0.5;// minimum delay 0.5, adjust for best results.
};

Hope that helps you mate. :)

Edit: I had not answered the trigger part of your question so I updated the demo to include a trigger!

Edited by twirly

Share this post


Link to post
Share on other sites

Very cool - had to remove some dependancies (on Vilas addons) from the mission.sqm to get it to work though. ;)

Share this post


Link to post
Share on other sites

Thanks binocs! I have been trying to get sound to work with the mortar script for a while! Thanks for your help! :bounce3:

A quick related question: I want the script to activate only when a player with his group are in trigger but dectivate when out. Not sure how to deactivate script?

Edited by CaptainBravo

Share this post


Link to post
Share on other sites

An interesting observation: The sound only works if sound file inside folder "sounds" :confused: If I place it in the normal sound folder it will not work. I know example mission has it under sounds.

I was trying to see why it is picking that specific sound from sounds instead of sound.

- Any ideas?

- Anyway of making the target area dfined by trigger area? so you have x and y axis (example 300x100) instead of just a circle of 100?

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

Edit: never mind question about sounds, description line in example had it under sounds.

Edited by CaptainBravo

Share this post


Link to post
Share on other sites
- Anyway of making the target area dfined by trigger area? so you have x and y axis (example 300x100) instead of just a circle of 100?

In the editor double click on the trigger and set axis a to 300 and axis b to 100.

Select Rectangle instead of Ellipse....set the Angle if you need to and you should be good to go.

You should really figure out how things work in the editor first before you move on to scripting! :)

Edited by twirly

Share this post


Link to post
Share on other sites
In the editor double click on the trigger and set axis a to 300 and axis b to 100.

Select Rectangle instead of Ellipse....set the Angle if you need to and you should be good to go.

You should really figure out how things work in the editor first before you move on to scripting! :)

Thanks twirly, I am familiar with setting up triggers :)

What I have meant is if you set trigger at say 300x200 but the script has 200as area, then the bombardant area will be that 200 in circle shape. My question can you get the hit area to match the trigger 300x200 instead of the 100 (not just activation but also target area)?

Share this post


Link to post
Share on other sites

:) ... sorry mate I didn't understand your problem....but I think I've got it for you now. Demo here.

This works with a rectangular marker. It will create a trigger at the same position and of the same shape as the marker.

The marker is named "mkr_impact" in this example. The code in the int.sqf below can be called from the marker itself.

init.sqf

nul = ["mkr_impact"] execVM "init_mortar.sqf";

init_mortar.sqf

private ["_mkr","_mkrdir","_mkrx","_mkry","_trig"];

_mkr = _this select 0;

_mkrdir = (markerDir _mkr) mod 360;
_mkrx = (getmarkerSize _mkr) select 0;
_mkry = (getmarkerSize _mkr) select 1;

_trig = createTrigger["EmptyDetector", getMarkerPos _mkr];
_trig setTriggerType "NONE";
_trig setTriggerArea[_mkrx, _mkry, _mkrdir, true];
_trig setTriggerActivation["EAST", "PRESENT", false];
_trig setTriggerStatements ["this", "nul = ['mkr_impact',8,3] execVM 'randmort.sqf'", ""];

randmort.sqf

private ["_mkr","_rounds","_del","_height","_ammo","_xy","_pos","_mkrposx","_mkrposy","_i","_bomb"];

_mkr = _this select 0;
_rounds = _this select 1;
_del = _this select 2;

_getmkrxy = {

private ["_mkr","_mkrdir","_mkrx","_mkry","_x1","_y1","_rotx","_roty"];

_mkr = _this select 0;

_mkrdir = markerDir _mkr;
_mkrx = (getmarkerSize _mkr) select 0;
_mkry = (getmarkerSize _mkr) select 1;

_x1 = (0-(_mkrx/2)) + random _mkrx;
_y1 = (0-(_mkry/2)) + random _mkry;

_rotx = _x1 * cos (_mkrdir) - _y1 * sin (_mkrdir);
_roty = _x1 * sin (_mkrdir) + _y1 * cos (_mkrdir);

[_rotx,_roty]

};

_height = 30;// increase this if you want the items to fall from the sky.
_ammo = "grenade";// Ammo can be changed for larger effects.

_xy = [];
_pos = [];
_mkrposx = (getMarkerPos _mkr) select 0;
_mkrposy = (getMarkerPos _mkr) select 1;

for [{_i = 0},{_i < _rounds},{_i = _i + 1}] do {
_xy = [_mkr] call _getmkrxy;
_pos = [_mkrposx + (_xy select 0),_mkrposy + (_xy select 1),_height];
_bomb = _ammo createVehicle _pos;
playsound "mortarwhizz";
sleep (random _del)+0.5;// minimum delay 0.5, adjust for best results.
};

I already see different ways to do this... but as it is...it works and I hope it helps you.

Share this post


Link to post
Share on other sites

Thanks twirly. I have tested and it works perfectly!!!

The only question is why use a script based trigger instead of an actual trigger placed on map?

Is it be easier (for noobs anyway) to edit a trigger on map (activation, condition, countdown, sound files activation). So you can place 2 seperate from each other, a trigger and a maker where trigger is used just to activate script and marker just for size and shape of area for target/bombardent.

Is that possible?

Thanks again for your great help.

Share this post


Link to post
Share on other sites
The only question is why use a script based trigger instead of an actual trigger placed on map?.

I used the scripted trigger because I didn't know how to get the dimensions of a trigger....I'm not sure if you can!

But you can get the dimensions of a marker.....and then create a trigger on top of the marker with same x and y dimensions and angle.

I agree it would be better/easier if we could just get the shape and angle of the trigger itself.

You can always make the marker invisible with setMarkerAlpha.

Share this post


Link to post
Share on other sites

A possible workaround is to set a condition in the scripted trigger. The condition will be based on another trigger placed on map. So the scripted trigger will have condition: Objective1 which is the name of a trigger placed on map elsewhere with its own activation and size.

Possible?

If yes, where do you place the condition in the scripted trigger?

Share this post


Link to post
Share on other sites

I'm a little lost why you want to do this but in the editor placed trigger you would set a variable to true if the trigger was tripped....and then check for that variable being true in the scripted trigger.

Create a variable called trig1_fired and set it's value to true in the editor placed trigger when the trigger is fired.

Then in the scripted trigger check to see if trig1_fired is true.

The code for the scripted trigger would be along these lines. This creates purple smoke at the triggers position:-

trig2 = createTrigger["EmptyDetector", getPos player];
trig2 setTriggerType "NONE";
trig2 setTriggerArea[10,10,0, true];
trig2 setTriggerActivation["NONE", "PRESENT", false];
trig2 setTriggerStatements ["[b]trig1_fired[/b]", "smoke = 'SmokeShellPurple' createVehicle (getPos trig2);", ""];

createTrigger and it's associated commands are here. Experiment with the code and see what happens.

Share this post


Link to post
Share on other sites

Thanks twirly. I will test butit looks like it will do the job nicely.

As to why another tigger is needed: I am want the activate mortar script when player group is inserted in an area so mortars will start firing in area B.

So you have a trigger 20x20 being activated by players group so a mortar script starts firing on marker 300x200.

I hope this clarifies the purpose :)

Thanks for your help.

Share this post


Link to post
Share on other sites

Ah...Ok...cool. That should work fine then!

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  

×