Frictional Games Forum (read-only)
Beginning Scripting, Requesting a [More thorough] Tutorial - 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: Beginning Scripting, Requesting a [More thorough] Tutorial (/thread-4644.html)



Beginning Scripting, Requesting a [More thorough] Tutorial - ErichK - 09-21-2010

Hi there! Long time fan, first time poster.

Anyway, I've been searching around and trying countless different things, but I have finally given up and resorted to posting on here.

I was trying to refer to this thread:

http://www.frictionalgames.com/forum/thread-4425.html

In order to make a "scary door." However, I have a few issues that the HPL2 tutorial didn't seem to want to go over.

Firstoff, here is my .hps file:

Code:
//The Waking Up Feature that starts as soon as map loads.
void wakeUp () {
    FadeOut(0);     // Instantly fades the screen out. (Good for starting the game)
    FadeIn(20);      // Amount of seconds the fade in takes
    FadeImageTrailTo(2, 2);
    FadeSepiaColorTo(100, 4);
    SetPlayerActive(false);    
    FadePlayerRollTo(50, 220, 220);                 // "Tilts" the players head
    FadeRadialBlurTo(0.15, 2);
    SetPlayerCrouching(true);              // Simulates being on the ground
    AddTimer("trig1", 11.0f, "beginStory");            // Change '11.0f' to however long you want the 'unconciousness' to last
}

void beginStory(string &in asTimer){
    ChangePlayerStateToNormal();
    SetPlayerActive(true);
    FadePlayerRollTo(0, 33, 33);        // Change all settings to defaults
    FadeRadialBlurTo(0.0, 1);
    FadeSepiaColorTo(0, 4);
    SetPlayerCrouching(false);
    FadeImageTrailTo(0,1);
}

////////////////////////////
// Run first time starting map
void OnStart()
{  
    //Allows you to wake up
    wakeUp();

    //Add the Lantern and 10 Tinderboxes when in Debug mode, always good to have light!
    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}

Everything on there works perfectly, but when I try to add the "scary door" code from the above link, all hell breaks loose.

I was wondering if anyone could please help me with the following issues:

1. Could you please provide a completed example of how the code would look in finished form, i.e. adding it to what code I posted here?

2. Elaborate on what needs to go where (in terms of in the script itself - for example, in:

Code:
SetEntityPlayerInteractCallback("name_of_door_here", "FunctionToCall", true);

Does "FunctionToCall" mean "insert text here," and if so, are these the functions?:

Code:
void FunctionToCall(string &in entity)
{
    PlaySoundAtEntity("instance_name", "soundfile.ogg/snt", "name_of_entity_to_play_sound_from", 0, false);
    SetEntityActive("name_of_grunt_or_brute", true); //Spawn monster
}

3. And lastly, what snippets of code do I put in the entity tab of the door, under the Callback function boxes?

Thanks for any help. I've been trying to pull up the developer code as well as examples from other custom stories, but I'm still too new at it to be able to figure it out on my own. I'm sure, however, that if I get an example of a finished (or close to finished) product, I can get the rest on my own. Thanks!

-Erich


RE: Beginning Scripting, Requesting a [More thorough] Tutorial - MulleDK19 - 09-21-2010

The code below assumes that your door is called "mansion_1" (without the quotes), and your monster is called "servant_brute_1" (without the quotes).

Code:
//The Waking Up Feature that starts as soon as map loads.
void wakeUp () {
    FadeOut(0);     // Instantly fades the screen out. (Good for starting the game)
    FadeIn(20);      // Amount of seconds the fade in takes
    FadeImageTrailTo(2, 2);
    FadeSepiaColorTo(100, 4);
    SetPlayerActive(false);    
    FadePlayerRollTo(50, 220, 220);                 // "Tilts" the players head
    FadeRadialBlurTo(0.15, 2);
    SetPlayerCrouching(true);              // Simulates being on the ground
    AddTimer("trig1", 11.0f, "beginStory");            // Change '11.0f' to however long you want the 'unconciousness' to last
}

void beginStory(string &in asTimer){
    ChangePlayerStateToNormal();
    SetPlayerActive(true);
    FadePlayerRollTo(0, 33, 33);        // Change all settings to defaults
    FadeRadialBlurTo(0.0, 1);
    FadeSepiaColorTo(0, 4);
    SetPlayerCrouching(false);
    FadeImageTrailTo(0,1);
}

////////////////////////////
// Run first time starting map
void OnStart()
{  
    //Allows you to wake up
    wakeUp();

    //Add the Lantern and 10 Tinderboxes when in Debug mode, always good to have light!
    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
    
    SetEntityPlayerInteractCallback("mansion_1", "InteractedWithDoor", true);
}

void InteractedWithDoor(string &in entity)
{
    PlaySoundAtEntity("", "insanity_monster_roar02.ogg", "mansion_1", 0, false);
    SetEntityActive("servant_brute_1", true); //Spawn monster
    GiveSanityDamage(15.0f, true);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}



RE: Beginning Scripting, Requesting a [More thorough] Tutorial - ErichK - 09-22-2010

Thanks! This helps a lot! But what snippet of code do I put in the callback function box for the entity in the editor? This one? :

Code:
void InteractedWithDoor(string &in entity)



RE: Beginning Scripting, Requesting a [More thorough] Tutorial - jens - 09-22-2010

None, this script is written so it does not use the level editor.

void InteractedWithDoor(string &in entity) is triggered by the line SetEntityPlayerInteractCallback("mansion_1", "InteractedWithDoor", true);

but

You can remove the line SetEntityPlayerInteractCallback("mansion_1", "InteractedWithDoor", true);

and then select the mansion_1 door in the editor, go to the entity tab, and there is an input named SetInteractCallback (or something like that) in which you would enter InteractedWithDoor to accomplish the same thing as the script line you removed.