OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: cragtek 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.
-
I am not sure how rusty you are, lets assume not too rusty :)
Some thing like
_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:
_soundobj setPos (_locations select _loc)with
_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:
_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.
-
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 :-)
-
Superb! Thanks very much guys, extremely helpful as always. :-)
-
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
-
_sounds = ["sound1","sound2",...]
_sound = random count _sounds
_sound = _sound - (_sound %1)
_soundobj say (_sounds select _sound)
-
Ah yes.
Well thanks enourmously!
-
Putting it all together you get:
_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"
-
Hrm, seems to be throwing up a problem with this line:
if (_sound >= count _sounds) then {goto"anotherSound"}
Error: Unknown operator.
-Craig
-
Where is the # in the error message?
You seem not to have a space between count and _sounds
-
_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.
-
I added the space and it doesn't seem to have made any difference.
-
Plank, you were close. It does require a space. But actually, it needs one here:
...
{goto"anotherLoc"}
...
{goto"anotherSound"}
...
which should actually look like:
....
{goto "anotherLoc"}
....
{goto "anotherSound"}
Notice the missing spaces in between goto and "anotherBlahBlah"
-
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.
-
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.
-
Oh yes, and ? instead of 'if'!
-
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.
-
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
-
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
-
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):
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[] = { };
};
};
-
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