[SOLVED] Finding Player Names?

I was playing the multiplayer level Dueling Grounds, and ran into an issue while defining two functions for my pet.
Here are the two functions:

def onDefeat():
    player = #The Player's username
    hero.say("You won, " + player +". Congratulations!")
pet.on("defeat", onDefeat)
def onVictory():
    player = #The Player's username
    hero.say("You won, " + player +". Congratulations!")
pet.on("victory", onVictory)

I was trying to say the player’s username, but I failed to figure out a way to find it. Is there any way to find the enemy player’s username, and if not, could a way to do that be added?

def on Defeat():
    #code for finding the enemy with the highest health
    player = enemy.id
    hero.say("you won," + player + ". Congratulations")

Also, which world are you in.

I was in the multiplayer level ‘Dueling Grounds’. In response to your proposed solution, I already tried that, but I got the id of the player’s hero. I am trying to figure out if there is a way to find the username of the player I’m fighting.
For example:

BeastBoy13 vs. JackAttack
player = # Player's username here
hero.say("Prepare to die, " + player + ".")

i mean in progress. Did you go up to desert.

Yes I have made it to the desert.

Nice Job!:grinning::grinning::grinning::grinning:

1 Like

Then I think that. you probably know the code to find the enemy who has the most health. Run that only once, so that there can’t be a case where your hero wins but you can’t find the original enemy.

Thank you! I appreciate the compliment.

1 Like

I don’t think you understand. I am trying to find the username of the player, not the name of the player’s hero.

id shows the name of the player. type shows the hero itself


def strongestEnemy(enemies):
    strongestHealth  = 0
    strongest = None
    for enemy in enemies:
        if enemy.health > strongestHealth:
            strongestHealth = enemy.health
            strongest  = enemy
    return strongest

enemies= hero.findEnemies()

I tried to do this in memory, so sorry if I’m wrong.

I don’t think you can find the usernames of enemies and make them a variable unless you manually type it in.

1 Like

Thank you for the clarification.

there is actually a forest level which you say the soldiers’ and munchkins’ names without actually knowing the names.

That’s names, which is using enemy.id, and it works for enemy players, but it says something like Pender, Omarn, Senick, etc not actually their username, I think

I’ll try a bit later.