Skip to content
Doc edited this page Apr 20, 2025 · 1 revision

Event

This class handles events or registers the same way ChatTriggers does however this adds a way to know whether the event has been registered or not as well as allowing for custom events

Importing the required class

Make sure the path to the folder is correct.

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

Creating Custom Events

tska Allows the users to create their own custom events in order to maintain customizability
If tska doesn't provide an event that you need, then it's ok you can create it yourself
First we need to create the boilerplate (the base)

Event.createEvent("eventName", (callback, ...args) => {})

Here's how the base would look like, the eventName param is a string which can be named anything but if you're going to make a lot of events it is advised that you name your own events depending on your module name i.e. @tska:stepFps
Note: it is not done this way for the current custom events of tska because tska is the priority here but your module won't be so to avoid overriding events you would need to follow this
The second param is a callback function which accepts another callback function and extra arguments, the callback function that is passed through to your function is the "register" itself, that's how you'll trigger it.
Note: The callback function needs to return a register
Knowing all this we can now proceed to create a simple custom event:

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

Event.createEvent("@tska:stepFps", (callback, fps) => {
    return register("step", () => {
        callback()
    }).setFps(fps)
})

Now you may be wondering "how do i use it now?", it's simple tska handles everything in the backend so you only need to do:

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

new Event("@tska:stepFps", () => {
    ChatLib.chat("hello")
}, /* FPS here */ 2).register()

Clone this wiki locally