I’m trying to make it so that when GameResults() runs, and the player dies with 0 gems,
“Lose Everything” prints, but it skips that line and goes right to “You Lose!”. I’ve been told, health in Fortnite is never 0.0, and the health goes back to 100.0 when the player dies. I’ve tried setting PlayerHealth to = 5.0 with 0 gems and the line executes, so I know it’s working, so how can I make it so that it recognizes the player died, and also is there another way to track a player’s death?
if (PlayerHealth <= 1.0 and GemCount = 0):
Print(“Lose Everything!”)
This is the line of code I’m having issues with. It’s at the bottom of the script under GameResults(): void =
using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
<# Solo Gem Hunt
*************
#>
# A Verse-authored creative device that can be placed in a level
hello_world_device_mk15 := class(creative_device):
<# I'm starting with two variables. One for how many
gems the player has, and one for the player's
health. I'm also setting a number that will be
the number of gems you need to find to win the game.
#>
var GemCount: int = 0
var PlayerHealth: float = 0.0
var PlayerDamage: float = 0.0
var GameWon: logic = true
var IsDead: logic = false
GemGoal: int = 100
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
<# These are the two functions that I called. GemAdjust
adjusts the number of gems the player has based on the
number I enter for it's argument. HealthAdjust does the
exact same thing, but for the players health. I'm adjusting
these arguments to test to see if the functions I made are
working properly.
#>
GemAdjust(0)
HealthAdjust(100.0)
DamagePlayer(100.0)
GameResults()
<# GemAdjust
=========
This function will adjust how many gems
the player has. I'll set limits on the numbers
so it doesn't go below 0 or above the GemGoal amount.
#>
GemAdjust(Gems: int): int =
set GemCount = GemCount + Gems
Print("Gem Count is {GemCount}!")
if (GemCount > GemGoal):
set GemCount = GemGoal
Print("Too many Gems! Gems now {GemCount}")
if (GemCount < 0):
set GemCount = 0
Print("Negative Gems!")
return GemCount
<# HealthAdjust
============
This function will allow me to adjust the
player's health. I'm setting the PlayerHealth
variable so that when I change the HealthAmount
parameter in the HealthAdjust function, it will
change the players health according to the number
I put in the function's argument when I call it.
#>
HealthAdjust(HealthAmount: float): void =
set PlayerHealth = PlayerHealth + HealthAmount
Playspace : fort_playspace = GetPlayspace()
AllPlayers: []player = Playspace.GetPlayers()
if (FirstPlayer: player = AllPlayers[0]):
if (FNCharacter:= FirstPlayer.GetFortCharacter[]):
FNCharacter.SetHealth(PlayerHealth)
set PlayerHealth =FNCharacter.GetHealth()
<# I'm making a DamagePlayer function cause for some reason
I can't set the Player's health to 0 with the .SetHealth method...
So I'll add a function with a parameter to damage the player instead.
Wow! So the key is to set the PlayerHealth to equal the Fortnite Character's
current health with the .GetHealth() method attached to the Character object.
That way, it will update the Player's health in real time with the function.
#>
DamagePlayer(DamageAmount:float): void =
Playspace : fort_playspace = GetPlayspace()
AllPlayers: []player = Playspace.GetPlayers()
if (FirstPlayer: player = AllPlayers[0]):
if (FNCharacter:= FirstPlayer.GetFortCharacter[]):
FNCharacter.Damage(DamageAmount)
set PlayerHealth = FNCharacter.GetHealth()
set PlayerDamage = PlayerHealth - DamageAmount
if (FNCharacter.GetHealth() <= 1.0):
set IsDead = true
<# GameResults
===========
This function will check the end game results.
If your gems equal the GemGoal AND you still have
health, you win! If the player's health is 0, you lose!
If both the player's gems and the player's health is 0
"Lost it All!" will print.
This one was a doozy. You can't set the Player's health to 0.0
from SetHealth, it only goes down to 1.0, so to test out the else if
statement, I had to make another function to damage the player to a full
100.0, and the function worked!
Had to ChatGPT it. Player health in Fortnite is never 0.0, so 0.0 cancels it
out. Only < or <= 1.0 will work when wanting to set less than 0. Also you
can return a void if the void has no value, and also you NEED to make an
early return in the codeblock so that the if statements underneath the ones
you want to execute don't execute.
#>
GameResults(): void =
Playspace : fort_playspace = GetPlayspace()
AllPlayers: []player = Playspace.GetPlayers()
if (FirstPlayer: player = AllPlayers[0]):
if (FNCharacter:= FirstPlayer.GetFortCharacter[]):
set PlayerHealth = FNCharacter.GetHealth()
if (PlayerHealth <= 1.0 and GemCount = 0):
Print("Lose Everything!")
else:
Print ("You Lose!")
return
if (PlayerHealth > 1.0):
if( GemCount = GemGoal):
Print ("You Win! Gem Count {GemCount}")
return