Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Teleport Script question

Jeanette Hailey
Diva Designs
Join date: 11 Mar 2005
Posts: 185
07-11-2006 19:11
Hi everyone! I'm trying to write a script that will go in a seat. When you sit in it, it will give you a dialog of possible locations and when you select it, it takes you to those coords.

The problem i'm running into is that the script i started with requires the destination *before* the av sits. Any idea how I could accomplish this? :confused:

Thanks in advance!
J-
_____________________
.-~+*Diva*+~-.
Sprocket Island: http://slurl.com/secondlife/Sprocket/68/127/22
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
07-11-2006 19:58
You probably need to move the initialization and teleport code to a listen, and then trigger an llDialog when someone sits on it. My WarpPos teleporter code might be the best suited to this, because most other teleporters work using sit targets.

Here's the code to my teleporter:
CODE

list rules;
vector dest;
vector home;

calcWarpPos( vector destpos)
{
//R&D by Keknehv Psaltery, ~05/25/2006
//with a little pokeing by Strife, and a bit more
//some more munging by Talarus Luan
//Final cleanup by Keknehv Psaltery
vector startpos = llGetPos();
// Compute the number of jumps necessary
integer jumps = (integer)(llVecDist(destpos, startpos) / 10.0) + 1;
// Try and avoid stack/heap collisions
if (jumps > 100 )
jumps = 100; // 1km should be plenty
rules = [ PRIM_POSITION, destpos ]; //The start for the rules list
integer count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules; //should tighten memory use.
rules = (rules=[]) + rules + llList2List( rules, (count - jumps) << 1, count);
}

doWarpPos()
{
llSetPrimitiveParams( rules );
}

default
{
state_entry()
{
llSitTarget(<0,0,0.01>,llGetRot());
home = llGetPos();
dest = (vector)llGetObjectDesc();
calcWarpPos( dest );
}

changed( integer change )
{
if ( change & CHANGED_LINK )
{
if ( llAvatarOnSitTarget() != NULL_KEY )
{
llSetLinkAlpha(LINK_SET,0,ALL_SIDES);
doWarpPos();
llUnSit( llAvatarOnSitTarget() );
calcWarpPos(home);
doWarpPos();
llSetLinkAlpha(LINK_SET,1,ALL_SIDES);
calcWarpPos(dest);
}
}
}
}


Or, you could post up the code to the teleporter that you're working from.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
07-11-2006 20:32
aye, if you change the sit target while someone is sitting it wont take effect untill the next person sits, so your looking at something like a touch (or listen, but im usually not happy reading a manual for everything i own for commands) to start off the llDialog, then ask the user to sit afterwards ...

in my personall use its usually a clunky experiance and usually end up with a elevator contraption (usually using Warp Pos)

it would flow something like this

av sit's
dialog av
choice made, rez a copy of the device (so theres one for the next person)
move the prim the av is sitting on
unsit
die

http://secondlife.com/badgeo/wakka.php?wakka=LibraryWarpPos

course my latest project (at New Citizens, still has a kink or 2) uses a map and red dot prims :)
Jeanette Hailey
Diva Designs
Join date: 11 Mar 2005
Posts: 185
07-13-2006 00:30
Hi again! Thanks to Keknehv's help, I was able to modify his script to allow notecard configuration for multiple destinations. Since he was kind enough to start me out, I thought it was only right to post my new version. It works fabulous. All you need is a notecard in the object formatted as follows:

Destination 1
<123, 128, 50>
Destination 2
<74, 86, 20>
(etc. with no blank lines)

Here is the code:

CODE
list rules;
vector dest;
vector home;
key avie;
list dests;
list coords;
list read;
integer linenum;
string notecard;
integer firsttimerun = TRUE;
integer done = FALSE;


calcWarpPos( vector destpos)
{
//R&D by Keknehv Psaltery, ~05/25/2006
//with a little pokeing by Strife, and a bit more
//some more munging by Talarus Luan
//Final cleanup by Keknehv Psaltery
//7/12/2006 ~ Added multiple destination option with notecard configuration ~ Jeanette Hailey
vector startpos = llGetPos();
// Compute the number of jumps necessary
integer jumps = (integer)(llVecDist(destpos, startpos) / 10.0) + 1;
// Try and avoid stack/heap collisions
if (jumps > 100 )
jumps = 100; // 1km should be plenty
rules = [ PRIM_POSITION, destpos ]; //The start for the rules list
integer count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules; //should tighten memory use.
rules = (rules=[]) + rules + llList2List( rules, (count - jumps) << 1, count);
}

doWarpPos()
{
llSetPrimitiveParams( rules );
}

read_notecard()
{
notecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
llOwnerSay("Retrieving coordinates...");
linenum = 0;
llGetNotecardLine(notecard, linenum);
}

default
{
state_entry()
{
if (firsttimerun == TRUE)
{
state firstrun;
}
llSay(0, "Ready to use.");
llSitTarget(<0,0,0.01>,llGetRot());
home = llGetPos();
}

changed( integer change )
{
if ( change & CHANGED_LINK )
{
avie = llAvatarOnSitTarget();
if ( llAvatarOnSitTarget() != NULL_KEY )
{
llListen(55, "", avie, "");
llDialog(avie, "Choose a destination", dests, 55);
}
}
}

listen(integer channel, string name, key id, string message)
{
integer posInList = llListFindList(dests, (list)message);
dest = llList2Vector(coords, posInList);
calcWarpPos( dest );
llSetLinkAlpha(LINK_SET,0,ALL_SIDES);
doWarpPos();
llUnSit( llAvatarOnSitTarget() );
calcWarpPos(home);
doWarpPos();
llSetLinkAlpha(LINK_SET,1,ALL_SIDES);
calcWarpPos(dest);
}
}

state firstrun
{
state_entry()
{
llSay(0, "Starting up... Touch to read notecard.");
}
touch(integer num_detected)
{
read_notecard();
}

dataserver(key query, string data) //get notecard settings
{
if (data == EOF)
{
llSay(0, "Finished reading.");
done = TRUE;
firsttimerun = FALSE;
integer length = llGetListLength(read);
length--; //I was getting a blank entry at the end of the list. This truncates that.
integer x;
for (x = 0; x <= length; x++)
{
dests = dests + llList2String(read, x);
x++;
coords = coords + (vector)llList2String(read, x);
}
state default;
}
else
{
read = read + data;
linenum = linenum + 1;
llGetNotecardLine(notecard, linenum);
}
}
}
_____________________
.-~+*Diva*+~-.
Sprocket Island: http://slurl.com/secondlife/Sprocket/68/127/22