I need help wit the leave it to cleaver this is my code:-- This shows how to define a function called cleaveWhenClose
– The function defines a parameter called target
local function cleaveWhenClose(target)
if hero:distanceTo(target) < 5 then
hero:attack(enemy)
– If cleave is ready, then cleave target
hero:cleave(enemy)
– else, just attack target!
else
hero:attack(enemy)
end
end
– This code is not part of the function.
while true do
local enemy = hero:findNearestEnemy()
if enemy then
– Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)
end
end
help please
1 Like
Please format your code according to the FAQ.
1 Like
FAQ is the </> button next to the quote link and other buttons like that at the top. Click that and it will say type or past code here. Copy and past the code into there and then the tabs will work and the code will look the same as it was originally in code combat so it is easier to read and we can help.
1 Like
enemy = hero.findNearestEnemy
This is pretty much what happens when you click the </> button on the top bar. Look for tools on this to bold italicize and just look to the right of the bold and italicize when you reply or make a post.
Then just copy your code on code combat and past it in the little box.
1 Like
In the if loop inside cleaveWhenClose:
if hero:distanceTo(target) < 5 then
hero:attack(enemy)
hero:cleave(enemy)
You need to check if cleave isReady
. Cleave is a special attack and has a cool down of 10 seconds, meaning you can’t just spam it. The code for the isReady function is: if hero:isReady("cleave") then
. Your code should look something similar to:
if hero:distanceTo(target) < 5 then
-- Check if cleave is ready using the example I showed above
hero:cleave(enemy)
else
-- just do a regular attack
end
end
Also please format your code according to FAQ. @BobBobson412 does a great job of showing how to do this.
1 Like