Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[HELP] CS2 leave it to cleaver level 32

The function defines a parameter called target

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
ready = hero.isReady(“cleave”)
hero.cleave(target)
# else, just attack target!
hero.attack(target)

This code is not part of the function.

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)

Hello, welcome to the CodeCombat forum. To help you out the best, it is important to post your code correctly so we can see all the possible issues. Since you are writing in Python, indentation is critical; but we can’t see if that is causing any of your problems when the code in improperly formatted.

You can use the if statement with other code to see if the hero is ready to use an attack (command). The if statement needs a boolean (True or False) answer. The code hero.isReady("cleave") checks to see if the hero is ready and returns True or False which means you can pair it right in an if statement.

if hero.isReady("cleave"): # if cleave is ready it returns True
    hero.cleave(target)
else:  # if not ready to cleave (False above) do this instead
    hero.attack(target)

The post below will walk you through posting your code correctly.

1 Like
[quote="vkisbest, post:1, topic:19833"]
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
ready = hero.isReady(“cleave”)
hero.cleave(target)
# else, just attack `target` !
hero.attack(target)

# This code is not part of the function.

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the `enemy` as `target` .
cleaveWhenClose(enemy)
[/quote]

To make your code format corrcetly, press the ` key (next to the 1 key) :smile: