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
Script Help [FIXED] "If get player health" function?
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#1
[FIXED] "If get player health" function?

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:

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:

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

Any ideas?
(This post was last modified: 05-12-2016, 09:03 PM by Slanderous.)
05-12-2016, 06:54 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: "If get player health" function?

I believe you check Player Health this way;

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

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


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

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 05-12-2016, 07:02 PM by Romulator.)
05-12-2016, 06:59 PM
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#3
RE: "If get player health" function?

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

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

PHP Code: (Select All)
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: (Select All)
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");

(This post was last modified: 05-12-2016, 07:19 PM by Slanderous.)
05-12-2016, 07:10 PM
Find
Darkfire Offline
Senior Member

Posts: 371
Threads: 22
Joined: May 2014
Reputation: 15
#4
RE: "If get player health" function?

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: (Select All)
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.

(This post was last modified: 05-12-2016, 08:34 PM by Darkfire.)
05-12-2016, 08:32 PM
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#5
RE: "If get player health" function?

(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: (Select All)
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.
(This post was last modified: 05-12-2016, 09:02 PM by Slanderous.)
05-12-2016, 08:50 PM
Find
Darkfire Offline
Senior Member

Posts: 371
Threads: 22
Joined: May 2014
Reputation: 15
#6
RE: "If get player health" function?

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.

05-12-2016, 09:03 PM
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#7
RE: [FIXED] "If get player health" function?

(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.
05-12-2016, 09:04 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#8
RE: [FIXED] "If get player health" function?

(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.

05-12-2016, 11:15 PM
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#9
RE: [FIXED] "If get player health" function?

(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: (Select All)
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"); 

05-14-2016, 12:09 PM
Find




Users browsing this thread: 1 Guest(s)