Frictional Games Forum

Full Version: Need a bit of help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

I am working on a small custom story and i need some commands to work but they aren't working. I need the player's max Health and Sanity to be 50 instead of 100 and i can't get it to work. Help is appreciated.
In your script file, all you need to do is add 2 lines of code to your OnStart method.

PHP Code:
void OnStart()
{
    SetPlayerHealth(50.0f);
    SetPlayerSanity(50.0f); 


You can find these functions on the wiki page: HPL2 Scripts
haha i guess i overthought it, does this method also prevent the player from having more than 50 HP/Sanity by using Sanity Potions or Sanity rewards from completing puzzles?

Edit: tested it and it doesn't, is it possible to do that?
Yes, it's expected. You could run a looping timer to always reduce the health to 50 if the player goes above the limit.
The timer frequency is set to an amount which shouldn't bug the game, but it's fast enough for players not to notice the change.
You also need to start the timer somewhere. And use RemoveTimer to stop it

Code:
void HealthCap(string &in asTimer)
{
   AddTimer("loop", 0.4f, "HealthCap");
   if( GetPlayerHealth()  > 50.0f)
   {
       SetPlayerHealth(50.0f);
   }
}
Interesting method, I'll see if it needs to be added but I think the custom story would work without it, i'll see.
Use it if you must, but avoid it if possible. Darkfire did consider this so the example isn't bad, but I want to elaborate on "bug the game."

Every time a callback is triggered (including timers), an index is incremented. This index must not exceed 65535, else the game will crash upon next loading screen.

Usually this is only a worry if you use a rapidly repeating timer. Darkfire's example loops about 5 times in 2 seconds, so it's frequent, but not rapid. To put this into perspective, if you loop a timer as fast as possible, being 60 times in 1 second, you will hit the limit in about 15 minutes of gameplay.

If you can avoid hitting the limit in about 3 hours, I say you're good to do as you please regarding these. This is an engine limitation.