Here is my first attempt at RLV scripting, adapting some code I have found around the web and adding comments to help understand the flow. I hope it is helpful to others.
Darius Renneville
// this script tests RLV in two ways: stepping upon prim, or colliding with prim will teleport victim to set coordinates then lock down tp and far touch for 20 seconds. Touching the prim will test if any avatars within 10m of the prim are wearing a RLV relay.
// format for a RLV command: llSay( Channel for Relay, "any string to help you remember what command you are sending" , ( comma) "string key of victim" , ( comma) "string of RLV commands. The first one must start with @. All commands separated with | " );
// to use this script, I rezzed two 3 x 3 x 0.1 boxes, one black and one white. I placed the x,y,z coordinates of the black box in the vector named "place" and this script in the white box. By stepping onto the white box with an active relay, I am instantly tp'ed to the black box with tp and far touch abilities locked out for 20 seconds. By touching the white box, I see that my relay is active ( or not ) and learn the version number of my relay.
// I hope this script helsp you understand how RLV commands work.
// Darius Renneville
integer rlvrc =-1812221819; // the channel used to send commands to a RLV relay. This channel is part of the RLV protocol and cannot be changed
integer sendchan = -4860475969; // the channel for receiving messages from the RLV relay
string cmd_name = "nothing here"; //arbitrary name, useful at times so you can identify commands
string victim;
vector place = <118, 112, 501.5>; // the coordinates of where I want to force tp the victim upon stepping on the prim.
string gohere = "118/112/501.5"; // above coordinates in text format
vector NoGoHere;
list Coords;
string NoTele = "@sittp=n|@tploc=n|@tplure=n|@tplm=n|@fartouch=n"; // string of RLV commands: no sit tp, location tp, invited tp, tp from an LM, or far touch.
string YesTele = "@sittp=y|@tploc=y|@tplure=y|@tplm=y|@fartouch=y|!release"; // string of RLV commands releasing the above restrictions.
list people;
integer handle;
key person;
default
{
state_entry()
{
NoGoHere = llGetRegionCorner() + place; // take the vector coordinates of my target and adjust to sim coordinates that RLV can understand
Coords = llParseString2List((string)NoGoHere,["<", ">", ","],[]); // parse the vector into a string that RLV can understand
gohere = llList2String(Coords,0)+"/"+llList2String(Coords,1)+"/"+llList2String(Coords,2);// set up the string containing the target vector in RLV format
}
collision_start(integer total_number) // potential victim has stepped on the prim
{
victim = (string)llDetectedKey(0); // grab victim's UUID key and save as a string
llSay(rlvrc,"teleport" +","+victim+","+"@tpto:"+gohere+"=force"); // send RLV command to teleport victim to the target vector
llSay(0,"teleport" +","+victim+","+"@tpto:"+gohere+"=force" );// debug message saying that teleport message was sent
llSay(0, "Sending teleport block command"); // debug message saying that tp abilities about to be blocked
llSay(rlvrc,"teleportno"+","+victim+","+NoTele); // send RLV command to block teleport and far touch
llSleep(20); // rest 20 seconds with victim's abilities blocked
llSay(rlvrc,"release"+","+victim+","+YesTele); // send RLV command to release the tp and far touch restrictions
llSay(0,"released"); // debug message stating that RLV restrictions should be released
}
touch_start(integer num) // touching prim will test if toucher is wearing an active RLV relay and give the version number of relay.
{
llSensor("",NULL_KEY,AGENT,10, PI);
}
sensor(integer detected)
{
while(detected--) // let's test for relays on all people detected within the range of the sensor
{
llSay(0,llDetectedName(detected)+" was detected."); // debug message. This avatar was detected by the sensor
llListenRemove(handle); // stop listening on this channel to minimize lag
person = llDetectedKey(detected); // grab key of detected person
handle = llListen(sendchan, "", "", ""); // listen for message from RLV relay
llSay(rlvrc, "TEST"+","+(string)llDetectedKey(detected)+","+"@versionnum="+(string)sendchan); // send detected person's relay a message to get version number
llSetTimerEvent(5.0); // if no response within 5 seconds, go to timer event and state no relay found.
}
}
listen(integer channel, string name, key id, string msg)
{
if( channel == sendchan) // message received from relay
{
llSetTimerEvent(0); // relay active, so kill timer event
llListenRemove(handle); // stop listening for relay and minimize lag
llSay(0, llGetDisplayName(person)+" is using RLV relay version "+msg); // debug message that detected person is wearing a relay with version msg
}
}
timer() // timer not stopped by listen event, so no RLV relay detected
{
llSetTimerEvent(0.0); // stop timer event
llListenRemove(handle); // stop listening for message from non existant relay
llSay(0, llGetDisplayName(person)+" is NOT wearing an active RLV relay!"); // debug message stating that no relay was detected on the avatar
}
}