Hi everyone,
I just start playing as a ranger, and I don’t really know all the “distancing” for the bow thing. This error did not occur to me when I was fighting other players, can someone tell me why this is happening?
By the way, I didn’t have that much gems for all good equipment for ritic, if I have any equipment loss, tell me, thanks.
Here’s my code:
# Defeat the enemy hero in a duel!
def findEnemyHero():
enemyHero = None
bestHealth = 0
for enemy in hero.findEnemies():
if enemy.maxHealth > bestHealth:
bestHealth = enemy.health
enemyHero = enemy
return enemyHero
while True:
enemy = findEnemyHero()
nearest = hero.findNearestEnemy()
mPos = hero.pos
if enemy and hero.distanceTo(nearest) > 10:
dist = hero.distanceTo(enemy)
ePos = enemy.pos
mX = mPos.x
mY = mPos.y
eX = ePos.x
eY = ePos.y
if mX > eX:
endX = 12
buildX = mX - 4
else:
endX = 66
buildX = mX + 4
if mY > eY:
endY = 16
buildY = mY - 3
else:
endY = 52
buildY = mY + 3
if hero.isReady("shadow-vortex"):
hero.shadowVortex(enemy.pos, Vector(endX, endY))
if hero.isReady("wall-of-darkness") and hero.time > 10:
hero.wallOfDarkness([hero.pos, Vector(buildX, buildY)]);
hero.scattershot(enemy)
elif nearest:
hero.scattershot(nearest)
Welcome to the forum @Watamelon ! This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Have a great time
I changed gift of the trees with the precision rifle, and I got the dragontooth, here’s my new code:
enemy = hero.findNearest([e for e in hero.findEnemies() if e.id is "Hero Placeholder"])
if enemy:
if hero.distanceTo(enemy) < 25:
hero.blink(enemy.pos)
else:
hero.phaseShift()
hero.backstab(enemy)
if hero.isReady("phase-shift"):
hero.phaseShift()
hero.moveXY(11, 16)
else:
hero.blink(Vector(11, 16))
for i in range(2):
if hero.pos.x != 11 and hero.pos.y != 16:
hero.blink(Vector(11, 16))
else:
hero.phaseShift()
hero.moveXY(11, 16)
x1 = 9
x2 = 16
y1 = 22
y2 = 14
while True:
enemy = hero.findNearest([e for e in hero.findEnemies() if e.id is "Hero Placeholder"])
nearest = hero.findNearestEnemy()
mPos = hero.pos
time = hero.time
if hero.gold > 80:
hero.buildXY("paladin", 13, 19)
for friend in hero.findByType("paladin"):
if friend.team == "ogres":
if friend.canCast("heal") and hero.health < 1400:
hero.command(friend, "cast", "heal", hero)
else:
hero.command(friend, "shield")
if enemy and nearest and hero.distanceTo(nearest) > 10:
dist = hero.distanceTo(enemy)
ePos = enemy.pos
mX = mPos.x
mY = mPos.y
eX = ePos.x
eY = ePos.y
if mX > eX:
endX = 12
else:
endX = 66
if mY > eY:
endY = 16
else:
endY = 52
if hero.isReady("wall-of-darkness"):
hero.wallOfDarkness([Vector(x1, y1), Vector(x2, y1), Vector(x2, y2)]);
if hero.isReady("shadow-vortex") and dist <= 30 and time > 10:
hero.shadowVortex(enemy.pos, Vector(endX, endY))
hero.attack(enemy)
elif nearest:
hero.attack(nearest)
if hero.health < 800 and hero.canCast("time-travel"):
hero.cast("time-travel", hero)
So my new strategy is to go into a corner and defend, making a wall and sniping people. It seems that weapons with more range can lower the chance of this error happening. But the problem is that when I face enemies that cast invis, my hero stop running.
Guys, I got a new code. This code can sucessfully beat basically all people who don’t cast invis. But when I duel people who cast invis, same error occurs and I can’t do anything.
# Defeat the enemy hero in a duel!
def onSpawn():
while True:
if pet.isReady("shape-shift"):
pet.shapeShift()
pet.moveXY(40, 36)
pet.on("spawn", onSpawn)
while True:
enemy = hero.findNearest([e for e in hero.findEnemies() if e.id is "Hero Placeholder"])
nearest = hero.findNearestEnemy()
mPos = hero.pos
time = hero.time
blink = hero.isReady("blink")
if hero.gold > 50:
hero.summon("griffin-rider")
for friend in hero.findByType("griffin-rider"):
if friend.team == "ogres":
target = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
elif target:
hero.command(friend, "attack", target)
if enemy and nearest and hero.distanceTo(nearest) > 10:
dist = hero.distanceTo(enemy)
ePos = enemy.pos
mX = mPos.x
mY = mPos.y
eX = ePos.x
eY = ePos.y
if mX > eX:
endX = 12
buildX = mX - 4
blinkX = mX + 25
else:
endX = 66
buildX = mX + 4
blinkX = mX - 25
if mY > eY:
endY = 16
buildY = mY - 3
blinkY = mY + 25
else:
endY = 52
buildY = mY + 3
blinkY = mY - 25
if hero.isReady("backstab"):
lastX = mX
lastY = mY
if hero.isReady("phase-shift"):
hero.phaseShift()
hero.backstab(enemy)
if blink:
hero.blink(Vector(lastX, lastY))
if dist < 12 and blink:
hero.blink(Vector(blinkX, blinkY))
if hero.isReady("shadow-vortex"):
hero.shadowVortex(enemy.pos, Vector(endX, endY))
if hero.isReady("wall-of-darkness") and time > 10:
hero.wallOfDarkness([hero.pos, Vector(buildX, buildY)]);
hero.scattershot(enemy)
elif nearest:
hero.scattershot(enemy)
if hero.health < 800 and hero.canCast("time-travel"):
hero.cast("time-travel", hero)
Performance & accuracy tip: use [e for e in hero.findEnemies() if "Hero" in e.id][0] instead of hero.findNearest([e for e in hero.findEnemies() if e.id is "Hero Placeholder"]) (unless in for strings/arrays doesn’t work in CodeCombat…)
@moonwatcher348@PeterPalov@Aya Same problem is occuring now. But it’s WAYY worser.
I didn’t even equip an invis ring, but I am somehow getting the invis effect and my hero is going idle, not even attacking decoys anymore.