content/hifi-public/tony/shock/shock-trigger.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

39 lines
1,011 B
JavaScript

//
// shock-trigger.js
//
// Entity script meant to be attached to a box entity.
//
var TRIGGER_CHANNEL = "shock-trigger-channel";
(function () {
var inside = false;
var timer = 0.0;
var entityID;
this.preload = function (id) {
entityID = id;
Script.update.connect(this.update);
};
this.enterEntity = function (id) {
inside = true;
this.sendUpdate();
};
this.leaveEntity = function (id) {
inside = false;
this.sendUpdate();
};
this.update = function (dt) {
timer += dt;
if (timer > 1) {
sendUpdate();
timer = 0;
}
};
function sendUpdate() {
Messages.sendMessage(TRIGGER_CHANNEL, JSON.stringify({ inside: inside, entityID: entityID }));
print("sendMessage inside = " + inside + ", entityID = " + entityID);
};
this.unload = function (entityID) {
Script.update.disconnect(this.update);
};
})