These are callbacks that refer to one specific entity only and include Interact-, LookAt- and .. just Callbacks. They are set in the entity tab of the entity in the level editor, but you can also add them in your script.
EntityCallback
void SetEntityCallbackFunc(string& asName, string& asCallback);
asName - name of the entity
asCallback - callback function
You may now ask yourself - "What is this used for? When is this even called?" Well, the secret lies in the callback function:
void asCallback(string &in Entityname, string &in Type)
type can be three things: OnPickup, Break, OnIgnite
You check these with an
if (type = x) condition!
OnPickup = this is used when the entity is picked up, so mostly for items if you want to make something happens when, for example, the player picks up a key (how Frictional triggers some monsters, for example).
Break = when the entity breaks (glass bottles, but also doors that monsters may break down!)
OnIgnite = this is used for (surprise!) lamps or candles
Example script
void BookPickUp(string &in EntityName, string &in Type)
{
if(Type == "OnPickup")
{
SetEntityActive("TeleportChangeItemArea", true);
}
}
I've written BookPickUp in the callback text field of an item, so there's no need to use SetEntityCallbackFunc here. So when the if condition has checked if
string &in Type is OnPickup, it activates an area called
TeleportChangeItemArea. I rarely use this type of callbacks, but there are occasions where they are necessary.
EntityLookAtCallback
void SetEntityPlayerLookAtCallback(string& asName, string& asCallback, bool abRemoveWhenLookedAt);
asName - name of the entity the player looks at
asCallback - callback function; as you can see, the syntax of these is pretty minimal
abRemoveWhenLookedAt - .. self-explanatory by now
This type of callback checks if the player looks at a specific entity. In a horror game, I think you can guess what these are used for.
Callback function syntax (this is where the fun begins):
void asCallback(string &in entity, int alState)
alState can be either 1 (player is looking) or -1 (player is not looking).
You don't have to use an if condition, in that case the callback function will automatically trigger when the player looks at the entity. Keep in mind that entities can be script areas too, so if you want to do something behind the player.. look at the example script!
Example script
void Surprise_Monster(string &in entity, int alState)
{
if (alState == -1)
{
SetEntityActive("Heinz", true);
ShowEnemyPlayerPosition("Heinz");
}
}
So.. how this works: Let's assume we have a little room. One half of that room is covered with a script area, which has the EntityLookAtCallback
Suprise_Monster, which only triggers when the player does NOT look at the script area, which means not looking at one half of the room which ensures the player has his back to the area when Heinz, our grunt, spawns there and attacks, with a little help from ShowEnemyPlayerPosition, the player.
Some of you may ask: "But what if the player even isn't in that room? Wouldn't the monster instantly spawn when the player is just somewhere else?" and I'd say "You're absolutely right!". The trick is only activating the callback when the player enters the room and deactivating it once he leaves. Use an EntityCollideCallback with an area that covers the whole room and checks when the player enters and leaves the area or the room!
EntityPlayerInteractCallback
void SetEntityPlayerInteractCallback(string& asName, string& asCallback, bool abRemoveOnInteraction);
asName - name of the entity the player interacts with.. you should get this by now
asCallback - callback function
abRemoveOnInteraction - self-explanatory
This one is simple. It calls its callback function once the player interacts with an entity, which could be opening a door / drawer, picking up a chest etc.
Callback function syntax:
void asCallback(string &in entity)
Example script
void OnStart()
{
SetEntityPlayerInteractCallback("pandora's box", "Bad_Move", true);
}
void Bad_Move(string &in entity)
{
PlaySoundAtEntity("pandora", "end_of_the_world.snt", "Player", 5.0f, false);
}
Once the player interacts (meaning grabbing it / opening it) with Pandora's box, we play an eerie sound which initiates the end of the world!