Trying to have my health/shield bar track all players and display for everyone, but I cant figure it out, currently it tracks the first player in the players array and thats it, how do I fix that?
OnBegin<override>()<suspends>:void=
# var players: []player = Self.GetPlayspace().GetPlayers()
# if(ValidPlayer := players[0]):
# AddUIToPlayer(ValidPlayer)
AllPlayers := GetPlayspace().GetPlayers()
if (Player := AllPlayers[0]):
AddUIToPlayer(Player)
loop:
Sleep(0.1)
if(Player : player = AllPlayers[0]):
if(FortniteCharacter: fort_character = Player.GetFortCharacter[]):
set healthFloat = FortniteCharacter.GetHealth()
set shieldFloat = FortniteCharacter.GetShield()
UpdateUI()
if(healthFloat <= 0.0):
break
AddUIToPlayer(Player:agent) : void=
if (PlayerUI := GetPlayerUI[player[Player]]):
PlayerUI.AddWidget(CreateUI())
The above specifically adds it to JUST the first player.
This may help:
var PlayersCustomCanvas: [player]canvas = map{}
[...]
# after building a canvas 'NewCanvas' I give each player their own copy
for (thisPlayer: Self.GetPlayspace().GetPlayers()):
# lots of stuff deleted
if:
set PlayersCustomCanvas[thisPlayer] = NewCanvas
# lots of stuff deleted
then:
SetCanvasVisiblity(thisPlayer, true)
# lots of stuff deleted
# hide/display the Custom UI canvas
SetCanvasVisiblity(thisPlayer: player, bVisible: logic): void =
if (CustomCanvas := PlayersCustomCanvas[thisPlayer]):
if (bVisible?):
CustomCanvas.SetVisibility(widget_visibility.Visible)
else:
CustomCanvas.SetVisibility(widget_visibility.Hidden)
You have to map a canvas to each player, and assign each player their canvas. I cannot recall if I HAD to make the canvas visible at the start, but I turn it on and off, so I may have turned it on at first for clarity.
Hey so I tried it but now my script is not working what so ever? Is there any way I could get in contact with you directly to look into it further, whether it be discord or twitter dms or something? this is something I gotta figure out and my script has changed since this post, my discord account is reksarts, if you’re willing to help me out with this.
You need to break the problem down into small pieces and test each one before trying to do something that complex.
Can you put a simple text HUD on each player that says, “Player 1”, “Player 2”, etc.? Because if you cannot do that, then something complex like doing your own health and shield bars will not happen.
Use “var Canvases: [player]canvas = map{}” to load a “Player 1”, “Player 2”, etc. canvas on each player and I can tell you the next step.