Frictional Games Forum (read-only)
Get Sanity to drain in the dark and increase in the light? - 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: Get Sanity to drain in the dark and increase in the light? (/thread-14703.html)

Pages: 1 2


Get Sanity to drain in the dark and increase in the light? - FragdaddyXXL - 04-11-2012

Is there a way for sanity to act like it does in the original Amnesia storyline? Otherwise, in custom stories, it seems more like an added effect than a game mechanic. I love the idea of this game mechanic and would like to just "turn it on" instead of making fartloads of script.



RE: Get Sanity to drain in the dark and increase in the light? - Datguy5 - 04-11-2012

Thats actually in custom stories too..


RE: Get Sanity to drain in the dark and increase in the light? - Cranky Old Man - 04-11-2012

(04-11-2012, 03:34 PM)Datguy5 Wrote: Thats actually in custom stories too..
Maybe these effects are absent in debug mode, I dunno.
Is it possible to amplify this effect somehow?




RE: Get Sanity to drain in the dark and increase in the light? - FragdaddyXXL - 04-11-2012

Yeah, I'll sit in the dark, get chased by monsters, and when I check my sanity level, it's "Crystal Clear". Then again, that was only within the first few minutes of starting the level. I might have just not noticed it.

But yeah, is there a way to make the player more sensitive to it?



RE: Get Sanity to drain in the dark and increase in the light? - Putmalk - 04-11-2012

By any chance, did you use this function:
SetSanityDrainDisabled(true);

If so, then sanity will be disabled. Otherwise, the sanity mechanic should work completely normal in custom stories, unless you disabled it via script.




RE: Get Sanity to drain in the dark and increase in the light? - Your Computer - 04-11-2012

(04-11-2012, 03:42 PM)FragdaddyXXL Wrote: But yeah, is there a way to make the player more sensitive to it?

Full conversion.


RE: Get Sanity to drain in the dark and increase in the light? - Cranky Old Man - 04-11-2012

I'm thinking that you could mess with the sanity effects, making you lose additional sanity by losing sanity. I've seen the sanity effects declared somewhere in a script file.



RE: Get Sanity to drain in the dark and increase in the light? - FragdaddyXXL - 04-12-2012

I guess you might be able to do an oldState/currentState thing. Where, if the old state (previous update) of sanity is higher than the current state, then you know you are losing sanity. If you know you are losing sanity, you can subtract a constant value (albeit a small one) from the sanity. But that may run into problems with gaining sanity. IDK, not a good time for me to think xD.



RE: Get Sanity to drain in the dark and increase in the light? - DRedshot - 04-12-2012

Well you could do a looping timer, which checks if (new_sanity >= old_sanity) 0.5 seconds ago.
If it isn't, it deducts x sanity from the player, and checks if (sanity >= (sanity - x)).
(If it is true it doesn't deduct sanity and recalls the timer)
This can loop every 0.5 seconds. x should be really small. The drawback is it will deduce extra sanity when you lose sanity other ways.

As mentioned earlier you can also make a full conversion, but if you weren't planning on making a full conversion in the first place, this is a pretty good alternative. (I've used it in my story Smile )



RE: Get Sanity to drain in the dark and increase in the light? - FragdaddyXXL - 04-13-2012

Code:
float sanityFactor = 10.0f;
float curSanity = 100.0f;
float oldSanity = 100.0f;

void OnStart()
{
    SetPlayerSanity(100.0f);
    AddTimer("SanityTimer", 0.5f, "UpdateSanity");  
}

void UpdateSanity(string &in asTimer)
{
    curSanity = GetPlayerSanity();
    float temp;
    if(curSanity < oldSanity)
    {
            temp = curSanity - sanityFactor;
            SetPlayerSanity(temp);
    }
    
    if (curSanity > oldSanity)
    {
        temp = curSanity + sanityFactor;
        if(temp <= 100.0f)
        {
            SetPlayerSanity(temp);
        }
        else
        {
            SetPlayerSanity(100.0f);
        }
    }  
    
    oldSanity = curSanity;    
    AddTimer("SanityTimer", 0.5f, "UpdateSanity");
}

I omitted any unrelated code (like lever turning lights on and off).
The draining works just fine when I turn the lights off, but as soon as I turn the lights, my sanity (no matter what) goes to "..."; basically, it doesn't gain sanity correctly. My code is insane somewhere.