Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Put this script in two objects that have reversed name/descriptions. (The name of one is the description of the other, and the reverse.)
- Doing so will cause the two prims to teleport to each other when you walk into them and remain still for a moment.
- The best part? The two prims can be absolutely anywhere on the grid.
- */
- key currentUser;
- float flash_wait = 1.0;
- list cooldown_list;
- integer cooldown_time = 2;
- float cooldown_area = 0.9;
- float scale;
- string LastKnownName;
- vector LastKnownPos;
- key readQuery;
- GetScale()
- {
- vector size = llGetScale();
- scale = size.x;
- }
- integer Allowed(key id)
- {
- if(llAgentInExperience(id))
- {
- llRequestExperiencePermissions(id, "");
- return TRUE;
- }
- else
- {
- llRequestExperiencePermissions(id, "");
- return FALSE;
- }
- }
- integer IsCool(key id)
- {
- integer index = llListFindList(cooldown_list, [id]);
- if(index == -1) return TRUE;
- else return FALSE;
- }
- AddToCooldown(key id)
- {
- cooldown_list += [id, llGetUnixTime()];
- }
- UpdateCooldownList()
- {
- integer i;
- integer length = llGetListLength(cooldown_list) / 2;
- for(i=0; i<length; i++)
- {
- integer time = llList2Integer(cooldown_list, i*2 + 1);
- if(time < llGetUnixTime() - cooldown_time)
- {
- key uuid = llList2Key(cooldown_list, i*2);
- list details = llGetObjectDetails(uuid, [OBJECT_POS]);
- vector pos = llList2Vector(details, 0);
- if(llVecDist(pos, llGetPos()) > cooldown_area)
- {
- if(!IsCloserThan(uuid, 0.5))
- {
- cooldown_list = llDeleteSubList(cooldown_list, i*2, i*2+1);
- }
- }
- }
- }
- }
- integer IsCloserThan(key target, float range)
- {
- range *= scale;
- list stuff = llGetObjectDetails(target, [OBJECT_POS]);
- vector theirPos = llList2Vector(stuff, 0);
- vector myPos = llGetPos();
- theirPos.z = myPos.z;
- return llVecDist(myPos, theirPos) < range;
- }
- integer IsStanding(key id)
- {
- return llGetAnimation(id) == "Standing";
- }
- TryToTeleport(key id)
- {
- if(currentUser == "")
- {
- if(IsCool(id))
- {
- if(llGetOwnerKey(id) == id)
- {
- if(IsCloserThan(id, 0.4))
- {
- if(IsStanding(id))
- {
- if(Allowed(id))
- {
- currentUser = id;
- readQuery = llReadKeyValue(llGetObjectDesc());
- }
- AddToCooldown(id);
- }
- }
- }
- }
- }
- }
- CheckKeyValue()
- {
- if(llGetObjectName() != LastKnownName || GetGlobalPos() != LastKnownPos)
- {
- UpdateKeyValue();
- }
- }
- UpdateKeyValue()
- {
- string currentName = llGetObjectName();
- vector currentPos = GetGlobalPos();
- llUpdateKeyValue(currentName, (string)currentPos, FALSE, "");
- llDeleteKeyValue(LastKnownName);
- LastKnownName = currentName;
- LastKnownPos = currentPos;
- }
- vector GetGlobalPos()
- {
- return llGetRegionCorner() + llGetPos();
- }
- default
- {
- state_entry()
- {
- GetScale();
- llSitTarget(<0,0,0.75>, ZERO_ROTATION);
- llSetTimerEvent(0.5);
- }
- collision(integer total)
- {
- TryToTeleport(llDetectedKey(0));
- }
- experience_permissions(key id)
- {
- cooldown_list = [];
- TryToTeleport(id);
- }
- changed(integer change)
- {
- if(change & CHANGED_LINK)
- {
- if(llAvatarOnSitTarget())
- {
- llRegionSayTo(llAvatarOnSitTarget(), 0, "You are meant to walk onto this teleporter, not sit on it.");
- llUnSit(llAvatarOnSitTarget());
- }
- }
- if(change & CHANGED_SCALE)
- {
- GetScale();
- }
- }
- timer()
- {
- UpdateCooldownList();
- CheckKeyValue();
- }
- dataserver(key query, string data)
- {
- if(query == readQuery)
- {
- if(llGetSubString(data, 0, 0) == "1")
- {
- llOwnerSay("got read");
- vector global = (vector)llGetSubString(data, 2, -1);
- list details = llGetObjectDetails(currentUser, [OBJECT_POS, OBJECT_ROT]);
- vector target_pos = llList2Vector(details, 0);
- rotation target_rot = llList2Rot(details, 1);
- vector target_rot_fwd = llRot2Fwd(target_rot);
- vector offset = target_pos - llGetPos();
- if(Allowed(currentUser))
- {
- offset.x = 0;
- offset.y = 0;
- if(IsCloserThan(currentUser, 0.5))
- {
- vector local = <global.x - ((integer)global.x / 256) * 256,
- global.y - ((integer)global.y / 256) * 256,
- global.z>;
- llTeleportAgentGlobalCoords(currentUser, global + offset, local + offset, local + offset + target_rot_fwd);
- }
- AddToCooldown(currentUser);
- currentUser = "";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement