Simple Health Manager Using Triggers
85,587 Views
-
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} 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
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.