Currently I’ve got a working leveling system device, but the player attributes won’t update upon leveling up. I’m looking to make the player HP increase by 20 points and shield by 10 points per level up. How would one write this into a working leveling system? All my efforts don’t seem to work.
I would personally save somewhere as a variable the HP per player
eg PlayerHealthMap : [agent]float = map{}
then when the player spawns I would have a function that grabs that value and also the fort_character of the player and updates them accordingly
if(FC:=Agent.GetFortCharacter[],Health:=PlayerHealthMap[Agent]):
FC.SetMaxHealth(Health)
FC.SetHealth(Health)
Thanks I tried something like that, but it wasn’t working. I’ve taken a different approach using another system and now the upgrades work. However, now the upgrades won’t persist. I’m trying to build a sort of rpg game and having level’s with hp upgrades persisting between sessions is a priority. Any help would be appreciated.
Adding the code here:
using { /Fortnite.com/UI }
using { /Fortnite.com/Devices }
using { /Verse.org/Assets }
using { /Verse.org/Colors }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Fortnite.com/Game }
MODIFICATIONTYPE := enum{Add,Set,Remove}
HPTYPE := enum{Health,Shield}
health_manager := class(creative_device):
@editable DeviceSettings : DefaultSettingsClass = DefaultSettingsClass{} # Compacted all Settings into a class so when exposed into the editor it will be collapsable and not take much space
var SaveHP :logic=true
var ReGrantTime : float = 10.0
var DefaultHP : HPAmounts = HPAmounts{}
var SavedSubscriptions : [agent]?cancelable = map{} # ?cancelable is a subscription that is saved in a map per player so when a player leaves the subscription that was running can be cancelled
@editable HPTriggers : []HPDeviceClass = array{} # Holds all the individual triggers along with how much HP and how to affect it
OnBegin<override>()<suspends>:void=
set SaveHP = DeviceSettings.SaveHP;set ReGrantTime = DeviceSettings.ReGrantTime;set DefaultHP = DeviceSettings.DefaultHP # This syncs the Settings from the DeviceSettingsClass to the ones in this device
for(HPClass:HPTriggers){HPClass.Init(Self,SaveHP)} # Initializes all the Triggers placed in the world
if(DeviceSettings.SaveHP?):
if(TeamSettings:=DeviceSettings.Optional_TeamSettingDevice?,TeamSettings.GetTransform().Translation.X<>0.0): # This checks for the validity of the Team Settings Device
TeamSettings.TeamMemberSpawnedEvent.Subscribe(PlayerSpawned) # If a Team Settings Device is provided it uses that instead of the alternative Detection for spawning
else:
for(Player:GetPlayspace().GetPlayers()). PlayerAdded(Player) # This just runs the PlayerAdded Function for all players who already were in the game
GetPlayspace().PlayerAddedEvent().Subscribe(PlayerAdded) # Handles Players Joining the game and assigns the PlayerEliminatedEvent to Re-Grant the Modified HP
GetPlayspace().PlayerRemovedEvent().Subscribe(PlayerRemoved) # Handles Players Leaving the game and cancels any subscriptions linked to the players who left
SyncHP(false)
PlayerAdded(Player:player):void= #Starts a Subscription of the player's EliminatedEvent and also Sync's the HP to the Current set Values (Only used if SaveHP is True AND no Team Settings Device has been provided)
if(FC:=Player.GetFortCharacter[]):
Subscription:=FC.EliminatedEvent().Subscribe(PlayerEliminatedP1)
if(set SavedSubscriptions[Player]=option{Subscription}){}
SyncHP(option{FC})
PlayerRemoved(Player:player):void= #Retrieves the Current Subscription of the leaving player and cancels it
if(SavedSubscription:=SavedSubscriptions[Player]?). SavedSubscription.Cancel()
PlayerEliminatedP1(EliminatedResult:elimination_result):void=spawn{PlayerEliminatedP2(EliminatedResult.EliminatedCharacter)}
PlayerEliminatedP2(FC:fort_character)<suspends>:void=
Sleep(ReGrantTime)
SyncHP(option{FC})
# This function is run instead of PlayerEliminated if a TeamSettings Device is supplied since it's more accurate to detecting when Player is spawned
PlayerSpawned(Agent:agent):void= if(FC:=Agent.GetFortCharacter[]){ SyncHP(option{FC} )}
SyncHP(MFC:?fort_character):void= # Fort_Character is an optional parameter in this function so it can both be used when Syncing HP for everyone and also if you only want to sync for an individual
if(FC:=MFC?):
FC.SetMaxHealth(DefaultHP.Health);FC.SetMaxShield(DefaultHP.Shield);FC.SetHealth(DefaultHP.Health);FC.SetShield(DefaultHP.Shield)
else if(SaveHP?):
for(Player:GetPlayspace().GetPlayers()):
if(FC:=Player.GetFortCharacter[]):
FC.SetMaxHealth(DefaultHP.Health);FC.SetMaxShield(DefaultHP.Shield);FC.SetHealth(DefaultHP.Health);FC.SetShield(DefaultHP.Shield)
ChangeHP(Type:MODIFICATIONTYPE,HPType:HPTYPE,Amount:float,MFC:?fort_character):void=
if(SaveHP?):
case(HPType):
HPTYPE.Health =>
set DefaultHP.Health = CalculateNewHP(DefaultHP.Health,Amount,Type)
HPTYPE.Shield =>
set DefaultHP.Shield = CalculateNewHP(DefaultHP.Shield,Amount,Type)
SyncHP(false)
else if(FC:=MFC?):
case(HPType):
HPTYPE.Health =>
NewHealth:=CalculateNewHP(FC.GetMaxHealth(),Amount,Type)
FC.SetMaxHealth(NewHealth);FC.SetHealth(NewHealth)
HPTYPE.Shield =>
NewShield:=CalculateNewHP(FC.GetMaxShield(),Amount,Type)
FC.SetMaxShield(NewShield);FC.SetShield(NewShield)
SyncHP( option{FC} )
CalculateNewHP(PreviousHP:float,Amount:float,ModificationType:MODIFICATIONTYPE):float=
case(ModificationType):
MODIFICATIONTYPE.Add => PreviousHP+Amount
MODIFICATIONTYPE.Remove => PreviousHP-Amount
MODIFICATIONTYPE.Set => Amount
MSG_RespawnTime<localizes>:message="How much time after the player gets eliminated should the HP Modifications be re-applied? (Leave this at around 8-9 secs more than the respawn time set in IslandSettings)"
MSG_DefaultHP<localizes>:message="Default HP Players will have (Only Works if SaveHP is ON)"
MSG_SaveHealthPerPlayer<localizes>:message="Do you wish for the edited Health/Shields to be saved and to stay even after respawns?\nDisable If you want to change HP individually Temporarily eg for health boosts lost after respawn"
MSG_TeamSettings<localizes>:message="Adding a Team Settings Device Helps by applying HP exactly when a player Spawns"
DefaultSettingsClass:=class<concrete>:
@editable {ToolTip:=MSG_TeamSettings} Optional_TeamSettingDevice : ?team_settings_and_inventory_device = false # If creator provides a team settings device it will use that instead of trying to guess respawn based on the playereliminated event
@editable {ToolTip:=MSG_DefaultHP} var DefaultHP : HPAmounts = HPAmounts{} # Exposes to the editor the ability to set the Default HP values the script will have
@editable {ToolTip:=MSG_RespawnTime} ReGrantTime : float = 9.0 # Since This Device is meant to require NO other devices linked to keep simplicity low, there's no way to retrieve a on SpawnedEvent, and thus Re-Grants HP a customizable amount after getting the Eliminated Event
@editable {ToolTip:=MSG_SaveHealthPerPlayer} SaveHP : logic = true # Exposes the option the ability
HPDeviceClass:=class<concrete>:
@editable ModifyType : MODIFICATIONTYPE = MODIFICATIONTYPE.Add # This exposes the enum MODIFICATIONTYPE which gives the option to pick what to do with the Health/Shield. Options: (Add,Remove,Set)
@editable Amount : float = 10.0 # Exposes the amount of HP that will be affected
@editable Type : HPTYPE = HPTYPE.Health # Exposes the enum HPTYPE which defines what part of the HP will be affected. Options: (Health,Shield)
@editable ResetHPOnChange : logic = false
@editable Trigger : trigger_device = trigger_device{} # The trigger that will need to be trigger for the modifications to be applied
var SelfDevice : health_manager = health_manager{} # Gets replaced with the current instance of the health_manager device to send events to
var SaveHP : logic = true #
Init(HealthDevice:health_manager,ShouldSave:logic):void=
set SelfDevice=HealthDevice;set SaveHP=ShouldSave
Trigger.TriggeredEvent.Subscribe(Triggered)
Triggered(MAgent:?agent):void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,option{MAgent?.GetFortCharacter[]})
HPAmounts:=class<concrete>:
@editable var Health:float=100.0
@editable var Shield:float=100.0
Lol no way I recognize that code, it’s from my snippet
thanks for using it
Here’s an updated copy of my health manager script (haven’t posted this in the snippets yet) which allows for per player health management.
Do you have an existing seperate code that saves the health/shields the players should have when they leave, if you have I can try adding a helper function for the health manager that takes an input of a player, a float for health and a float for shield so it can load those values
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
MODIFICATIONTYPE := enum{Add,Set,Remove}
HPTYPE := enum{Health,Shield}
SaveType:=enum{NoSave,PerPlayer,Everyone}
health_manager := class(creative_device):
@editable {ToolTip:=MSG_TeamSettings,Categories:=array{MSG_DeviceSettings}} Optional_TeamSettingDevice : ?team_settings_and_inventory_device = false # If creator provides a team settings device it will use that instead of trying to guess respawn based on the playereliminated event
@editable {ToolTip:=MSG_DefaultHP,Categories:=array{MSG_DeviceSettings}} var DefaultHP : HPAmounts = HPAmounts{} # Exposes to the editor the ability to set the Default HP values the script will have
@editable {ToolTip:=MSG_RespawnTime,Categories:=array{MSG_DeviceSettings}} ReGrantTime : float = 9.0 # Since This Device is meant to require NO other devices linked to keep simplicity low, there's no way to retrieve a on SpawnedEvent, and thus Re-Grants HP a customizable amount after getting the Eliminated Event
@editable {ToolTip:=MSG_SaveHealthPerPlayer,Categories:=array{MSG_DeviceSettings}} SaveHP : SaveType = SaveType.NoSave # Exposes the option the ability
var SavedHPPerPlayer : [agent]HPAmounts = map{} # Maps each Player to their own HPAmounts so when they respawn they get the same HP/Shields as before
var SavedSubscriptions : [agent]?cancelable = map{} # ?cancelable is a subscription that is saved in a map per player so when a player leaves the subscription that was running can be cancelled
@editable HPTriggers : []HPDeviceClass = array{} # Holds all the individual triggers along with how much HP and how to affect it
OnBegin<override>()<suspends>:void=
for(HPTrigger:HPTriggers){HPTrigger.Init(Self)}
if(TeamSettings:=Optional_TeamSettingDevice?): # This checks for the validity of the Team Settings Device
TeamSettings.TeamMemberSpawnedEvent.Subscribe(PlayerSpawned) # If a Team Settings Device is provided it uses that instead of the alternative Detection for spawning
else:
for(Player:GetPlayspace().GetPlayers()). PlayerAdded(Player) # This just runs the PlayerAdded Function for all players who already were in the game
GetPlayspace().PlayerAddedEvent().Subscribe(PlayerAdded) # Handles Players Joining the game and assigns the PlayerEliminatedEvent to Re-Grant the Modified HP
GetPlayspace().PlayerRemovedEvent().Subscribe(PlayerRemoved) # Handles Players Leaving the game and cancels any subscriptions linked to the players who left
SyncHP()
PlayerAdded(Player:player):void= #Starts a Subscription of the player's EliminatedEvent and also Sync's the HP to the Current set Values (Only used if SaveHP is True AND no Team Settings Device has been provided)
if(FC:=Player.GetFortCharacter[]):
if(SaveHP=SaveType.PerPlayer):
if(set SavedHPPerPlayer[Player]=HPAmounts{Health:=DefaultHP.Health,Shield:=DefaultHP.Shield}){}
Subscription:=FC.EliminatedEvent().Subscribe(PlayerEliminatedP1)
if(set SavedSubscriptions[Player]=option{Subscription}){}
SyncHP(?MaybeFC:=option{FC})
PlayerRemoved(Player:player):void= #Retrieves the Current Subscription of the leaving player and cancels it
if(SavedSubscription:=SavedSubscriptions[Player]?). SavedSubscription.Cancel()
PlayerEliminatedP1(EliminatedResult:elimination_result):void=spawn{PlayerEliminatedP2(EliminatedResult.EliminatedCharacter)}
PlayerEliminatedP2(FC:fort_character)<suspends>:void=
Sleep(ReGrantTime)
SyncHP(?MaybeFC:=option{FC})
# This function is run instead of PlayerEliminated if a TeamSettings Device is supplied since it's more accurate to detecting when Player is spawned
PlayerSpawned(Agent:agent):void= if(FC:=Agent.GetFortCharacter[]){ SyncHP(?MaybeFC:=option{FC} )}
SyncHP(?MaybeFC:?fort_character=false):void= # Fort_Character is an optional parameter in this function so it can both be used when Syncing HP for everyone and also if you only want to sync for an individual
if(FC:=MaybeFC?):
if(SaveHP=SaveType.Everyone):
FC.SetMaxHealth(DefaultHP.Health);FC.SetMaxShield(DefaultHP.Shield);FC.SetHealth(DefaultHP.Health);FC.SetShield(DefaultHP.Shield)
else if(SaveHP=SaveType.PerPlayer):
if(SavedHP:=SavedHPPerPlayer[FC.GetAgent[]]):
FC.SetMaxHealth(SavedHP.Health);FC.SetMaxShield(SavedHP.Shield);FC.SetHealth(SavedHP.Health);FC.SetShield(SavedHP.Shield)
else if(SaveHP<>SaveType.NoSave):
for(Player:GetPlayspace().GetPlayers()):
if(FC:=Player.GetFortCharacter[]):
SyncHP(?MaybeFC:=option{FC})
ChangeHP(Type:MODIFICATIONTYPE,HPType:HPTYPE,Amount:float,MFC:?fort_character):void=
if(SaveHP=SaveType.Everyone):
case(HPType):
HPTYPE.Health =>
set DefaultHP.Health = CalculateNewHP(DefaultHP.Health,Amount,Type)
HPTYPE.Shield =>
set DefaultHP.Shield = CalculateNewHP(DefaultHP.Shield,Amount,Type)
SyncHP()
else if(SaveHP=SaveType.PerPlayer):
if(FC:=MFC?,SavedHP:=SavedHPPerPlayer[FC.GetAgent[]]):
case(HPType):
HPTYPE.Health =>
NewHealth:=CalculateNewHP(SavedHP.Health,Amount,Type)
set SavedHP.Health=NewHealth
HPTYPE.Shield =>
NewShield:=CalculateNewHP(SavedHP.Shield,Amount,Type)
set SavedHP.Shield=NewShield
SyncHP(?MaybeFC:=option{FC})
else if(FC:=MFC?):
case(HPType):
HPTYPE.Health =>
NewHealth:=CalculateNewHP(FC.GetMaxHealth(),Amount,Type)
FC.SetMaxHealth(NewHealth);FC.SetHealth(NewHealth)
HPTYPE.Shield =>
NewShield:=CalculateNewHP(FC.GetMaxShield(),Amount,Type)
FC.SetMaxShield(NewShield);FC.SetShield(NewShield)
CalculateNewHP(PreviousHP:float,Amount:float,ModificationType:MODIFICATIONTYPE):float=
case(ModificationType):
MODIFICATIONTYPE.Add => PreviousHP+Amount
MODIFICATIONTYPE.Remove => PreviousHP-Amount
MODIFICATIONTYPE.Set => Amount
MSG_RespawnTime<localizes>:message="How much time after the player gets eliminated should the HP Modifications be re-applied? (Leave this at around 8-9 secs more than the respawn time set in IslandSettings)"
MSG_DefaultHP<localizes>:message="Default HP Players will have (Only Works if SaveHP is ON)"
MSG_SaveHealthPerPlayer<localizes>:message="Do you wish for the edited Health/Shields to be saved and to stay even after respawns?\nDisable If you want to change HP individually Temporarily eg for health boosts lost after respawn"
MSG_TeamSettings<localizes>:message="Adding a Team Settings Device Helps by applying HP exactly when a player Spawns"
MSG_DeviceSettings<localizes>:message="Device Settings"
HPDeviceTrigger:=class(HPDeviceClass):
@editable Trigger : trigger_device = trigger_device{}
Init<override>(HealthDevice:health_manager):void=
set SelfDevice=HealthDevice
Trigger.TriggeredEvent.Subscribe(TriggeredMaybeAgent)
HPDeviceChannel:=class(HPDeviceClass):
@editable ChannelDevice : channel_device = channel_device{}
Init<override>(HealthDevice:health_manager):void=
set SelfDevice=HealthDevice
ChannelDevice.ReceivedTransmitEvent.Subscribe(TriggeredMaybeAgent)
HPDeviceClass:=class<abstract>:
@editable ModifyType : MODIFICATIONTYPE = MODIFICATIONTYPE.Add # This exposes the enum MODIFICATIONTYPE which gives the option to pick what to do with the Health/Shield. Options: (Add,Remove,Set)
@editable Amount : float = 10.0 # Exposes the amount of HP that will be affected
@editable Type : HPTYPE = HPTYPE.Health # Exposes the enum HPTYPE which defines what part of the HP will be affected. Options: (Health,Shield)
#@editable Trigger : trigger_device = trigger_device{} # The trigger that will need to be trigger for the modifications to be applied
var SelfDevice : health_manager = health_manager{} # Gets replaced with the current instance of the health_manager device to send events to
Init(HealthDevice:health_manager):void=
set SelfDevice=HealthDevice
#Trigger.TriggeredEvent.Subscribe(Triggered)
TriggeredMaybeAgent(MAgent:?agent):void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,option{MAgent?.GetFortCharacter[]})
TriggeredAgent(Agent:agent):void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,option{Agent.GetFortCharacter[]})
Triggered():void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,false)
HPAmounts:=class<unique><concrete>:
@editable var Health:float=100.0
@editable var Shield:float=100.0
I do not currently have a separate code for saving the health and shields. I was simply trying to use a save point device. I think I need to do some more reading to understand what I’m missing here. I’ve applied your updated code and still nothing saves. Health and shield always reverts back to 100 when I end game and start again.
Yes My code does not have verse persistence, the previous iteration of the code intended to save the Health globally so all players would share the same max health/shield the change gave you the option of whether to locally save the Health PerPlayer/ForEveryone or to NotSave and have it revert when a player dies
I am trying to add a verse persistence version of this script that includes a player weak_map but keep in mind if this script includes a weak_map and you publish with it once, you will NEVER be able to remove it, it’s the reason I mainly avoided doing it
I see. Thanks for the information. I am looking for these upgrades to be done on individual players based on leveling up within the game. These upgrades will need to persist on the individual as well. I appreciate all your responses, but I guess I’ll need a different solution entirely. Back to the drawing board!
Give this script a try it should save your HP across sessions I havent fully tested it though
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
MODIFICATIONTYPE := enum{Add,Set,Remove}
HPTYPE := enum{Health,Shield}
SaveType:=enum{NoSave,PerPlayer,Everyone}
var PlayerHPWeakMap : weak_map(player,tuple(float,float)) = map{}
health_manager := class(creative_device):
@editable {ToolTip:=MSG_TeamSettings,Categories:=array{MSG_DeviceSettings}} Optional_TeamSettingDevice : ?team_settings_and_inventory_device = false # If creator provides a team settings device it will use that instead of trying to guess respawn based on the playereliminated event
@editable {ToolTip:=MSG_DefaultHP,Categories:=array{MSG_DeviceSettings}} var DefaultHP : HPAmounts = HPAmounts{} # Exposes to the editor the ability to set the Default HP values the script will have
@editable {ToolTip:=MSG_RespawnTime,Categories:=array{MSG_DeviceSettings}} ReGrantTime : float = 9.0 # Since This Device is meant to require NO other devices linked to keep simplicity low, there's no way to retrieve a on SpawnedEvent, and thus Re-Grants HP a customizable amount after getting the Eliminated Event
@editable {ToolTip:=MSG_SaveHealthPerPlayer,Categories:=array{MSG_DeviceSettings}} SaveHP : SaveType = SaveType.NoSave # Exposes the option the ability
#@editable {Categories:=array{MSG_DeviceSettings}} SaveHPAcrossSession : logic = false
var SavedHPPerPlayer : [agent]HPAmounts = map{} # Maps each Player to their own HPAmounts so when they respawn they get the same HP/Shields as before
var SavedSubscriptions : [agent]?cancelable = map{} # ?cancelable is a subscription that is saved in a map per player so when a player leaves the subscription that was running can be cancelled
@editable HPTriggers : []HPDeviceClass = array{} # Holds all the individual triggers along with how much HP and how to affect it
OnBegin<override>()<suspends>:void=
for(HPTrigger:HPTriggers){HPTrigger.Init(Self)}
if(TeamSettings:=Optional_TeamSettingDevice?): # This checks for the validity of the Team Settings Device
TeamSettings.TeamMemberSpawnedEvent.Subscribe(PlayerSpawned) # If a Team Settings Device is provided it uses that instead of the alternative Detection for spawning
else:
for(Player:GetPlayspace().GetPlayers()). PlayerAdded(Player) # This just runs the PlayerAdded Function for all players who already were in the game
GetPlayspace().PlayerAddedEvent().Subscribe(PlayerAdded) # Handles Players Joining the game and assigns the PlayerEliminatedEvent to Re-Grant the Modified HP
GetPlayspace().PlayerRemovedEvent().Subscribe(PlayerRemoved) # Handles Players Leaving the game and cancels any subscriptions linked to the players who left
SyncHP()
PlayerAdded(Player:player):void= #Starts a Subscription of the player's EliminatedEvent and also Sync's the HP to the Current set Values (Only used if SaveHP is True AND no Team Settings Device has been provided)
if(FC:=Player.GetFortCharacter[]):
Subscription:=FC.EliminatedEvent().Subscribe(PlayerEliminatedP1)
if(set SavedSubscriptions[Player]=option{Subscription}){}
SyncHP(?MaybeFC:=option{FC})
PlayerRemoved(Player:player):void= #Retrieves the Current Subscription of the leaving player and cancels it
if(SavedSubscription:=SavedSubscriptions[Player]?). SavedSubscription.Cancel()
PlayerEliminatedP1(EliminatedResult:elimination_result):void=spawn{PlayerEliminatedP2(EliminatedResult.EliminatedCharacter)}
PlayerEliminatedP2(FC:fort_character)<suspends>:void=
Sleep(ReGrantTime)
SyncHP(?MaybeFC:=option{FC})
# This function is run instead of PlayerEliminated if a TeamSettings Device is supplied since it's more accurate to detecting when Player is spawned
PlayerSpawned(Agent:agent):void= if(FC:=Agent.GetFortCharacter[]){ SyncHP(?MaybeFC:=option{FC} )}
SyncHP(?MaybeFC:?fort_character=false):void= # Fort_Character is an optional parameter in this function so it can both be used when Syncing HP for everyone and also if you only want to sync for an individual
if(FC:=MaybeFC?):
if(SaveHP=SaveType.Everyone):
FC.SetMaxHealth(DefaultHP.Health);FC.SetMaxShield(DefaultHP.Shield);FC.SetHealth(DefaultHP.Health);FC.SetShield(DefaultHP.Shield)
else if(SaveHP=SaveType.PerPlayer):
if(Player:=player[FC.GetAgent[]],Player.IsActive[]):
if(SavedHP:=SavedHPPerPlayer[Player]):
FC.SetMaxHealth(SavedHP.Health);FC.SetMaxShield(SavedHP.Shield);FC.SetHealth(SavedHP.Health);FC.SetShield(SavedHP.Shield)
else:
SavedHP:=LoadHP(Player)
FC.SetMaxHealth(SavedHP.Health);FC.SetMaxShield(SavedHP.Shield);FC.SetHealth(SavedHP.Health);FC.SetShield(SavedHP.Shield)
else if(SaveHP<>SaveType.NoSave):
for(Player:GetPlayspace().GetPlayers()):
if(FC:=Player.GetFortCharacter[]):
SyncHP(?MaybeFC:=option{FC})
ChangeHP(Type:MODIFICATIONTYPE,HPType:HPTYPE,Amount:float,MFC:?fort_character):void=
if(SaveHP=SaveType.Everyone):
case(HPType):
HPTYPE.Health =>
set DefaultHP.Health = CalculateNewHP(DefaultHP.Health,Amount,Type)
HPTYPE.Shield =>
set DefaultHP.Shield = CalculateNewHP(DefaultHP.Shield,Amount,Type)
SyncHP()
else if(SaveHP=SaveType.PerPlayer):
if(FC:=MFC?):
if(Agent:=FC.GetAgent[],SavedHP:=SavedHPPerPlayer[Agent]):
case(HPType):
HPTYPE.Health =>
NewHealth:=CalculateNewHP(SavedHP.Health,Amount,Type)
set SavedHP.Health=NewHealth
SetHealthWM(Agent, NewHealth)
HPTYPE.Shield =>
NewShield:=CalculateNewHP(SavedHP.Shield,Amount,Type)
set SavedHP.Shield=NewShield
SetShieldWM(Agent, NewShield)
else:
if(Agent:=FC.GetAgent[],SavedHP:=LoadHP(MFC?.GetAgent[])):
case(HPType):
HPTYPE.Health =>
NewHealth:=CalculateNewHP(SavedHP.Health,Amount,Type)
set SavedHP.Health=NewHealth
SetHealthWM(Agent, NewHealth)
HPTYPE.Shield =>
NewShield:=CalculateNewHP(SavedHP.Shield,Amount,Type)
set SavedHP.Shield=NewShield
SetShieldWM(Agent, NewShield)
SyncHP(?MaybeFC:=option{FC})
else if(FC:=MFC?):
case(HPType):
HPTYPE.Health =>
NewHealth:=CalculateNewHP(FC.GetMaxHealth(),Amount,Type)
FC.SetMaxHealth(NewHealth);FC.SetHealth(NewHealth)
HPTYPE.Shield =>
NewShield:=CalculateNewHP(FC.GetMaxShield(),Amount,Type)
FC.SetMaxShield(NewShield);FC.SetShield(NewShield)
SetHealthWM(Agent:agent,Health:float):void=
if(Player:=player[Agent],Player.IsActive[]):
if(Data:=PlayerHPWeakMap[Player]):
if. set PlayerHPWeakMap[Player]=(Health,Data(1))
SetShieldWM(Agent:agent,Shield:float):void=
if(Player:=player[Agent],Player.IsActive[]):
if(Data:=PlayerHPWeakMap[Player]):
if. set PlayerHPWeakMap[Player]=(Data(0),Shield)
LoadHP(Agent:agent)<transacts>:HPAmounts=
if(Player:=player[Agent],Player.IsActive[]):
if(Data:=PlayerHPWeakMap[Player]):
NewClass:=HPAmounts{Health:=Data(0),Shield:=Data(1)}
if. set SavedHPPerPlayer[Player]=NewClass
return NewClass
else:
if. set PlayerHPWeakMap[Player]=(DefaultHP.Health,DefaultHP.Shield)
if. set SavedHPPerPlayer[Agent]=HPAmounts{Health:=DefaultHP.Health,Shield:=DefaultHP.Shield}
return HPAmounts{Health:=DefaultHP.Health,Shield:=DefaultHP.Shield}
CalculateNewHP(PreviousHP:float,Amount:float,ModificationType:MODIFICATIONTYPE):float=
case(ModificationType):
MODIFICATIONTYPE.Add => PreviousHP+Amount
MODIFICATIONTYPE.Remove => PreviousHP-Amount
MODIFICATIONTYPE.Set => Amount
MSG_RespawnTime<localizes>:message="How much time after the player gets eliminated should the HP Modifications be re-applied? (Leave this at around 8-9 secs more than the respawn time set in IslandSettings)"
MSG_DefaultHP<localizes>:message="Default HP Players will have (Only Works if SaveHP is ON)"
MSG_SaveHealthPerPlayer<localizes>:message="Do you wish for the edited Health/Shields to be saved and to stay even after respawns?\nDisable If you want to change HP individually Temporarily eg for health boosts lost after respawn"
MSG_TeamSettings<localizes>:message="Adding a Team Settings Device Helps by applying HP exactly when a player Spawns"
MSG_DeviceSettings<localizes>:message="Device Settings"
HPDeviceTrigger:=class(HPDeviceClass):
@editable Trigger : trigger_device = trigger_device{}
Init<override>(HealthDevice:health_manager):void=
set SelfDevice=HealthDevice
Trigger.TriggeredEvent.Subscribe(TriggeredMaybeAgent)
HPDeviceChannel:=class(HPDeviceClass):
@editable ChannelDevice : channel_device = channel_device{}
Init<override>(HealthDevice:health_manager):void=
set SelfDevice=HealthDevice
ChannelDevice.ReceivedTransmitEvent.Subscribe(TriggeredMaybeAgent)
HPDeviceClass:=class<abstract>:
@editable ModifyType : MODIFICATIONTYPE = MODIFICATIONTYPE.Add # This exposes the enum MODIFICATIONTYPE which gives the option to pick what to do with the Health/Shield. Options: (Add,Remove,Set)
@editable Amount : float = 10.0 # Exposes the amount of HP that will be affected
@editable Type : HPTYPE = HPTYPE.Health # Exposes the enum HPTYPE which defines what part of the HP will be affected. Options: (Health,Shield)
#@editable Trigger : trigger_device = trigger_device{} # The trigger that will need to be trigger for the modifications to be applied
var SelfDevice : health_manager = health_manager{} # Gets replaced with the current instance of the health_manager device to send events to
Init(HealthDevice:health_manager):void=
set SelfDevice=HealthDevice
#Trigger.TriggeredEvent.Subscribe(Triggered)
TriggeredMaybeAgent(MAgent:?agent):void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,option{MAgent?.GetFortCharacter[]})
TriggeredAgent(Agent:agent):void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,option{Agent.GetFortCharacter[]})
Triggered():void=
SelfDevice.ChangeHP(ModifyType,Type,Amount,false)
HPAmounts:=class<unique><concrete>:
@editable var Health:float=100.0
@editable var Shield:float=100.0
That works beautifully so far! Thanks so much for your speedy fixes! My first creative island isn’t going to be super fancy, but I want it to be somewhat fun and complex. This will definitely help!

