Skip to content

Instantly share code, notes, and snippets.

@antonyfairport
Created October 16, 2011 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonyfairport/1291058 to your computer and use it in GitHub Desktop.
Save antonyfairport/1291058 to your computer and use it in GitHub Desktop.
Z&A As the Crow Flies (Measure points on a sim)
//////////////////////////////////////////////////////////////////////
// Z&A As the Crow Flies -- Find the distance between two points.
// By Antony Fairport
//
// Rez one or more prims around a place where you want to know how
// far away they are. Name each prim to something that will mean
// something to you. Now drop this script in each of them. Finally,
// touch the prim that you consider to be the point from which you
// want to measure.
//
// This is handy for things like ensuring that your hunt objects
// are within a specific distance of your sign or landing point if
// you're taking part in a hunt with a rule about how far an object
// can be from where hunters land.
//////////////////////////////////////////////////////////////////////
// Globals.
integer g_iChannel;
integer g_iListen;
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// Configure the script.
state_entry()
{
// Create the channel based on the owner's UUID.
g_iChannel = ( -1 * (integer) ( "0x" + llGetSubString( (string) llGetOwner(), -5, -1 ) ) );
// Offset the channel a little so we don't obviously clash with anything else
// that has the same idea. Not really needed but... meh, why not, eh?
g_iChannel += 23;
// Listen for a call.
g_iListen = llListen( g_iChannel, "", NULL_KEY, "" );
}
//////////////////////////////////////////////////////////////////
// On touch, send out the information for this prim.
touch_start( integer total_number )
{
llRegionSay( g_iChannel, "AsTheCrowFlys|" + ( (string) llGetOwner() ) + "|" + ( (string) llGetPos() ) + "|" + llGetObjectName() );
}
//////////////////////////////////////////////////////////////////
// React to a message coming in on a listen event.
listen( integer channel, string name, key id, string message )
{
// If it's on the right channel...
if ( channel == g_iChannel )
{
// Split the message up
list lMessage = llParseString2List( message, [ "|" ], [] );
// Is it a ping from another AtCF object?
if ( llList2String( lMessage, 0 ) == "AsTheCrowFlys" )
{
// From the owner?
if ( llList2String( lMessage, 1 ) == ( (string) llGetOwner() ) )
{
// Get the information we need about the other object.
vector vPos = (vector) llList2String( lMessage, 2 );
string sName = llList2String( lMessage, 3 );
float nDistance = llVecDist( llGetPos(), vPos );
// Send a message to the owner, telling them how far away it is.
llInstantMessage( llGetOwner(), "Distance to object '" + sName + "': " + ( (string) nDistance ) + "m" );
}
}
}
}
//////////////////////////////////////////////////////////////////
// Look for a change event.
changed( integer change )
{
// If the owner has changed...
if ( change & CHANGED_OWNER )
{
// ...do a reset.
llResetScript();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment