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
Need a bit of help
RaXZerGamingZ Offline
Junior Member

Posts: 11
Threads: 3
Joined: Jan 2019
Reputation: 0
#1
Need a bit of help

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.
01-19-2019, 07:35 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Need a bit of help

In your script file, all you need to do is add 2 lines of code to your OnStart method.

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


You can find these functions on the wiki page: HPL2 Scripts

01-19-2019, 10:22 PM
Find
RaXZerGamingZ Offline
Junior Member

Posts: 11
Threads: 3
Joined: Jan 2019
Reputation: 0
#3
RE: Need a bit of help

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?
(This post was last modified: 01-19-2019, 11:58 PM by RaXZerGamingZ.)
01-19-2019, 11:22 PM
Find
Darkfire Offline
Senior Member

Posts: 371
Threads: 22
Joined: May 2014
Reputation: 15
#4
RE: Need a bit of help

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

void HealthCap(string &in asTimer)
{
   AddTimer("loop", 0.4f, "HealthCap");
   if( GetPlayerHealth()  > 50.0f)
   {
       SetPlayerHealth(50.0f);
   }
}

(This post was last modified: 01-20-2019, 04:18 PM by Darkfire.)
01-20-2019, 04:16 PM
Find
RaXZerGamingZ Offline
Junior Member

Posts: 11
Threads: 3
Joined: Jan 2019
Reputation: 0
#5
RE: Need a bit of help

Interesting method, I'll see if it needs to be added but I think the custom story would work without it, i'll see.
01-20-2019, 04:32 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#6
RE: Need a bit of help

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.

01-20-2019, 07:15 PM
Find




Users browsing this thread: 1 Guest(s)