Frictional Games Forum (read-only)

Full Version: Causing sanity damage to yourself
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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.
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.
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)
    }
}
This is frustrating, I tried almost everything and I still can't get it to work
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.
(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.
I think the function is SetPlayerLookAt.
To start pointing the player at a desired entity:
Code:
StartPlayerLookAt(string& asEntityName, float afSpeedMul, float afMaxSpeed, string &asAtTargetCallback;

To stop it:
Code:
StopPlayerLookAt();
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();
}
(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.
Pages: 1 2