Frictional Games Forum (read-only)
[SCRIPT] [FIXED] "If get player health" 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] [FIXED] "If get player health" function? (/thread-47103.html)



[FIXED] "If get player health" function? - Slanderous - 05-12-2016

I tried to write a script that would do a certain action after player's health level reaches 100, so I took a line from the original game I thought looked familiar and modified it to the idea I had in mind. However, upon starting my level, I get the following error:

[Image: M833GbE.png]

Here's the function I'm trying to get to work:

Code:
if(GetPlayerHealth(100)) FadeImageTrailTo(0,0.2f); CompleteQuest("quest_heal", "heal");

As you might know, in the original game's entry hall there's a following function:

Code:
if(HasItem("key_study_1")) SetMessage("Ch01Level02", "InteractDoorHaveKey", 0);

Any ideas?


RE: "If get player health" function? - Romulator - 05-12-2016

I believe you check Player Health this way;

PHP Code:
if(GetPlayerHealth() == 100.0f//code here 

PHP Code:
if(GetPlayerHealth() == 100.0f)
{
    
//code here


Keep in mind, it's 4am here and I haven't done HPL2 in a couple of months~


RE: "If get player health" function? - Slanderous - 05-12-2016

(05-12-2016, 06:59 PM)Romulator Wrote: I believe you check Player Health this way;

PHP Code:
if(GetPlayerHealth() == 100.0f//code here 

PHP Code:
if(GetPlayerHealth() == 100.0f)
{
    
//code here


Keep in mind, it's 4am here and I haven't done HPL2 in a couple of months~

Yeah, now my game loaded just fine, although it still doesn't work. How I'm executing the code is by placing a big script area which basically covers the whole map, changing it so that it would check the health costantly, and if the health level is equal to 100, the quest i want and image trail effects are gone. However, that doesn't work.

Here's how the script fragment basically looks like:

PHP Code:
void onStart()
{
AddEntityCollideCallback("Player""check_health""healing"false0); 
}

void healing(string &in asParentstring &in asChildint alState
{
    if(
GetPlayerHealth() == 100.0fFadeImageTrailTo(0,0.2f); CompleteQuest("quest_heal""heal");




RE: "If get player health" function? - Darkfire - 05-12-2016

This way it will check the health only once. If you want to check it constantly, you have to use a timer loop (or is there maybe a different way ? I dunno one)
For example
PHP Code:
void OnStart()
{
     
AddTimer("TimerName"1.0f"TimerFunction");
}

void TimerFunction(string &in asTimer)
{
     if(
GetPlayerHealth() == 100.0f
         {
             
FadeImageTrailTo(0,0.2f); 
             
CompleteQuest("quest_heal""heal");
         }
      
AddTimer("TimerName"1.0f"TimerFunction"); 

You end up with this: a timer calls a function, which checks if you have health and then starts another timer which leads back to the same function. Loop closed.
Note how to use "if" functions: there's no ; semicolon and another function bracket {} next to the statement - because it's function within a function. Inception shit, eh ?

EDIT:
If you want it to be triggered after entering an area just put the first timer function in the entity collide function.


RE: "If get player health" function? - Slanderous - 05-12-2016

(05-12-2016, 08:32 PM)Darkfire Wrote: This way it will check the health only once. If you want to check it constantly, you have to use a timer loop (or is there maybe a different way ? I dunno one)
For example
PHP Code:
void OnStart()
{
     
AddTimer("TimerName"1.0f"TimerFunction");
}

void TimerFunction(string &in asTimer)
{
     if(
GetPlayerHealth() == 100.0f
         {
             
FadeImageTrailTo(0,0.2f); 
             
CompleteQuest("quest_heal""heal");
         }
      
AddTimer("TimerName"1.0f"TimerFunction"); 

You end up with this: a timer calls a function, which checks if you have health and then starts another timer which leads back to the same function. Loop closed.
Note how to use "if" functions: there's no ; semicolon and another function bracket {} next to the statement - because it's function within a function. Inception shit, eh ?

EDIT:
If you want it to be triggered after entering an area just put the first timer function in the entity collide function.

I want the code to be triggered constantly, but thanks for your propositions anyway.

The problem has been resolved, you can lock up the thread.


RE: "If get player health" function? - Darkfire - 05-12-2016

Shit. I forgot that the entities will collide all the time, so most likely you're right.
However If you set the timer to 0.01f the delay will be unnoticeable.


RE: [FIXED] "If get player health" function? - Slanderous - 05-12-2016

(05-12-2016, 09:03 PM)Darkfire Wrote: Shit. I forgot that the entities will collide all the time, so most likely you're right.
However If you set the timer to 0.01f the delay will be unnoticeable.

Nah, man no worries. Someone helped me out with that, so it's no longer an issue.


RE: [FIXED] "If get player health" function? - Daemian - 05-12-2016

(05-12-2016, 09:03 PM)Darkfire Wrote: Shit. I forgot that the entities will collide all the time, so most likely you're right.
However If you set the timer to 0.01f the delay will be unnoticeable.
But you were right imo, I think that code is not working too.
He probably solved it using timers cause -as you know- that callback should only trigger when the player enters/leaves the area, and that happens only once.


RE: [FIXED] "If get player health" function? - Slanderous - 05-14-2016

(05-12-2016, 11:15 PM)Daemian Wrote:
(05-12-2016, 09:03 PM)Darkfire Wrote: Shit. I forgot that the entities will collide all the time, so most likely you're right.
However If you set the timer to 0.01f the delay will be unnoticeable.
But you were right imo, I think that code is not working too.
He probably solved it using timers cause -as you know- that callback should only trigger when the player enters/leaves the area, and that happens only once.

PHP Code:
void OnStart()
{
AddTimer("tmr_heal"0.01f"healing_timer");
}
void healing_timer(string &in asTimer)
{
    if(
GetPlayerHealth() >= 40.0f
        {
            
FadeImageTrailTo(0,0.2f); 
            
CompleteQuest("quest_heall""heal");
            
RemoveTimer("tmr_heal");
            
AddTimer("tmr_chapter"4.0f"chapter_switch"); 
            
SetLevelDoorLocked("level_celler_1"false);
            return;
        }
    
//AddDebugMessage("Health = " + GetPlayerHealth(), false);
    
SetPlayerHealth(30.0f);
    
AddTimer("tmr_heal"0.01f"healing_timer");