2021-08-16 03:17:53 +00:00
|
|
|
// Checkpoint Flag.
|
2022-01-19 05:24:36 +00:00
|
|
|
var isCurrentCheckpoint = false,
|
|
|
|
playerEntered = false
|
|
|
|
broadcastCooldown = time.Now();
|
2021-08-16 03:17:53 +00:00
|
|
|
|
|
|
|
function main() {
|
|
|
|
Self.SetHitbox(22 + 16, 16, 75 - 16, 86);
|
|
|
|
setActive(false);
|
|
|
|
|
2022-01-19 05:24:36 +00:00
|
|
|
// If the checkpoint is linked to any doodad, the player character will
|
|
|
|
// become that doodad when they cross this checkpoint.
|
|
|
|
let skin = null;
|
|
|
|
for (let actor of Self.GetLinks()) {
|
|
|
|
skin = actor.Filename;
|
|
|
|
actor.Destroy();
|
|
|
|
}
|
|
|
|
|
2021-08-16 03:17:53 +00:00
|
|
|
// Checkpoints broadcast to all of their peers so they all
|
|
|
|
// know which one is the most recently activated.
|
2022-01-17 04:09:27 +00:00
|
|
|
Message.Subscribe("broadcast:checkpoint", (currentID) => {
|
2021-08-16 03:17:53 +00:00
|
|
|
setActive(false);
|
2022-01-19 05:24:36 +00:00
|
|
|
return "a ok";
|
2021-08-16 03:17:53 +00:00
|
|
|
});
|
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Events.OnCollide((e) => {
|
2021-08-16 03:17:53 +00:00
|
|
|
if (!e.Settled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only care about the player character.
|
|
|
|
if (!e.Actor.IsPlayer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCheckpoint(Self.Position());
|
|
|
|
setActive(true);
|
2022-01-19 05:24:36 +00:00
|
|
|
|
|
|
|
// Don't spam the PubSub queue or we get races and deadlocks.
|
|
|
|
if (time.Now().After(broadcastCooldown)) {
|
|
|
|
Message.Broadcast("broadcast:checkpoint", Self.ID());
|
|
|
|
broadcastCooldown = time.Now().Add(5 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we setting a new player skin?
|
|
|
|
if (skin && e.Actor.Doodad().Filename !== skin) {
|
|
|
|
Actors.SetPlayerCharacter(skin);
|
|
|
|
}
|
2021-08-16 03:17:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setActive(v) {
|
|
|
|
if (v && !isCurrentCheckpoint) {
|
|
|
|
Flash("Checkpoint!");
|
|
|
|
}
|
|
|
|
|
|
|
|
isCurrentCheckpoint = v;
|
|
|
|
Self.ShowLayerNamed(v ? "checkpoint-active" : "checkpoint-inactive");
|
2022-01-17 04:09:27 +00:00
|
|
|
}
|