osgrid.org
https://forums.osgrid.org/

Board (fake vehicle)
https://forums.osgrid.org/viewtopic.php?f=5&t=4274
Page 1 of 1

Author:  Artemis Tesla [ Sat Jul 07, 2012 1:31 am ]
Post subject:  Board (fake vehicle)

its a script for a surfboard like object. Hope you like it.

{L_CODE}:
default
{
    on_rez(integer flag) { do { llSay(0, "Resetting..."); llResetScript(); } while (TRUE); }

    state_entry()
    {
        llSetClickAction(CLICK_ACTION_SIT);
       
        llSitTarget(<-0.25, 0.0, 0.75>, <0.0, 0.0, 0.0, 0.0>);
       
        llSetCameraEyeOffset(<-5, 0, 2> *  <0.0, 0.0, 0.0, 0.0>);
        llSetCameraAtOffset(<3, 0, 1> *  <0.0, 0.0, 0.0, 0.0>);
    }

    changed(integer change)
    {
        if ( change & (CHANGED_REGION_RESTART | CHANGED_REGION_START))
            do { llOwnerSay("Resetting..."); llResetScript(); } while (TRUE);

        if (change & CHANGED_LINK)
        {
            key avatar = llAvatarOnSitTarget();
            if ( avatar != NULL_KEY ) llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
            else if (llGetPermissionsKey() != NULL_KEY)
            {
                llStopAnimation("surf");
                llReleaseControls();

                vector pos = llGetPos();
                float ground = llGround(ZERO_VECTOR);
                rotation rot = llGetRot();
                vector euler = llRot2Euler(rot) * RAD_TO_DEG;
               
                rot = <rot.x, rot.y, rot.z, -rot.s> * rot * llEuler2Rot(<0.0, 0.0, euler.z> * DEG_TO_RAD);
               
                if ((pos.z - ground) < 10.0) llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, <pos.x, pos.y, ground + 0.0125>]);
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, rot]);
               
                llSay(0,"I have released control");
            }
        }
    }

    run_time_permissions(integer perm)
    {
        if (perm & ( PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS ))       
        {
            llStopAnimation("sit");
            llSleep(0.1);
            llStartAnimation("surf");

            llTakeControls(CONTROL_FWD | CONTROL_BACK |
                           CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT |
                           CONTROL_UP | CONTROL_DOWN,
                           TRUE, FALSE);

            llSay(0,"I have control");
        }
    }
   
    control(key id, integer held, integer change)
    {
        vector pos = llGetPos();
        vector sim = ZERO_VECTOR;
        rotation rot = llGetRot();
       
        // Check sim boundry and Move
        if (held & CONTROL_FWD)
        {
            sim = pos + (llRot2Fwd(rot) * 1);
            if ((sim.x > 5.0) && (sim.x < 250.0) && (sim.y > 5.0) && (sim.y < 250.0)) { pos = sim; }
        }
           
        if (held & CONTROL_BACK)
        {
             sim = pos - (llRot2Fwd(rot) * 1);
             if ((sim.x > 5.0) && (sim.x < 250.0) && (sim.y > 5.0) && (sim.y < 250.0)) { pos = sim; }
        }
        // adjust rotation z axis
        if (held & CONTROL_ROT_LEFT)  { rot = rot * llEuler2Rot(<0.0, 0.0,  15.0> * DEG_TO_RAD); }
        if (held & CONTROL_ROT_RIGHT) { rot = rot * llEuler2Rot(<0.0, 0.0, -15.0> * DEG_TO_RAD); }
       
        // add banking
        if (held & change & CONTROL_ROT_LEFT)  { rot = llEuler2Rot(<-10.0, 0.0, 0.0> * DEG_TO_RAD) * rot; }
        if (held & change & CONTROL_ROT_RIGHT) { rot = llEuler2Rot(< 10.0, 0.0, 0.0> * DEG_TO_RAD) * rot; }
       
        // remove banking
        if (~held & change & CONTROL_ROT_LEFT)  { rot = llEuler2Rot(< 10.0, 0.0, 0.0> * DEG_TO_RAD) * rot; }
        if (~held & change & CONTROL_ROT_RIGHT) { rot = llEuler2Rot(<-10.0, 0.0, 0.0> * DEG_TO_RAD) * rot; }

        // Adjust rotation local y axis
        if (held & CONTROL_UP)   { rot = llEuler2Rot(<0.0,  1.0, 0.0> * DEG_TO_RAD) * rot; }
        if (held & CONTROL_DOWN) { rot = llEuler2Rot(<0.0, -1.0, 0.0> * DEG_TO_RAD) * rot; }

//        if (held & CONTROL_UP)   { pos = pos + (llRot2Up(rot) * 1); }
//        if (held & CONTROL_DOWN) { pos = pos - (llRot2Up(rot) * 1); }

        // fall have to change this.
        float ground = llGround(llGetPos() - pos);
        if (pos.z > ground) pos.z = pos.z - 0.25;
        if (pos.z < 1.0) pos.z = 1.0;

        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, pos, PRIM_ROTATION, rot]);
    }
}

Author:  Sarah Kline [ Sun Jul 08, 2012 1:50 am ]
Post subject:  Re: Board (fake vehicle)

It's fun :-) I always wondered how to bank a vehicle. Thanks for all the nice scripts your pasting here.

Author:  Samantha Alexander [ Wed Jul 03, 2013 5:17 pm ]
Post subject:  Re: Board (fake vehicle)

Very bad script. You get lost underground as soon as you touch an up or down button.
That's your dead in the water. You then have to stand up if you can then goto world, about region, debug, get top scripts and hope you can return it
to the lost and found folder so you can delete it.
Sorry

Author:  Xxaxx Constantine [ Thu Jul 04, 2013 1:27 pm ]
Post subject:  Re: Board (fake vehicle)

Thanks for posting the board script.
It's always nice to see people's experiments in this direction.

If you don't mind a slightly off-topic question, what is the purpose of the on_rez being written the way you have it.
I have seen this form in other scripts.

{L_CODE}:
on_rez(integer flag) { do { llSay(0, "Resetting..."); llResetScript(); } while (TRUE); }


I use the simpler (eh simplistic?) form of:

{L_CODE}:
on_rez(integer flag) {
      llResetScript();
}


I am wondering what the do while wrapper is doing.

Does this mean that the llResetScript(); can fail leading to the need to be called again?

Regards,

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/