Frictional Games Forum (read-only)

Full Version: Sanity Function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
Thanks a lot ^.-
It is pretty simple I do not have any questionsSmile