Change font size
It is currently Fri Aug 17, 2018 7:44 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 2   [ 12 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Train Script Functional
PostPosted: Tue Jan 27, 2009 11:03 pm 

Joined: Sat Feb 02, 2008 5:08 pm
Posts: 16
This script is from Nebadon's library and was working fine on SecondLife maingrid. I have tested the 'Train Engine v1.1.txt" and it runs on "Io" which is setup for dotnetengine. With the addition of one line, it runs on xengine. That one line is the comment line at the top to tell OpenSim it is a dotnetengine script. There are three parts to it. 1) A readme 2) Train engine and 3) Train car.

First the readme:

Train Engine/Car v1.1
~~~~~~~~~~~~~~~~~~~~
Note: The checkpoints are already setup for MonopolyMall.

Version History
--------------------
- v1.1
* Ability for Start, Stop, Running, and Idle sounds added.
- v1.0
* Initial Release


Multiple Cars
--------------------
Find "carnumber = 1;" in the Car script and change it to the next number from the previous car. For instance.... The engine would be considered 0, the number of the first car after the engine would be 1, the second car after the engine would be 2 and so on.... So in the first car the 'carnumber' would be 1 ("carnumber = 1;"), second car would be 2 ("carnumber = 2;"), and so on...

Train Offset
--------------------
Find "cpoffset = <0.0, 0.0, -1.199>;" in both the Engine and Car script and modify them as needed. This offset allows you to change the position of all of the checkpoints... This will allow you to make modifications on the positioning of the train on the track without having to change all of the checkpoints. So, if the train is 1 meter above the track you would change "<0.0, 0.0, -1.199>" to "<0.0, 0.0, -1.0>". If it is 1 meter below the track, you would change it to "<0.0, 0.0, 1.0>". (Note: There is the possibility to change the position of the "direction prim" instead of using this offset. For more information on the "direction prim" see 'Advanced Information - Train/Car Prim Setup')

Speed
--------------------
Find "speed = 10.0;" in both the Engine and Car script and change the "10.0" number to your wanted speed. (They must match in each script). Slower = Higher number. Faster = Lower number. (Note: The faster it is the more jumpy it will look.)

Multiple Trains
--------------------
Find "enginechannel = -549816546;" in both the Engine and Car script and change them to something different. (They must match in each script)
It is suggested to only use negative numbers. (Any number from -1 to -2147483648). Make sure that this number is different for each train.

Checkpoints
--------------------
There isn't any 'automated' way to add, remove, or modify the location of a checkpoint... Open the Engine script and find the line that says "list checkpoints = " all of the stuff behind the equal sign is what makes up the track of the train. Between the quote marks are the cordinates, the time to wait for, the current station name, and the next station name. e.g. "<108.21135, 63.93224, 63.44129>:20:Reading Railroad:Pennsylvania Railroad" - "<108.21135, 63.93224, 63.44129>" are the cordinates, "20" is the number of seconds to wait for, "Reading Railroad" is the name of the station, and "Pennsylvania Railroad" is the name of the next station. (If you change the 'checkpoints' in the Engine script, make sure to also change it in the Car scripts)
Update: If there is an s after the time to wait for, the stopping sound will be played when the train arrives at that checkpoint.

Train/Car Prim Setup
--------------------
The easiest thing to do is to make a small prim (0.1x0.1x0.1) and make it the root prim and center it on the train or car, then rotate the prim you just made so the +Z axis is facing in the direction you want the train to face when it is moving. It may take awhile to get the rotation for the direction correct. (*Warning*: I have hard coded the start rotation of the train into the code for MonopolyMall, so then the rotation wouldn't become 'strange' after making several rounds on the track. So if this is used somewhere else you will need to change the hardcoded rotation.)

Usage
--------------------
After making any needed changes to the script/train. Put the car script in each car of the train and change the 'carnumber' as needed. When finished doing the cars, put the Engine Script into the engine of the train.

Sound
--------------------
Open the Train Engine script and modify the stop, stopvolume, running, runningvolume, start, startvolume, and stopsoundlength variables.
* stop - The name or UUID of the sound to play when stopping at a station.
- e.g. 'string stop = "train_stop";' or 'string stop = "0bbda905-2797-5522-1eb5-7057937c7830";'.
* stopvolume - The volume to play the stopping sound.
- e.g. 'float stopvolume = 1.0;'.
* running - The name or UUID of the sound to play when moving on the track.
- e.g. 'string running = "train_running";' or 'string running = "38a3de37-8250-f77c-9d68-57fb0ce3e82b";'.
* runningvolume - The volume to play the running sound.
- e.g. 'float runningvolume = 1.0;'.
* idle - The name or UUID of the sound to play when moving on the track.
- e.g. 'string idle = "train_idle";' or 'string idle = "38a3de37-8250-f77c-9d68-57fb0ce3e82b";'.
* idlevolume - The volume to play the idle sound.
- e.g. 'float idlevolume = 1.0;'.
* start - The name or UUID of the sound to play when leaving a station.
- e.g. 'string start = "train_start";' or 'string start = "c55b672b-4054-0725-ac7b-ab71eda7ddfb";'.
* startvolume - The volume to play the starting sound.
- e.g. 'float startvolume = 1.0;'.
* startsoundlength - The time that the starting sound plays for, in seconds. (Needed so then the script will know when to start playing the running sound)
- e.g. 'float startsoundlength = 0.5;'.
Note (stop, running, idle, start): If your going to use the name of the sound, the sound file must be in the same prim as the script. To not play a sound during start, running, or stop leave the variable empty. e.g. 'string stop = "";'

Next the Train Engine:
{L_CODE}:
// vvv Configuration/Settings vvv
    // Sounds
        // Arrive at Station
            string stop = "";
            float stopvolume = 1.0;
        // Running
            string running = "";
            float runningvolume = 1.0;
        // Idle
            string idle = "";
            float idlevolume = 1.0;
        // Leave Station
            string start = "";
            float startvolume = 1.0;
            float startsoundlength = 0.5;
    // Multiple Trains
        integer enginechannel = -549816546;
    // Speed
        float speed = 10.0;
    // Train Offset
        vector cpoffset = <0.0, 0.0, -1.199>;
    // Train Checkpoints
        list checkpoints = ["<128.21408, 64.01570, 63.43275>", "<118.21558, 64.01607, 63.44098>:0s:", "<108.21135, 63.93224, 63.44129>:20:Reading Railroad:Pennsylvania Railroad", "<98.64242, 64.58298, 63.43275>", "<89.63821, 66.57278, 63.44098>", "<82.54501, 70.11105, 63.44129>", "<76.58730, 75.55882, 63.43275>", "<71.72843, 81.54896, 63.44098>", "<68.27763, 88.99255, 63.44129>", "<66.32258, 98.22130, 63.43275>", "<65.64206, 107.66950, 63.44098>", "<65.64206, 117.63175, 63.44129>", "<65.64170, 127.63023, 63.43275>", "<65.64206, 137.62869, 63.44098>:0s:", "<65.64206, 147.61710, 63.44098>:20:Pennsylvania Railroad:B. & O. Railroad", "<66.35152, 157.35495, 63.43275>", "<68.34132, 166.35918, 63.44098>", "<71.87959, 173.45236, 63.44129>", "<77.32736, 179.41008, 63.43275>", "<83.31750, 184.26895, 63.44098>", "<90.76109, 187.71974, 63.44129>", "<99.98985, 189.67482, 63.43275>", "<109.43803, 190.35532, 63.44098>", "<119.40030, 190.35532, 63.44129>", "<129.39877, 190.35568, 63.43275>", "<139.39725, 190.35532, 63.44098>:0s:", "<149.22479, 190.33736, 63.44098>:20:B. & O. Railroad:Short Line", "<158.96265, 189.62785, 63.43275>", "<167.96687, 187.63806, 63.44098>", "<175.06004, 184.09982, 63.44128>", "<181.01776, 178.65202, 63.43275>", "<185.87663, 172.66190, 63.44098>", "<189.32744, 165.21828, 63.44129>", "<191.28250, 155.98955, 63.43275>", "<191.96301, 146.54137, 63.44098>", "<191.96301, 136.57907, 63.44129>", "<191.96336, 126.58061, 63.43275>", "<191.96300, 116.58212, 63.44098>:0s:", "<191.97081, 106.75428, 63.44098>:20:Short Line:Reading Railroad", "<191.26131, 97.01643, 63.43275>", "<189.27151, 88.01220, 63.44098>", "<185.73326, 80.91902, 63.44129>", "<180.28548, 74.96130, 63.43275>", "<174.29536, 70.10243, 63.44098>", "<166.85175, 66.65163, 63.44129>", "<157.62302, 64.69656, 63.43275>", "<148.17484, 64.01606, 63.44098>", "<138.21254, 64.01606, 63.44129>"];
// ^^^ Configuration/Settings ^^^

integer checkpoint = 0;
integer numcheckpoints = 0;
vector next_pos;
string cpdata;
string spause;
float pause;
string csname;
string nsname;
integer cpdataloc;
rotation rot;
vector increment;
integer i;
integer soundstart = 0;

next_checkpoint()
{
    if (checkpoint >= numcheckpoints)
    {
        checkpoint = 0;
        llSetRot(<0.70711, 0.00000, -0.70711, 0.00000>);
        if (llGetFreeMemory() <= 2000) llResetScript();
    }
    next_pos = ZERO_VECTOR;
    cpdata = llList2String(checkpoints, checkpoint);
    spause = "";
    pause = 0.0;
    csname = "";
    nsname = "";
    cpdataloc = llSubStringIndex(cpdata, ":");
    if (cpdataloc == -1)
    {
        next_pos = ((vector)cpdata + cpoffset);
    }
    else
    {
        next_pos = ((vector)llGetSubString(cpdata, 0, cpdataloc - 1) + cpoffset);
        cpdata = llDeleteSubString(cpdata, 0, cpdataloc);
        cpdataloc = llSubStringIndex(cpdata, ":");
        spause = llGetSubString(cpdata, 0, cpdataloc - 1);
        if (llGetSubString(spause, -1, -1) == "s" && stop != "")
        {
            llStopSound();
            llPlaySound(stop, stopvolume);
            pause = (float)llGetSubString(cpdata, 0, cpdataloc - 2);
        }
        else
        {
            pause = (float)llGetSubString(cpdata, 0, cpdataloc - 1);
        }
        cpdata = llDeleteSubString(cpdata, 0, cpdataloc);
        cpdataloc = llSubStringIndex(cpdata, ":");
        if (cpdataloc != -1)
        {
            if (idle != "")
            {
                llLoopSound(idle, idlevolume);
            }
            csname = llGetSubString(cpdata, 0, cpdataloc - 1);
            cpdata = llDeleteSubString(cpdata, 0, cpdataloc);
            nsname = llGetSubString(cpdata, 0, -1);
            if (llStringLength(csname) > 0) llWhisper(0, "Arrived at " + csname + ".");
        }
        if (pause > 0.0)
        {
            llSleep(pause);
            if (start != "")
            {
                llStopSound();
                llPlaySound(start, startvolume);
                llResetTime();
                soundstart = 1;
            }
        }
        if (llStringLength(nsname) > 0) llWhisper(0, "Next stop " + nsname + ".");
    }
    if (soundstart == 1)
    {
        if (llGetTime() >= startsoundlength)
        {
            soundstart = 0;
            llLoopSound(running, runningvolume);
        }
    }
    llShout(enginechannel, "nextpos");
    rot = llGetRot() * llRotBetween(<0,0,1> * llGetRot(), next_pos - llGetPos());
    increment = (next_pos - llGetPos()) / speed;
    for(i=0;i<speed;++i)
    {
        llSetPrimitiveParams([PRIM_POSITION, (llGetPos() + increment), PRIM_ROTATION, rot]);
    }
    checkpoint++;
    next_checkpoint();
}

default
{
    state_entry()
    {
        numcheckpoints = llGetListLength(checkpoints);
        checkpoint = 0;
        llSetRot(<0.70711, 0.00000, -0.70711, 0.00000>);
        next_checkpoint();
    }

    on_rez(integer start_param)
    {
        llResetScript();
    }
}


Lastly the Train car:

{L_CODE}:
// vvv Configuration/Settings vvv
    // Multiple Cars
        integer carnumber = 1;
    // Multiple Trains
        integer enginechannel = -549816546;
    // Speed
        float speed = 10.0; // Higher = Slower, but will look smoother.
    // Train Offset
        vector cpoffset = <0.0, 0.0, -1.884>;
    // Train Checkpoints
        list checkpoints = ["<128.21408, 64.01570, 63.43275>", "<118.21558, 64.01607, 63.44098>:0s:", "<108.21135, 63.93224, 63.44129>:20:Reading Railroad:Pennsylvania Railroad", "<98.64242, 64.58298, 63.43275>", "<89.63821, 66.57278, 63.44098>", "<82.54501, 70.11105, 63.44129>", "<76.58730, 75.55882, 63.43275>", "<71.72843, 81.54896, 63.44098>", "<68.27763, 88.99255, 63.44129>", "<66.32258, 98.22130, 63.43275>", "<65.64206, 107.66950, 63.44098>", "<65.64206, 117.63175, 63.44129>", "<65.64170, 127.63023, 63.43275>", "<65.64206, 137.62869, 63.44098>:0s:", "<65.64206, 147.61710, 63.44098>:20:Pennsylvania Railroad:B. & O. Railroad", "<66.35152, 157.35495, 63.43275>", "<68.34132, 166.35918, 63.44098>", "<71.87959, 173.45236, 63.44129>", "<77.32736, 179.41008, 63.43275>", "<83.31750, 184.26895, 63.44098>", "<90.76109, 187.71974, 63.44129>", "<99.98985, 189.67482, 63.43275>", "<109.43803, 190.35532, 63.44098>", "<119.40030, 190.35532, 63.44129>", "<129.39877, 190.35568, 63.43275>", "<139.39725, 190.35532, 63.44098>:0s:", "<149.22479, 190.33736, 63.44098>:20:B. & O. Railroad:Short Line", "<158.96265, 189.62785, 63.43275>", "<167.96687, 187.63806, 63.44098>", "<175.06004, 184.09982, 63.44128>", "<181.01776, 178.65202, 63.43275>", "<185.87663, 172.66190, 63.44098>", "<189.32744, 165.21828, 63.44129>", "<191.28250, 155.98955, 63.43275>", "<191.96301, 146.54137, 63.44098>", "<191.96301, 136.57907, 63.44129>", "<191.96336, 126.58061, 63.43275>", "<191.96300, 116.58212, 63.44098>:0s:", "<191.97081, 106.75428, 63.44098>:20:Short Line:Reading Railroad", "<191.26131, 97.01643, 63.43275>", "<189.27151, 88.01220, 63.44098>", "<185.73326, 80.91902, 63.44129>", "<180.28548, 74.96130, 63.43275>", "<174.29536, 70.10243, 63.44098>", "<166.85175, 66.65163, 63.44129>", "<157.62302, 64.69656, 63.43275>", "<148.17484, 64.01606, 63.44098>", "<138.21254, 64.01606, 63.44129>"];
// ^^^ Configuration/Settings ^^^

key owner;
integer checkpoint = 0;
integer numcheckpoints = 0;
vector next_pos;
string cpdata;
integer cpdataloc;
rotation rot;
vector increment;
integer i;

next_checkpoint()
{
    if (checkpoint >= numcheckpoints)
    {
        checkpoint = 0;
        llSetRot(<0.70711, 0.00000, -0.70711, 0.00000>);
    }
    else if (checkpoint == (numcheckpoints - 1) - carnumber && llGetFreeMemory() <= 2000)
    {
        llResetScript();
    }
    next_pos = ZERO_VECTOR;
    cpdata = llList2String(checkpoints, checkpoint);
    cpdataloc = llSubStringIndex(cpdata, ":");
    if (cpdataloc == -1)
    {
        next_pos = ((vector)cpdata + cpoffset);
    }
    else
    {
        next_pos = ((vector)llGetSubString(cpdata, 0, cpdataloc - 1) + cpoffset);
        cpdata = llDeleteSubString(cpdata, 0, cpdataloc);
        cpdataloc = llSubStringIndex(cpdata, ":");
    }
    rot = llGetRot() * llRotBetween(<0,0,1> * llGetRot(), next_pos - llGetPos());
    increment = (next_pos - llGetPos()) / speed;
    for(i=0;i<speed;++i)
    {
        llSetPrimitiveParams([PRIM_POSITION, (llGetPos() + increment), PRIM_ROTATION, rot]);
    }
    checkpoint++;
}

default
{
    state_entry()
    {
        owner = llGetOwner();
        llListen(enginechannel, "", NULL_KEY, "nextpos");
        numcheckpoints = llGetListLength(checkpoints);
        checkpoint = (numcheckpoints - 1) - carnumber;
        next_checkpoint();
        llSetRot(<0.70711, 0.00000, -0.70711, 0.00000>);
    }

    on_rez(integer start_param)
    {
        llResetScript();
    }

    listen(integer channel, string name, key id, string message)
    {
        if (llGetOwnerKey(id) == owner)
        {
            next_checkpoint();
        }
    }
}


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Mon Nov 15, 2010 4:34 am 

Joined: Mon Nov 15, 2010 4:30 am
Posts: 1
I tested this script on my local OS server. Here is the result http://www.youtube.com/watch?v=1mKoXT7H7mo.

Would it be possible for someone to please clarify the license of this train script?

TIA,

Roel Cantada


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Tue Dec 14, 2010 12:24 am 

Joined: Wed Aug 25, 2010 4:34 pm
Posts: 21
Could someone please clarify the following comments by explaining exactly what needs to be added to the script to make it work on xengine?

" I have tested the 'Train Engine v1.1.txt" and it runs on "Io" which is setup for dotnetengine. With the addition of one line, it runs on xengine. That one line is the comment line at the top to tell OpenSim it is a dotnetengine script."


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Wed Dec 15, 2010 3:31 am 
Furious Typer
User avatar

Joined: Fri Jul 17, 2009 5:57 am
Posts: 142
Location: Germany
Ken Savage {L_WROTE}:
Could someone please clarify the following comments by explaining exactly what needs to be added to the script to make it work on xengine?

The DotNetEngine has been removed from OpenSim and XEngine is the default now. Hence you do not need to change anything.


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Wed Dec 15, 2010 4:00 pm 
OSG Elite
User avatar

Joined: Sat Nov 06, 2010 10:19 am
Posts: 1055
Location: Czech Republic
Ken Savage {L_WROTE}:
Could someone please clarify the following comments by explaining exactly what needs to be and it runs on "Io"

Might mean that you need to set
{L_QUOTE}:
OSFunctionThreatLevel = Low

In the OpenSim.ini Try run it and watch the error meassgeas, please

Bo


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Tue Jun 25, 2013 5:43 am 
User avatar

Joined: Sat Oct 08, 2011 10:30 am
Posts: 7
Ok so I have been testing out this script seeing how it works but seem to have run into a little problem. When I reset the scripts they start and head off but just after a few seconds they are coming to a stop due to the server Script Instance Aborting the script due to a 100ms timeout. I am rather new to this running of my own sims and I am not sure what I need to change or do to fix this. Any help grateful... ;-)

_________________
Allways happy to help if I can.
Your Friend
MadLad Clip


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Tue Jun 25, 2013 4:24 pm 
Furious Typer

Joined: Tue Oct 28, 2008 4:53 pm
Posts: 166
I have a fully working train and script ported from SL, I made a few minor adjustments for it to work using XEngine, it works perfectly, the train is a phantom sculpty, and has an engineer pose and menu for whistle, bell, headlight, steam, start engine, and speed control.

I'm not sure if the script uses physics or not, (it's been a long time since I looked at the script), but it uses a scanning event that looks for a prim called 'guide', I have had it successfully working at all speeds with very smooth movement, control is also by keyboard pgup/pgdown for speed.

It also includes the track, which are linked prims with a central rail (the central rail is not scripted), the rail is the guiding track for the train, and when the tracks are laid out, the central rail has to be unlinked and made invisible and phantom, but must never be deleted, nor it's name changed.

After all tracks have been laid, and the central rails edited, the train is rezzed next to the track,,, it will find the first guide rail and auto align and move itself on the track ready for use, if it comes to the end of a track, it will auto rotate 180 and continue, until the train is stopped by pressing pgdown until the train has stopped.

The script(s) for the train, the main script, steam whistle, etc etc are to big to post here, but I can box up the track and train and rez them in OSGrid, if someone has a freebie area that I can rez it on, then I'll post it's location here in the forum for all to get.

ADDENDUM:
Because of object entry across region boundries are not yet perfected in opensim, the train will not successfully cross regions, but will work in a megaregion, but will lose sound, and also if the end of the track is in a child region of a megaregion, the train script will crash, so, if using the train in a mega region, make sure the track is a closed loop.

Also, there are track switches, but they are very complicated to set up and align, I can include those if anyone wants to have a shot at track switching.


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Tue Jun 25, 2013 11:41 pm 
User avatar

Joined: Thu Aug 30, 2012 8:49 am
Posts: 40
TY for your offer Marlon, I for one would be very interested in this to fiddle with and learn about vehicles in OS.


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Wed Jun 26, 2013 9:20 am 
Furious Typer
User avatar

Joined: Sat May 26, 2012 8:56 pm
Posts: 280
For MadLad, you may want to change this setting in the Xengine part of your Opensim.ini file :

ScriptStopStrategy = co-op

This helps when your scripts are stopped from running, due to timeouts.. well it helped me out a lot.


Top
 Profile  
 
 Post subject: Re: Train Script Functional
PostPosted: Wed Jun 26, 2013 5:26 pm 
Furious Typer

Joined: Tue Oct 28, 2008 4:53 pm
Posts: 166
Sheera Khan {L_WROTE}:
TY for your offer Marlon, I for one would be very interested in this to fiddle with and learn about vehicles in OS.

I have boxed up the necessary parts and set them all to full perm, and now looking for somewhere in OSG to rez it for all to get.

I did have my own home region server running, but, recently I converted one of the bathrooms into a computer room and have yet to route the network cable to the router on the other side of the house, the computer I'm using now is using wifi, and periodically have 1 region running, connected to OSGrid, for testing and boxing up freebies, which means I need somewhere in OSGrid to rez any freebies I create or mod, for people to get.

I could create an IAR, but I don't have anywhere to upload it to, being that my home server is not only a region server but also a file sharing server too, and is offline until I get the network cable routed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 12 posts ]
Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net