Dunes help. Not sure on how to void an enemy


#1

What i current got is

loop:
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()
    if enemy:
        if enemy.type is 'sand-yak' or enemy.type is 'burl':
            
 # Don't fight Sand Yaks or Burls! Just keep collecting coins.
            pass
        if enemy:
            self.attack(enemy)
        # But if the enemy is a 'thrower' or an 'ogre', fight them.
        
    elif item:
        pos = item.pos
        a = pos.x
        b = pos.y
        self.moveXY(a, b)

My issue is that for
if enemy.type is 'sand-yak' or enemy.type is 'burl':
I don’t know how to not attack the sand-yak and the burl.
Any suggestions on how to fix this? thank you in advance.


#2

Good question. The sample code already avoids attacking sand-yaks and burls. (The pass statement does nothing.) You need to add an else clause in there to say what to do when you see an enemy that isn’t one of those two types. Does that make any sense?


#3

yep or you can change that line to

if enemy.type is 'thrower' or enemy.type is 'ogre':

then put the attack statement inside there.


#4

Yes that makes sense but i have issues setting that up, in my head.


#5

I tried this

if enemy.type is 'thrower' or enemy.type is 'ogre':
            self.attack()

But it seems not to be working?
I’m sorry but i am still new to this :slight_smile:


#6

I figured it out thanks everyone for their help :slight_smile: I forgot to define the class name of

if enemy.type is 'thrower' or enemy.type is 'ogre':
            self.attack(enemy)

#7

Im new sorry if im supposed to do something. :smiley:


#8

Is there any resource on here that lists all the different enemy types in perfect syntax? I’m trying to avoid a sand-yak, but my code isn’t recognizing the type.

Thanks,
Jacob


#9

Not that I know of.

“sand-yak” is the correct type for sand yaks.

usually if you click on the mob on the screen it will switch who you are “focused” on and it then shows “name - type” (the real type is all lowercase and hyphenated if more than one word) and/or you can try say(enemy.type) to get it yourself. I thought there was a message where someone listed a bunch of them but I couldn’t find it. so here is my attempt (off the top of my head)

sand-yak, peon, peasant, munchkin, soldier, archer, thrower, shaman, headhunter, fang-rider, orge, brawler, etc

I’m sure there are more but as I said that is off the top of my head (to much hair to find any others).
(I can never remember if it is head-hunter or headhunter, I think no ‘-’, but…)

The heroes also have a type see this post.


#10

What will give you this “enemy.type” Will the glasses called kithgard workers give you “enemy.type” due to skills granted “find by type” I"m also trying to avoid attacking a herd of sand yaks.


#11

FindByType is not needed for this case, because you should have an array of all enemies, including the yaks with the herof.findEnemies() function

Lets say you have your array of enemies, called enemies.
you can check each array member through a loop, and then check if that specific variable, lets say i in this case, is of type “sand-yak” I dont think you need a specific glasses to check for enemy type. I believe it is either included in the game already, or its in the same equipment needed to check for gold, position, value, etc.