Crab.onChat()
From 8x9craft
function onChat(callback: Function): void
Set a function as an event listener that is run each time a chat message has been sent by nearby players.
Parameters:
- callback: Function - function with signature
(message: string, player: Player) => void
that gets called after the occurrence of the event.
Examples
// Respond to chat messages from nearby players.
crab.onChat(function(message) {
if (message == 'Hi') crab.say('Hello');
});
crab.handleEvents();
// Talk only to good-mannered players.
crab.onChat(function(message, player) {
if (player.getFacing().opposite == crab.getFacing()) {
crab.say('Hello, ' + player.getName() + '!');
} else {
crab.say('Please face me if you want to tell me something!');
}
});
while(true){
crab.sleep(1)
}