Round Settings Device not working

Hello, i have a script to make the Round to end when onle keeps one player alive, but when i invoke the EndRound call, with the winner as parameter, in the game it shows me draw. I know actually last standing wins isn’t working, but this should work, dont it?
i`ll link the code below:
RoundWinnerController := class(creative_device):

@editable
EndRoundDevice : round_settings_device = round_settings_device{}
var PlayerAlive : int = 0

# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=

    AllPlayers := GetPlayspace().GetPlayers()
    set PlayerAlive = AllPlayers.Length
    
    for (Agent : AllPlayers, Player := player[Agent], FortCharacter := Player.GetFortCharacter[]):
        FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)

OnPlayerEliminated(Result : elimination_result): void =
    AllPlayers := GetPlayspace().GetPlayers()
    set PlayerAlive = PlayerAlive-1

    Print("DIES")

    if(PlayerAlive = 1):
        Print("End it")
        EndGame()

EndGame(): void =
    Print("Ended")
    AllPlayers := GetPlayspace().GetPlayers()
    for (Agent : AllPlayers, Player := player[Agent], FortCharacter := Player.GetFortCharacter[]):
        if(PlayerHealth := FortCharacter.GetHealth() > 0.0):
            EndRoundDevice.EndRound(Player)

Thanks!

This looks close, but maybe it’s the second-to-last line where you have the health comparison. Try separating this into two expressions so the PlayerHealth is set to FortCharacter.GetHealth( ) first, then compare PlayerHealth > 0.0. Just a guess.

My eyes burn! It should work if you’re not letting people join while game is in progress and you disable spawn limit but I think a dynamic method would suit more.

Anyway, I’m not sure how to fix your issue but since I don’t use the round_settings_device to end rounds in my map I guess it’s not working, if your map is not FFA, you could use the team_settings_and_inventory_device.TeamOutOfRespawnsEvent() instead, it should be way easier. And you can call team_settings_and_inventory_device.EndRound() to choose the winning team.

my game is a FFA and i avoid to join with the round in progress, the script is working. It finish the game so its calling the endRound, but its not getting the player who has won(the player i call as parameter).

Replace this :

for (Agent : AllPlayers, Player := player[Agent], FortCharacter := Player.GetFortCharacter[]):

by this :

for (Agent : AllPlayers, Player := player[Agent], FortCharacter := Player.GetFortCharacter[], FortCharacter.IsActive[]):

it will call the loop on alive players only, so your last player if everything works fine

Have you ever managed to credit the win to the last player?

1 Like