One Player Remaining Detector
Module — 2 files
These files compile together (same module folder).
one_player_detector_device.verse
using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
using { /Verse.org/Colors/NamedColors }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
<# Code developed by Dragon (dragonstudio.pro)
View my FNC Maps: http://fortnite.com/@blze.dragon
This code was created with assistance of FortniteCreativeGPT - ( www.fortnitecreativegpt.com )
It provided a structure in which I corrected and build from, combining elements from Maestrosharks UI Code (Youtube @MaestroShark)
View FNC+GPT code beginnings at : https://chat.openai.com/share/84617e2f-6e32-46c0-be0e-766c9c4ad49a
I was able to improve upon the structure provided by FNC+GPT and fully develop the code.
Learn more about FortniteCreative+GPT and stay up to date on the latest news!
FortniteCreative+GPT Discord: https://discord.gg/kwb3szRu3u
Get help in all your creative needs from Unreal Engine to UEFN at The Creative Blok Discord!
https://discord.com/invite/P5JU6gzUFV
Devices Needed
Player Spawner Pads #>
one_player_detector_device := class(creative_device):
# Player Counter Marker UI / Credit to MaestroShark! Hype!
S2M<localizes>(S:string):message="{S}"
@editable
PlayerSpawners : []player_spawner_device = array{}
@editable
RefreshRate : float = 0.1
var ResourceTextBlockPerAgent : [agent]?text_block = map{}
OnBegin<override> ()<suspends>: void =
# Attach Player Counter UI
for(PS:PlayerSpawners):
PS.SpawnedEvent.Subscribe(PlayerSpawned)
# Count how many Players are in Game
PlayerCount := GetPlayspace().GetPlayers().Length
Print("PlayerCount = {PlayerCount}")
# Send an Event upon a Player being removed or leaving the game
GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
# Will reduce the count when a player is removed or leaves the game
OnPlayerRemoved (OutPlayer:player): void =
PlayerCount := GetPlayspace().GetPlayers().Length
if (PlayerCount = 1):
# Add your code here to perform an event when one player left in game
Print("One Player Left in Game")
Print("PlayerCount = {PlayerCount}")
else:
Print("PlayerCount = {PlayerCount}")
Print ("Players Still In Game")
<# QUICK NOTE
Please note the UI does not update properly and is only there to help you visually see the player
count. Feel free to remove this when implementing it into your game.You are able to see the events being
called correctly in the log, and are able to add your own events to call #>
<# This UI is optional and can be removed. If removed, be sure to remove this portion under On Begin:
for(PS:PlayerSpawners):
PS.SpawnedEvent.Subscribe(PlayerSpawned)
and all the code below #>
# Player Counter UI Marker
PlayerSpawned(Agent:agent):void=
Print("Player Spawned")
if(MyTextBlock:=ResourceTextBlockPerAgent[Agent]?){}
else:
AssignUI(Agent)
AssignUI(Agent:agent):void=
Print("Assigning UI")
MyCanvas:=MakeCanvas(Agent)
if:
PlayerUI:=GetPlayerUI[player[Agent]]
then:
PlayerUI.AddWidget(MyCanvas)
spawn{RefreshUI(Agent)}
RefreshUI(Agent:agent)<suspends>:void=
Print("Starting to Refresh")
PlayerCount := GetPlayspace().GetPlayers().Length
if(TextBlock := ResourceTextBlockPerAgent[Agent]?):
loop:
Sleep(RefreshRate)
TextBlock.SetText(S2M("Players: {PlayerCount}"))
MakeCanvas(Agent:agent):canvas=
Print("Making Canvas")
MyTextBlock:=text_block:
DefaultTextColor:=White
if(set ResourceTextBlockPerAgent[Agent] = option{MyTextBlock}){}
MyCanvas:=canvas:
Slots:=array:
canvas_slot:
Widget:=MyTextBlock
Anchors:=anchors{Minimum:=vector2{X:=0.0,Y:=0.0},Maximum:=vector2{X:=1.0,Y:=1.0}}
Offsets:=margin{Left:=844.0,Top:=520.0,Right:=911.0,Bottom:=519.0}
return MyCanvas
Sign in to download module
Copy-paste each file above is always free.