How to add new events
Tutorial "How to add new event key to the game and trigger it"
In the game, we use an "event keys" system. An event key is like a signal or trigger that the game sends out when something specific happens (like when the player gets an item or reaches a milestone).
The
p_game.gdscript is where events are handled. Inside this script, there’s a function that listens for these event keys.The function takes a
event_key_idas a parameter. This ID represents the event key the game is waiting for.When the player receives the event key (from anywhere in the game), the function with that
event_key_idis triggered, and the game executes whatever code is connected to that event key.
So, if you want to create a mod or add new content, you can trigger these event keys to make things happen in the game, like unlocking new features, changing the environment, or starting a special event.
Files & folders needed:
assets/scripts/p_game.gd
So basically event key can be received from, scripts, dialogues, items using, trigger zones. So you create a event key ID in assets/scripts/p_game.gd file, in the function called:
func on_event_key_add(key): # key -> is string ID of eventthere you'll see a match statement, that trying to match key. So if game will match your event key ID, it will do something inside the function. Basically this on_event_key_add is callback and calls at the end of :
func AddEventKey(key)function from GameManager. You can manipulate with events keys in scripts by:
func AddEventKey(key : String) # add new e.key
func DeleteEventKey(key : String) # delete e.key
func DontHasEventKey(key : String) # return true if no e.key
func HasEventKey(key : String) # return true if has e.keySo let's create event key where we can add NPC to the level. Open assets/scripts/p_game.gd. Go to on_event_key_add function and create new event key ID. Let's name it my_event_key.

Unfortunately I didn't create simple function for NPC creating, so we can create it together! Look into source code of the game at SOURCE_PROJECT/scripts/GameManager.gd and find there function:
This function load json levels from files, but there is NPC creation code, that we can rewrite into separate function. Original NPC spawn code looks like:
Lets create our new function in separate *.gd file near p_game.gd script. Call new file an you want, for now it will be "my_mod_functions.gd" with this code:
then go back to p_game.gd script to the on_event_key_add where is our new event key and call SpawnNPC(id,profile,pos,rot) function from my_mod_functions.gd:
Then let's add event key at the start of new game. Go to function:
Add into "intro" level this code:
Start new game and you wll see:

Lets get some coordinates, turn on debug fly and debug mode in assets/scripts/p_app.gd:
When we start new game, we will see new window at the right top corner:

Fly at needed position with WASD and rotate camera where you want to NPC to look.
Let's do it near helicopter.


Keep in mind, player's rotation a little opposite to NPC rotation data, at screenshot you see -174 Y coordinate, but for NPC it must be 0 if it's equal to player 180 degrees, if you put -174 or 174 Y coordinate to NPC rotation then it will stands with back to where player was looked. My bad.
Add inside your event key code position and rotation for SpawnNPC().
It will be looks like this:

Start new game again.

Last updated