content/hifi-content/huffman/ctf/portalBulletClientEntity.js
2022-02-13 23:27:08 +01:00

47 lines
1.7 KiB
JavaScript

(function() {
this.preload = function(entityID) {
print("Loading portal bullet script");
this.teleportSound = SoundCache.getSound(Script.resolvePath("sounds/teleport.raw"));
this.portalTargetLocation = undefined;
var userData = Entities.getEntityProperties(entityID, 'userData').userData;
try {
this.portalTargetLocation = JSON.parse(userData).portalTargetLocation;
} catch (e) {
this.portalTargetLocation = undefined;
}
if (this.portalTargetLocation === undefined) {
print("ERROR, could not find portalTargetLocation in userData");
} else {
print("Portal target location is: ", this.portalTargetLocation);
}
};
this.enterEntity = function(entityID) {
print("Entered bullet entity, the destination is " + this.portalTargetLocation);
if (this.teleportSound.downloaded) {
var position = Entities.getEntityProperties(this.entityID, 'position').position;
Audio.playSound(this.teleportSound, {
position: position,
volume: 0.40,
localOnly: true
});
}
if (this.portalTargetLocation !== undefined) {
print("Teleporting to " + this.portalTargetLocation);
Window.location = this.portalTargetLocation;
}
// Notify any instances of the ball that we have been hit ensuring that
// the ball will be dropped if we are holding it.
Messages.sendLocalMessage("Portal-Game", "hit");
};
this.unload = function() {
print("unloading teleport script");
};
});