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
PlaySound
nerdboyxxx Offline
Junior Member

Posts: 11
Threads: 5
Joined: Sep 2010
Reputation: 0
#1
PlaySound

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.

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
(This post was last modified: 12-14-2010, 09:54 AM by nerdboyxxx.)
12-14-2010, 05:22 AM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#2
RE: PlaySound

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.


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-14-2010, 05:42 PM
Find
nerdboyxxx Offline
Junior Member

Posts: 11
Threads: 5
Joined: Sep 2010
Reputation: 0
#3
RE: PlaySound

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... :|
(This post was last modified: 12-14-2010, 11:30 PM by nerdboyxxx.)
12-14-2010, 10:59 PM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#4
RE: PlaySound

Add this in Collide_Area and activate 'Show Debug Messages' in the debug menu (F1):

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


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-14-2010, 11:34 PM
Find
nerdboyxxx Offline
Junior Member

Posts: 11
Threads: 5
Joined: Sep 2010
Reputation: 0
#5
RE: PlaySound

(12-14-2010, 11:34 PM)Frontcannon Wrote: Add this in Collide_Area and activate 'Show Debug Messages' in the debug menu (F1):

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).

//=========================================
     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.
(This post was last modified: 12-15-2010, 12:31 AM by nerdboyxxx.)
12-15-2010, 12:11 AM
Find
nerdboyxxx Offline
Junior Member

Posts: 11
Threads: 5
Joined: Sep 2010
Reputation: 0
#6
RE: PlaySound

I found the problem; turns out that "Player" isn't "player"... Well, at least I got it working XD
12-15-2010, 03:09 AM
Find




Users browsing this thread: 1 Guest(s)