Skip to main content

Class: UniBehaviour<T>

UniBehaviours are a core building block of the UniScript system. They are used to define the behavior of a bot. You can use them to define specific actions, such as moving to a specific location, attacking a specific target, or looting specific items. You can also use them to define more complex behaviors, such as a sequence of actions, or a decision tree.

The tick method is called every tick, and should return false if the behaviour is still active, or true if it is finished, that can be used to chain behaviours together.

Usage example:

import { UniBehaviour } from 'unibot-api/UniBehaviour';
import { UniCore } from 'unibot-api/UniCore';

// Create a new behaviour that says hello to a specific target.
const myBehaviour = new UniBehaviour((context, target: string) => {
console.log(`Hello, ${target}!`);
return true;
});

UniCore.On("tick", () => {
// Run the behaviour every tick.
myBehaviour.tick("world");
});

Type Parameters

T extends any[]

Constructors

new UniBehaviour()

new UniBehaviour<T>(tick): UniBehaviour<T>

Constructs a new UniBehaviour. The tick method will be called everytime .tick on your behaviour is called. The tick method should return false if the behaviour is still active, or true if it is finished. The first parameter of the tick method is the context, which contains the player object. The rest of the parameters will map to arguments you need to pass to the .tick method your newly created UniBehaviour instance.

Parameters

tick

Returns

UniBehaviour<T>

Methods

tick()

tick(...args): boolean

Parameters

• ...args: T

Returns

boolean