Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Put this script in two objects that have reversed name/descriptions. (The name of one is the description of the other, and the reverse.)
  3. Doing so will cause the two prims to teleport to each other when you walk into them and remain still for a moment.
  4. The best part? The two prims can be absolutely anywhere on the grid.
  5. */
  6.  
  7. key     currentUser;
  8. float   flash_wait = 1.0;
  9. list    cooldown_list;
  10. integer cooldown_time = 2;
  11. float   cooldown_area = 0.9;
  12. float   scale;
  13. string  LastKnownName;
  14. vector  LastKnownPos;
  15. key     readQuery;
  16.  
  17. GetScale()
  18. {
  19.     vector size = llGetScale();
  20.     scale = size.x;
  21. }
  22.  
  23. integer Allowed(key id)
  24. {
  25.     if(llAgentInExperience(id))
  26.     {
  27.         llRequestExperiencePermissions(id, "");
  28.         return TRUE;
  29.     }
  30.     else
  31.     {
  32.         llRequestExperiencePermissions(id, "");
  33.         return FALSE;
  34.     }
  35. }
  36.  
  37. integer IsCool(key id)
  38. {
  39.     integer index = llListFindList(cooldown_list, [id]);
  40.     if(index == -1) return TRUE;
  41.     else return FALSE;
  42. }
  43.  
  44. AddToCooldown(key id)
  45. {
  46.     cooldown_list += [id, llGetUnixTime()];
  47. }
  48.  
  49. UpdateCooldownList()
  50. {
  51.     integer i;
  52.     integer length = llGetListLength(cooldown_list) / 2;
  53.     for(i=0; i<length; i++)
  54.     {
  55.         integer time = llList2Integer(cooldown_list, i*2 + 1);
  56.         if(time < llGetUnixTime() - cooldown_time)
  57.         {
  58.             key uuid = llList2Key(cooldown_list, i*2);
  59.             list details = llGetObjectDetails(uuid, [OBJECT_POS]);
  60.             vector pos = llList2Vector(details, 0);
  61.             if(llVecDist(pos, llGetPos()) > cooldown_area)
  62.             {
  63.                 if(!IsCloserThan(uuid, 0.5))
  64.                 {
  65.                     cooldown_list = llDeleteSubList(cooldown_list, i*2, i*2+1);
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
  71.  
  72. integer IsCloserThan(key target, float range)
  73. {
  74.     range *= scale;
  75.     list stuff = llGetObjectDetails(target, [OBJECT_POS]);
  76.     vector theirPos = llList2Vector(stuff, 0);
  77.     vector myPos = llGetPos();
  78.     theirPos.z = myPos.z;
  79.     return llVecDist(myPos, theirPos) < range;
  80. }
  81.  
  82. integer IsStanding(key id)
  83. {
  84.     return llGetAnimation(id) == "Standing";
  85. }
  86.  
  87. TryToTeleport(key id)
  88. {
  89.     if(currentUser == "")
  90.     {
  91.         if(IsCool(id))
  92.         {
  93.             if(llGetOwnerKey(id) == id)
  94.             {
  95.                 if(IsCloserThan(id, 0.4))
  96.                 {
  97.                     if(IsStanding(id))
  98.                     {
  99.                         if(Allowed(id))
  100.                         {
  101.                             currentUser = id;
  102.                             readQuery = llReadKeyValue(llGetObjectDesc());
  103.                         }
  104.                         AddToCooldown(id);
  105.                     }
  106.                 }
  107.             }
  108.         }
  109.     }
  110. }
  111.  
  112. CheckKeyValue()
  113. {
  114.     if(llGetObjectName() != LastKnownName || GetGlobalPos() != LastKnownPos)
  115.     {
  116.         UpdateKeyValue();
  117.     }
  118. }
  119.  
  120. UpdateKeyValue()
  121. {
  122.     string currentName = llGetObjectName();
  123.     vector currentPos  = GetGlobalPos();
  124.     llUpdateKeyValue(currentName, (string)currentPos, FALSE, "");
  125.     llDeleteKeyValue(LastKnownName);
  126.     LastKnownName      = currentName;
  127.     LastKnownPos       = currentPos;
  128. }
  129.  
  130. vector GetGlobalPos()
  131. {
  132.     return llGetRegionCorner() + llGetPos();
  133. }
  134.  
  135. default
  136. {
  137.     state_entry()
  138.     {
  139.         GetScale();
  140.         llSitTarget(<0,0,0.75>, ZERO_ROTATION);
  141.         llSetTimerEvent(0.5);
  142.     }
  143.    
  144.     collision(integer total)
  145.     {
  146.         TryToTeleport(llDetectedKey(0));
  147.     }
  148.    
  149.     experience_permissions(key id)
  150.     {
  151.         cooldown_list = [];
  152.         TryToTeleport(id);
  153.     }
  154.    
  155.     changed(integer change)
  156.     {
  157.         if(change & CHANGED_LINK)
  158.         {
  159.             if(llAvatarOnSitTarget())
  160.             {
  161.                 llRegionSayTo(llAvatarOnSitTarget(), 0, "You are meant to walk onto this teleporter, not sit on it.");
  162.                 llUnSit(llAvatarOnSitTarget());
  163.             }
  164.         }
  165.         if(change & CHANGED_SCALE)
  166.         {
  167.             GetScale();
  168.         }
  169.     }
  170.  
  171.     timer()
  172.     {
  173.         UpdateCooldownList();
  174.         CheckKeyValue();
  175.     }
  176.    
  177.     dataserver(key query, string data)
  178.     {
  179.         if(query == readQuery)
  180.         {
  181.             if(llGetSubString(data, 0, 0) == "1")
  182.             {
  183.                 llOwnerSay("got read");
  184.                 vector global =  (vector)llGetSubString(data, 2, -1);
  185.                 list details = llGetObjectDetails(currentUser, [OBJECT_POS, OBJECT_ROT]);
  186.                 vector target_pos = llList2Vector(details, 0);
  187.                 rotation target_rot = llList2Rot(details, 1);
  188.                 vector target_rot_fwd = llRot2Fwd(target_rot);
  189.                 vector offset = target_pos - llGetPos();
  190.                 if(Allowed(currentUser))
  191.                 {
  192.                     offset.x = 0;
  193.                     offset.y = 0;
  194.                     if(IsCloserThan(currentUser, 0.5))
  195.                     {
  196.                         vector local = <global.x - ((integer)global.x / 256) * 256,
  197.                                         global.y - ((integer)global.y / 256) * 256,
  198.                                         global.z>;
  199.                         llTeleportAgentGlobalCoords(currentUser, global + offset, local + offset, local + offset + target_rot_fwd);
  200.                     }
  201.                     AddToCooldown(currentUser);
  202.                     currentUser = "";
  203.                 }
  204.             }
  205.         }
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement