Frictional Games Forum (read-only)
[SCRIPT] How to achieve this scenario? - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] How to achieve this scenario? (/thread-20106.html)

Pages: 1 2


How to achieve this scenario? - serbusfish - 01-30-2013

The scenario;

You enter a room, the sound of a plate or vase smashing is heard from another room, the centre dot 'looks' to where the sound came from, then the sound of a monster walking is heard followed by the sound of a door shutting.

How would I go about doing this? I have the actual level built ready, I just have no clue about scripting, I understand the basic idea of it but I cant just open up a text doc and type in what I want to do, whereas I have no problem opening the level editor and building a random set of aesthetically pleasing rooms (imo Smile).


RE: How to achieve this scenario? - NaxEla - 01-30-2013

Well, you'll need to use timers and these functions:
PHP Code:
void AddTimer(stringasNamefloat afTimestringasFunction);
void PlaySoundAtEntity(stringasSoundNamestringasSoundFilestringasEntityfloat afFadeTimebool abSaveSound);
void StartPlayerLookAt(stringasEntityNamefloat afSpeedMulfloat afMaxSpeedstringasAtTargetCallback);
void StopPlayerLookAt(); 



RE: How to achieve this scenario? - serbusfish - 01-30-2013

Thanks a lot for the commands, very helpful, though im still a long way off understanding what to do with it Smile

As an example for now, where it says 'asName', do you put after that the filename + extension or does it actually have to be the full path to the file?


RE: How to achieve this scenario? - FlawlessHappiness - 01-30-2013

asName is the name of the timer. If you don't know how to use it leave it like this: ""

If you'd like to know I'll just selfpromote my own thread here Wink
http://www.frictionalgames.com/forum/thread-18368.html

You should be able to find your answer there Smile

You might want to check up some basic scripting, and how fx. timers work.


RE: How to achieve this scenario? - The chaser - 01-30-2013

(01-30-2013, 01:54 AM)serbusfish Wrote: The scenario;

You enter a room, the sound of a plate or vase smashing is heard from another room, the centre dot 'looks' to where the sound came from, then the sound of a monster walking is heard followed by the sound of a door shutting.

How would I go about doing this? I have the actual level built ready, I just have no clue about scripting, I understand the basic idea of it but I cant just open up a text doc and type in what I want to do, whereas I have no problem opening the level editor and building a random set of aesthetically pleasing rooms (imo Smile).

Okay, it would be like this:

Code:
void OnStart()
{
AddEntityCollideCallback("Player", "Area", "Stuff", true, 1); //The area is when you enter the room.
}

void Stuff (string &in asParent, string &in asChild, int alState)
{
SetPropHealth("Vase_to_be_broken", 0);
StartPlayerLookAt("Area_to_look_at", 1, 1, ""); ///The numbers can change if necessary
AddTimer("", 1, "Sound");
}

void Sound (string &in asEntity)
{
///Play monster walking sound
AddTimer("", 1, "Anothersound");
}

void Anothersound (string &in asTimer)
{
///Door shutting sound
StopPlayerLookAt();
}



RE: How to achieve this scenario? - TheGreatCthulhu - 01-30-2013

OK, I'll expand a bit on what others have said.

First, for some basic understanding of how the game and the script interact with each other, read this short article.

Now, here we go:
(01-30-2013, 01:54 AM)serbusfish Wrote: You enter a room,
To detect if a player has entered a room or not, you normally set up the script to detect a collision with a script area. So, first make sure that the map itself contains a script area that can be used for this. Depending on what exactly you want to happen, you can just put a thin script area right in front of the door, or you can place a big box in the center of the room to define an inner region where this should happen. In the script file, you would use an AddEntityCollideCallback() to "subscribe to" collision detection with that area, as described above by The chaser and BeeKayK (a more detailed explanation on how to use basic functions and parameters here, and of callbacks here)

(01-30-2013, 01:54 AM)serbusfish Wrote: the sound of a plate or vase smashing is heard from another room,
Similarly, you need something in your level to define the source of the sound. Either edit the script file to break an actual vase entity using SetPropHealth() as The chaser did, or use the level editor to add a script area in the other room (or just near or behind the wall, in empty space - if there's no really another room) to define where the sound should come from. Once this is done, just find the appropriate sound, and edit the script file to make a call to PlaySoundAtEntity() in place of SetPropHealth(), like this (replace the names to match the names in your level - "internal.sound.id" can be whatever you like, the number 0.0f is sound fade in time in seconds (the f is just some data type suffix, don't worry about that)):
PHP Code:
PlaySoundAtEntity("internal.sound.id""SoundFileName.snt""ScriptAreaName"0.0f false); 

(01-30-2013, 01:54 AM)serbusfish Wrote: the centre dot 'looks' to where the sound came from,
Use StartPlayerLookAt() as described by The chaser above, and then AddTimer() so that you can exit the forced look-at state after some time, by calling StopPlayerLookAt() inside the timer callback (which The chaser forgot to do).

(01-30-2013, 01:54 AM)serbusfish Wrote: then the sound of a monster walking is heard
Either immediately use PlaySoundAtEntity() as before (but perhaps on a different script area) to play a monster walking sound (just find some footstep sounds that came with the game), or first add a timer if you want to offset the sound playback by some time amount.

(01-30-2013, 01:54 AM)serbusfish Wrote: followed by the sound of a door shutting.
Same as before.

P.S. Consult the engine script functions reference page to find out more about the available functions, and how to use them (what their parameters mean).


RE: How to achieve this scenario? - serbusfish - 01-31-2013

Wow thanks a lot guys, I really appreciate that info, im starting to get my head around scripting and managed to put ambient music into my level, its small but its a start.

Im going to go through your info step by step, have a mess around and hopefully i'll achieve the effect im after Smile


RE: How to achieve this scenario? - serbusfish - 01-31-2013

Ok im a little stuck. I cant get the vase to break when I enter the room. Here is what I have atm:

Quote: {
AddEntityCollideCallback("Player", "ScriptArea_2", "stuff", true, 1); //The area is when you enter the room.
{
SetPropHealth("pot_plant_small02_1", 0);
}
}
Now I know more is needed to make the vase break when I enter the area but I cant figure out what, I tried adding the other lines but I get an error and my map wont load :?


RE: How to achieve this scenario? - FlawlessHappiness - 01-31-2013

You haven't done the script correctly.
You need to understand how the script works.

This is how it should look:

Code:
void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea_2", "BreakPotPlant", true, 1);
}

void BreakPotPlant(string &in asParent, string &in asChild, int alState)
{
SetPropHealth("pot_plant_small02_1", 0);
}

IMPORTANT
You cannot have 2 void OnStart's, so you'll have to take the line in this void OnStart, and put it inside your void OnStart next to all the other lines.


RE: How to achieve this scenario? - serbusfish - 02-01-2013

Thanks for being patient with me, but something is still wrong because I pasted that exact code and the game throws up an error message saying 'ERR - expected '('.

It must have something to do with the line

"void BreakPotPlant(string &in asParent, string &in asChild, int alState)"

because the map loads when this is deleted. Am I supposed to replace the text in this line?

If it helps here is the entire content of my .hps file so far:

Code:
//===========================================
     // This runs when the map first starts
     void OnStart()
{

        if(ScriptDebugOn())

        
    {
              
       GiveItemFromFile("tinderbox", "tinderbox.ent");
          {
              AddEntityCollideCallback("Player", "ScriptArea_2", "BreakPotPlant", true, 1);
                 }

                     void BreakPotPlant(string &in asParent, string &in asChild, int alState)
                         {
                             SetPropHealth("pot_plant_small02_1", 0);
                         }
     }         
  
}        
      
     //===========================================
     // This runs when the player enters the map
     void OnEnter()
   {
  
   //----AUDIO----//
    PlayMusic("10_amb", true, 5, 1, 0, true);
}
     //===========================================
     // This runs when the player leaves the map
     void OnLeave()
     {
     }