Last active
March 11, 2016 09:58
-
-
Save SydoxX/3bfdc51119ae9833a193 to your computer and use it in GitHub Desktop.
A simple teleporter script for High Fidelity(https://highfidelity.com/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simple Teleporter Version 0.2 | |
2014 by Konstantin @High Fidelity | |
####ATTENTION#### | |
This script is broken and will probably never work with HiFi again. | |
*/ | |
var ignoreteleporters = false; | |
function createMenu() | |
{ | |
Menu.addMenu("Teleporter"); | |
Menu.addMenuItem({ | |
menuName: "Teleporter", | |
menuItemName: "Create Teleporter", | |
isCheckable: false | |
}); | |
Menu.addMenuItem({ | |
menuName: "Teleporter", | |
menuItemName: "Ignore Teleporters", | |
isCheckable: true | |
}); | |
Menu.addMenuItem({ | |
menuName: "Teleporter", | |
menuItemName: "Help", | |
isCheckable: false | |
}); | |
} | |
function menuItemEvent(menuItem) | |
{ | |
if(menuItem == "Create Teleporter") | |
{ | |
createteleporter(); | |
} | |
if(menuItem == "Ignore Teleporters") | |
{ | |
Window.alert("Still work in progress!"); | |
} | |
if(menuItem == "Help") | |
{ | |
help() | |
} | |
} | |
createMenu(); | |
Menu.menuItemEvent.connect(menuItemEvent); | |
function createteleporter() | |
{ | |
do{ | |
var televoxelenter = Window.prompt("Please insert where the teleporter should be placed", "X,Y,Z or here"); | |
televoxel = televoxelenter.split(','); | |
if(televoxel[0] == "here") | |
{ | |
televoxelX = Math.floor(MyAvatar.position.x) - 1; | |
televoxelY = Math.floor(MyAvatar.position.y) - 1; | |
televoxelZ = Math.floor(MyAvatar.position.z) - 1; | |
correctinput = true | |
} | |
else if(!isNaN(televoxel[0]) && !isNaN(televoxel[1]) && !isNaN(televoxel[2])) | |
{ | |
televoxelX = parseInt(televoxel[0]); | |
televoxelY = parseInt(televoxel[1]); | |
televoxelZ = parseInt(televoxel[2]); | |
correctinput = true | |
} | |
else | |
{ | |
Window.alert("Wrong input!"); | |
correctinput = false | |
} | |
}while(!correctinput); | |
do{ | |
var telelocenter = Window.prompt("Please insert where you should be teleported", "X,Y,Z"); | |
teleloc = telelocenter.split(','); | |
if(!isNaN(teleloc[0]) && !isNaN(teleloc[1]) && !isNaN(teleloc[2])) | |
{ | |
var telelocX = parseInt(teleloc[0]); | |
var telelocY = parseInt(teleloc[1]); | |
var telelocZ = parseInt(teleloc[2]); | |
print(telelocX + "," + telelocY + "," + telelocZ); | |
correctinput = true | |
} | |
else | |
{ | |
Window.alert("Wrong input!"); | |
correctinput = false | |
} | |
}while(!correctinput); | |
// decimal to RGB calculation | |
// x-axis | |
redX = Math.floor(telelocX / 65536); | |
greenX = Math.floor((telelocX - redX * 65536) / 256); | |
blueX = telelocX - redX * 65536 - greenX * 256; | |
// y-axis | |
redY = Math.floor(telelocY / 65536); | |
greenY = Math.floor((telelocY - redY * 65536) / 256); | |
blueY = telelocY - redY * 65536 - greenY * 256; | |
// z-axis | |
redZ = Math.floor(telelocZ / 65536); | |
greenZ = Math.floor((telelocZ - redZ * 65536) / 256); | |
blueZ = telelocZ - redZ * 65536 - greenZ * 256; | |
// teleporter voxel | |
Voxels.setVoxel(televoxelX,televoxelY,televoxelZ,0.5,0,90,255); | |
// create border voxel | |
Voxels.setVoxel(televoxelX + 0.5,televoxelY,televoxelZ + 0.5,0.5,0,0,255); | |
Voxels.setVoxel(televoxelX + 0.5,televoxelY,televoxelZ - 0.5,0.5,0,0,255); | |
Voxels.setVoxel(televoxelX - 0.5,televoxelY,televoxelZ + 0.5,0.5,0,0,255); | |
Voxels.setVoxel(televoxelX - 0.5,televoxelY,televoxelZ - 0.5,0.5,0,0,255); | |
// create coordinate voxels | |
// x-axis | |
Voxels.setVoxel(televoxelX + 0.5,televoxelY,televoxelZ,0.5,redX,greenX,blueX); | |
// y-axis | |
Voxels.setVoxel(televoxelX,televoxelY,televoxelZ + 0.5,0.5,redY,greenY,blueY); | |
// z-axis | |
Voxels.setVoxel(televoxelX - 0.5,televoxelY,televoxelZ,0.5,redZ,greenZ,blueZ); | |
} | |
Script.setInterval(function() {scanner()}, 200); | |
function scanner() | |
{ | |
if((Math.floor(MyAvatar.position.x) != xs || Math.floor(MyAvatar.position.y) != avaposbeforeY || Math.floor(MyAvatar.position.z) != zs) && ignoreteleporters == false) | |
{ | |
var xs = Math.floor(MyAvatar.position.x); | |
var ys = Math.floor(MyAvatar.position.y - 0.6); | |
var zs = Math.floor(MyAvatar.position.z); | |
//When teleportervoxel is found | |
if(Voxels.getVoxelAt(xs,ys,zs,0.5).red == 0 && Voxels.getVoxelAt(xs,ys,zs,0.5).green == 90 && Voxels.getVoxelAt(xs,ys,zs,0.5).blue == 255 && Voxels.getVoxelAt(xs + 0.5,ys,zs + 0.5,0.5).red == 0 && Voxels.getVoxelAt(xs + 0.5,ys,zs + 0.5,0.5).green == 0 &&Voxels.getVoxelAt(xs + 0.5,ys,zs + 0.5,0.5).blue == 255 && Voxels.getVoxelAt(xs + 0.5,ys,zs - 0.5,0.5).red == 0 && Voxels.getVoxelAt(xs + 0.5,ys,zs - 0.5,0.5).green == 0 &&Voxels.getVoxelAt(xs + 0.5,ys,zs - 0.5,0.5).blue == 255 && Voxels.getVoxelAt(xs - 0.5,ys,zs + 0.5,0.5).red == 0 && Voxels.getVoxelAt(xs - 0.5,ys,zs + 0.5,0.5).green == 0 &&Voxels.getVoxelAt(xs - 0.5,ys,zs + 0.5,0.5).blue == 255 && Voxels.getVoxelAt(xs - 0.5,ys,zs - 0.5,0.5).red == 0 && Voxels.getVoxelAt(xs - 0.5,ys,zs - 0.5,0.5).green == 0 &&Voxels.getVoxelAt(xs - 0.5,ys,zs - 0.5,0.5).blue == 255) | |
{ | |
//x-axis | |
xcoord = (Voxels.getVoxelAt(xs+0.5,ys,zs,0.5).red) * 65536 + (Voxels.getVoxelAt(xs+0.5,ys,zs,0.5).green) * 256 + (Voxels.getVoxelAt(xs+0.5,ys,zs,0.5).blue) | |
//y-axis | |
ycoord = (Voxels.getVoxelAt(xs,ys,zs+0.5,0.5).red) * 65536 + (Voxels.getVoxelAt(xs,ys,zs+0.5,0.5).green) * 256 + (Voxels.getVoxelAt(xs,ys,zs+0.5,0.5).blue) | |
//z-axis | |
zcoord = (Voxels.getVoxelAt(xs-0.5,ys,zs,0.5).red) * 65536 + (Voxels.getVoxelAt(xs-0.5,ys,zs,0.5).green) * 256 + (Voxels.getVoxelAt(xs-0.5,ys,zs,0.5).blue) | |
print("Teleporting to (" + xcoord + "," + ycoord + "," + zcoord + ")"); | |
url = location.hostname; | |
location = "hifi://" + url + "/" + xcoord + "," + ycoord + "," + zcoord + "/"; | |
} | |
// only y-axis, because the other avaposbefore are the same as *s | |
var avaposbeforeY = Math.floor(MyAvatar.position.y); | |
} | |
} | |
function help() | |
{ | |
Window.alert("Copyright 2014 by Konstantin@HighFidelity \nTo use the teleporter, step onto the voxel in the middle (The slight blue one)."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment