Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Causing sanity damage to yourself
RaptorRed Offline
Junior Member

Posts: 6
Threads: 1
Joined: Sep 2010
Reputation: 0
#1
Causing sanity damage to yourself

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.
09-17-2010, 06:24 AM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#2
RE: Causing sanity damage to yourself

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

//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.
(This post was last modified: 09-21-2010, 06:20 AM by jens.)
09-17-2010, 06:54 AM
Website Find
RaptorRed Offline
Junior Member

Posts: 6
Threads: 1
Joined: Sep 2010
Reputation: 0
#3
RE: Causing sanity damage to yourself

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:

////////////////////////////
// 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)
    }
}
09-17-2010, 07:08 AM
Find
RaptorRed Offline
Junior Member

Posts: 6
Threads: 1
Joined: Sep 2010
Reputation: 0
#4
RE: Causing sanity damage to yourself

This is frustrating, I tried almost everything and I still can't get it to work
09-17-2010, 08:20 AM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#5
RE: Causing sanity damage to yourself

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:

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.
(This post was last modified: 09-21-2010, 06:20 AM by jens.)
09-17-2010, 08:28 AM
Website Find
Cgturner Offline
Junior Member

Posts: 28
Threads: 7
Joined: Sep 2010
Reputation: 0
#6
RE: Causing sanity damage to yourself

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

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.
09-17-2010, 07:40 PM
Find
Armored Cow Offline
Member

Posts: 72
Threads: 3
Joined: Sep 2010
Reputation: 0
#7
RE: Causing sanity damage to yourself

I think the function is SetPlayerLookAt.
09-17-2010, 08:22 PM
Find
iTIMMEH Offline
Junior Member

Posts: 40
Threads: 2
Joined: Sep 2010
Reputation: 0
#8
RE: Causing sanity damage to yourself

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

To stop it:
StopPlayerLookAt();
09-17-2010, 08:37 PM
Find
Armored Cow Offline
Member

Posts: 72
Threads: 3
Joined: Sep 2010
Reputation: 0
#9
RE: Causing sanity damage to yourself

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.

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, 09:11 PM
Find
RaptorRed Offline
Junior Member

Posts: 6
Threads: 1
Joined: Sep 2010
Reputation: 0
#10
RE: Causing sanity damage to yourself

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

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.
09-19-2010, 08:21 PM
Find




Users browsing this thread: 1 Guest(s)