Skip to content
ASArcaneMP Scripting APIScripting reference
GuideMaintainer authored

Brooms and mounts

Give players brooms and creatures to ride, put them on and take them off from a client script, set how fast brooms fly, change how a broom handles, aim from a broom, and keep riders out of an area.

Players fly brooms and ride the game’s creatures, and everyone else sees them do it without any script. Client scripts control the local player’s riding with Broom, FlyingMount and GroundMount. The server decides what each player owns, through their inventory, and how fast their broom flies, but has no call to put a player on a broom or take them off.

A player can only ride what is in their inventory, and a joining player starts with an empty one, so give them a broom or a creature first:

Kind Item ids
Brooms BroomHouse, BroomFamilyAntique, BroomFlyingClass1 to BroomFlyingClass3, BroomAeromancer, BroomBrightSpark, BroomDarkWizard1, BroomDarkWizard2, BroomEmberDash, BroomInfiltrator, BroomLicketySwift, BroomMoonTrimmer, BroomNightDancer, BroomSilverArrow, BroomSkyScythe, BroomWildFire, BroomWindWisp, BroomYewWeaver
Flying creatures HippogriffMount, OnyxHippogriffMount, ThestralMount
Ground creature GraphornMount

The first broom a player is given goes straight into their active slot, ready to ride; later ones go into storage. The same goes for each kind of creature. The onyx hippogriff and the thestral need the game’s add-ons that unlock them.

server/main.js
Events.on("loadingFinished", (player) => {
if (!player.inventory.has("BroomHouse")) player.inventory.give("BroomHouse", 1);
});

Taking the item away is how the server keeps a player from summoning it; a player already riding is taken off by their client, as in Keeping riders out. The server cannot see whether a player is riding, and no event fires when anyone mounts or dismounts, so client scripts check for themselves.

Broom.mount() gets the local player on the broom in their active slot, and Broom.equip(itemId) picks which of their brooms that is. mount returns whether the game accepted the request, not whether the player is riding: they settle on the broom over a second or so, and the first request can be turned down while the game loads the broom, so ask again until they are on.

Call Returns
Broom.mounted() Whether the player is on a broom or getting on
Broom.state().mountSettled Whether they are seated and flying
Broom.canMount() Whether the game lets them fly here and now; it does not check that they own a broom
Broom.isEquipped() Whether a broom is in their active slot
client/main.js
Events.on("broom:mount", () => {
if (!Broom.isEquipped()) Broom.equip();
let attempts = 0;
const timer = setInterval(() => {
if (Broom.state().mountSettled || ++attempts > 10) {
clearInterval(timer);
return;
}
if (!Broom.mounted()) Broom.mount();
}, 500);
});

Broom.dismount() takes the player off at once, wherever they are, so a player in the air falls. Broom.dismount(true) asks the game to land them the normal way instead, which does nothing where the game will not let them land. Both return false until the player is seated. equip and unequip refuse while the player is riding.

The server sets how fast each player’s broom flies. player.setBroomUpgradeTier(tier) gives a player the game’s broom upgrades from Albie Weekes’ shop, from 0 to 3: each tier flies and boosts faster, and lets the boost meter refill higher above the ground. player.setBroomSpeedMultiplier(multiplier) scales cruising, boost and turbo speed on top of that, from 0.25 to 3. Faster than 3 would outrun the world loading around the player.

server/main.js
Events.on("loadingFinished", (player) => {
player.setBroomUpgradeTier(3);
player.setBroomSpeedMultiplier(1.5); // half again as fast as a fully upgraded broom
});

Both apply at once, mounted or not, and last through respawns and travel. null sets them back to the server’s defaults, mod.broomUpgradeTier and mod.broomSpeedMultiplier in server.json, which every joining player starts with. player.broomUpgradeTier and player.broomSpeedMultiplier read them back. A value outside its range throws. Broom races keep their own speeds.

Call Does
Broom.setMaxHeight(z) Caps how high the broom can climb, as a world height; clearMaxHeight() lifts it
Broom.setInputDisabled(disabled) Stops the rider steering
Broom.setForceLand(forceLand) Brings the broom down
Broom.addBoost(fraction) Fills part of the boost meter; boost() and inTurbo() read it
Broom.setCastingAllowed(allowed) Lets the rider cast spells other than heavy ones while flying
Broom.teleport(x, y, z, yaw) Moves a rider and stops them dead; leaving out yaw faces them to 0, not their heading

These belong to the client, not to your resource, and stay until something changes them. Broom.resetOverrides() undoes every one of them set through Broom, so call it when your game ends and as your resource stops.

A knock out of the sky, without dismounting:

client/main.js
Events.on("broom:stun", () => {
Broom.setInputDisabled(true);
Broom.setForceLand(true);
setTimeout(() => {
Broom.setForceLand(false);
Broom.setInputDisabled(false);
}, 3000);
});

On a broom the game’s camera follows the broom’s pitch: the mouse turns the view left and right, but not up and down, and the game shows no crosshair in flight. Two client switches change that for the local player’s rides:

Call Does
Camera.setBroomFreeLook(enabled) Lets the mouse and the right stick look up and down; the view stays where the player puts it instead of following the broom’s pitch
Camera.setBroomCrosshair(shown) Draws a crosshair at the centre of the view, and steps the camera right over the rider’s shoulder so they are not under it

Both are off by default, return the setting they kept, and Camera.getBroomFreeLook() and Camera.getBroomCrosshair() read them back. A setting holds for every ride until you change it: dismounting hands the pitch back to the game, and the next ride frees it again, while turning free look off mid-ride hands it back at once. The broom still climbs and dives on its own keys. On a gamepad those are on the right stick, so climbing tilts the view as well. The crosshair hides with the game’s HUD, behind a game menu, and while a custom camera has the view.

Spells.broomCastTry(slot, 5) casts the spell in one of the four slots of the spell bar, 0 to 3, where the crosshair points: at the first thing the centre of the view covers beyond the rider, their broom ignored, or 40 m out along the view when nothing is there. The 5 picks that aim. It returns a line describing the cast, for your logs. Spells.broomCastReady() turns true once a player with a wand has sat on a broom for a second and a half, so a key bound to cast stays inert on foot and does not fire as they mount:

client/main.js
// Keys 1 to 4 cast the spell bar's spells from a broom, at the crosshair.
Camera.setBroomFreeLook(true);
Camera.setBroomCrosshair(true);
["1", "2", "3", "4"].forEach((key, slot) => {
Key.bind(key, () => {
if (Spells.broomCastReady()) Spells.broomCastTry(slot, 5);
});
});

The two camera switches belong to the client, not to your resource, and Broom.resetOverrides() leaves them alone, so turn them off as your resource stops.

FlyingMount rides the hippogriffs and the thestral, and GroundMount the graphorn. They work like Broom:

  • equip(itemId) puts one of the player’s creatures in the active slot, and mount(options) summons it. mount returns whether the request was accepted, so check mounted(), which only turns true once the player is seated, and summoning() for the summon in between.
  • mount({ transition: false }) skips the summon animation, and FlyingMount.mount({ inFlight: true }) starts the player in the air.
  • dismount() takes the player off. Called during a summon, it cancels the summon instead, so call it again.
  • canMount() asks the game whether creatures are allowed here. It can return false because another player stands somewhere creatures are not allowed, so treat false as a maybe.

A rider on a flying creature can be steered with FlyingMount.takeoff(), FlyingMount.land() and FlyingMount.setAutoLanding(enabled), and FlyingMount.setFlyingGait(gait) sets the slowest pace the rider can drop to: "stop", "hover", "slow" or "fast". takeoff is a request, so check FlyingMount.isFlying() and ask again.

client/main.js
Events.on("hippogriff:fly", () => {
FlyingMount.equip("HippogriffMount");
FlyingMount.mount({ inFlight: true });
});

state() on either reports the creature’s species, whether the player is mounted, and for flying creatures whether they are flying.

A broom is drawn at its rider’s size: player.setScale resizes the broom a player rides along with them, in either mode and on every client. In flight it keeps a native broom’s collision. A creature keeps its own size.

player.setVisible(false) hides the broom or creature a player rides along with the player, the broom’s flight trails included. A broom or creature they summon while hidden stays hidden too.

To keep players off brooms and creatures in an arena, take the items away on the server while they are inside, and have their client dismount them and keep the game’s tool wheel, where players summon them, shut:

client/main.js
Events.on("arena:enter", () => {
Game.setToolWheelEnabled(false);
if (Broom.mounted()) Broom.dismount();
if (FlyingMount.mounted()) FlyingMount.dismount();
if (GroundMount.mounted()) GroundMount.dismount();
});
Events.on("arena:leave", () => Game.setToolWheelEnabled(true));

The server’s part is the one that holds: a client script can be changed by its player, an inventory cannot.

  • Races for running the game’s broom races on tracks of your own.
  • Inventory for giving and taking items.
  • Camera for the rest of what scripts change about the game’s camera.