Skip to content
ASArcaneMP Scripting APIScripting reference
GuideMaintainer authored

Doors

Hold the game's doors locked, unlocked, open or closed for every player, set the Alohomora level a padlock asks for, share the locks players open, find a door's name, decide when a locked door opens for someone, and open other houses' common rooms to a player.

Hogwarts and Overland are full of the game’s own doors and locks, and each player’s game normally keeps their state in that player’s save. The server can take over any of them, so that a door is locked or open for everyone.

Portcullises, the Astronomy rune gate, goblin camp gates and crawl grates are not doors, and no Doors call reaches them. See Gates.

Doors.set(selector, state) holds a door’s lock, its open state or both, for every player:

server/main.js
Doors.set(vaultDoor, { locked: true, open: null });
Doors.set(hallDoor, { locked: null, open: true });
Field true false null
locked Held locked. Only a door that has a lock can be locked. Held unlocked Left to each player’s save
open Held open Held closed; it still swings for anyone who walks into it unless it is locked Left to swing on its own

At runtime a field you leave out keeps whatever the server already holds for it, but the current type declarations ask for every field, lockLevel included, so pass null for the ones you mean to leave to the game.

Each player’s game re-applies what the server holds as the door streams in, so players who arrive later see it too.

  • Doors.get(selector) returns the state held under a selector, and Doors.list() every held state.
  • Doors.clear(selector) releases a selector, and Doors.clearAll() releases them all. A released door keeps its current state until it streams in again, when each player’s save takes over.
  • A selector left holding nothing, with every field null, is released.
  • Each leaf of a double door is its own door and swings on its own, so hold both leaves to keep a double door shut.

A padlocked door asks for a level of Alohomora, from 1 to 3, and its callout shows that level. lockLevel holds the level for every player, so a player needs that level of Alohomora to cast it on the door. null leaves the door at the level it shipped with. Only padlocked doors carry a level.

server/main.js
Doors.set(towerDoor, { locked: null, open: null, lockLevel: 3 });

Players gain the levels through the Alohomora locks in Progression. Held together with locked: true, the lock refuses even a player whose Alohomora is high enough, and the server raises doorUnlockRequest so your script can decide.

A selector names one door, or several, in one of three ways:

Selector Matches
An actor name Every placed door with that name, which may be several
A persistent id, <name>:<guid> Exactly one door, even where names repeat
Its full path, holding / The placement at that path, which also tells apart doors sharing a name

To learn a door’s name and id, stand next to it with a client script that lists the doors around the player:

client/main.js
Events.on("resourceStart", (resourceName) => {
if (resourceName !== "my-gamemode") return;
for (const door of Doors.list(800)) {
console.log(`${door.name} id=${door.id} locked=${door.locked} ${Math.round(door.dist)} cm away`);
}
});

Doors.list(radius) returns each loaded door within radius centimetres, 3000 by default, with its name, persistent id, full path, distance and lock state. A padlocked door also has its lockLevel, or "key" when only a key opens it. The output goes to the client log.

When a player opens a lock with a key or Alohomora, the server holds that door unlocked for everyone, under its persistent id or, without one, its path. Doors.setShareUnlocks(false) keeps each unlock in the player’s own game instead, and Doors.getShareUnlocks() reads the setting.

Either way the server raises doorUnlocked with the player and the door: its name, persistent id, path and whether the unlock was shared. id is empty for a lock that is not on a door.

server/main.js
Events.on("doorUnlocked", (player, door) => {
if (!door.shared) return;
Chat.sendToAll(`${player.nickname} unlocked ${door.name} for everyone.`);
});

Doors.set or Doors.clear on that selector takes a shared unlock back. An unlock is not shared while the server holds the door locked, unless Doors.allowUnlock let that player open it.

When a player tries to open a lock the server holds shut, with a key or Alohomora, their game refuses at once and the server raises doorUnlockRequest with the player and the door: its selector, name and id. It fires at most once a second for each door. Release the lock there if the player should get in:

server/main.js
const vaultKeyHolders = new Set();
Events.on("doorUnlockRequest", (player, door) => {
if (door.selector !== vaultDoor) return;
if (vaultKeyHolders.has(player.id)) {
Doors.set(vaultDoor, { locked: false, open: null });
} else {
player.sendChat("The vault does not open for you.");
}
});

Unlocking with Doors.set unlocks the door for everyone, not only the player who asked.

  • On a double door, selector may name the other leaf, when that leaf’s held lock is what refused the player.
  • A lock the player’s own client policy keeps shut raises it too, with an empty selector.

Doors.set opens the lock at once. To have the player open it the game’s way instead, answer with Doors.allowUnlock(player, selector): their wand cast and the lockpicking minigame play out, or their key turns. If they are still at the lock, no more than a metre from where they tried it and no more than 5 seconds later, their game tries again for them. Otherwise their next try goes through.

server/main.js
Events.on("doorUnlockRequest", (player, door) => {
if (door.selector !== towerDoor) return;
if (isPrefect(player)) {
Doors.allowUnlock(player, door.selector);
} else {
player.sendChat("Only prefects may pick this lock.");
}
});

Once they open it, the server holds the lock unlocked for everyone, as Doors.set(selector, { locked: false }) would, and raises doorUnlocked with shared true, even while Doors.setShareUnlocks(false) is in force. If they give up on the minigame, the door stays locked.

  • The permission lasts 60 seconds, or until they use it.
  • It returns false when the selector holds no lock or the player is not connected, and throws a TypeError when player is not a player or the selector is malformed.
  • A double door held under two selectors needs both allowed.

The game opens each house’s common-room entrance only to members of that house. These entrances are not doors either, and no Doors call reaches them. player.commonRooms lists the other houses whose entrances open for a player besides their own house, such as for staff:

server/main.js
function giveStaffAccess(player) {
player.commonRooms = ["Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"];
}
function takeStaffAccess(player) {
player.commonRooms = [];
}

Those entrances open for them as they would for a member of that house, with the game’s own animations. Their house, robes and crest stay as they are.

  • House names are matched in any case and read back spelt as above. An unknown house, or "Unaffiliated", which has no common room, throws, and so does setting it on a player who is not connected.
  • An entrance decides as someone walks up to it, so a change reaches a player already standing in the doorway the next time they walk up.
  • The entrance opens only in that player’s game. Other players’ games still show it closed.
  • It lasts for the player’s connection, so set it again when they rejoin.

Client scripts can change doors too, but only for their own player, and the server’s held state always wins:

  • Doors.setLocked(selector, locked) locks or unlocks matching doors on this client only, until they stream in again.
  • Doors.setPolicy(policy) keeps streamed doors unlocked or locked on this client: unlock all of them, a list, or all except a list, and lock a list, which beats any unlock.
  • Doors.superAlohomora(true) lets every lock open to a key or Alohomora, whatever the player’s Alohomora level, key-only locks included. Locks the server holds still refuse, and it is cleared on disconnect.
  • Doors.held() lists the door states the server holds, as this client received them.

Foundations’ hmp-doors decides which doors, gates and locks each player may pass, from ranked rules in its data/hmp-doors.json. A rule allows, denies or locks doors by name or path, can apply only to players in certain hmp-core groups, and can hold a padlock’s lockLevel for everyone. Lower priorities are stronger. shareUnlocks turns shared unlocks on, and is false by default.

{
"shareUnlocks": false,
"rules": [
{ "priority": 1000, "action": "allow", "doors": "*" },
{ "priority": 100, "action": "lock", "doors": ["BP_Door_Headmaster"], "lockLevel": 3 }
]
}

That is a fragment of the file. Staff in its adminGroups manage it in game with /doors: /doors list [radius] lists the doors near you with their names and paths. Its README covers every rule, grant and command, and its gate rules are in Gates.

  • Gates for portcullises, the rune gate, camp gates and crawl grates.
  • Loot for chests behind your doors.
  • Authority for why a request like doorUnlockRequest is the server’s to decide.
  • Appearance for setting a player’s house.