Frictional Games Forum (read-only)
[SCRIPT] Sanity Function - 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] Sanity Function (/thread-53841.html)



Sanity Function - PeterP - 08-05-2017

Hello! I am working on a mod and I would like to know how to use an area to trigger a function ONLY when sanity is below a certain level. I know this is a dumb thing to not know so I keep this text short ;p any answers? Thanks for your time.


RE: Sanity Function - Romulator - 08-05-2017

Hello! It's actually rather simple. We simply use an "If-Conditional" to check whether the sanity is lesser than a certain value, and if so, execute some code. If you see the first if-block on that page I linked, and combine it with a function where we return a value on the Engine Scripts page, you can make something like this:

Spoiler below!
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""Area_sanity_collide_event""trigger_function"false0);
}

void trigger_function(string &in asParentstring &in asChildint alState)
{
    if(
GetPlayerSanity() < 33.0f)
    {
    
//Code, if true, here. That is, if the player has less than 33.0 sanity.
    
}


Or

PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""Area_sanity_collide_event""trigger_function"false1);
}

void trigger_function(string &in asParentstring &in asChildint alState)
{
    if(
GetPlayerSanity() < 33.0f)
    {
    
//Code, if true, here. That is, if the player has less than 33.0 sanity.
    
}
    else
    {
    
//Code, if false, here. That is, if the player has more than 33.0 sanity.
    
}



A few notes:
  • We know that we can check the Player's sanity because of how it is written in the Engine Scripts page. Because it is called a float, we can use that in the if-conditional to check something, as it "returns" that value. Thus, we could check the Player's health or local variables in a similar manner.
  • In the above examples, the game will check every time you pass through the ScriptArea. You can fix that by changing the false to true in the CollideCallback declaration.

Feel free to ask if you have questions! Smile


RE: Sanity Function - PeterP - 08-05-2017

Thanks a lot ^.-
It is pretty simple I do not have any questionsSmile