CALCULATE POSITION AND ROTATION FOR REZZED OBJECT, RELATIVE TO THE REZZER
integer iChannel = -39251389;//an arbitrary channel
key kOwner;
default {
state_entry() {
llListen(iChannel,"","","");
kOwner = llGetOwner();
}
listen(integer channel, string name, key id, string message) {
if(llGetOwnerKey(id) == kOwner){//if the object sending the message belongs to the owner of the object containing this script (the object)
list temp = llGetObjectDetails(id, [OBJECT_POS,OBJECT_ROT]);//read its position and rotation on the region
vector vMyPos = llGetPos();//read the position on the region of the object containing this script (the rezzer)
vector vObjectPos = llList2Vector(temp,0);//pull out the object's region position
rotation rMyRot = llGetRot();//read the rezzer's rotation on the region
rotation rObjectRot = llList2Rot(temp,1);//pull out the object's rotation.
vector vOffset = (vObjectPos/rMyRot) - (vMyPos/rMyRot); //calculate the object's offset from the rezzer, correcting for the rezzer's local rotation
//this formula gives what the result would be if the rezzer is at ZERO_ROTATION and the object is in the same position relative to the rezzer
//that is, so many metres in front of the rezzer/behind it, to its left/to its right
rObjectRot = rObjectRot/rMyRot;//
//does a similar correction for the object's rotation, so it's "facing the rezzer/with its back to the rezzer/looking to the rezzer's left/looking to tje rezzer's right right "
float f = llVecDist(vMyPos,vObjectPos);
if(f>10.0){
llOwnerSay("Warning: the object "+name+" is "+(string)f+" metres from the rezzer. llRezAtRoot fails if the rez position is > 10,0 metres. Consider rezzing the "+name+" at the rezzer position, sending it the final destination in chat and using llSetRegionPos to move it there");
}
llOwnerSay("[\""+name+"\","+(string)vOffset+","+(string)rObjectRot+"];");
}
}
}