making a script for a ferry to cross water

Creating scripts
User avatar
Lucy Brown
Posts: 27
Joined: Thu Jun 14, 2018 1:55 pm
Location: United Kingdom
Has thanked: 47 times
Been thanked: 41 times

making a script for a ferry to cross water

Post by Lucy Brown »

Hi all, I am rather bad at scripting, I need a script to work a water crossing passenger ferry, it needs to move to a coordinate or a prim on touch and sit, it then needs to allow the passenger off and then return to the starting point, ( I would run a ferry from each side so both sides will always have a ferry waiting), any ideas please?
These users thanked the author Lucy Brown for the post (total 4):
Ilan TochnerMichael TimelessRobert StanleyGenavieve Page
User avatar
Michael Timeless
Posts: 113
Joined: Thu Sep 24, 2015 5:13 am
Location: Crestwood, Illinois
Has thanked: 393 times
Been thanked: 153 times
Contact:

Re: making a script for a ferry to cross water

Post by Michael Timeless »

Lucy
There are several hundred scripts at this location. One of them might suit your needs. If you grab the free LSL Editor you will be able to see, read and change the script and it will help you effect changes.

https://www.outworldz.com/

You will also find textures and other very useful items there.

Michael Timeless
These users thanked the author Michael Timeless for the post (total 2):
Robert StanleyLucy Brown
User avatar
Lucy Brown
Posts: 27
Joined: Thu Jun 14, 2018 1:55 pm
Location: United Kingdom
Has thanked: 47 times
Been thanked: 41 times

Re: making a script for a ferry to cross water

Post by Lucy Brown »

nothing I can find that is suitable, I am not a scripting wizard hence my plea for help, anybody please? :)
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: making a script for a ferry to cross water

Post by Graham Mills »

It has been a while since I did any scripting but I will have a look at this, probably at the weekend. What's the purpose of the initial touch event?
These users thanked the author Graham Mills for the post (total 3):
Ilan TochnerRobert StanleyLucy Brown
User avatar
Lucy Brown
Posts: 27
Joined: Thu Jun 14, 2018 1:55 pm
Location: United Kingdom
Has thanked: 47 times
Been thanked: 41 times

Re: making a script for a ferry to cross water

Post by Lucy Brown »

Just to start it moving, or it could commence movement once the passenger sits, that may be problematic though if there are multiple passengers!

It needs to cross a stretch of water to a set coordinate ( or maybe some sort of "target" prim), allow the passenger/s to unseat and disembark then return to it's point of origin, there would be two ferries, each with it's home at opposing sides of the crossing,


many thanks
:D
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: making a script for a ferry to cross water

Post by Graham Mills »

As I said, it's been a while but here are some first thoughts but first some caveats.

This script is provided as-is without support. It is unsuitable for beginners and no responsibility is accepted for any damage caused to regions as a result of its use. There is little by way of error-handling at present. It has been tested over a distance of 60 m between start and dock.

At present the system is reasonably simple. This is how it works...

The ferry will move from its starting place ("start") in a direct line to a prim that will act as the docking point ("dock") on the opposite side of the water course, e.g. river. The dock prim should be a little larger than the ferry and positioned just under the surface of the water such that it will catch avatars as they are forcibly unseated on arrival. You will need the key value for the dock prim. This can be obtained via the General tab on the Edit dialog. With the dock prim selected simply press the button labelled "Copy keys" (in Firestorm). The dock prim can, of course, be made transparent when in normal service.

Create a prim that will serve as the ferry. Open the Edit dialog and with the ferry prim selected paste the clipboard contents (the key value) into the Description field.

With the Edit dialog still open, move the ferry prim to the start and add the following script via the Content tab, save it and sit your avatar on the prim (You can use either the rightclick menu or change the default response to touch on the General tab of the Edit dialog such that your avatar is seated by touching the ferry prim).

After a DELAY of 10 sec the ferry prim will move to the dock prim over a DURATION of 15 sec. Any avatars will be unseated on arrival and after a further 10 sec delay the ferry will return to the start so the process can be repeated.

Comment: the code uses llSetKeyframedMotion for animation and a sensor to detect the dock. Handling of moving_end and llSetPos is apparently the approved method but I found it more problematic. YMMV.

UPDATED 25/08/2018

Code: Select all

vector DESTINATION_POS;
key DESTINATION_KEY;
vector START_POS;
rotation START_ROT;
integer LINK_COUNT;
float DELAY = 10.0;
float DURATION = 15.0;
float X;
float Y;

default
{
    state_entry()
    {
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);//random sit; delete or comment out if sit positions already defined    
    }
 
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        { 
            key avatarID = llAvatarOnSitTarget();
            if (avatarID)
            {
                llSay(0, "Ferry leaves in 10 sec. Please be seated.");
                START_POS = llGetPos();
                START_ROT = llGetRot();
                DESTINATION_KEY = llGetObjectDesc();
                list baseProps = llGetObjectDetails(DESTINATION_KEY, [OBJECT_POS]);
                DESTINATION_POS = llList2Vector(baseProps, 0);
                llOwnerSay("start: "+(string)START_POS+" / end: "+(string)DESTINATION_POS);
                llSetTimerEvent(DELAY); 
            }
        }
        else if (change & CHANGED_REGION_RESTART)
        {
            llSetRegionPos(START_POS);
            llSetRot(START_ROT);
        }
    }
    
    timer()
    {
        float x = 0;
        if (START_POS.x > DESTINATION_POS.x) 
        {
            X = DESTINATION_POS.x - START_POS.x;
        }
        else 
        {
            X = DESTINATION_POS.x - START_POS.x;
        }
        
        float y = 0;
        if (START_POS.y > DESTINATION_POS.y) 
        {
            Y = DESTINATION_POS.y - START_POS.y;
        }
        else 
        {
            Y = DESTINATION_POS.y - START_POS.y;
        }
        llSetKeyframedMotion([<X, Y, 0>, DURATION],[KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_FORWARD]);
        llSetTimerEvent(0.0);
        llSensorRepeat("", DESTINATION_KEY, PASSIVE, 10.0, PI, 5.0);
    }
    
    sensor(integer n)
    {
        state arrived;
    }
}

state arrived
{
    state_entry()
    {
        llSay(0, "Arrived. Returning to base in 10 sec");
        llSetTimerEvent(DELAY);
        //from SL wiki
        integer objectPrimCount = llGetObjectPrimCount(llGetKey());
        integer currentLinkNumber = llGetNumberOfPrims();
 
        for (; objectPrimCount < currentLinkNumber; --currentLinkNumber)
            llUnSit(llGetLinkKey(currentLinkNumber));
    }
    
    changed(integer change)
    {
        if (change & CHANGED_REGION_RESTART)
        {
            llSetRegionPos(START_POS);
            llSetRot(START_ROT);
        }
    }
    
    timer()
    {
         if (START_POS.x < DESTINATION_POS.x) 
        {
            X = -(DESTINATION_POS.x - START_POS.x);
        }
        else 
        {
            X = START_POS.x-DESTINATION_POS.x;
        }
        
        float y = 0;
        if (START_POS.y < DESTINATION_POS.y) 
        {
            Y = -(DESTINATION_POS.y - START_POS.y);
        }
        else 
        {
            Y = START_POS.y-DESTINATION_POS.y;
        }
        llSetKeyframedMotion([<X, Y, 0>, DURATION],[KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_FORWARD]);
        llSetTimerEvent(0.0);
        state default;
    }
}

Last edited by Graham Mills on Sat Aug 25, 2018 7:15 pm, edited 2 times in total.
These users thanked the author Graham Mills for the post (total 7):
Robert StanleyIlan TochnerMichael TimelessLucy BrownSelby EvansHypatia EmersonAlexina Proctor
User avatar
Lucy Brown
Posts: 27
Joined: Thu Jun 14, 2018 1:55 pm
Location: United Kingdom
Has thanked: 47 times
Been thanked: 41 times

Re: making a script for a ferry to cross water

Post by Lucy Brown »

wow, thank you sooo much, I will be trying that out as soon as I can. :D
User avatar
Lucy Brown
Posts: 27
Joined: Thu Jun 14, 2018 1:55 pm
Location: United Kingdom
Has thanked: 47 times
Been thanked: 41 times

Re: making a script for a ferry to cross water

Post by Lucy Brown »

Ok, had a chance to try it out and some odd things are happening!

travelling from an island in the centreish to a shoreline not far from the southern sim edge (4x4) everything works fine, trying to get another ferry to go from shoreline back to the island though no way!, the ferry dives for the sim edge or the corner 0,0,0, I have tried numerous times and consistantly get the same result, any ideas? one would think that if it works fine in one direction then it would the other, baffles me.
User avatar
Hypatia Emerson
Posts: 17
Joined: Thu Aug 02, 2018 10:18 pm
Has thanked: 47 times
Been thanked: 22 times
Contact:

Re: making a script for a ferry to cross water

Post by Hypatia Emerson »

Lucy Brown wrote:
Tue Aug 14, 2018 8:31 am
Ok, had a chance to try it out and some odd things are happening!

travelling from an island in the centreish to a shoreline not far from the southern sim edge (4x4) everything works fine, trying to get another ferry to go from shoreline back to the island though no way!, the ferry dives for the sim edge or the corner 0,0,0, I have tried numerous times and consistantly get the same result, any ideas? one would think that if it works fine in one direction then it would the other, baffles me.
Just a wild guess and I may be way off mark but did you by chance shift copy? That could very well do it... I would recommend starting with fresh prim and being sure to reset the script before testing.
These users thanked the author Hypatia Emerson for the post (total 2):
Ilan TochnerLucy Brown
Full Moon Mesh is available in Kitely Marketplace and soon coming to a shop near you!
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: making a script for a ferry to cross water

Post by Graham Mills »

Thanks for the feedback and glad there was some success. Good ideas from Hypatia but I'm guessing it's a math error. Apologies for this, will hopefully fix at weekend and maybe incorporate rotation as well.
These users thanked the author Graham Mills for the post (total 3):
Lucy BrownHypatia EmersonMichael Timeless
Post Reply