Home   Help Search Login Register  

Author Topic: Screaming in the woods...  (Read 3115 times)

0 Members and 1 Guest are viewing this topic.

cragtek

  • Guest
Screaming in the woods...
« on: 22 Jan 2006, 07:05:38 »
Hi guys,

It's been a while but I'm back in the OFP fold! I'm working on a new 1-on-1 multiplayer map and could use some help in the sound side of things.

The map is set at night in thunder and rain and is in the flagfight format. The drop-off point is surrounded by woods. I'm trying to have a sound play randomly from a randomly-selected marker (of which there will be several - i.e. one per wood) at a random interval once or twice during a half-hour period.

The sound is a scream to keep the player suitably on their toes and thoroughly harrowed. I'm intrigued by the possibility of hearing a scream in the woods from across the map in the dark.

So, basically I'm a little rusty and haven't got a clue how to set this up. If you give me a general idea, I can work the specifics myself. Any help would be great.

Cheers in advance,

Craig.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Screaming in the woods...
« Reply #1 on: 22 Jan 2006, 10:43:56 »
I am not sure how rusty you are, lets assume not too rusty  :)

Some thing like

Code: [Select]
_soundobj = "logic" createvehicle [0,0,0]
_locations = [getMarkerPos "marker1",getMarkerPos "marker2",....]

#loop
~120 + random 240
#again
_loc = random count _locations
_loc = _loc - (_loc % 1)
if (_loc >= count _locations) then {goto"again"}
_soundobj setPos (_locations select _loc)
_soundobj say "nameofscream"
goto "loop"

It should give you a scream at a randomly selected marker position.  The time between the screams will be somewhere between 120 and 360 seconds.

Totally untested so there may be some typos or the syntax may not be perfect - but logic is fine.  I can't remember if OFP puts gamelogics at sealevel when it moves them - it certainly does that for triggers.  If you cannot hear the scream then you may need to replace the line:
Code: [Select]
_soundobj setPos (_locations select _loc)with
Code: [Select]
_soundobj setPos [(_locations select _loc) select 0,(_locations select _loc) select 1,0]
You might also want to look at:
http://www.ofpec.com/editors/faq_view.php?id=409
Using that you could then select a point for the sound that is randomly selected near the marker instead of the sound always coming from the marker position.  Something like:

Code: [Select]
_dist = 150*(random 1)^0.5
_theta = random 360
_soundobj setPos [((_locations select _loc) select 0) +dist*sin (_theta),((_locations select _loc) select 1) + dist*cos(_theta),0]

All that is for SP, I have no experience with MP.
« Last Edit: 22 Jan 2006, 11:35:42 by THobson »

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:Screaming in the woods...
« Reply #2 on: 22 Jan 2006, 14:41:27 »
Just a little comment about gamelogics: OFP handles them like units, so they will be placed on ground level. I use them as camera positions and if i don't setpos them 2 meters above ground, camera looks like set to ground :-)

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #3 on: 22 Jan 2006, 16:58:35 »
Superb! Thanks very much guys, extremely helpful as always. :-)

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #4 on: 22 Jan 2006, 18:00:49 »
Just one more thing... say if I had 4 or 5 sounds (woman screaming, man screaming, wolf howl etc), how would I make it randomly select a sound to play too?

Thanks very much,

Craig




Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Screaming in the woods...
« Reply #5 on: 22 Jan 2006, 18:21:47 »
Code: [Select]
_sounds = ["sound1","sound2",...]

_sound = random count _sounds
_sound = _sound - (_sound %1)

_soundobj say (_sounds select _sound)

« Last Edit: 22 Jan 2006, 18:22:29 by THobson »

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #6 on: 22 Jan 2006, 18:23:04 »
Ah yes.

Well thanks enourmously!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Screaming in the woods...
« Reply #7 on: 22 Jan 2006, 18:27:52 »
Putting it all together you get:

Code: [Select]
_soundobj = "logic" createvehicle [0,0,0]
_locations = [getMarkerPos "marker1",getMarkerPos "marker2",....]
_sounds = ["sound1","sound2",...]

#loop
~120 + random 240

#anotherLoc
_loc = random count _locations
_loc = _loc - (_loc % 1)
if (_loc >= count _locations) then {goto"anotherLoc"}
_dist = 150*(random 1)^0.5
_theta = random 360
_soundobj setPos [((_locations select _loc) select 0) +dist*sin (_theta),((_locations select _loc) select 1) + dist*cos(_theta),0]

#anotherSound
_sound = random count _sounds
_sound = _sound - (_sound %1)
if (_sound >= count _sounds) then {goto"anotherSound"}
_soundobj say (_sounds select _sound)
goto "loop"

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #8 on: 22 Jan 2006, 23:24:51 »
Hrm, seems to be throwing up a problem with this line:

if (_sound >= count _sounds) then {goto"anotherSound"}

Error: Unknown operator.

-Craig

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Screaming in the woods...
« Reply #9 on: 23 Jan 2006, 00:07:35 »
Where is the # in the error message?

You seem not to have a space between count and _sounds
« Last Edit: 23 Jan 2006, 00:11:07 by THobson »

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #10 on: 23 Jan 2006, 00:12:02 »
Code: [Select]
_soundobj = "logic" createvehicle [0,0,0]
_locations = [getMarkerPos "marker1",getMarkerPos "marker2"]
_sounds = ["ScreamF","ScreamM"]

#loop
~120 + random 240

#anotherLoc
_loc = random count _locations
_loc = _loc - (_loc % 1)
if (_loc >= count _locations) then {goto"anotherLoc"}
_dist = 150*(random 1)^0.5
_theta = random 360
_soundobj setPos [((_locations select _loc) select 0) +dist*sin (_theta),((_locations select _loc) select 1) + dist*cos(_theta),0]

#anotherSound
_sound = random count _sounds
_sound = _sound - (_sound %1)
if (_sound >= count _sounds) then {goto"anotherSound"}
_soundobj say (_sounds select _sound)
goto "loop"

Thanks for the help on this, much appreciated.

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #11 on: 23 Jan 2006, 00:27:26 »
I added the space and it doesn't seem to have made any difference.

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:Screaming in the woods...
« Reply #12 on: 23 Jan 2006, 00:36:07 »
Plank, you were close. It does require a space. But actually, it needs one here:
Code: [Select]
...
{goto"anotherLoc"}
...
{goto"anotherSound"}
...

which should actually look like:
Code: [Select]
....
{goto "anotherLoc"}
....
{goto "anotherSound"}

Notice the missing spaces in between goto and "anotherBlahBlah"
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #13 on: 23 Jan 2006, 00:46:23 »
Hrm. Ok, still having the same problem... unknown operator on these two lines. Firstly, this one is thrown up:

if (_sound >= count _sounds) then {goto "anotherSound"}

If I comment that out, it throws up a problem with:

if (_loc >= count _locations) then {goto "anotherLoc"}

Again, unknown operator. The # is after the if in both cases. If I comment both out, no further errors, but obviously the script doesn't work if I do that.

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:Screaming in the woods...
« Reply #14 on: 23 Jan 2006, 00:48:44 »
Okay, well I think I fixed something still ;D

Anyway, try this:

if (_sound >= (count _sounds)) then {goto "anotherSound"}

with both of them.

also, try

_loc = random (count _locations)

and do the same for the other.
« Last Edit: 23 Jan 2006, 00:51:30 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #15 on: 23 Jan 2006, 00:57:35 »
Oh yes, and ? instead of 'if'!

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #16 on: 23 Jan 2006, 01:20:46 »
No errors, but still not hearing any screams! Please could you tell me what exactly I should create in the editor?

I have defined the sounds in description.ext too.
« Last Edit: 23 Jan 2006, 03:13:17 by cragtek »

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:Screaming in the woods...
« Reply #17 on: 23 Jan 2006, 04:46:33 »
Im not sure. I was just looking for syntax errors. I don't really know what would be causing any problems. Do you have the sounds defined in the description.ext properly, etc etc? As in proper folders? Just double checking... :P
« Last Edit: 23 Jan 2006, 04:50:30 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Screaming in the woods...
« Reply #18 on: 23 Jan 2006, 08:45:23 »
I would stick with using if and not ?  It is so much more powerful and flexible.

I suggest you write a script to get one sound working in one place and then use this script to randomise the whole thing.

Tyger:  Thanks it looks like  I was a bit lazy with the brackets

« Last Edit: 23 Jan 2006, 08:46:05 by THobson »

cragtek

  • Guest
Re:Screaming in the woods...
« Reply #19 on: 23 Jan 2006, 14:46:15 »
Yep, sounds are defined. Should I be creating two markers called marker1 and marker2, or should I be creating gamelogics?

For some reason if I use 'if' I get the operator error. With '?' the errors disappear, but then the script doesn't do anything.

Sorry about this, guys, must be a right pain!

-Craig

PS. Incidentally, I've tried commenting out lines and still no joy. Could it be a problem with the 'say' command?

Here is my description.ext (or the relevant parts at least):

Code: [Select]
class CfgSounds
{
sounds[] =
{
UScore, ScreamM, ScreamF, UCapture
};

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

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

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

class UCapture
{
name = "UCapture";
sound[] = {"UCapture.ogg", 10, 1.0};
titles[] = { };
};
};

« Last Edit: 23 Jan 2006, 15:37:18 by cragtek »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Screaming in the woods...
« Reply #20 on: 23 Jan 2006, 17:46:39 »
Just a quick look:

I specify the folder in my sound definitions:

sound[] = {"\sound\UScore.ogg", 1, 1.0};

Is the volume of the sounds loud enough?

On the if line.  Those lines are a piece of belt and braces protection against a very rare event.  Generally they can be left out of the script.  But they should work.  I have never had the problems you describe.  Will you please copy and paste your script here so we can see it exactly - with the offending ifs