Skip to content

Commit

Permalink
Adding Portal Sound and Maximum Spawn protection
Browse files Browse the repository at this point in the history
Adding Portal Sound and Maximum Spawn protection
  • Loading branch information
AleziaKurdis authored Jan 17, 2025
1 parent febb84e commit ec47320
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 34 deletions.
73 changes: 41 additions & 32 deletions scripts/system/places/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
var channel = "com.overte.places";

var portalChannelName = "com.overte.places.portalRezzer";
var MAX_DISTANCE_TO_CONSIDER_PORTAL = 50.0; //in meters
var MAX_DISTANCE_TO_CONSIDER_PORTAL = 100.0; //in meters
var PORTAL_DURATION_MILLISEC = 45000; //45 sec
var rezzerPortalCount = 0;
var MAX_REZZED_PORTAL = 15;

var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");

Expand Down Expand Up @@ -587,37 +589,44 @@
}

function generatePortal(position, url, name, placeID) {
var TOLERANCE_FACTOR = 1.1;
if (Vec3.distance(MyAvatar.position, position) < MAX_DISTANCE_TO_CONSIDER_PORTAL) {
var height = MyAvatar.userHeight * MyAvatar.scale * TOLERANCE_FACTOR;

var portalPosition = Vec3.sum(position, {"x": 0.0, "y": height/2, "z": 0.0});
var dimensions = {"x": height * 0.618, "y": height, "z": height * 0.618};
var userdata = {
"url": url,
"name": name,
"placeID": placeID
};

var portalID = Entities.addEntity({
"position": portalPosition,
"dimensions": dimensions,
"type": "Shape",
"shape": "Sphere",
"name": "Portal to " + name,
"canCastShadow": false,
"collisionless": true,
"userData": JSON.stringify(userdata),
"script": ROOT + "portal.js",
"visible": "false",
"grab": {
"grabbable": false
}
}, "local");

Script.setTimeout(function () {
Entities.deleteEntity(portalID);
}, PORTAL_DURATION_MILLISEC);
if (rezzerPortalCount <= MAX_REZZED_PORTAL) {
var TOLERANCE_FACTOR = 1.1;
if (Vec3.distance(MyAvatar.position, position) < MAX_DISTANCE_TO_CONSIDER_PORTAL) {
var height = MyAvatar.userHeight * MyAvatar.scale * TOLERANCE_FACTOR;

var portalPosition = Vec3.sum(position, {"x": 0.0, "y": height/2, "z": 0.0});
var dimensions = {"x": height * 0.618, "y": height, "z": height * 0.618};
var userdata = {
"url": url,
"name": name,
"placeID": placeID
};

var portalID = Entities.addEntity({
"position": portalPosition,
"dimensions": dimensions,
"type": "Shape",
"shape": "Sphere",
"name": "Portal to " + name,
"canCastShadow": false,
"collisionless": true,
"userData": JSON.stringify(userdata),
"script": ROOT + "portal.js",
"visible": "false",
"grab": {
"grabbable": false
}
}, "local");
rezzerPortalCount = rezzerPortalCount + 1;

Script.setTimeout(function () {
Entities.deleteEntity(portalID);
rezzerPortalCount = rezzerPortalCount - 1;
if (rezzerPortalCount < 0) {
rezzerPortalCount = 0;
}
}, PORTAL_DURATION_MILLISEC);
}
}
}

Expand Down
33 changes: 31 additions & 2 deletions scripts/system/places/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
var portalURL = "";
var portalName = "";
var TP_SOUND = SoundCache.getSound(ROOT + "sounds/teleportSound.mp3");
var PORTAL_SOUND = SoundCache.getSound(ROOT + "sounds/portalSound.mp3");
var portalInjector = Uuid.NONE;
var portalPosition;

this.preload = function(entityID) {

var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions"]);
var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions", "position"]);
var userDataObj = JSON.parse(properties.userData);
portalURL = userDataObj.url;
portalName = userDataObj.name;
portalPosition = properties.position;
var portalColor = getColorFromPlaceID(userDataObj.placeID);


Expand Down Expand Up @@ -116,6 +120,26 @@
"spinFinish": 0
},"local");

if (PORTAL_SOUND.downloaded) {
playLoopSound();
} else {
PORTAL_SOUND.ready.connect(onSoundReady);
}
}

function onSoundReady() {
PORTAL_SOUND.ready.disconnect(onSoundReady);
playLoopSound();
}

function playLoopSound() {
var injectorOptions = {
"position": portalPosition,
"volume": 0.15,
"loop": true,
"localOnly": true
};
portalInjector = Audio.playSound(PORTAL_SOUND, injectorOptions);
}

this.enterEntity = function(entityID) {
Expand All @@ -129,11 +153,16 @@

var timer = Script.setTimeout(function () {
Window.location = portalURL;
portalInjector.stop();
Entities.deleteEntity(entityID);
}, 1000);

};
};

this.unload = function(entityID) {
portalInjector.stop();
};

function getColorFromPlaceID(placeID) {
var idIntegerConstant = getStringScore(placeID);
var hue = (idIntegerConstant%360)/360;
Expand Down
Binary file added scripts/system/places/sounds/portalSound.mp3
Binary file not shown.

0 comments on commit ec47320

Please sign in to comment.