This is the documentation for the API available to scripts in UniBot Pro.
WORK IN PROGRESS
Scripts get loaded from C:\Program Files\UniBot Pro\scripts
if installed using the default installation path.
This example uses the "player-changed" event to react on a new current player and output a greeting message to log.
const { UniCore } = require("UniCore");
UniCore.On("player-changed", (currentPlayer) => {
UniCore.Log(`Hello ${currentPlayer.get("name")}`)
});
This example uses the "tick" event to run on every UniBot tick and remembers the last time it did something using the time helper functions UniCore provides.
const { UniCore } = require("UniCore");
let lastMessageOutputAt = UniCore.GetMicrotime();
UniCore.On("tick", () => {
const currentPlayer = UniCore.GetCurrentPlayer();
if (UniCore.TimeSinceInSeconds(lastMessageOutputAt) > 5) {
UniCore.Log(`Hello ${currentPlayer.get("name")}`)
lastMessageOutputAt = UniCore.GetMicrotime();
}
});
This example uses the "player-changed" event to react on a new current player on which it will then register on the "hp-changed" event to press 1 if hp got lower than 1000.
const { UniCore } = require("UniCore");
const { UniInput } = require("UniInput");
UniCore.On("player-changed", (currentPlayer) => {
currentPlayer.on("hp-changed", (currentHP) => {
if (currentHP < 1000) {
UniInput.QueueKeyPress("1");
}
});
});
This example shows how to use UniNavigation to navigate towards a location if too far away.
const { UniCore } = require("UniCore");
const { UniNavigation } = require("UniNavigation");
let targetPosition = { x: 8500, z: 2050 }
UniCore.On("tick", () => {
if (UniNavigation.IsNavigating()) {
//Do not do any clicks on mobs or on ground while navigating!
//Clicking ui elements and triggering hotkeys is fine tho.
//in this example we just do nothing if we are currently navigating;
return;
}
let currentPlayer = UniCore.GetCurrentPlayer();
if (currentPlayer.GetDistanceTo(targetPosition) > 40) {
//Start navigating to targetpos if we are over 40 units away
UniNavigation.NavigateTo(targetPosition, false, () => false);
}
});
This example shows how to use UniCore.On to listen to chat messages.
//Import UniCore to access scripting api
const { UniCore } = require("UniCore");
//Register an event listener that will get triggered for every general chat message
UniCore.On("chat-message", (message, senderID) => {
//In the case of general chat we only know the id of the sender, lets try to fetch this Mover
let matchingEntity = UniCore.GetMoverByProperty("targetID", senderID);
if (matchingEntity) {
//We found the mover so we can directly use the name of it
UniCore.Log(`Normal Chat message "${message}" from "${matchingEntity.get("name")}"`);
} else {
//We did not find the mover so we only have the senderid
UniCore.Log(`Normal Chat message "${message}" from target id "${senderID}"`);
}
});
//Register an event listener that will get triggered for every received say message
UniCore.On("chat-say-message", (message, sender) => {
UniCore.Log(`say Chat message "${message}" from "${sender}"`);
});
//Register an event listener that will get triggered for every received shout message
UniCore.On("chat-shout-message", (message, sender) => {
UniCore.Log(`shout Chat message "${message}" from "${sender}"`);
});
Generated using TypeDoc