Jump to content
Sign in to follow this  
cornhelium

Looping a sourced sound

Recommended Posts

Hi there,

I'm trying to place a sound on the map that will loop for as long as no human is present within 50m of the sound's source. When a human comes within 50m the sound should stop, only starting after all humans have left the area again.

The effect I'm after is that birds and animals in the jungle canopy will fall silent when humans are near - mainly to increase the tension as an enemy patrol approaches your ambush. wink_o.gif

I'm having 2 problems:

1. How do I get the sound to loop as long as nobody is present? At the moment I'm placing a gamelogic "birds1" to be the sound source and then using this line in triggers:

birds1 say "mysound"

...but of course it only plays once.

2. When I try to start the above with just 1 trigger, set to Nobody present, it won't work because the gamelogic "birds1" is right in the middle of the trigger area.

I have to use 4 separate triggers - one each for East, West, Guer and Civ not present. But then, the sound triggers 4 times biggrin_o.gif

Can I get 1 trigger to activate when no units >except< gamelogics are present?

Thanks,

CH

Share this post


Link to post
Share on other sites

Make the trigger activated by anyone and have a looping script playing the sound with a delay roughly equal to sound lenght or whatever delay you want in between repeating the sound. In the looping script, check if anyone is in the trigger area with 'list triggername' command. If list returns game logic just subtract it from the list array or use 'count list triggername > 1' as condition.

Share this post


Link to post
Share on other sites

Thanks guys, I really appreciate it.

One last question from a scripting newbie: what would be the syntax to subtract the gamelogic class from the trigger array?

Cheers,

CH

Share this post


Link to post
Share on other sites

Like this: new_list = (list triggername) - [gl_name];

Or multiple gamelogics new_list = (list triggername) - [gl_name1, gl_name2, gl_name3];

Or you could go trough the array with forEach and remove objects of logic type.

Share this post


Link to post
Share on other sites

Sorry guys,

Scripting f*rtcknocker that I am, I can't get this to work.

Using the script below, the sound doesn't stop playing when a unit walks into the trigger area:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_list1 = (list trig1) - [bird1, bird2]

_check1 = count _list1

#loop

~2

? _check1 > 0 : exit

bird1 say "bas_af_attack1"

goto "loop"

Any ideas please?

Thanks,

CH

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#loop

_list1 = (list trig1) - [bird1, bird2]

_check1 = count _list1

? _check1 > 0 : bird1 say "bas_af_attack1";

~2

goto "loop"

wink_o.gif

And also make sure it's run only once, you can run it from init.sqs or from a gamelogic init line with: [] exec "script.sqs";

Share this post


Link to post
Share on other sites

Wow thanks Metal Heart, sorted!

This works nicely:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#loop

;approx length of sound to be looped

~3

;list units in trigger area, excluding the sound source gamelogics

_list1 = (list trig1) - [bird1, bird2]

;check if more units have entered trigger area

;if so then wait silently

? count _list1 > 0 : goto "wait"

;if not then bird sings and loops

bird1 say "bas_af_attack1"

goto "loop"

#wait

~20

;check again to see if units have left area

;if not wait and check again

_list1 = (list trig1) - [bird1, bird2]

? count _list1 > 0 : goto "wait"

;if area is clear again restart singing loop

goto "loop"

So you're moving into the jungle, birds and monkeys ahead of you are happily singing & chattering away. When you get too close, they see you and keep quiet until you've gone away. Or, you set up an ambush on the edge of the same jungle and wait. ...As the enemy approaches the birds and monkeys fall silent, giving you better tactical awareness.

Here's a variant with an "alarm call":

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#loop

~3

_list1 = (list trig1) - [bird1, bird2]

? count _list1 > 0 : goto "wait"

bird1 say "bas_af_attack1"

goto "loop"

#wait

;give alarm call

bird1 say "bas_af_attack2"

;wait and check to see if units have left area

;if not give alarm call wait and check again

~20

_list1 = (list trig1) - [bird1, bird2]

? count _list1 > 0 : goto "wait"

goto "loop"

Sure is rewarding when things like this work out. ...hope I can make a full wildlife environment for a mission without lagging it to death  wink_o.gif

2 variations that would be super-cool:

a) alarm call triggers another script, in which there's a chance that any East, West or Guer units within 150m will come towards the soundsource to check it out, then go back to what they were doing xmas_o.gif

b) once an alarm call is made, the script gets the direction of the unit whose presence triggered it. Then, it relocates the trigger and soundsource gamelogic somewhere in a 120 degree cone, 50-150m ahead of that unit, making sure that the new location is on land and waiting 1-5 minutes before starting the whole singing loop up again. As most animals/birds move away from the thing that alarmed them then settle down, this would be pretty realistic, and combined with a) you'd have to plan your approach to the enemy very carefully wink_o.gif

Cheers,

CH

Share this post


Link to post
Share on other sites

OK, I'm going crazy now  banghead.gif

* I have one 500m trigger, set to triggered once by player group, called "nightjar_hunting1_start1". This starts the nightjar_hunting1.sqs when the player first comes into earshot.

* Inside that trigger is another 100m trigger, called "nightjar_hunting1_trig". This is there so the script can detect if someone comes too close to the gamelogic in the center.

* The gamelogic in the center of these triggers is called "nightjar_hunting1_logic". This actually emits the sounds of a Eurasian Nightjar hunting, when the script tells it to.

The problem: It all works fine, except I can't get the script to move to the "playercheck" part. Can anyone tell me where I'm going wrong please?

Alternatively, if the script could move between the "loop" and "playercheck" sections depending on the player group's distance from "nightjar_hunting1_logic", I could do away with the big trigger altogether.

I'd like to have quite a few of these environmental sounds on the map, and want to cut down on CPU/memory usage as much as possible.

nightjar_hunting1.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#loop

;list units in trigger area, excluding the sound source gamelogics

_list1 = (list nightjar_hunting1_trig) - [nightjar_hunting1_logic]

;check if more units have entered trigger area

;if so then wait silently

? count _list1 > 0 : goto "wait"

;if not then bird sings and loops

nightjar_hunting1_logic say "nightjar_eurasian_hunting"

~20

;check that player has not left wider trigger area

;if so then go to the playercheck section

? !aP in (list nightjar_hunting1_start1):goto "playercheck"

goto "loop"

#wait

~10

;check again to see if units have left area

;if not wait and check again

_list1 = (list nightjar_hunting1_trig) - [nightjar_hunting1_logic]

? count _list1 > 0 : goto "wait"

;if area is clear again restart singing loop

goto "loop"

#playercheck

;wait for 3 minutes before checking again for player in wider trigger area

hint "waiting for player"

~180

? aP in list nightjar_hunting1_start1 : goto "loop"

goto "playercheck"

Also, if someone could show me how to set up the script so that multiple gamelogic/trigger pairs can exec it please, I'd be eternally grateful. I've tried a few times, but keep getting "type x, expected y" errors sad_o.gif

Thanks a mil thumbs-up.gif

CH

Share this post


Link to post
Share on other sites

Ah, got it:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#loop

;list units in trigger area, excluding the sound source gamelogics

_list1 = (list nightjar_hunting1_trig) - [nightjar_hunting1_logic]

;check if more units have entered trigger area

;if so then wait silently

? count _list1 > 0 : goto "wait"

;if not then bird sings and loops

nightjar_hunting1_logic say "nightjar_eurasian_hunting"

~20

;check that player has not left wider trigger area

;if so then go to the playercheck section

?(player distance nightjar_hunting1_logic > 200):goto "playercheck"

goto "loop"

#wait

~10

;check again to see if units have left area

;if not wait and check again

_list1 = (list nightjar_hunting1_trig) - [nightjar_hunting1_logic]

? count _list1 > 0 : goto "wait"

;if area is clear again restart singing loop

goto "loop"

#playercheck

;wait for 3 minutes before checking again for player in wider trigger area

hint "waiting for player"

~180

?(player distance nightjar_hunting1_logic > 200):goto "playercheck"

goto "loop"

If someone could show me how to make this script exec-able by multiple gamelogics please, that would be great.

I've tried putting this in the gamelogic:

[this, nightjar_hunting1_trig] exec "nightjar_hunting1.sqs"

so that the soundsource logic and area check trigger are passed to the script as this select 0 and this select 1, but no matter what I try I can't get the syntax working in-script huh.gif

Cheers,

CH

Share this post


Link to post
Share on other sites

That'd be something like: [this, trig_1] exec "speak.sqs";

;speak.sqs

_soundsource = _this select 0

_trigger = _this select 1

#loop

?player in list _trigger :_soundsource say "Rus16";

~2

goto "loop";

exit;

But maybe you should create the trigger from the script (I'm not sure if this is possible), you'd save some work as you could just copy paste the game logics all over the place and it would work without any modification of their init lines or anything. The init could be like: [this,"sound_name"] exec "playsound.sqs";

Or maybe you could use the distance command.

Share this post


Link to post
Share on other sites

Thanks mate,

I'll come back to this after my exams, but your answer gives me exactly what I need to move on notworthy.gif

As you suggest, I've also modified it so that the gamelogics themselves exec the script when the player comes within xxx meters.

Cheers,

CH

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  

×