Skip to content

Feature

Doc edited this page Apr 20, 2025 · 2 revisions

Feature

This class handles event(s) depending on the area/subarea the user is currently in, it will register/unregister all of the events inside its list.
Note: You're the one that has to make the location listener and then pass it through to this feature so it knows when to register/unregister depending on the area/subarea

Importing the requires class

Make sure the path to the folder is correct.

import { Feature } from "../tska/event/Feature"

Creating a Feature

Creating a feature is very simple because you only need to create a new instance with the area/subarea where your events may only register

const myFeature = new Feature("catacombs")

Adding Events

Adding events to a feature is quite easy since it provides everything you need to not worry much about it

myFeature.register("stepFps", () => {
    ChatLib.chat("hello")
}, /* FPS */2)

Adding Sub Events

Why a sub event? sub events in this context are meant to be events that only need to run whenever all the criteria of the feature is matched BUT also a "custom" criteria added by you (or more commonly known registerWhen)

myFeature.registersub("stepFps", () => {
    ChatLib.chat("hello from sub")
}, () => {
    // This is the registerWhen function
    // This function should always return a boolean

    return false // Will never register
})

update()

Why is update() important? This will basically tell the Feature to update the sub events to check whether their registerWhen function returned true or not so it can register these events.

myFeature.update() // Call whenever you think it should check for the sub events' `registerWhen` function

Listeners

This also provides some useful listeners

// Called whenever the events get registered
myFeature.onRegister(() => {})
// Called whenever the events get unregistered
myFeature.onUnregister(() => {})

How does it know what area we're in?

That's the thing, it doesn't you have to tell it.
For this you can use the Location class to add a listener and trigger the necessary functions

Location.onWorldChange((areaName) => {
    myFeature.onAreaChange(areaName)
})

Location.onAreaChange((subareaName) => {
    myFeature.onSubareaChange(subareaName)
})

Clone this wiki locally