User:Tyken Hightower/SimRez

From Second Life Wiki
Jump to navigation Jump to search

<lsl> // This function replaces llRezObject or llRezAtRoot. sim_rez(string object, vector target, rotation rot) {

   integer packed_target = (((integer)target.x & 511) << 22) | (((integer)target.y & 511) << 13) | ((integer)target.z & 8191);
   vector offset = target - <(integer)target.x, (integer)target.y, (integer)target.z>;
   target = llGetPos();
   target = <(integer)target.x + offset.x, (integer)target.y + offset.y, (integer)target.z + offset.z>;
   llRezAtRoot(object, target, <0.0, 0.0, 0.0>, rot, packed_target);

}

// This goes in a script inside the rezzed object. The data you pass to it is the start parameter. It's wise to do something like 'if (start_param) rez_warp(start_param);' in order to avoid warping when you rez it by hand. rez_warp(integer data) {

   vector target = <(data >> 22), ((data >> 13) & 511), (data & 8191)>;
   vector offset = llGetPos();
   target = target + offset - <(integer)offset.x, (integer)offset.y, (integer)offset.z>;
   integer jumps = (integer)(llVecDist(llGetPos(), target) / 10.0) + 1;
   if (jumps > 100) jumps = 100;
   integer i = 1;
   list rules = [PRIM_POSITION, target];
   while ((i = i << 1) < jumps) rules = (rules = []) + rules + rules;
   llSetPrimitiveParams(rules + llList2List(rules, (i - jumps) << 1, i));

} </lsl>