Activator that plays sounds in a random order

Post » Sat May 28, 2011 7:26 am

Heya,

I'm looking for some help with creating a script that will play a few selected sounds in a random order. (one at a time)
Let's say I have about 6 sound files (Sound1, Sound2, etc), would this require complicated scripting?

Any help would be appreciated.
User avatar
Multi Multi
 
Posts: 3382
Joined: Mon Sep 18, 2006 4:07 pm

Post » Fri May 27, 2011 6:58 pm

I think this will work, it needs to be tested.

Begin RandomSoundShort RandNumIf ( OnActivate == 1 )	Set RandNum to Random, 5	If ( RandNum == 0 )		Playsound, "MySound1"	ElseIf ( RandNum == 1 )		Playsound, "MySound2"	ElseIf ( RandNum == 2 )		Playsound, "MySound3"	ElseIf ( RandNum == 3 )		Playsound, "MySound4"	ElseIf ( RandNum == 4 )		Playsound, "MySound5"	Else		Playsound, "mySound6"	EndIfEndIfEnd

User avatar
Dragonz Dancer
 
Posts: 3441
Joined: Sat Jun 24, 2006 11:01 am

Post » Sat May 28, 2011 6:34 am

I think this will work, it needs to be tested.

Begin RandomSoundShort RandNumIf ( OnActivate == 1 )	Set RandNum to Random, 5	If ( RandNum == 0 )		Playsound, "MySound1"	ElseIf ( RandNum == 1 )		Playsound, "MySound2"	ElseIf ( RandNum == 2 )		Playsound, "MySound3"	ElseIf ( RandNum == 3 )		Playsound, "MySound4"	ElseIf ( RandNum == 4 )		Playsound, "MySound5"	Else		Playsound, "mySound6"	EndIfEndIfEnd



That does indeed work, but there are some errors.

First, it seems to be playing alot of sounds at the same time.
Secondly the sounds continue to play after leaving the cell.

The idea was to have one (random) sound playing all over the cell as soon as you enter (I'm using it in interior only), and the next (random) one starting after the first had finished playing. The sound stops playing as soon as you leave the cell.

Thanks for the input so far, much appreciated.
User avatar
Lucky Girl
 
Posts: 3486
Joined: Wed Jun 06, 2007 4:14 pm

Post » Sat May 28, 2011 2:07 am

That does indeed work, but there are some errors.

First, it seems to be playing alot of sounds at the same time.
Secondly the sounds continue to play after leaving the cell.

The idea was to have one (random) sound playing all over the cell as soon as you enter (I'm using it in interior only), and the next (random) one starting after the first had finished playing. The sound stops playing as soon as you leave the cell.

Thanks for the input so far, much appreciated.


Ok, i just assumed these were short sounds. I have a few questions before I try writing another script. Are you wanting the activator to play music? How long are the sounds? Do you want the sound to be a 3D sound and make it so it sounds like it is coming from the activator? What if the next random sound was the same as the first ( this could happen sometimes) would that bother you? I might be able to figure a way around that.
User avatar
alicia hillier
 
Posts: 3387
Joined: Tue Feb 06, 2007 2:57 am

Post » Fri May 27, 2011 11:50 pm

Hmm, now I'm having trouble with getsoundplaying.

Here is the script that is attached to an activator:
Begin RandomSoundShort RandNumIf ( OnActivate == 1 )	If ( GetSoundPlaying, "BM Nord attackf" == 1 )  ;I tried If ( "MyActivator"->GetSoundPlaying, "BM Nord attackf" == 1 ) but the script wouldn't run at all when i did that.		Return	ElseIf ( GetSoundPlaying, "WindBag" == 1 )		Return	ElseIf ( GetSoundPlaying, "WolfItem3" == 1 )		Return	ElseIf ( GetSoundPlaying, "WolfNPC3" == 1 )		Return	ElseIf ( GetSoundPlaying, "WolfHit3" == 1 )		Return	ElseIf ( GetSoundPlaying, "rmnt scream" == 1 )		Return	EndIf	Set RandNum to Random, 5	If ( RandNum == 0 )		Playsound, "BM Nord attackF"	ElseIf ( RandNum == 1 )		Playsound, "WindBag"	ElseIf ( RandNum == 2 )		Playsound, "WolfItem3"	ElseIf ( RandNum == 3 )		Playsound, "WolfNPC3"	ElseIf ( RandNum == 4 )		Playsound, "WolfHit3"	Else		Playsound, "rmnt scream"	EndIfEndIfEnd


It isn't registering the sound playing, and it plays another one while the original is still playing. Ideas anybody? Did I do something stupid :facepalm: .
User avatar
Emmanuel Morales
 
Posts: 3433
Joined: Sat Oct 06, 2007 2:03 pm

Post » Sat May 28, 2011 9:39 am

Ok, i just assumed these were short sounds. I have a few questions before I try writing another script. Are you wanting the activator to play music? How long are the sounds? Do you want the sound to be a 3D sound and make it so it sounds like it is coming from the activator? What if the next random sound was the same as the first ( this could happen sometimes) would that bother you? I might be able to figure a way around that.


Yeah the activator plays a short piece of music (as .wav files, not meant to replace the actual ingame music) that should be heard in the entire interior cell, so not coming from the activator (which is invisible).
They're about 0:32 to 0:44 long. The same sound playing twice would not be a problem. Short pauses between the files is allowed, but not necessary.
User avatar
Sheila Esmailka
 
Posts: 3404
Joined: Wed Aug 22, 2007 2:31 am

Post » Fri May 27, 2011 11:45 pm

Yeah the activator plays a short piece of music (as .wav files, not meant to replace the actual ingame music) that should be heard in the entire interior cell, so not coming from the activator (which is invisible).They're about 0:32 to 0:44 long. The same sound playing twice would not be a problem. Short pauses between the files is allowed, but not necessary.


Cool, that should be no problem to do, once I figure out the GetSoundPlaying function that is. It should be pretty strait forward but it isnt working :brokencomputer: .
User avatar
Tammie Flint
 
Posts: 3336
Joined: Mon Aug 14, 2006 12:12 am

Post » Fri May 27, 2011 8:44 pm

Cool, that should be no problem to do, once I figure out the GetSoundPlaying function that is. It should be pretty strait forward but it isnt working :brokencomputer: .


Great, do keep me posted on your progress!
User avatar
Samantha Pattison
 
Posts: 3407
Joined: Sat Oct 28, 2006 8:19 pm

Post » Sat May 28, 2011 2:08 am

I've got a thread started on another forum to try and figure out why getsoundplaying isn't working. Hopefully it will be answered soon.
User avatar
Fluffer
 
Posts: 3489
Joined: Thu Jul 05, 2007 6:29 am

Post » Sat May 28, 2011 9:13 am

OK, I think i got it.

Attach this script to your activator:
Begin RandomSoundIf ( OnActivate == 1 )		StartScript, Mf_Global_RandomSoundEndIfEnd



And just save this script in the editor, don't attach it to anything:
Begin Mf_Global_RandomSoundShort ConVarIf ( GetPcCell, "CellName" != 1 )	;Cell name goes here	If ( Player->GetSoundPlaying, "MySong1" == 1 )		Player->StopSound, "MySong1"	ElseIf ( Player->GetSoundPlaying, "MySong2" == 1 )		Player->StopSound, "MySong2"	ElseIf ( Player->GetSoundPlaying, "MySong3" == 1 )		Player->StopSound, "MySong3"	ElseIf ( Player->GetSoundPlaying, "MySong4" == 1 )		Player->StopSound, "MySong4"	ElseIf ( Player->GetSoundPlaying, "MySong5" == 1 )		Player->StopSound, "MySong5"	ElseIf ( Player->GetSoundPlaying, "MySong6" == 1 )		Player->StopSound, "MySong6"	EndIf	StopScript, Mf_Global_RandomSound  ;when you hit save on the script editor you will get an error, don't worry about it and hit save again	ReturnEndIfIf ( Player->GetSoundPlaying, "MySong1" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong2" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong3" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong4" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong5" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong6" == 1 )	ReturnEndIfSet ConVar to Random, 6If ( ConVar == 0 )	Player->PlaySound3d, "MySong1"ElseIf ( ConVar == 1 )	Player->PlaySound3d, "MySong2"ElseIf ( ConVar == 2 )	Player->PlaySound3d, "mySong3"ElseIf ( ConVar == 3 )	Player->PlaySound3d, "mySong4"ElseIf ( ConVar == 4 )	Player->PlaySound3d, "mySong5"ElseIf ( ConVar == 5 )	Player->PlaySound3d, "mySong6"EndIfEnd


If you have any problems just report it in here and i'll see if I can fix it.
User avatar
Jeneene Hunte
 
Posts: 3478
Joined: Mon Sep 11, 2006 3:18 pm

Post » Sat May 28, 2011 2:50 am

This works perfectly, except for one more thing;

Right now the activator only works in one cell (the one I had to put in the script). Is there a way to get it playing in any cell where I put the activator? (They will only be placed in interiors)

edit: Also, if I want the script to start without *activating* the activator, then changing "If ( OnActivate == 1 )" to "If ( OnActivate == 0 )" would fix that, right?
User avatar
Lily
 
Posts: 3357
Joined: Mon Aug 28, 2006 10:32 am

Post » Sat May 28, 2011 9:35 am

Change the activator script to this:

Begin RandomSoundIf ( ScriptRunning, Mf_Global_RandomSound == 1 )		ReturnEndIfIf ( OnActivate == 0 )		StartScript, Mf_Global_RandomSoundEndIfEnd


Tell me the names of all the cells you want the music to play in and I'll fix the script. Or you might be able to do it yourself, Is this in a large dungeon with many cells? Is the name of the cell similar to "Mycave, Entrance" and the next cell connected to that cell is "MyCave, Main room". Is it something to that effect? If so, change:

If ( GetPcCell, "MyCave, Entrance" != 1 )

to

If ( GetPcCell, "MyCave" != 1 ). This function can accept partial information. So it will work for all cells that start with the name "MyCave".
User avatar
Rachael
 
Posts: 3412
Joined: Sat Feb 17, 2007 2:10 pm

Post » Fri May 27, 2011 9:40 pm

The activator only placed in the current ingame manors. (There's a few in Balmora, Ald'Ruhn, Vivec and Mournhold)
Will it work if I change the script to "If ( GetPcCell, "Manor" != 1 )" or does it only work when the cell name starts with that word?

If not perhaps I can just copy/paste the script and make a different activator and script for each cell.
User avatar
Alina loves Alexandra
 
Posts: 3456
Joined: Mon Jan 01, 2007 7:55 pm

Post » Sat May 28, 2011 10:21 am

There are alot of manor cells, I wouldn't want to make a new script for each one. I'll try and figure out a way to make it easier.
User avatar
Big mike
 
Posts: 3423
Joined: Fri Sep 21, 2007 6:38 pm

Post » Fri May 27, 2011 11:09 pm

Ok, here is the newest version. There is one tiny flaw, Once you enter the manor (the random music will play like normal) and once you go into another room/cell connected to that manor it will stop the current random song and start a new random song, but that is if you have the activator in the other room. I don't think I'll be able to figure a way around this. But hey, may be the people in that room don't like the other peoples choice of music and they want to hear something different :lmao:

You'll have to make a global called Mf_G_Sound.
In case you don't know how to do that go to gameplay->Globals->New then enter "Mf_G_Sound" without the "" and thats that.

Attach this to the activator, and place the activator in every cell you want to hear the music in:
Begin RandomSoundIf ( GetDistance, "Player" > 4000 )	Set Mf_G_Sound to 1EndIfIf ( ScriptRunning, Mf_Global_RandomSound == 1 )	ReturnEndIfIf ( GetDistance, "Player" <= 4000 )	Set Mf_G_Sound to 0	StartScript, Mf_Global_RandomSoundEndIfEnd


And this is the loose script:
Spoiler
Begin Mf_Global_RandomSoundShort ConVarIf ( CellChanged == 1 )	Set Mf_G_Sound to 1EndIfIf ( Mf_G_Sound == 1 )	Set Mf_G_Sound to 0	If ( Player->GetSoundPlaying, "MySong1" == 1 )		Player->StopSound, "MySong1"	ElseIf ( Player->GetSoundPlaying, "MySong2" == 1 )		Player->StopSound, "MySong2"	ElseIf ( Player->GetSoundPlaying, "MySong3" == 1 )		Player->StopSound, "MySong3"	ElseIf ( Player->GetSoundPlaying, "MySong4" == 1 )		Player->StopSound, "MySong4"	ElseIf ( Player->GetSoundPlaying, "MySong5" == 1 )		Player->StopSound, "MySong5"	ElseIf ( Player->GetSoundPlaying, "MySong6" == 1 )		Player->StopSound, "MySong6"	EndIf;when you hit save on the script editor you will get an error, don't worry about it and hit save again	StopScript, Mf_Global_RandomSound	ReturnEndIfIf ( Player->GetSoundPlaying, "MySong1" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong2" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong3" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong4" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong5" == 1 )	ReturnElseIf ( Player->GetSoundPlaying, "MySong6" == 1 )	ReturnEndIfSet ConVar to Random, 6If ( ConVar == 0 )	Player->PlaySound3d, "MySong1"ElseIf ( ConVar == 1 )	Player->PlaySound3d, "MySong2"ElseIf ( ConVar == 2 )	Player->PlaySound3d, "mySong3"ElseIf ( ConVar == 3 )	Player->PlaySound3d, "mySong4"ElseIf ( ConVar == 4 )	Player->PlaySound3d, "mySong5"ElseIf ( ConVar == 5 )	Player->PlaySound3d, "mySong6"EndIfEnd


This still needs some testing so I'll keep an eye out on this thread in case you have any problems.
User avatar
katie TWAVA
 
Posts: 3452
Joined: Tue Jul 04, 2006 3:32 am

Post » Sat May 28, 2011 7:20 am

This works like a charm!
Many thanks for the effort you put into this and the swift feedback, very much appreciated!
User avatar
Sammygirl
 
Posts: 3378
Joined: Fri Jun 16, 2006 6:15 pm

Post » Sat May 28, 2011 3:06 am

I'm glad you like it, hopefully you wont run into any errors with it.
User avatar
Elisha KIng
 
Posts: 3285
Joined: Sat Aug 18, 2007 12:18 am


Return to III - Morrowind