Disclaimer, I didn't test this at all just coded it and compiled it here you go I_ShaunY_I.
Edited: Version 1.0.0.2 // Forgot to start checkBuffs and prepareforCombat functions and changed your if statement to only check if the target is with in 20m before fighting it, the rest is useless since...