Difference between revisions of "User:SignpostMarv Martin/LSL2/random:location"
(committing random:location) |
m (lsl-typo: parcel name is included in response body) |
||
Line 88: | Line 88: | ||
llList2String(data,0), | llList2String(data,0), | ||
< | < | ||
(float)llList2String(data,2), | (float)llList2String(data,2), | ||
(float)llList2String(data,3) | (float)llList2String(data,3), | ||
(float)llList2String(data,4) | |||
>, | >, | ||
ZERO_VECTOR | ZERO_VECTOR |
Revision as of 11:08, 15 August 2008
//* @package sw_slr //* @subpackage teleport //* @author SignpostMarv Martin //* @license Creative Commons BY-SA UK 2.0 http://creativecommons.org/licenses/by-sa/2.0/uk/ //* @link http://blog.signpostmarv.name/2008/08/15/random-location-script/ //* Example implementation of random:location service. //* Example script is intended to be used in a HUD. //**
//** //* @param key Used for storing the key returned by llHTTPRequest() //** key random_location_http;
//** //* @param list Used to store the parsed data of the last succesful random location query //** list data;
//** //* @param integer UNIX timestamp of last successful HTTP request response //** integer timestamp;
//** //* @param list foo The list data to format //* @return string Returns a newline seperated string of the input list. //** string debug_message(list foo) {
return ("\n" + llDumpList2String(foo,"\n"));
}
//** //* @param string region The name of the region to get a random location from. Optionaly empty to get from entire grid. //* @return key A key returned by llHTTPRequest() //** key random_location(string region) {
return llHTTPRequest("http://svc.sl.net.marvulous.co.uk/place/random:location/" + llEscapeURL(region),[],"");
} default {
state_entry() {
//** //* Fires off a HTTP request for a random location //**
random_location_http = random_location(""); } http_response(key q,integer s,list m,string r) {
//** //* Checks if the http_response event is expected //**
if(q == random_location_http) {
//** //* Checks if the HTTP request was succesful //**
if(s == 200) {
//** //* Stores current UNIX timestamp in a global variable //**
timestamp = llGetUnixTime();
//** //* Seperates the response body by \n and stores it in a global variable //**
data = llParseString2List(r,["\n"],[]); } else {
//** //* If the HTTP Status code was not 200, give debugging information //**
llOwnerSay(debug_message(["Error getting random location:",s,r])); } } }
//** //* @uses llMapDestination to load the world map to the destination point //**
touch_start(integer touched) { llMapDestination( llList2String(data,0), < (float)llList2String(data,2), (float)llList2String(data,3), (float)llList2String(data,4) >, ZERO_VECTOR ); }
//** //* Starts a timer on teleport to reset the script //**
changed(integer change) { if(change & CHANGED_TELEPORT) { llSetTimerEvent(30); } } timer() { llResetScript(); }}</lsl>