Event Listeners

Introduction

These functions operate in response to specific situations that may happen in a ZEP Space such as players typing specified words or attacking a specific object.

πŸ“š API Description and Example

Event Listeners at a Glance

// Calls event for every chat that players enter into the chat window
// Text that begins with ! is not displayed in the chat window,
// but can be used in the onSay function.App.onSay.Add(function(player, text) {
});

// Calls event when a player collides with another player
App.onPlayerTouched.Add(function(sender, target, x, y){
});

// Calls event when the player collides with an object
App.onObjectTouched.Add(function(sender, x, y, tileID) {  
});

// Calls event when the player collides with an object with a key value
App.onAppObjectTouched.Add(function(key, sender, x, y){});

// Calls event when the player attacks another player (Z key)
App.onUnitAttacked.Add(function(sender, x, y, target) {
});

// Calls event when the player attacks an object (Z key)
App.onObjectAttacked.Add(function(sender, x, y){
});

// Calls event when an avatar attacks an object with a key value with the Z key
App.onAppObjectAttacked.Add(function (sender, x, y, layer, key) {
});

onSay

App.onSay.Add(function(player, text){});

This function operates when a player enters chat.

Parameters

Example

Hangul quiz - Makes a function to guess the answer via chat:

_answer = "ZEP" // Correct
// Executes when a player enters chat
App.onSay.add(function(player, text) {
    if(_answer == text){
        App.showCenterLabel(player.name + ' Correct!\nThe answer is ' + _answer);
    }
});

onPlayerTouched

App.onPlayerTouched.Add(function(sender, target, x, y){});

This function operates when an avatar collides with another avatar.

Parameters

Example

Display a message when two avatars collide.

// Calls event when two players collide
App.onPlayerTouched.Add(function (sender, target, x, y) {
	App.showCenterLabel(
		`${sender.name} and ${target.name} have collided at the coordinates: (${x}, ${y}).`
	);
});

onObjectTouched

App.onObjectTouched.Add(function(sender, x, y){});

This function operates when an avatar collides with an object.

Parameters

Example

Label display

⭐ A collision with an object without the overlap: true attribute cannot call this function.

let testObject = App.loadSpritesheet("object.png");

App.onStart.Add(function () {
	Map.putObject(5, 5, testObject, { overlap: true });
});

// Calls event when the player collides with an object
App.onObjectTouched.Add(function (sender, x, y, tileID) {
	Map.putObject(x, y, null);
	App.showCenterLabel(
		`${sender.name} has collided with an object at the coordinates: (${x}, ${y}).`
	);
});

let testObject = App.loadSpritesheet("object.png");
// available ObjectEffectType
const ObjectEffectType = {
    NONE = 0,
    SHOW_NOTE = 1,
    SHOW_IMAGE = 2,
    PASSWORD_DOOR = 3,
    LINK_WEBSITE = 4,
    EMBED_WEBSITE = 5,
    API_CALL = 6,
    REPLACE_IMAGE = 7,
    NFT_GIVEAWAY = 8,
    NFT_DOOR = 9,
    POST_MESSAGE = 10,
    SHOW_CHAT_BALLOON = 11,
    FT_DOOR = 12,
    POST_MESSAGE_TO_APP = 13,
    DONATION_DOOR = 14,
    IMPASSABLE = 15,
    STAMP = 16,
    TOKEN_DONATION_DOOR = 17,
    CHANGE_OBJECT = 18,
    ANIMATION = 19,
    NFT_DOOR_MOVE = 20,
    INTERACTION_WITH_ZEPSCRIPTS = 21,
    MULTIPLE_CHOICE = 22,
}

App.onStart.Add(function () {
	Map.putObject(5, 5, testObject, { overlap: true });
});

// Calls event when the player collides with an object
App.onObjectTouched.Add(function (sender, x, y, tileID, obj) {
	Map.putObject(x, y, null);
	App.showCenterLabel(
		`${sender.name} has collided with an object at the coordinates: (${x}, ${y}).(Type: ${obj.type})`
	);
});

onAppObjectTouched

App.onAppObjectTouched.Add(function(key, sender, x, y){});

️This function operates when an avatar collides with an object with a key value.

Parameters

Example

Label display

⭐ A collision with an object without the overlap: true attribute cannot call this function.

let blueman_dance = App.loadSpritesheet(
	"blueman.png",
	48,
	64,
	[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37],
	8
);

// Activates function when q is pressed
App.addOnKeyDown(81, function (player) {
	App.sayToAll("Collision test with an object that has a key value");
	Map.putObjectWithKey(8, 5, blueman_dance, { overlap: true, key: "blueman" });
});

App.onAppObjectTouched.Add(function (player, key, x, y) {
	App.sayToAll(
		`${sender.name} has collided with an object whose value is ${key} at the coordinates: (${x}, ${y}).`
	);
});

onUnitAttacked

App.onUnitAttacked.Add(function(sender, x, y, target){});

This function operates when an avatar attacks another avatar with Z.

Parameters

Example

Display a message when a player attacks another player.

// Calls event when the player attacks another player (Z key)
App.onUnitAttacked.Add(function (sender, x, y, target) {
	App.showCenterLabel(`${sender.name} has attacked ${target.name}.`);
	App.sayToAll(`(${x}, ${y})`);
});

onObjectAttacked

App.onObjectAttacked.Add(function(sender, x, y){});

This function operates when an avatar attacks an object with the Z key.

Parameters

Example

Display a message when an avatar attacks an object.

⭐ An attack on an object without the overlap: true attribute cannot execute the function.

let testObject = App.loadSpritesheet("object.png");

App.onStart.Add(function () {
	Map.putObject(5, 5, testObject, { overlap: true });
});
// Calls event when the player attacks an object (Z key)
App.onObjectAttacked.Add(function(sender, x, y){
	App.showCenterLabel(
		`${sender.name} has attacked an object at the coordinates: (${x}, ${y}).`
	);
})

onSidebarTouched

App.onSidebarTouched.Add(function(player){});

This function operates when a player touches the Sidebar app.

Parameters

Example

Display a message on touching the Sidebar app.

App.onSidebarTouched.Add(function (player) {
	App.sayToAll(`${player.name} has touched the Sidebar app.`)
});

Related Tutorial

Sidebar App Example

onTriggerObject

App.onTriggerObject.Add(function(player, layerID, x, y){});

This function that when an avatar interacts with an object with the F key.

Parameters

Example

Display a message on interacting with the object.

App.onTriggerObject.Add(function (player, layerID, x, y) {
	App.sayToAll(`playerName: ${player.name} / layer: ${layerID} / coordinates:(${x}, ${y})`);
});

onAppObjectAttacked

App.onAppObjectAttacked.Add(function (sender, x, y, layer, key) {});

This function operates when an avatar attacks an object with a key value with the Z key.

Reference: Object npcProperty

Parameters

Example

Display a message on attacking an object with a key value.

⭐ Attacking an object without the collide: true property does not execute the function.

App.onAppObjectAttacked.Add(function (sender, x, y, layer, key) {
    App.showCenterLabel(
        `sender: ${sender.name} 
        coordinates: (${x}, ${y})
        layer: ${layer}
        key: ${key}`
    );
})ja

Reference

Last updated