Frictional Games Forum (read-only)
How do I do this? (scripting) - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: How do I do this? (scripting) (/thread-7235.html)



How do I do this? (scripting) - Solarn - 04-07-2011

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.


RE: How do I do this? (scripting) - Russ Money - 04-07-2011

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.


RE: How do I do this? (scripting) - Solarn - 04-07-2011

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.


RE: How do I do this? (scripting) - MrBigzy - 04-07-2011

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


RE: How do I do this? (scripting) - Solarn - 04-07-2011

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


RE: How do I do this? (scripting) - MrBigzy - 04-07-2011

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.


RE: How do I do this? (scripting) - Dalroc - 04-07-2011

(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


RE: How do I do this? (scripting) - palistov - 04-07-2011

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


RE: How do I do this? (scripting) - Solarn - 04-07-2011

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.


RE: How do I do this? (scripting) - palistov - 04-08-2011

Glad to have helped! Best of luck Smile