Frictional Games Forum (read-only)

Full Version: PlaySound
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

Below is the code I am using. I am trying to make a sound play when the player makes contact with a certain area. When the player makes contact with this area, the sound will play from the location of another entity (in this case another script area).

Below is the code I am currently using. I have been reading through the tutorials and teaching myself as I go, so far it has gone well however I am stuck at the moment. I can't see where I am going wrong at all.

Code:
void OnStart()
     {
     AddTimer("Timer_1", 2, "MonsterSpawn");
     AddEntityCollideCallback("player", "Child_Cry_1", "Collide_Area", true, 1);
    
      if(ScriptDebugOn())
     {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
     }
    
     }
    
     void Collide_Area(string &in asParent, string &in asChild, int alState)
     {
     PlaySoundAtEntity("BabyCry", "scare_Baby_Cry.snt", "child_cry_scare", 0, false);
     }

If you could help fix up my script and explain where I went wrong I would be very grateful.

Thanks for all the help Smile
It seems alright, but the name of the sound file doesn't contain caps, I think. I don't know if that matters, though.

How far away is the sound area from the player? Some sounds can't be heard over certain distances.
I have it behind a wall, if that matters. It is right over the player. I will try and use the name without caps and see if that works though, because I think that might be the problem.

EDIT: That is not the problem Sad. Could it possibly be that it will simply not run in-game? Maybe I have to change some settings? Because I am getting no errors when I run the map in Amnesia.

It should be running, but it isn't... :|
Add this in Collide_Area and activate 'Show Debug Messages' in the debug menu (F1):

Code:
AddDebugMessage("this should be a sound", false);
(12-14-2010, 11:34 PM)Frontcannon Wrote: [ -> ]Add this in Collide_Area and activate 'Show Debug Messages' in the debug menu (F1):

Code:
AddDebugMessage("this should be a sound", false);

Hmmm, no debug messages appeared when I collided with the Area... I'm stumped.
Just in case it will help, I've posted my entire script below (don't worry, it isn't that long Tongue).

Code:
//=========================================
     void OnStart()
     {
     AddEntityCollideCallback("player", "Child_Cry_1", "Collide_Area", true, 1);
     AddEntityCollideCallback("player", "slamdoorpianoplay", "Hallway_Collide", true, 1);
    
    
      if(ScriptDebugOn())
     {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
     }
    
     }
    
     void Collide_Area(string &in asParent, string &in asChild, int alState)
      
     {
         AddDebugMessage("this should be a sound", false);
         PlaySoundAtEntity("BabyCry", "scare_baby_cry5.ogg", "Child_Cry_Scare", 1.0f, false);
         AddTimer("BabyCryStop", 4.0f, "BabyCry")
     }
    
     void BabyCry(string &in asTimer)
    
     {
     StopSound("BabyCry", 1.5f);
     }
    
     void Hallway_Collide(string &in asParent, string &in asChild, int alState)
    
     {
         AddDebugMessage("Door should start to close here, player looks at door", false);
          StartPlayerLookAt("mansion_door_swing_close", 1.0f, 3.5f, "");
         AddTimer("MansionDoorClose", 0.6f, "LookAtDoor");
     }
    
     void LookAtDoor(string &in asTimer)
    
     {
         AddDebugMessage("Door should close and lock, player should be shocked", false);
         SetSwingDoorClosed("mansion_door_swing_close", true, true);
         PlaySoundAtEntity("ShockBreathe", "react_breath1.ogg", "Player", 0.5f, false);
         StopPlayerLookAt();
         StopSound("ShockBreathe", 1.0f);
         SetSwingDoorLocked("mansion_door_swing_close", true, false);
         AddTimer("PianoPlay", 5.0f, "Ghost_Piano");    
     }
        
     void Ghost_Piano(string &in asTimer)
    
     {
         AddDebugMessage("Play piano here, sanity damage", false);
         PlaySoundAtEntity("PianoPlay1", "general_piano02.ogg", "Piano_Play_1", 2.0f, false);
         GiveSanityDamage(20.0f, true);
         StopSound("PianoPlay1", 4.0f);
     }    
    

     //===========================================
    
    
     void OnEnter()
     {
    
     }

     //===========================================
     void OnLeave()
     {
    
     }

Hopefully there is a problem with my formatting so I can fix it quickly Tongue.
I found the problem; turns out that "Player" isn't "player"... Well, at least I got it working XD