-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvip_guard.ts
More file actions
47 lines (41 loc) · 1.79 KB
/
vip_guard.ts
File metadata and controls
47 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* The vip_guard.ts is a script that prevents characters from using an exit
* unless they are added to the VIP list that is kept by the vip_list.ts script.
*
* When a character tries to use the exit, a request is sent to vip_list.ts to
* check whether or not they are VIP characters. The vip_guard.ts script and
* vip_list.ts may (and should) be running in different rooms.
*/
// Post address to the vipList script. Replace this.
// To get a room script's address, type: roomscript <KEYWORD>
const vipListAddr = "room.aaaaaaaaaaaaaaaaaaaa#bbbbbbbbbbbbbbbbbbbb"
// ID of the exit to guard. Replace this.
// To get a room script's address, type: get exit <KEYWORD>
// The leading # should not be included.
const exitId = "aaaaaaaaaaaaaaaaaaaa"
export function onActivate(): void {
// Always listen and intercept any use of the exit.
Room.listenExit(exitId)
}
// onExitUse is called when someone tries to use the exit.
export function onExitUse(addr: string, exitAction: ExitAction): void {
// Send a request to the vip_list.ts script. It waits until we receive a response.
const response = Script.request(vipListAddr, "isVip", JSON.stringify(exitAction.charId))
// Assert we didn't get an error response.
if (response.isError()) {
// We look the error for debugging purpose
console.debug("Request error: " + response.error!)
// We cancel the exit use attempt with a message.
exitAction.cancel("The guard can't seem to find the VIP list.")
return
}
// Parse the response. The vip_list.ts should have sent a boolean value.
const isVip = response.parseResult<boolean>()
if (isVip) {
// We let the character use the exit.
exitAction.useExit()
} else {
// We cancel the exit use attempt with a message.
exitAction.cancel("The guard blocks your way as they cannot find you in the VIP list.")
}
}