Jump to content

What is the script code of player's health?


haohao69869

Recommended Posts

Hello haohao68869, 1 to you too sir or mam.

To get the player's health the script needs to know which actor to look at and which "actor value" you want from it. To tell the script this you use "properties." This happens at the way top of the script below the script name.

 

Cipscis guide that touches on what exactly is a property and how do I use it?

Cipscis scripting beginner guide

Papyrus primer from creation kit wiki


ActorValue property Health auto   ;You can choose any name you want instead of "Health" as long as you use it consistently in your script
actor property PlayerREF auto     ;You can choose any name you want instead of "PlayerREF" as long as you use it consistently in your script
;These properties are written at the top of the script below the script name.

float function MyFunctionThatGetsPlayerHealth()  ;This function will "return" a float
    
    float VariableWithYourHealth  ; making a new variable to store the information

    VariableWithYourHealth = PlayerREF.GetValue(Health)    ;getting the player's CURRENT health and setting your variable to equal it. If you want the BASE health use .GetBaseValue() instead

return VariableWithYourHealth ;This will be the "output" of the Function

endFunction

This can be done in a more compact way too but the above was for illustrative purposes.

 

More compact:

ActorValue property Health auto
actor property PlayerREF auto 

float function MyFunctionThatGetsPlayerHealth()
    
    return PlayerREF.GetValue(Health)

endFunction

It is very important that after you compile the script, you open the "Properties" screen on the script and choose which property you want to fill the "Health" and "PlayerREF" slot declared on the first 2 lines of this code. The Creation Kit will not do this automatically for you. You can name these anything you want instead of "Health" or "PlayerREF" but if you name your properties exactly the same as the item you are looking for, you will be able to use the "AutoFill" buttons on the property screen. When you press this button the properties will fill for you and you won't have to search or type in the drop down box.

 

Edit: You could also put this in an event instead of a "function" if you aren't familiar or comfortable yet with functions.

ActorValue property Health auto
actor property PlayerREF auto

Event OnInit() ;or whichever Event you are using
    
    float VariableWithYourHealth = PlayerREF.GetValue(Health) ;you've put the value in a variable

endFunction
Edited by shatsnazzle
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...