[SOLVED] Finding Player Names?


#1

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?


#2
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.


#3

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 + ".")

#4

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


#5

Yes I have made it to the desert.


#6

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


#7

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.


#8

Thank you! I appreciate the compliment.


#9

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


#10

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

ex

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()
hero.say(strongestEnemy(enemies))
        

#11

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


#12

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


#13

Thank you for the clarification.


#14

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


#15

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


#16

I’ll try a bit later.