Hello can someone explain to me what this code means, I’m new to Nalfar Cryptor and I need some guides on some of his spells.
pet.moveXY(25,70)
def shouldIUsePoison():
enemies = hero.findEnemies()
for enemy in enemies:
if enemy and hero.distanceTo(enemy)>10 and hero.distanceTo(enemy)<=30:
return enemy
def DIE(enemy):
if hero.distanceTo(enemy)<=15:
hero.cast("drain-life", enemy)
elif hero.distanceTo(enemy)<=45:
hero.attack(enemy)
while True:
hero.moveXY(87, 71)
if hero.canCast("raise-dead"):
corpses = hero.findCorpses()
if corpses.length>5:
hero.cast("raise-dead")
if hero.canCast("summon-burl"):
hero.cast("summon-burl")
if hero.canCast("summon-undead"):
hero.cast("summon-undead")
foes=hero.findEnemies()
warlocks=hero.findByType("warlock",foes)
witchs=hero.findByType("witch",foes)
enemies=warlocks+witchs
enemy=hero.findNearest(enemies)
if enemy:
DIE(enemy)
else:
fangriders=hero.findByType("fangrider",foes)
throwers=hero.findByType("thrower",foes)
shamans=hero.findByType("shaman",foes)
enemies=fangriders+throwers+shamans
enemy=hero.findNearest(enemies)
if enemy:
DIE(enemy)
else:
enemy = hero.findNearestEnemy()
if enemy:
DIE(enemy)
should=shouldIUsePoison()
if hero.canCast("poison-cloud") and should:
hero.cast("poison-cloud", should)
friends=hero.findFriends()
if friends:
BFF=friends[0]
for friend in friends:
if friend.health>BFF.health:
BFF=friend
if BFF and hero.canCast("sacrifice"):
hero.cast("sacrifice",BFF)
The first one (for enemy in enemies) loops over all of the enemies and call each one of them enemy (the for loops are explained in the mountain) and the second one (if corpses.length > 5) checks if the array corpses has 7 or more elements (if you use Phyton you can write len(corpses) instead of corpses.length). Do you understand?
In this case, the length of the array is 4. The line ‘if corpses.length > 5’ is testing to see if at least 6 or more corpses are available. This allows for maximum efficiency when casting “raise-dead”.
Not sure I understand your question, but the default usage in PY is len(something). However, the other method, ‘something.length’ (which is default for JS) is also supported in PY.
It means pretty much what the statement says (python is sometimes very like english):
while-itemIndex-is-less-than-the-amount-of-items: ----Then do something:
itemIndex is a variable probably with an integer value (whole number 1,2,3) And items is an array of items.
Normally at the end of the code inside one of those loops you would increment (increase by one) itemIndex, so that the code loops through the exact same amount of times as the number of coins you have.
Danny