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 Delay sound from playing
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#1
Delay sound from playing

I've placed the sound "insanity_imageflash01.snt" (as shown in the script) to start playing when i open the map, but i want it to play a few seconds later than it does. Not right away. I need to use a timer for this right? However the scripting is beyond me. Do i place the:

"void AddTimer(string& asName, float afTime, string& asFunction);" in void OnStart()? If so, how do i connect it to "insanity_imageflash01.snt"? Thanks

void OnStart()

{
wakeUp();
PlaySoundAtEntity("", "insanity_imageflash01.snt", "Player", 1, false);
AddEntityCollideCallback("Player", "Musik", "CollideStartMusic", true, 1);
AddEntityCollideCallback("Player", "Flaska", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Ljud", "start", true, 1);
AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("", "Nyckel", "Rumpa", "UseKeyOnDoor", true);
AddUseItemCallback("", "Tillskap", "Skap", "UseKeyOnDoor", true);

}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "Unlock_door.snt", asEntity, 10, false);
RemoveItem(asItem);
}

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
}

void PlaySound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "21_intro_scream.snt", "Player", 1, false);
}

void CollideStartMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("02_amb_safe.ogg", false, 1.0f, 0, 0, true);
}

void wakeUp () {
    FadeOut(0);     // Instantly fades the screen out. (Good for starting the game)
    FadeIn(30);      // Amount of seconds the fade in takes
    FadeImageTrailTo(8, 2);
    SetPlayerActive(false);    
    FadePlayerRollTo(50, 220, 220);                 // "Tilts" the players head
    FadeRadialBlurTo(0.15, 2);
    SetPlayerCrouching(true);              // Simulates being on the ground
    AddTimer("trig1", 11.0f, "beginStory");            // Change '11.0f' to however long you want the 'unconciousness' to last
}

void beginStory(string &in asTimer){
    ChangePlayerStateToNormal();
    SetPlayerActive(true);
    FadePlayerRollTo(0, 33, 33);        // Change all settings to defaults
    FadeRadialBlurTo(0.0, 1);
    FadeSepiaColorTo(0,200);
    SetPlayerCrouching(false);
    FadeImageTrailTo(0,1);
}
(This post was last modified: 02-03-2015, 03:56 PM by LDOriginal.)
02-03-2015, 03:55 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Delay sound from playing

The timer function will run another set of code after it expires. It's quite simple.

If you want to run a script after 5 seconds of starting the map, here's an example snippet:

PHP Code: (Select All)
void OnStart()
{
    
AddTimer("timername"5.0f"TimerFunction");
}

void TimerFunction(string &in asTimer)
{
    
RunScript();


Use the AddTimer line to create a new timer. The first argument is the internal reference name for the timer. You can keep it blank for the most part, unless you need to remove the timer before it expires.

The second argument is the time until it expires (here 5 seconds).

The last argument is the function that will be called when it expires. Write a name here, then create that callback somewhere else in your script.

The callback must have the matching constructor parameters for a timer function (being string &in asTimer). Inside that block, run whatever lines you want to happen after the specified time. In your case, use the PlaySoundAtEntity one.

02-03-2015, 04:06 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#3
RE: Delay sound from playing

(02-03-2015, 04:06 PM)Mudbill Wrote: The timer function will run another set of code after it expires. It's quite simple.

If you want to run a script after 5 seconds of starting the map, here's an example snippet:

PHP Code: (Select All)
void OnStart()
{
    
AddTimer("timername"5.0f"TimerFunction");
}

void TimerFunction(string &in asTimer)
{
    
RunScript();


Use the AddTimer line to create a new timer. The first argument is the internal reference name for the timer. You can keep it blank for the most part, unless you need to remove the timer before it expires.

The second argument is the time until it expires (here 5 seconds).

The last argument is the function that will be called when it expires. Write a name here, then create that callback somewhere else in your script.

The callback must have the matching constructor parameters for a timer function (being string &in asTimer). Inside that block, run whatever lines you want to happen after the specified time. In your case, use the PlaySoundAtEntity one.

Getting "Error: Expected Data Type" Am i even close? lol

void OnStart()

{
AddTimer("timername", 5.0f, "PlaySound");
wakeUp();
PlaySoundAtEntity("", "insanity_imageflash01.snt", "Player", 1, false);
AddEntityCollideCallback("Player", "Musik", "CollideStartMusic", true, 1);
AddEntityCollideCallback("Player", "Flaska", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Ljud", "start", true, 1);
AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("", "Nyckel", "Rumpa", "UseKeyOnDoor", true);
AddUseItemCallback("", "Tillskap", "Skap", "UseKeyOnDoor", true);

}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "Unlock_door.snt", asEntity, 10, false);
RemoveItem(asItem);
}

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
}

void PlaySound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "21_intro_scream.snt", "Player", 1, false);
}

void CollideStartMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("02_amb_safe.ogg", false, 1.0f, 0, 0, true);
}

void wakeUp () {
    FadeOut(0);     // Instantly fades the screen out. (Good for starting the game)
    FadeIn(30);      // Amount of seconds the fade in takes
    FadeImageTrailTo(8, 2);
    SetPlayerActive(false);    
    FadePlayerRollTo(50, 220, 220);                 // "Tilts" the players head
    FadeRadialBlurTo(0.15, 2);
    SetPlayerCrouching(true);              // Simulates being on the ground
    AddTimer("trig1", 11.0f, "beginStory");            // Change '11.0f' to however long you want the

'unconciousness' to last
}

void beginStory(string &in asTimer){
    ChangePlayerStateToNormal();
    SetPlayerActive(true);
    FadePlayerRollTo(0, 33, 33);        // Change all settings to defaults
    FadeRadialBlurTo(0.0, 1);
    FadeSepiaColorTo(0,200);
    SetPlayerCrouching(false);
    FadeImageTrailTo(0,1);
}

void TimerFunction("PlaySound")
{
     RunScript("PlaySoundAtEntity(string &in asTimer", "insanity_imageflash01.snt", "Player", 1, false);

}
02-03-2015, 04:46 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Delay sound from playing

Not quite there. Let's take a look:

PHP Code: (Select All)
void TimerFunction("PlaySound")
{
     
RunScript("PlaySoundAtEntity(string &in asTimer""insanity_imageflash01.snt""Player"1false);



Notice that in my example, I left the constructor (which is the line that starts with void) with the part you usually see on the engine scripts page. That's because that's how they must be. Don't edit that. If you see on the script page, it says callback syntax beneath AddTimer. Basically copy/paste that into your script (as long as the name matches).

I just did RunScript(); as an example. RunScript(); doesn't do anything, neither does it exist at the moment. This is where you want to put your own. Replace RunScript(); with whatever you want to run.

It should look more like this:

PHP Code: (Select All)
void TimerFunction(string &in asTimer)
{
     
PlaySoundAtEntity("""insanity_imageflash01.snt""Player"1false);


If you look closely at the wakeUp() script you have, it features a timer called beginStory().

(This post was last modified: 02-03-2015, 06:22 PM by Mudbill.)
02-03-2015, 06:20 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#5
RE: Delay sound from playing

(02-03-2015, 06:20 PM)Mudbill Wrote: Not quite there. Let's take a look:

PHP Code: (Select All)
void TimerFunction("PlaySound")
{
     
RunScript("PlaySoundAtEntity(string &in asTimer""insanity_imageflash01.snt""Player"1false);



Notice that in my example, I left the constructor (which is the line that starts with void) with the part you usually see on the engine scripts page. That's because that's how they must be. Don't edit that. If you see on the script page, it says callback syntax beneath AddTimer. Basically copy/paste that into your script (as long as the name matches).

I just did RunScript(); as an example. RunScript(); doesn't do anything, neither does it exist at the moment. This is where you want to put your own. Replace RunScript(); with whatever you want to run.

It should look more like this:

PHP Code: (Select All)
void TimerFunction(string &in asTimer)
{
     
PlaySoundAtEntity("""insanity_imageflash01.snt""Player"1false);


If you look closely at the wakeUp() script you have, it features a timer called beginStory().

Yes i noticed that. It works now. At first it played two times. Once at the beginning like before and at the timers que, but i removed it from void OnStart() and now it plays as it should. Thanks for you help. It's not that i want the more experienced to just hand the codes to paste in the script. I want to learn this, but it's really, really hard for me to grasp the logic of it. But i enjoy it at the same time. I guess i'll be back later for another problem, lol.
02-03-2015, 07:14 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#6
RE: Delay sound from playing

A new timer related problem i'm trying to solve. I have a script area placed and when collided with, a screen effect takes place. I want this to stop after 10 seconds but i'm not getting the scripting done. The effect just goes on. Been trying several things from advices and explanations. But it's not going so well. Am i close to getting it to work?
void OnStart()

{
AddEntityCollideCallback("Player", "Snurrig", "CollideFadeImageTrailTo", true, 1);
wakeUp();
AddTimer("timername", 11.5f, "TimerFunction");
AddEntityCollideCallback("Player", "Musik", "CollideStartMusic", true, 1);
AddEntityCollideCallback("Player", "Flaska", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Ljud", "start", true, 1);
AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("", "Nyckel", "Rumpa", "UseKeyOnDoor", true);
AddUseItemCallback("", "Tillskap", "Skap", "UseKeyOnDoor", true);

}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "Unlock_door.snt", asEntity, 10, false);
RemoveItem(asItem);
}

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
}

void PlaySound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "21_intro_scream.snt", "Player", 1, false);
}

void CollideStartMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("02_amb_safe.ogg", false, 1.0f, 0, 0, true);
}

void wakeUp () {
    FadeOut(0);     // Instantly fades the screen out. (Good for starting the game)
    FadeIn(20);      // Amount of seconds the fade in takes
    FadeImageTrailTo(6, 2);
    FadeSepiaColorTo(0, 0);
    SetPlayerActive(false);    
    FadePlayerRollTo(50, 220, 220);                 // "Tilts" the players head
    FadeRadialBlurTo(0.15, 2);
    SetPlayerCrouching(true);              // Simulates being on the ground
    AddTimer("trig1", 11.0f, "beginStory");            // Change '11.0f' to however long you want the 'unconciousness' to last
}

void beginStory(string &in asTimer){
    ChangePlayerStateToNormal();
    SetPlayerActive(true);
    FadePlayerRollTo(0, 33, 33);        // Change all settings to defaults
    FadeRadialBlurTo(0.0, 1);
    FadeSepiaColorTo(0, 4);
    SetPlayerCrouching(false);
    FadeImageTrailTo(0,1);
}

void TimerFunction(string &in asTimer)
{
     PlaySoundAtEntity("TimerFunction", "insanity_imageflash01.snt", "Player", 1, false);
}

void CollideFadeImageTrailTo(string &in asParent, string &in asChild, int alState)
{
FadeImageTrailTo(6, 2);
AddTimer("this_is_just_a_timer_name", 10.0f, "CollideFadeImageTrailTo");  
}

void MyFunc(string &in asTimer)
{
FadeImageTrailTo(0,1);
}
(This post was last modified: 02-04-2015, 11:52 PM by LDOriginal.)
02-04-2015, 11:50 PM
Find




Users browsing this thread: 1 Guest(s)