Game Events - Skirlez/nubbys-forgery GitHub Wiki
Nubby's Number Factory has a Game Events system. This system is notably used for item/perk triggers: The trigger condition of every item/perk is the name of some Game Event. You can see a list of available Game Events on this wiki, here.
Functions
scr_GameEv(name)
This base game function triggers a Game Event.
subscribe_to_game_event(name, callback)
Subscribes to a Game Event. You provide a callback function, and it will be ran when the Game Event is triggered.
When a mod is unloaded, its callbacks will be removed automatically.
Example usage:
subscribe_to_game_event("5Popped", fun {
-- Ran when "5Popped" is triggered
})
Important! At certain points in the game, Game Events may trigger, but they will not trigger items or perks, for example after pressing the End Round button when a round goes on for a while. However, callbacks provided using subscribe_to_game_event
will always get called, regardless of the game state.
Creating your own Game Events
Nubby's Forgery patches the game so you can pass any string to scr_GameEv
and it will work as a Game Event.
Let's say we want to define a Game Event called "ThingHappens"
, and we want one of our items to trigger when it triggers.
All you'd have to do is set game_event
to "ThingHappens"
in the item's struct, and call scr_GameEv("ThingHappens")
when you want your event to trigger.
Additionally, you can subscribe to the event with subscribe_to_game_event("ThingHappens", fun { })
.
There is no need to explicitly create/register new Game Events.