User:Jana Kamachi/NPV

From Second Life Wiki
Jump to navigation Jump to search

If you like this script, or any script I've released, please post on my Talk page, or I'll most likely never see it o: If you want to improve a script, just go for it!


float   speed       =   0.5;

vector  velocity    =   <0,0,0>;



warpPos( vector destpos ){

        integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;

        if (jumps > 100 )

        jumps = 100;

        list rules = [ PRIM_POSITION, destpos ];

        integer count = 1;

        while ( ( count = count << 1 ) < jumps)

        rules = (rules=[]) + rules + rules;

        llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );

        if ( llVecDist( llGetPos(), destpos ) > .001 )

        while ( --jumps )

        llSetPos( destpos );

}



default{

        state_entry(){

                llSitTarget(<0,0,-110>,<0,0,0,0>);

                llSetCameraEyeOffset(<0.0, 0.0, -108>);

                llSetCameraAtOffset(<0.0, 0.0, -108>);

                llListen(4,"",llGetOwner(),"");

        }



        changed(integer c){

                if(c & CHANGED_LINK && llAvatarOnSitTarget() == llGetOwner()){

                        llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS | PERMISSION_CONTROL_CAMERA);

                        warpPos(llGetPos() + <0,0,110>);

                }else if(c & CHANGED_LINK && llAvatarOnSitTarget() == NULL_KEY){

                        warpPos(llGetPos() - <0,0,110>);

                }

        }



        listen(integer c, string n, key id, string msg){

                speed = (float)msg;

        }



        run_time_permissions(integer perm){

                if(perm & PERMISSION_TRIGGER_ANIMATION && llAvatarOnSitTarget() == llGetOwner()){

                        llStopAnimation("Sit");

                        llStartAnimation("!WAway");

                }

                if(perm & PERMISSION_TAKE_CONTROLS && llAvatarOnSitTarget() == llGetOwner()){

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

                }

        }



        touch_start(integer n){

                llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS | PERMISSION_CONTROL_CAMERA);

        }



        control(key id, integer held, integer change){

                rotation rot;

                if(held & CONTROL_FWD)

                velocity.x = velocity.x + speed;

                else

                velocity.x *= 0.75;

                if(held & CONTROL_BACK)

                velocity.x = velocity.x - speed;

                else

                velocity.x *= 0.75;



                if(held & CONTROL_LEFT)

                velocity.y = velocity.y - speed;

                else

                velocity.y *= 0.75;

                if(held & CONTROL_RIGHT)

                velocity.y = velocity.y + speed;

                else

                velocity.y *= 0.75;

                if(held & CONTROL_UP)

                llSetPos(llGetPos() + <0,0,speed>);

                if(held & CONTROL_DOWN)

                llSetPos(llGetPos() + <0,0,-speed>);

                if(held & CONTROL_ROT_LEFT){

                        rot = llGetRot() * llEuler2Rot(<0,0,0.12>);

                        llSetRot(rot);

                }

                if(held & CONTROL_ROT_RIGHT){

                        rot = llGetRot() * llEuler2Rot(<0,0,-0.12>);

                        llSetRot(rot);

                }

                llSetPos(velocity * llGetRot() + llGetPos());

        }

}