Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Creating a distant sound
bagobonez Offline
Member

Posts: 66
Threads: 11
Joined: Jul 2011
Reputation: 0
#1
Creating a distant sound

Want to create a distant sound at a specific location that only sounds off when a player interacts with a certain door. Tried a few different things but not quite sure how to get it to work right.
05-19-2012, 04:33 PM
Find
SilentStriker Offline
Posting Freak

Posts: 950
Threads: 26
Joined: Jul 2011
Reputation: 43
#2
RE: Creating a distant sound

Place down a script area where you want the sound to be played, and when the player interacts with the door you make the sound play at the script area.

Edit: I realized you wanted it to stop when the player interacts with the door?

then you would do like rapture said

(This post was last modified: 05-19-2012, 04:40 PM by SilentStriker.)
05-19-2012, 04:35 PM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#3
RE: Creating a distant sound

You could make a timer in the function that calls the same function, so it loops on itself.

Then when the player interacts with the door, you can have it call a RemoveTimer(string& asName); + StopSound(string& asSoundName, float afFadeTime);
(This post was last modified: 05-19-2012, 04:38 PM by Rapture.)
05-19-2012, 04:36 PM
Find
bagobonez Offline
Member

Posts: 66
Threads: 11
Joined: Jul 2011
Reputation: 0
#4
RE: Creating a distant sound

(05-19-2012, 04:36 PM)Rapture Wrote: You could make a timer in the function that calls the same function, so it loops on itself.

Then when the player interacts with the door, you can have it call a RemoveTimer(string& asName); + StopSound(string& asSoundName, float afFadeTime);
Ok, sorry to be so needy, but can you post the exact script I would need (obviously substitute your_sound_file.snt) or whatever... I'm still a little confused. Not too experienced with timers because this is my first mod.
05-19-2012, 04:48 PM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#5
RE: Creating a distant sound

//The sound will be called when you enter the area "Area_Sound". I will have it play the sound and set a Timer that calls back onto itself every 4 seconds.
void OnStart()
{
  AddEntityCollideCallback("Player", "Area_Sound", "Script_Sound", true, 1);
}

//This is the callback
void Script_Sound(string &in asParent, string &in asChild, int alState)
{
  PlaySoundAtEntity("Sound_Grunt01", "amb_alert.snt", "Area_Sound01", 0, false);

  AddTimer("Sound01", 4, "Script_Sound");
}

//This part will be called when the player interacts with your "Door". I'm assuming you know how to have a callback function work on a Entity. (On the Door's properties)
void DoorTouch(string &in entity, string &in type)
{
  RemoveTimer("Sound01");
  StopSound("Sound_Grunt01", 1);
}

Does anyone else have problems with the frictional forums text editor... I'm spending more time trying to fix up all the text it screwes up, as opposed to helping someone.
05-19-2012, 06:10 PM
Find
bagobonez Offline
Member

Posts: 66
Threads: 11
Joined: Jul 2011
Reputation: 0
#6
RE: Creating a distant sound

(05-19-2012, 06:10 PM)Rapture Wrote: //The sound will be called when you enter the area "Area_Sound". I will have it play the sound and set a Timer that calls back onto itself every 4 seconds.
void OnStart()
{
  AddEntityCollideCallback("Player", "Area_Sound", "Script_Sound", true, 1);
}

//This is the callback
void Script_Sound(string &in asParent, string &in asChild, int alState)
{
  PlaySoundAtEntity("Sound_Grunt01", "amb_alert.snt", "Area_Sound01", 0, false);

  AddTimer("Sound01", 4, "Script_Sound");
}

//This part will be called when the player interacts with your "Door". I'm assuming you know how to have a callback function work on a Entity. (On the Door's properties)
void DoorTouch(string &in entity, string &in type)
{
  RemoveTimer("Sound01");
  StopSound("Sound_Grunt01", 1);
}

Does anyone else have problems with the frictional forums text editor... I'm spending more time trying to fix up all the text it screwes up, as opposed to helping someone.
Wow, thanks a lot. Will give this a try!
05-19-2012, 08:26 PM
Find
bagobonez Offline
Member

Posts: 66
Threads: 11
Joined: Jul 2011
Reputation: 0
#7
RE: Creating a distant sound

(05-19-2012, 08:26 PM)bagobonez Wrote:
(05-19-2012, 06:10 PM)Rapture Wrote: //The sound will be called when you enter the area "Area_Sound". I will have it play the sound and set a Timer that calls back onto itself every 4 seconds.
void OnStart()
{
  AddEntityCollideCallback("Player", "Area_Sound", "Script_Sound", true, 1);
}

//This is the callback
void Script_Sound(string &in asParent, string &in asChild, int alState)
{
  PlaySoundAtEntity("Sound_Grunt01", "amb_alert.snt", "Area_Sound01", 0, false);

  AddTimer("Sound01", 4, "Script_Sound");
}

//This part will be called when the player interacts with your "Door". I'm assuming you know how to have a callback function work on a Entity. (On the Door's properties)
void DoorTouch(string &in entity, string &in type)
{
  RemoveTimer("Sound01");
  StopSound("Sound_Grunt01", 1);
}

Does anyone else have problems with the frictional forums text editor... I'm spending more time trying to fix up all the text it screwes up, as opposed to helping someone.
Wow, thanks a lot. Will give this a try!
Ugh, I'm still confused. Let me explain exactly what I'm doing because I'm not sure you guys understand exactly what it is I'm trying to do. I have a set of strewn about armor pieces on a table. When the player leaves the area and is out of eyesight of the armor, I want there to be a hammering sound that plays AT THE AREA OF THE ARMOR and just plays the one time, and when the player returns to that area he notices the armor has been assembled into a full statue. The assembling of the armor I don't have a problem with, it's just getting that sound to play once and once only AT THE AREA of the armor and only when the player triggers the callback to have the armor assemble. So it doesn't technically have to be when the player interacts with a door, it could be a simple collide area script if that would make it easier. But I don't want the sound to start playing a loop and then the player walks back to the armor and says "Well, i notice this armor somehow assembled itself, but why is the hammering sound still going?"
05-19-2012, 11:28 PM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#8
RE: Creating a distant sound

Umm ok, then just get rid of the Timer. The sound will just play once.
05-20-2012, 12:01 AM
Find




Users browsing this thread: 3 Guest(s)