content/hifi-content/elisa/production/rust-pills/scripts/discoPillServer.js
2022-02-13 23:16:46 +01:00

63 lines
No EOL
2 KiB
JavaScript

//
// discoPillServer.js
// Specifies the pill appearance, behavior and drop
//
// Author: Elisa Lupin-Jimenez
// Derived from script by: Liv Erickson
//
// Copyright High Fidelity 2018
//
// Licensed under the Apache 2.0 License
// See accompanying license file or http://apache.org/
//
(function() {
var SOUND_URL = Script.resolvePath("../sounds/PartyHorn4.wav");
var SOUND = SoundCache.getSound(SOUND_URL);
var PILL;
var PILL_URL = Script.resolvePath("../models/pill.fbx");
var SWALLOW_PILL_SCRIPT = Script.resolvePath("../scripts/swallowDiscoPill.js");
var PILL_AMOUNT = 10;
var PILL_SIZE = {x: 0.1259, y: 0.1259, z: 0.3227};
var LIFETIME = 30;
var SPAWN_POSITION;
var isInactive = true;
this.remotelyCallable = [
"dropPills"
];
this.preload = function(entityID) {
SPAWN_POSITION = Entities.getEntityProperties(entityID, "position").position;
PILL = {
type: "Model",
shapeType: "capsule-z",
name: "disco-pill",
modelURL: PILL_URL,
script: SWALLOW_PILL_SCRIPT,
lifetime: LIFETIME,
position: SPAWN_POSITION,
dynamic: true,
dimensions: PILL_SIZE,
gravity: {x: 0, y: -9.8, z: 0},
velocity: {x:0, y: -0.1, z: 0},
collisionless: false,
userData : "{\"grabbableKey\":{\"grabbable\":true}}"
};
};
this.dropPills = function() {
if (isInactive) {
isInactive = false;
Audio.playSound(SOUND, {volume: 0.5, position: SPAWN_POSITION});
for (var i = 0; i < PILL_AMOUNT; i++) {
// adds as avatar entity to prevent drugging other users
Entities.addEntity(PILL, true);
}
Script.setTimeout(function() {
isInactive = true;
}, LIFETIME * 1000);
}
};
});