Frictional Games Forum (read-only)
Causing sanity damage to yourself - 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: Causing sanity damage to yourself (/thread-4459.html)

Pages: 1 2


Causing sanity damage to yourself - RaptorRed - 09-17-2010

I am completely new to this level editor, I made my own level to mess around in, well in the level I have a lever, how can I make it so by using the lever the player's sanity gets damaged, is it possible?

I have zero experience when it comes to scripting, do I need to script something in order for this thing to work?

Help is appreciated.


RE: Causing sanity damage to yourself - jens - 09-17-2010

Yes, you will need scripting for this. But it is fairly simply, if you begin by making a script file as on the wiki in the first step in the script tutorial 1. Then you only have to do 1 thing in the script and 1 thing in the editor.

In the editor, select the lever, click the Entity tab. For ConnectionStateChangeCallback enter a name for a function, like PullLever

Then in the script file, anywhere that is not within OnStart, OnEnter or OnLeave you add

Code:
//Function as you specified in ConnectionStateChangeCallback
void PullLever(string &in asEntity, int alState)
{
    //If the lever is pulled max up or down then give sanity damage
    if(alState == 1 or alState == -1)
    {
        GiveSanityDamage(10, true);  //10 = amount of damage, true = effects are used (vision distorts and such)
    }
}

I think this will work, this is not the 100% intended use of ConnectionStateChangeCallback, but I think I used it like this in one of the levels. As you say 0 experience, to make sure you are not confused, all the lines that start with // are comments I added to explain what is going on, those do not actually have to be in the script.


RE: Causing sanity damage to yourself - RaptorRed - 09-17-2010

Well, What am I doing wrong, I get a fatal error claiming it couldn't load script file "yy.hps" main (31, 35) : ERR because it expected data type

I have no idea what it is referring to when it says Data type

This is my code:

Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
    //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()
{

}

////////////////////////////
//Function as you specified in ConnectionStateChangeCallback
Void PullLever(string &in lever1, in -1)
{
    //If the lever is pulled max up or down then give sanity damage
    if(alState == 1 or alState == -1)
    {
        GiveSanityDamage(30, true);  //10 = amount of damage, true = effects are used (vision distorts and such)
    }
}



RE: Causing sanity damage to yourself - RaptorRed - 09-17-2010

This is frustrating, I tried almost everything and I still can't get it to work


RE: Causing sanity damage to yourself - jens - 09-17-2010

You changed the script here, Void PullLever(string &in lever1, in -1) and that is incorrect. I also noticed my original had an error, it should not say "in" at all for alState so the correct is:

Code:
void PullLever(string &in asEntity, int alState)

It is meant to be like that, so do not edit that part at all!

To explain: alState can be either 0, -1 or 1 and that is why in the script you say IF alState is -1 or 1 then you should do GiveSanityDamage.


RE: Causing sanity damage to yourself - Cgturner - 09-17-2010

(09-17-2010, 08:28 AM)jens Wrote: You changed the script here, Void PullLever(string &in lever1, in -1) and that is incorrect. I also noticed my original had an error, it should not say "in" at all for alState so the correct is:

Code:
void PullLever(string &in asEntity, alState)

It is meant to be like that, so do not edit that part at all!

To explain: alState can be either 0, -1 or 1 and that is why in the script you say IF alState is -1 or 1 then you should do GiveSanityDamage.

This works very nicely! What script do you use to make the player's head turn at the same time as the insanity effect? I've got a squeal coming from behind the player once he walks into an area, and I want him to look when the noise starts.


RE: Causing sanity damage to yourself - Armored Cow - 09-17-2010

I think the function is SetPlayerLookAt.


RE: Causing sanity damage to yourself - iTIMMEH - 09-17-2010

To start pointing the player at a desired entity:
Code:
StartPlayerLookAt(string& asEntityName, float afSpeedMul, float afMaxSpeed, string &asAtTargetCallback;

To stop it:
Code:
StopPlayerLookAt();



RE: Causing sanity damage to yourself - Armored Cow - 09-17-2010

I would make a function that sets the player to look at an area as well as play a sound at that area when the player steps into the trigger area. Also include in the function a timer, maybe 3 seconds, that then triggers a function to stop the player looking.

Code:
void Onstart()
{
AddEntityCollideCallback("Player", "trigger_area", "Look", true, 1);
}

void Look(string &in asParent, string &in asChild, int alState)
{
AddTimer("", 3.0f, "StopLook");
PlaySoundAtEntity("", "squeal.snt", "area_squeal", 0, false); //area_squeal is the area you make for the sound to appear at
StartPlayerLookAt("area_squeal", 2, 3, "");
GiveSanityDamage(15.0f, true);
}

void StopLook(string &in asTimer)
{
StopPlayerLookAt();
}



RE: Causing sanity damage to yourself - RaptorRed - 09-19-2010

(09-17-2010, 07:40 PM)Cgturner Wrote:
(09-17-2010, 08:28 AM)jens Wrote: You changed the script here, Void PullLever(string &in lever1, in -1) and that is incorrect. I also noticed my original had an error, it should not say "in" at all for alState so the correct is:

Code:
void PullLever(string &in asEntity, alState)

It is meant to be like that, so do not edit that part at all!

To explain: alState can be either 0, -1 or 1 and that is why in the script you say IF alState is -1 or 1 then you should do GiveSanityDamage.

This works very nicely! What script do you use to make the player's head turn at the same time as the insanity effect? I've got a squeal coming from behind the player once he walks into an area, and I want him to look when the noise starts.

It works for you?, thats odd mine says identifier alState is not of data type and that it should be of boolean type.