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.
Name
Description
onSay
Function that operates when a player types chat
onPlayerTouched
Function that operates when avatars collide with each other
onObjectTouched
Function that operates when an avatar collides with an object
onAppObjectTouched
Function that operates when an avatar collides with an object with a key value
onUnitAttacked
Function that operates when an avatar attacks another avatar with the Z key
onObjectAttacked
Function that operates when an avatar attacks an object with the Z key
onSidebarTouched
Function that operates when a player touches the Sidebar app
onTriggerObject
Function that operates when an avatar interacts with an object with the F key
onAppObjectAttacked
Function that operates when an avatar attacks an object with a key value with the Z key

📚 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
Name
Type
Description
player
Player
The player’s parameter refers to the player who enters chat. The player’s parameter names can be changed arbitrarily.
text
String
Text refers to the entered chat content. The text’s parameter names can be changed arbitrarily.
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
Name
Type
Description
sender
Player
The player who collides
target
String
The player who is the object of the collision
x, y
Number
The X and Y coordinate of the location where the collision occurs
The parameter name of sender, target, X, and Y can be changed arbitrarily
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
Name
Type
Description
sender
Player
The player who collides with the object
x, y
Number
The X and Y coordinate of the location where the collision occurs
tileID
Number
The tile ID of the object
obj
Object
Object
Example
Label display
⭐ A collision with an object without the overlap: true attribute cannot call this function.
예제_onObjectTouched.zip
2KB
Binary
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
Name
Type
Description
key
String
The key value of the object
sender
Player
The player who collides with the object
x, y
Number
The X and Y coordinate of the location where the collision occurs
Example
Label display
⭐ A collision with an object without the overlap: true attribute cannot call this function.
예제_onAppObjectTouched.zip
29KB
Binary
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
Name
Type
Description
sender
Player
The player who attacks
x, y
Number
The X and Y coordinate of the location of the player who attacks
target
Player
The player who is under attack
The parameter name of sender, target, x, and y can be changed arbitrarily
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
Name
Type
Description
sender
Player
The player who attacks
x, y
Number
The X and Y coordinate of the location of the object
The parameter name of sender, x, and y can be changed arbitrarily.
Example
Display a message when an avatar attacks an object.
⭐ An attack on an object without the overlap: true attribute cannot execute the function.
예제_onObjectAttacked.zip
2KB
Binary
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
Name
Type
Description
player
Player
The player who touches the Sidebar app
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

onTriggerObject

App.onTriggerObject.Add(function(player, layerID, x, y){});
This function that when an avatar interacts with an object with the F key.
Parameters
Name
Type
Description
player
Player
The player who interacts with the object
layerID
Number
The ID of the layer where the object is installed Object: layerID = 3 Top object: layerID = 5
x, y
Number
The X and Y coordinate of the location of the object
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
Name
Type
Description
sender
Player
The player who attacks
x, y
Number
The X and Y coordinate of the location of the object
layer
Number
The layer where the object is installed
key
String
The key value of the object
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 modified 4mo ago