What's wrong with my character in Cavern Survival?!

So i’m starting to get used to the PvP and so far my character is smokin’ the competition with other more noobish players, but what i don’t understand is that, my character always seems to have problem with focusing on the enemy around him and instead he keeps going for the door, and no matter what i do, he always comes back to the door and take it down without any hesitation whatsoever.

I know that i can prevent his by using the flags, but then this is PvP, so i can’t do that when my code is being played back by other player, and when he fought with another player that has better armor and stronger weaponry, he always loses the fight, and that’s irritating considering i’m confident that he could win the match if only he avoided the door like the other player character would.

So anyway here’s my coding:

loop:
    enemy = self.findNearest(self.findEnemies())
    newX = self.pos.x - 15
    newY = self.pos.y
    if enemy:
        distance = self.distanceTo(enemy)
        self.findByType("door")
        if enemy.type is "door":
                self.moveXY(40, 86)  
        if distance <8:
            self.attack(enemy)
        self.attack(enemy)
        self.findByType("headhunter")
        if enemy.type is "headhunter":
            if self.isReady("bash"):
                self.bash(enemy)
            else:
                self.shield()

I’ll keep trying to fix this, meanwhile you guys can help fixing it by giving me a string of code that would make him avoid the door. Thanks for reading beforehand :slight_smile:

the way to do this is basically singling out the door.
such as:

loop:
    headhunter = self.findNearest(self.findByType('headhunter', self.findEnemies()))
    munchkin = self.findNearest(self.findByType('munchkin', self.findEnemies()))
    fangrider = self.findNearest(self.findByType('fangrider', self.findEnemies()))
    ogre = self.findNearest(self.findByType('ogre', self.findEnemies()))
    # fangriders are priority.
    # then, headhunters.
    # then, ogres.
    # and finally, munchkins.
    if fangrider:
        self.attack(fangrider)
    elif headhunter:
        attack(headhunter)
    #etc.
    

@ARasberrypy-thon
I fail to see how that would make him avoid the door .-.

Hi! It’s because you don’t actually attack the door.

@ARasberrypy-thon
Nope he’s still wanted to kill the door

dont use the ‘bash’ because you bash the nearest enemy.

@ARasberrypy-thon
So you think he bashed the door? -_-

Yeah, I do. What’s wrong with that?

is it like, you don’t think he is?

@ARasberrypy-thon
This is, he just attack it, he didn’t bash it or anything

i think he added my code to his.
Look at his code.[quote=“Agalondia, post:1, topic:6976”]
if self.isReady(“bash”):
self.bash(enemy)
[/quote]

sorry, you added my code to yours.
Sorry for the mistake there.

what about:

loop:
    enemy = self.findNearest(self.findEnemies())
    newX = self.pos.x - 15
    newY = self.pos.y
    if enemy:
        distance = self.distanceTo(enemy)
        self.findByType("door")
        if enemy.type is "door":
                self.moveXY(40, 86)  
        elif distance <8:
        # notice the elif.
            self.attack(enemy)
        self.attack(enemy)
        self.findByType("headhunter")
        if enemy.type is "headhunter":
            if self.isReady("bash"):
                self.bash(enemy)
            else:
                self.shield()

He’s still coming back to attack the door :frowning:

you’re attacking one enemy in your elif distance < 8:
And one in your if enemy.
Which will attack the nearest enemy.
Which is…
THE DOOR! ba-dum-tish
Sorry for the bad sense of humour there.
put BOTH attack enemy’s
in the elif distance < 8:

@ARasberrypy-thon
Well this work:

loop:
    enemy = self.findNearest(self.findEnemies())
    newX = self.pos.x - 15
    newY = self.pos.y
    if enemy:
        headhunter = self.findNearest(self.findByType('headhunter', self.findEnemies()))
        munchkin = self.findNearest(self.findByType('munchkin', self.findEnemies()))
        fangrider = self.findNearest(self.findByType('fangrider', self.findEnemies()))
        ogre = self.findNearest(self.findByType('ogre', self.findEnemies()))
        thrower = self.findNearest(self.findByType("thrower", self.findEnemies()))
    distance = self.distanceTo(enemy)
    if munchkin:
        self.attack(munchkin)
    if fangrider:
        self.attack(fangrider)
    if headhunter:
        if distance >8:
            self.shield()
        if distance <8:            
            if self.isReady("bash"):
                self.bash(headhunter)
    if thrower:
        self.attack(thrower)            

But how do i make him to prioritize headhunter?

Use elif.
Yes, the topic you were posting about.
like this.
OR you could use nested ifs and elses.
Which work way more reliably.
It’s a mouthful, I assure you.


loop:
    enemy = self.findNearest(self.findEnemies())
    newX = self.pos.x - 15
    newY = self.pos.y
    if enemy:
        headhunter = self.findNearest(self.findByType('headhunter', self.findEnemies()))
        munchkin = self.findNearest(self.findByType('munchkin', self.findEnemies()))
        fangrider = self.findNearest(self.findByType('fangrider', self.findEnemies()))
        ogre = self.findNearest(self.findByType('ogre', self.findEnemies()))
        thrower = self.findNearest(self.findByType("thrower", self.findEnemies()))
        distance = self.distanceTo(enemy)
        if headhunter:
            self.attack(headhunter)
        else:
            if fangrider:
                self.attack(fangrider)
            else:
                if thrower:
                    self.attack(thrower)
                else:
                    if munchkin:
                        self.attack(munchkin)





1 Like

It worked! :slight_smile:
Thanks man!

Now to tweak it.

XD. I tweaked it a little by using some for loops with the higher level stuff like brawlers.

Having a very slow run.