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 playerApp.onPlayerTouched.Add(function(sender,target,x,y){});// Calls event when the player collides with an objectApp.onObjectTouched.Add(function(sender,x,y,tileID){});// Calls event when the player collides with an object with a key valueApp.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 keyApp.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);
}
});
// 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}).`
);
});
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})`
);
});
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}).`
);
});
// 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})`);
});
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}).`
);
})
App.onSidebarTouched.Add(function (player) {
App.sayToAll(`${player.name} has touched the Sidebar app.`)
});