Hi, I can’t figure out what to write to define the function below.
The goal of my code is to give a vfx to the top score player.
(tbh I’ve never coded anything in my life, it’s kinda hard rn😂)
OnElim() : =
var PlayerList:[]tuple(agent, int) = for {Agent -> Score : PlayerScores} do {Agent, Score} # Create a list of players and their scores
set PlayerList = SortPlayerList(PlayerList) # Sort the player list by scores
if (PlayerList1 := PlayerList[0]): # Get the first player, will fail if there isn't one.
PlayerReference1.Register(PlayerList1(0)) # Set the first player reference
if : PlayerList1(0) HasEffect
return # do nothing
else :
Crown_VFX.pickup(PlayerList1(0))
Also, here is the full code : (tell me if you see anything wrong tho)
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
crown_device := class(creative_device):
@editable Crown_VFX : visual_effect_powerup_device = visual_effect_powerup_device{}
@editable PlayerSpawner : player_spawner_device = player_spawner_device{}
@editable ElimManager : elimination_manager_device = elimination_manager_device{}
@editable ScoreManagerDevice : score_manager_device = score_manager_device{}
OnBegin<override>()<suspends>:void=
ElimManager.EliminationEvent.Subscribe(OnElim)
var PlayerScores : [agent]int = map{} # Map to keep track of player scores
OnElim() : =
var PlayerList:[]tuple(agent, int) = for {Agent -> Score : PlayerScores} do {Agent, Score} # Create a list of players and their scores
set PlayerList = SortPlayerList(PlayerList) # Sort the player list by scores
if (PlayerList1 := PlayerList[0]): # Get the first player, will fail if there isn't one.
PlayerReference1.Register(PlayerList1(0)) # Set the first player reference
if : PlayerList1(0) HasEffect
return # do nothing
else :
Crown_VFX.pickup(PlayerList1(0))
# Function to sort the player list by scores
SortPlayerList(PlayerList:[]tuple(agent, int)):[]tuple(agent, int)=
Print("Sorting Player List") # Debug print
var NewList: []tuple(agent, int) = PlayerList
for:
I := 0..NewList.Length - 1 # Outer loop for bubble sort
do:
for:
J := 0..NewList.Length - I - 2 # Inner loop for bubble sort
Item := NewList[J] # Get the first player
SecondItem := NewList[J + 1] # Get the second player
Item(1) < SecondItem(1) # Compare the scores
do:
option{ set NewList[J] = SecondItem } # Swap the players
option{ set NewList[J + 1] = Item } # Swap the players
return NewList
Thank you in advance.