Difference between revisions of "User:SignpostMarv Martin/LSL2/random:location"
Jump to navigation
Jump to search
(committing random:location) |
m (<lsl> tag to <source>) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
<div style="font-size:1.4em;">< | <div style="font-size:1.4em;"><source lang="lsl2">//** | ||
//* @package sw_slr | //* @package sw_slr | ||
//* @subpackage teleport | //* @subpackage teleport | ||
Line 23: | Line 23: | ||
//** | //** | ||
integer timestamp; | integer timestamp; | ||
//** | |||
//* @param string URL for reduced liklihood of coming across a fellow traveller | |||
//** | |||
string url_solo = "http://svc.sl.net.marvulous.co.uk/place/random:location/"; | |||
//** | |||
//* @param string URL for increased liklihood of coming across a fellow traveller | |||
//** | |||
string url_flashmob = "http://svc.sl.net.marvulous.co.uk/place/random:location:flashmob/"; | |||
//** | //** | ||
Line 39: | Line 49: | ||
key random_location(string region) | key random_location(string region) | ||
{ | { | ||
return llHTTPRequest( | return llHTTPRequest(url_flashmob + llEscapeURL(region),[],""); | ||
} | } | ||
default | default | ||
Line 70: | Line 80: | ||
//** | //** | ||
data = llParseString2List(r,["\n"],[]); | data = llParseString2List(r,["\n"],[]); | ||
llOwnerSay("Touch me to go to \"" + llList2String(data,1) + "\" in " + llList2String(data,0)); | |||
} | } | ||
else | else | ||
Line 88: | Line 99: | ||
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 | ||
Line 109: | Line 120: | ||
llResetScript(); | llResetScript(); | ||
} | } | ||
}</ | }</source></div> | ||
[[Category:LSL Library|random:location]] | [[Category:LSL Library|random:location]] |
Latest revision as of 11:05, 25 January 2015
//**
//* @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 string URL for reduced liklihood of coming across a fellow traveller
//**
string url_solo = "http://svc.sl.net.marvulous.co.uk/place/random:location/";
//**
//* @param string URL for increased liklihood of coming across a fellow traveller
//**
string url_flashmob = "http://svc.sl.net.marvulous.co.uk/place/random:location:flashmob/";
//**
//* @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(url_flashmob + 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"],[]);
llOwnerSay("Touch me to go to \"" + llList2String(data,1) + "\" in " + llList2String(data,0));
}
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();
}
}