Skip to content

Instantly share code, notes, and snippets.

@antonyfairport
Created June 15, 2011 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save antonyfairport/1026770 to your computer and use it in GitHub Desktop.
Save antonyfairport/1026770 to your computer and use it in GitHub Desktop.
Simple Second Life region map grab/update script. Uses the gridsurvey.com API
//////////////////////////////////////////////////////////////////////
// Holds the key of the last request.
key g_keyRequest;
//////////////////////////////////////////////////////////////////////
// Force a refresh of the region map.
RefreshMap()
{
g_keyRequest = llHTTPRequest( "http://api.gridsurvey.com/simquery.php?" +
"region=" + llEscapeURL( llGetRegionName() ) + "&item=objects_uuid",
[ HTTP_METHOD, "GET" ], "" );
}
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// Start entry.
state_entry()
{
// Do an initial refresh.
RefreshMap();
// Set a timer so we refresh every so often.
llSetTimerEvent( 43200 );
}
//////////////////////////////////////////////////////////////////
// Refresh on touch.
touch_start( integer total_number )
{
RefreshMap();
}
//////////////////////////////////////////////////////////////////
// Refresh on timer.
timer()
{
RefreshMap();
}
//////////////////////////////////////////////////////////////////
// Handle the HTTP response from the request for the map UUID.
http_response( key request_id, integer status, list metadata, string body )
{
// If the response is in response to our request...
if ( request_id = g_keyRequest )
{
// ...if it's not an error...
if ( llGetSubString( body, 0, 4 ) != "Error" )
{
// Set the texture of the first face to the map.
llSetTexture( body, 0 );
}
}
}
}
//////////////////////////////////////////////////////////////////////
// Holds the key of the last request.
key g_keyRequest;
//////////////////////////////////////////////////////////////////////
// Force a refresh of the region map.
RefreshMap()
{
g_keyRequest = llHTTPRequest( "http://api.gridsurvey.com/simquery.php?" +
"region=" + llEscapeURL( llGetRegionName() ) + "&item=objects_uuid",
[ HTTP_METHOD, "GET" ], "" );
}
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// Start entry.
state_entry()
{
// Do an initial refresh.
RefreshMap();
// Set a timer so we refresh every so often.
llSetTimerEvent( 43200 );
}
//////////////////////////////////////////////////////////////////
// Refresh on touch.
touch_start( integer total_number )
{
RefreshMap();
}
//////////////////////////////////////////////////////////////////
// Refresh on timer.
timer()
{
RefreshMap();
}
//////////////////////////////////////////////////////////////////
// Handle the HTTP response from the request for the map UUID.
http_response( key request_id, integer status, list metadata, string body )
{
// If the response is in response to our request...
if ( request_id == g_keyRequest )
{
// ...if it's not an error...
if ( llGetSubString( body, 0, 4 ) != "Error" )
{
// Set the texture of the first face to the map.
llSetTexture( body, 0 );
}
}
}
}
@antonyfairport
Copy link
Author

I just noticed I have a typo on line 48 ("=" when I should have "=="). I've tried to edit this but gist doesn't seem to want to retain the edit. O_o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment