Movement (basic)
A basic code example that shows you how to make the bot move between two locations.
MovementTask.cs
public class MovementTask : ITask, ITickListener {
public static ILocation Location1 = new Location(100, 10, 100);
public static ILocation Location2 = new Location( 1, 10, 100);
public override bool Exec() {
// Do not execute 'OnTick' if the bot is dead.
return !Context.Player.IsDead();
}
public async Task OnTick() {
// The 'await' keyword waits until MoveTo completes/fails and
// only then continues the execution.
var moveResult = await Context.Player.MoveTo(Location1).Task;
if(moveResult.Result != MoveResultType.Completed) {
// Failed to move to the location, lets output an error
// to the console and return.
Console.WriteLine($"Failed to move to {Location1}!");
return;
}
// We have successfully reached Location1,
// now we can start moving to Location2.
var moveTask = Context.Player.MoveTo(Location2);
/*
As the MoveTo(Location2) code does not have the 'await' keyword
we can execute other actions parallel and optionally await later
for the task to complete.
*/
// Wait until MoveTo completes/fails to Location2. We do not care
// if it succeeded therefore we do no assign the result to any variable.
await moveTask.Task;
}
}Last updated