02-18-2013, 02:02 AM
string text = "Touch To Teleport";
vector text_color = <1.0,1.0,1.0>;
integer access_mode = 1; // 1 - public; 2 - owner; 3 - group;
string menu_message = "Select location:";
list location_list = [ // The data of the locations name and thier coordinates - 12 locations max
"Location 1",<10,10,1000>,
"Location 2",<20,20,2000>,
"Location 3",<30,30,3000>];
posJump( vector target_position ) {
llSetPrimitiveParams([PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>, PRIM_POSITION, target_position ]);
}
warpPos( vector destpos ) {
float safety_range = 1000.0; // The larger the range, the quicker the TP, however, eats up more memory
integer arrived = FALSE;
integer within_range = FALSE;
vector inter_pos = ZERO_VECTOR;
vector current_pos = llGetPos();
vector checking_pos = destpos;
integer jumps = 0;
list rules = [];
integer count = 0;
//
if (llVecDist(destpos, current_pos) <= safety_range) {
jumps = (integer)(llVecDist(destpos, current_pos) / 10.0) + 1;
rules = [ PRIM_POSITION, destpos ];
count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
}
else {
while (!arrived) {
current_pos = llGetPos();
checking_pos = destpos;
within_range = FALSE;
while (!within_range) {
if (llVecDist(checking_pos,current_pos) > safety_range) {
checking_pos = <(current_pos.x + checking_pos.x) / 2.0,(current_pos.y + checking_pos.y) / 2.0,(current_pos.z + checking_pos.z) / 2.0>;
}
else {
within_range = TRUE;
if (llVecDist(destpos, current_pos) <= safety_range ) {
jumps = (integer)(llVecDist(destpos, current_pos) / 10.0) + 1;
rules = [ PRIM_POSITION, destpos ];
count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
arrived = TRUE;
}
}
}
if (!arrived) {
jumps = (integer)(llVecDist(checking_pos, current_pos) / 10.0) + 1;
rules = [ PRIM_POSITION, checking_pos ];
count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
}
}
}
}
//
integer listen_num = -1;
vector destination = ZERO_VECTOR;
integer selected = FALSE;
default {
state_entry() {
llSitTarget(<0.0, 0.0, 0.01>, ZERO_ROTATION);
llSetText(text,text_color,1.0);
llSetSitText("Teleport");
}
//
touch_start(integer int) {
key user = llDetectedKey(0);
integer access_granted = FALSE;
if (access_mode == 1)
access_granted = TRUE;
else if (access_mode == 2) {
if (user == llGetOwner())
access_granted = TRUE;
else
llSay(0," sorry, owner access only.");
}
else if (access_mode == 3) {
if (llSameGroup(user))
access_granted = TRUE;
else
llSay(0," sorry, group memeber access only.");
}
if (access_granted) {
list button_list = [];
integer i = 0;
for (i = 0; i <= llGetListLength(location_list) - 1; i++) {
if (i < 23)
button_list += llList2String(location_list,i);
i += 1;
}
integer menu_chan = 0 - (integer)llFrand(2147483647);
listen_num = llListen(menu_chan,"", user,"");
llDialog(user, menu_message, button_list, menu_chan);
llSetTimerEvent(60.0);
}
}
//
timer() {
llListenRemove(listen_num);
llSetTimerEvent(0.0);
}
//
listen(integer channel, string name, key id, string message) {
llListenRemove(listen_num);
llSetTimerEvent(0.0);
integer choice_index = llListFindList(location_list, (list)message);
if (choice_index != -1) {
destination = llList2Vector(location_list,choice_index + 1);
selected = TRUE;
llSay(0," location [ "+message+" ] @ "+(string)((integer)destination.x)+", "+(string)((integer)destination.y)+", "+(string)((integer)destination.z)+" selected, right click > Teleport.");
}
}
//
changed(integer change) {
if (change & CHANGED_LINK) {
key user = llAvatarOnSitTarget();
if ( (!selected) && (user != NULL_KEY) ) {
llUnSit(user);
llSay(0," sorry, please touch and select location before teleport.");
}
else {
if (llGetAgentSize(user) != ZERO_VECTOR) {
vector init_pos = llGetPos();
warpPos(destination); // use warPos() function
// posJump(destination); // use posJump() function
llUnSit(user);
llSleep(0.2);
warpPos(init_pos); // use warPos() function
// posJump(init_pos); // use posJump() function
selected = FALSE;
}
}
}
}
}
vector text_color = <1.0,1.0,1.0>;
integer access_mode = 1; // 1 - public; 2 - owner; 3 - group;
string menu_message = "Select location:";
list location_list = [ // The data of the locations name and thier coordinates - 12 locations max
"Location 1",<10,10,1000>,
"Location 2",<20,20,2000>,
"Location 3",<30,30,3000>];
posJump( vector target_position ) {
llSetPrimitiveParams([PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>, PRIM_POSITION, target_position ]);
}
warpPos( vector destpos ) {
float safety_range = 1000.0; // The larger the range, the quicker the TP, however, eats up more memory
integer arrived = FALSE;
integer within_range = FALSE;
vector inter_pos = ZERO_VECTOR;
vector current_pos = llGetPos();
vector checking_pos = destpos;
integer jumps = 0;
list rules = [];
integer count = 0;
//
if (llVecDist(destpos, current_pos) <= safety_range) {
jumps = (integer)(llVecDist(destpos, current_pos) / 10.0) + 1;
rules = [ PRIM_POSITION, destpos ];
count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
}
else {
while (!arrived) {
current_pos = llGetPos();
checking_pos = destpos;
within_range = FALSE;
while (!within_range) {
if (llVecDist(checking_pos,current_pos) > safety_range) {
checking_pos = <(current_pos.x + checking_pos.x) / 2.0,(current_pos.y + checking_pos.y) / 2.0,(current_pos.z + checking_pos.z) / 2.0>;
}
else {
within_range = TRUE;
if (llVecDist(destpos, current_pos) <= safety_range ) {
jumps = (integer)(llVecDist(destpos, current_pos) / 10.0) + 1;
rules = [ PRIM_POSITION, destpos ];
count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
arrived = TRUE;
}
}
}
if (!arrived) {
jumps = (integer)(llVecDist(checking_pos, current_pos) / 10.0) + 1;
rules = [ PRIM_POSITION, checking_pos ];
count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
}
}
}
}
//
integer listen_num = -1;
vector destination = ZERO_VECTOR;
integer selected = FALSE;
default {
state_entry() {
llSitTarget(<0.0, 0.0, 0.01>, ZERO_ROTATION);
llSetText(text,text_color,1.0);
llSetSitText("Teleport");
}
//
touch_start(integer int) {
key user = llDetectedKey(0);
integer access_granted = FALSE;
if (access_mode == 1)
access_granted = TRUE;
else if (access_mode == 2) {
if (user == llGetOwner())
access_granted = TRUE;
else
llSay(0," sorry, owner access only.");
}
else if (access_mode == 3) {
if (llSameGroup(user))
access_granted = TRUE;
else
llSay(0," sorry, group memeber access only.");
}
if (access_granted) {
list button_list = [];
integer i = 0;
for (i = 0; i <= llGetListLength(location_list) - 1; i++) {
if (i < 23)
button_list += llList2String(location_list,i);
i += 1;
}
integer menu_chan = 0 - (integer)llFrand(2147483647);
listen_num = llListen(menu_chan,"", user,"");
llDialog(user, menu_message, button_list, menu_chan);
llSetTimerEvent(60.0);
}
}
//
timer() {
llListenRemove(listen_num);
llSetTimerEvent(0.0);
}
//
listen(integer channel, string name, key id, string message) {
llListenRemove(listen_num);
llSetTimerEvent(0.0);
integer choice_index = llListFindList(location_list, (list)message);
if (choice_index != -1) {
destination = llList2Vector(location_list,choice_index + 1);
selected = TRUE;
llSay(0," location [ "+message+" ] @ "+(string)((integer)destination.x)+", "+(string)((integer)destination.y)+", "+(string)((integer)destination.z)+" selected, right click > Teleport.");
}
}
//
changed(integer change) {
if (change & CHANGED_LINK) {
key user = llAvatarOnSitTarget();
if ( (!selected) && (user != NULL_KEY) ) {
llUnSit(user);
llSay(0," sorry, please touch and select location before teleport.");
}
else {
if (llGetAgentSize(user) != ZERO_VECTOR) {
vector init_pos = llGetPos();
warpPos(destination); // use warPos() function
// posJump(destination); // use posJump() function
llUnSit(user);
llSleep(0.2);
warpPos(init_pos); // use warPos() function
// posJump(init_pos); // use posJump() function
selected = FALSE;
}
}
}
}
}