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
How do I do this? (scripting)
Solarn Offline
Junior Member

Posts: 36
Threads: 3
Joined: Mar 2011
Reputation: 0
#1
How do I do this? (scripting)

I'm starting a custom story and so far I managed to work every script-related problem out by studying the original maps' scripts, but this time I'm at a loss. I have an area which I want to trigger a script when the player enters it, that will play footstep sounds (I was thinking of step_walk_wood_squeaky) at certain points at certain intervals, to make it sound like someone is walking above the player. I placed the area and the points I want the footsteps at, but no matter how I try scripting it, nothing will be heard.

To elaborate, this is my ideal situation:
- Player enters area.
- Music starts (search_grunt).
- Grunt noises happen at a point above the player (amb_alert). Sanity loss also happens.
- At about 1.5 second intervals, five footsteps are heard from five points on the ceiling of the room, forming a line. It would be nice if a falling dust particle effect could be applied to each step as well.
- a bit after the last footstep, music ends.

Here's what actually happens:
- Player enters area.
- Music starts (search_grunt).
- Sanity loss happens.
- After a while, music ends.

Here are the map and the script file (disregard the lantern-and-tinderbox-giving script, that's just the example debug script from the wiki that I found useful for testing purposes). Please tell me what I need to do differently.
04-07-2011, 05:14 PM
Find
Russ Money Offline
Senior Member

Posts: 360
Threads: 25
Joined: Dec 2010
Reputation: 4
#2
RE: How do I do this? (scripting)

I checked out your script and it's nothing I've seen before in custom stories, but then again I don't know a whole lot on Javascript. I suggest creating areas under where you want the footsteps, then add script for each area to a collide callback to play the sounds, particles and sanity damage.

(This post was last modified: 04-07-2011, 05:24 PM by Russ Money.)
04-07-2011, 05:24 PM
Find
Solarn Offline
Junior Member

Posts: 36
Threads: 3
Joined: Mar 2011
Reputation: 0
#3
RE: How do I do this? (scripting)

The whole switch/case thing is something that's used a lot in the original maps, I took the idea from there. I probably didn't use it quite right, though.
04-07-2011, 05:43 PM
Find
MrBigzy Offline
Senior Member

Posts: 616
Threads: 18
Joined: Mar 2011
Reputation: 8
#4
RE: How do I do this? (scripting)

You've used it right, but your syntax for sound functions is wrong. The first one is name, which I'm not sure if you can leave blank or not, but the problem is the 2nd paramter, which is the file. You have to put the .snt extension for those. Same with particles, particles need the .ps extension.
Switch is pretty simple as well; if the case parameter is equal to the switch parameter, the case will play. (as well as everything below it if there isn't a break) So yea, you used it right. Tongue
(This post was last modified: 04-07-2011, 05:49 PM by MrBigzy.)
04-07-2011, 05:45 PM
Find
Solarn Offline
Junior Member

Posts: 36
Threads: 3
Joined: Mar 2011
Reputation: 0
#5
RE: How do I do this? (scripting)

(04-07-2011, 05:45 PM)MrBigzy Wrote: You've used it right, but your syntax for sound functions is wrong. The first one is name, which I'm not sure if you can leave blank or not, but the problem is the 2nd paramter, which is the file. You have to put the .snt extension for those.
Switch is pretty simple as well; if the case parameter is equal to the switch parameter, the case will play. (as well as everything below it if there isn't a break) So yea, you used it right. Tongue
Nope, doesn't change anything. Maybe the sounds are just too low to be heard from that far away? But the particle systems aren't showing up either. ARGH. This would be so much more simple to figure out if I could set the sound volume. I tried doing it with FadeGlobalSoundVolume, but it didn't seem to do anything.
04-07-2011, 05:56 PM
Find
MrBigzy Offline
Senior Member

Posts: 616
Threads: 18
Joined: Mar 2011
Reputation: 8
#6
RE: How do I do this? (scripting)

You have to set the volume in the .snt file, and yea, good chance they're too far away. Just put them closer, it doesn't matter if it's in the spot you want to hear it from, as long as you hear it from the general direction. You'll be able to make sure if its working if they're closer anyway.

And the .snt file applies to the game as well, just a heads up.
04-07-2011, 06:12 PM
Find
Dalroc Offline
Member

Posts: 57
Threads: 2
Joined: Mar 2011
Reputation: 0
#7
RE: How do I do this? (scripting)

(04-07-2011, 05:56 PM)Solarn Wrote: Nope, doesn't change anything. Maybe the sounds are just too low to be heard from that far away? But the particle systems aren't showing up either. ARGH.
Use debug messages to check where the script fails
04-07-2011, 07:36 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#8
RE: How do I do this? (scripting)

First off, you need to create a callback for the player entering the room. Put this function under your OnStart() function:

AddEntityCollideCallback("Player", "AreaRoomTrigger", "FuncScaryStuff", false, 1);

~~

The footsteps thing can be created using a loop:

for(int i=1;i<7;i++) AddTimer("step"+i, 1.5 * i, "FuncCreateStep");

void FuncCreateStep(string &in asTimer)
{
PlaySoundAtEntity(asTimer, "soundfile.snt", "area_"+asTimer, 0, false);
if(asTimer == "step6") StopMusic(3.0f, 3);
}

Do NOT create an area_step6. The extra timer in the loop is only to stop the music. Make sure the int alPrio in your music is above the ambient music. I put 3 as an example. That three that is bolded is the alPrio of the music you want to stop; it must be equal to the music you want to play during the event.


Create 5 script areas and name them area_step1, are_step2, etc

(This post was last modified: 04-07-2011, 07:40 PM by palistov.)
04-07-2011, 07:39 PM
Find
Solarn Offline
Junior Member

Posts: 36
Threads: 3
Joined: Mar 2011
Reputation: 0
#9
RE: How do I do this? (scripting)

Thanks. I already did the whole thing with a switch/case statement, but your solution looks more elegant. What really helped, though, was the suggestion that I use Script areas. That was what I needed.
(This post was last modified: 04-07-2011, 08:27 PM by Solarn.)
04-07-2011, 08:12 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#10
RE: How do I do this? (scripting)

Glad to have helped! Best of luck Smile

04-08-2011, 12:34 AM
Find




Users browsing this thread: 2 Guest(s)