overte-Armored-Dragon/unpublishedScripts/marketplace/shortbow/displayServerEntity.js
2017-02-03 10:14:30 -08:00

37 lines
1.3 KiB
JavaScript

(function() {
Script.include('utils.js');
Display = function() {
};
Display.prototype = {
preload: function(entityID) {
this.entityID = entityID;
this.entityIDsThatHaveCollidedWithMe = [];
var props = Entities.getEntityProperties(this.entityID, ['userData', 'parentID']);
var data = utils.parseJSON(props.userData);
if (data !== undefined && data.displayType !== undefined) {
this.gameChannel = data.displayType + "-" + props.parentID;
} else {
print("scoreboardEntity.js | ERROR: userData does not contain a game channel and/or team number");
}
Messages.subscribe(this.gameChannel);
Messages.messageReceived.connect(this, this.onReceivedMessage);
},
unload: function() {
Messages.unsubscribe(this.gameChannel);
Messages.messageReceived.disconnect(this, this.onReceivedMessage);
},
onReceivedMessage: function(channel, message, senderID) {
if (channel === this.gameChannel) {
Entities.editEntity(this.entityID, {
text: message
});
}
},
};
return new Display();
});