User:Decimus Schomer/Scripts/Jump Slab

From The SchomEmunity Wiki
< User:Decimus Schomer‎ | Scripts
Revision as of 11:17, 9 September 2007 by Decimus Schomer (talk | contribs) (A couple of slight modifications)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Decimus' user page | Decimus' talk page | Decimus' scripts | Decimus' script libraries | Decimus' projects
Main scripts page | Toggling Rotate script | UUID-getter scripts | Texture changer | Channel spier | Chatbot | Jump slab | Emailer | Fractal viewer | Grammar analyser | SPD viewer


This script is used in my 'jump slab'. Basically, it allows you to go anywhere fairly fast (twice as fast as you can fly up but slightly slower than you can fall, though to be honest the fastest way of getting anywhere would just be to rez a random prim, sit on it and use the Edit dialog to move it to where you want to move it to :p).

'Built' into the script is a simple velocimeter, which tells you how fast you're going (it jumps around between 40m/s and 45m/s, usually), a display of the target and a distance-to-target measurer.

The mess of code at the start could be done with '(vector)msg' apart from the fact that the check (to ensure that it doesn't interpret, say, '<0a,1abc,2d>' as an instruction to go to <0,1,2>) if I had used vectors would require you to enter the exact number of decimal places which SL includes when casting floats to strings, which may change across different versions of SL (though I don't expect it will, it's still possible).

// Jump slab
// Copyright (C) 2007 Decimus Schomer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

default
{
    state_entry()
    {
        llListen(1, "", llGetOwner(), "");
        llSetText("Ready", <0, 0, 1>, 10);
    }

    listen(integer channel, string name, key id, string msg)
    {
        integer i = llSubStringIndex(msg, ",");
        if ((i == -1) || (i >= llStringLength(msg)-3))
            return;
        string s1 = llGetSubString(msg, 0, i-1);
        string s2 = llGetSubString(msg, i+1, -1);
        i = llSubStringIndex(s2, ",");
        if ((i == -1) || (i == llStringLength(s2)-1))
            return;
        string s3 = llGetSubString(s2, i+1, -1);
        s2 = llGetSubString(s2, 0, i-1);
        s1 = llStringTrim(s1, STRING_TRIM);
        s2 = llStringTrim(s2, STRING_TRIM);
        s3 = llStringTrim(s3, STRING_TRIM);
        integer x = (integer)s1;
        integer y = (integer)s2;
        integer z = (integer)s3;
        vector v = <x, y, z>;
        if (((string)x != s1) || ((string)y != s2) || ((string)z != s3))
            return;
        vector pos = v;
        vector ppos = v;
        float t1 = llGetTime();
        float t2;
        integer f = 0;
        while (1)
        {
            pos = llGetPos();
            if (ppos == pos)
            {
                llSay(0, "Target is unreachable");
                llSetText("Ready", <0, 0, 1>, 10);
                return;
            }
            if (pos == v)
            {
                llSay(0, "At target");
                llSetText("Ready", <0, 0, 1>, 10);
                return;
            }
            if (f)
            {
                t2 = llGetTime();
                float d = llVecDist(ppos, pos);
                llSetText("Speed: " + (string)(d / (t2-t1)) + "m/s\nDist to dest (= <"+ (string)x + ", " + (string)y + ", " + (string)z + ">): " + (string)llVecDist(pos, v) + "m", <0, 0, 1>, 10);
            }
            else
                f = 1;
            ppos = pos;
            llSetPos(v);
            t1 = t2;
        }
    }
}