How to detect when a player is eliminated by themselves?

Below is a snippet of code from a Gun Game script I’m debugging. When a player is eliminated, this method is called, and if the Eliminating character is a player, then a “PromotePlayer” method is called that gives them a new weapon.

OnPlayerEliminated(Result : elimination_result) : void=
        Eliminator := Result.EliminatingCharacter
        Eliminated := Result.EliminatedCharacter
        if(Eliminator = Eliminated):
            Print("Contgratulations, you played yourself")
        else:
            if (FortCharacter := Eliminator?, EliminatingAgent := FortCharacter.GetAgent[]):
                Print("Promoting Player...")
                PromotePlayer(EliminatingAgent)

The issue is that, with explosive weapons, a player can eliminate themselves. With this code, the player is still given a new weapon. With line 4, I’ve attempted to account for this by comparing the EliminatingCharacter to the EliminatedCharacter, and if they are the same, do not promote them to the next weapon. But this does not seem to work.

Is there an easy way to check for self-elimination in Verse?

1 Like

A discord user revealed the solution for me. You have to convert the fort_characters to Agents before comparing them in an if statement. Below is the working method:

OnPlayerEliminated(Result : elimination_result) : void=
        Eliminator := Result.EliminatingCharacter
        Eliminated := Result.EliminatedCharacter
        if (EliminatingFortCharacter := Eliminator?, EliminatingAgent := EliminatingFortCharacter.GetAgent[]):
            if (EliminatedFortCharacter := Eliminated, EliminatedAgent := EliminatedFortCharacter.GetAgent[]):
                    if(EliminatedAgent<>EliminatingAgent):
                        Print("Promoting Player...")
                        PromotePlayer(EliminatingAgent)
5 Likes