This TypeScript-based system, designed for the Roblox platform, manages access control through a clearance-based mechanism using keycards and gatekeepers. It allows developers to check if players have sufficient clearance levels or specific keycards to access restricted areas or resources guarded by gatekeepers.
The ClearanceController is an abstract class providing static methods to validate and manage interactions between players, keycards, and gatekeepers. It relies on predefined constants, type validators, and type definitions to ensure robust type safety and functionality within a Roblox game environment.
- Constants.ts: Defines tags used to identify keycards and gatekeepers.
- Validators.ts: Contains type validators to ensure objects meet the structural requirements for keycards and gatekeepers.
- ClearanceController.d.ts: TypeScript declaration file defining the types for
KeyCard,Gatekeeper, and their configurations. - index.ts: Core logic implementing the clearance control system with methods to check player clearance, retrieve keycards, and validate gatekeeper interactions.
Constants.ts: Defines constant tags for keycards and gatekeepers.Validators.ts: Provides type-checking utilities using the@rbxts/tlibrary.ClearanceController.d.ts: Declares TypeScript interfaces forKeyCardandGatekeeper.index.ts: Implements theClearanceControllerclass with static methods for clearance checks and keycard/gatekeeper management.
- Ensure you have a Roblox TypeScript project set up with the
@rbxts/tlibrary installed for type validation. - Place the provided files (
Constants.ts,Validators.ts,ClearanceController.d.ts,index.ts) in your project's source directory. - Configure your Roblox game to include the necessary object hierarchy (e.g.,
Toolinstances for keycards,Configurationinstances for keycard and gatekeeper settings).
- KeyCard: A
Toolinstance tagged withKeyCardand containing aKeyCardConfig(Configurationwith aLevelNumberValue). - Gatekeeper: An
Instancetagged withGatekeeperand containing aGatekeeperConfig(Configurationwith aClearanceNumberValue and aKeyCardsFolder). - Clearance Level: A numerical value representing the access level of a keycard or the required level for a gatekeeper.
- KeyCard Validation: Ensures a tool is a valid keycard using tags and structural checks.
- Gatekeeper Validation: Ensures an instance is a valid gatekeeper with the correct configuration.
-
Create a KeyCard:
- Create a
Toolinstance in Roblox Studio. - Add a tag named
KeyCard(as defined inConstants.ts). - Add a
Configurationchild namedKeyCardConfig. - Inside
KeyCardConfig, add aNumberValuenamedLevelwith a value (e.g.,5).
- Create a
-
Create a Gatekeeper:
- Create an
Instance(e.g., aPartorModel) in Roblox Studio. - Add a tag named
Gatekeeper. - Add a
Configurationchild namedGatekeeperConfig. - Inside
GatekeeperConfig, add:- A
NumberValuenamedClearancewith a value (e.g.,3). - A
FoldernamedKeyCardscontainingStringValueinstances, each with aValuecorresponding to the name of an acceptable keycard (e.g.,KeyCard1).
- A
- Create an
-
Integrate ClearanceController:
- Use the
ClearanceControllerclass in your scripts to check if a player can access a gatekeeper-protected area.
- Use the
import ClearanceController from "index";
import { Players } from "@rbxts/services";
// Example: Check if a player can access a gatekeeper
const player = Players.GetPlayers()[0];
const gatekeeper = game.Workspace.FindFirstChild("GatekeeperPart")!;
if (ClearanceController.PlayerHasClearance(player, gatekeeper)) {
print(`${player.Name} has access to the gatekeeper!`);
} else {
print(`${player.Name} does not have sufficient clearance.`);
}
// Example: Get player's highest clearance level
const clearanceLevel = ClearanceController.GetPlayerClearanceLevel(player);
print(`${player.Name}'s highest clearance level: ${clearanceLevel}`);
// Example: Get accepted keycards for a gatekeeper
const acceptedKeyCards = ClearanceController.GetGatekeeperKeyCards(gatekeeper);
print(`Gatekeeper accepts keycards: ${acceptedKeyCards.join(", ")}`);