Воскресенье, 20.07.2025, 20:16

Мой блог

Главная | Регистрация | Вход
Приветствую Вас Гость
RSS
Форма входа
Календарь
«  Декабрь 2012  »
Пн Вт Ср Чт Пт Сб Вс
     12
3456789
10111213141516
17181920212223
24252627282930
31
Поиск
Друзья сайта
Статистика

Дневник


Главная » 2012 » Декабрь » 18 » Предмет будет двигаться за аватаром (Follow Me Script)
Предмет будет двигаться за аватаром (Follow Me Script)
19:48
/////////////// CONSTANTS ///////////////////
string  FWD_DIRECTION   = "-y";
vector POSITION_OFFSET  = <0.0, 0.75, -0.8>; // Local coords
float   SCAN_REFRESH    = 0.2;
string FOLLOW   = "/follow";
string STAY     = "/stay";
integer FOLLOW_STOP     = 5000;
integer FOLLOW_START    = 5001;
float   MOVETO_INCREMENT    = 6.0;
///////////// END CONSTANTS /////////////////

///////////// GLOBAL VARIABLES ///////////////
key gOwner;
rotation gFwdRot;
float   gTau;
float   gMass;
integer count;
integer repeat;
/////////// END GLOBAL VARIABLES /////////////

help()
{
    llWhisper(0,"You can say the following commands:");
    llWhisper(0,"/follow <-- I will follow you around when I am able.");
    llWhisper(0,"/stay <-- I will stay where I am.");
    llWhisper(0,"/help <-- I will repeat this message.");
    llWhisper(0,"if I lose you I will IM my position to you unless");
    llWhisper(0,"I am in a no script area, then I can do nothing.");
}

StartScanning() 
{
    llSetStatus(STATUS_PHYSICS, TRUE);
    llSensorRepeat("", gOwner, AGENT, 96.0, PI, SCAN_REFRESH);
    llWhisper(0, "I will follow you :)");
}

StopScanning() 
{
    llSetStatus(STATUS_PHYSICS, FALSE);
    llSensorRemove();
    llWhisper(0, "I must stay here :(");
}

// Move to a position far away from the current one.
MoveTo(vector target) 
{
    vector Pos = llGetPos();
    
    while (llVecDist(Pos, target) > MOVETO_INCREMENT) 
    {
        Pos += llVecNorm(target - Pos) * MOVETO_INCREMENT;
        llSetPos(Pos);
    }
    llSetPos(target);    
}

rotation GetFwdRot() 
{
    // Special case... 180 degrees gives a math error
    if (FWD_DIRECTION == "-x") 
    {
        return llAxisAngle2Rot(<0, 0, 1>, PI);
    }
    
    string Direction = llGetSubString(FWD_DIRECTION, 0, 0);
    string Axis = llToLower(llGetSubString(FWD_DIRECTION, 1, 1));
    
    vector Fwd;
    if (Axis == "x")
        Fwd = <1, 0, 0>;
    else if (Axis == "y")
        Fwd = <0, 1, 0>;
    else
        Fwd = <0, 0, 1>;
        
    if (Direction == "-")
        Fwd *= -1;
       
    return llRotBetween(Fwd, <1, 0, 0>); 
}

rotation GetRotation(rotation rot) 
{
    vector Fwd;
    Fwd = llRot2Fwd(rot);
    
    float Angle = llAtan2( Fwd.y, Fwd.x );
    return gFwdRot * llAxisAngle2Rot(<0, 0, 1>, Angle);
}

default 
{
    state_entry() 
    {
        llSetStatus(STATUS_PHANTOM, TRUE);
        gOwner = llGetOwner();
        gFwdRot = GetFwdRot();
        gMass = llGetMass();
        gTau = 0.2;
        llListen(0, "", "", "");
        llSetTimerEvent(1.5);
        StartScanning();
        llMoveToTarget(llGetPos(), gTau);
    }
    
    sensor(integer num_detected) 
    {
        rotation TargetRot;
        vector Pos = llDetectedPos(0);
        rotation Rot = llDetectedRot(0);
        vector size = llGetAgentSize(llDetectedKey(0));
        if((llGetAnimation(gOwner) == "Flying") || (llGetAnimation(gOwner) == "FlyingSlow"))
        {
            TargetRot = llEuler2Rot( <80, 0, 10> * DEG_TO_RAD) * GetRotation(Rot);
            POSITION_OFFSET  = <2.0, 0.75, 0.0>;
        }
        else 
        { 
            TargetRot = GetRotation(Rot); 
            POSITION_OFFSET  = <0.0, 0.75, (-size.z / 2) + 0.1>;        
        }
        vector Offset = POSITION_OFFSET * Rot;
        Pos += Offset;
        llRotLookAt(TargetRot, gTau * 5.0, gTau);
        llMoveToTarget(Pos, gTau);
        count=0;
        repeat=0;
    }
    
    no_sensor()
    {
        count += 1;
        if(count > 150)
        {
            repeat += 1;
            string name = llKey2Name(llGetOwner());
            string pos = (string)llGetPos();
            string simName=llGetRegionName();
            if(repeat < 2) 
            { 
                llInstantMessage(llGetOwner(),name + ", I am lost at:" + simName + pos + ". Hurry as I get bored easy");
            }
            else
            {
                llInstantMessage(llGetOwner(),name + ", Party time so I am off, Bye !");
                llSleep(10.0);
                llDie();
            }
            count=0;
        }
    }
    
    listen(integer channel, string name, key id, string mesg) 
    {
        mesg = llToLower(mesg);
        if ((id == gOwner) && (mesg == FOLLOW)) 
        {
            StartScanning();
        }
        else if ((id == gOwner) && (mesg == STAY)) 
        {
            StopScanning();
        }
        else if ((id == gOwner) && (mesg == "/help")) 
        {
            help();
        }
        else
        {
            integer stop;
            string word;
            integer check = FALSE;
            if((id==gOwner) || (name == "Little Pengi")) { check=TRUE;}
            if(check == FALSE)
            {
                do
                {
                    stop = llSubStringIndex(mesg, " ");
                    if(stop == -1) { stop = 0;}
                    word = llGetSubString(mesg, 0, stop - 1);
                    mesg = llDeleteSubString(mesg, 0, stop);
                    if(word=="cute") 
                    { 
                        llSay(0,"Your cute too ;)");
                        stop = 0;
                    }
                    else if(word=="pengi") 
                    { 
                        llSay(0,"You called? ;)");
                        stop = 0;
                    }
                    else if((word=="cool") || (word=="kewl")) 
                    { 
                        llSay(0,word + ", I can warm you? ;)");
                        stop = 0;
                    }
                    else if((word=="hi") || (word=="hello")) 
                    { 
                        llSay(0,word + " " + name + " :)");
                        stop = 0;
                    }
                    else if((word=="cya") || (word=="bye") || (word=="goodbye")) 
                    { 
                        llSay(0,word + " " + name + " :)");
                        stop = 0;
                    }
                    else if((word=="food") || (word=="eat") || (word=="ate")) 
                    { 
                        float rnd = llFrand(10.0);
                        if(rnd < 5) { llSay(0,"Food!! I luv FISH !");}
                        else { llSay(0,name + ", your making me feel hungry ;P");}
                        stop = 0;
                    }
                    else if(word=="butt") 
                    { 
                        llSay(0,"Mine is cute ;)");
                        stop = 0;
                    }
                    else if(word=="hell") 
                    { 
                        llSay(0,"That's HOT! ;)");
                        stop = 0;
                    }
                } while(stop != 0);
            }
        }
    }
    
    touch_start(integer num)
    {
        integer choice = (integer)llFrand(5.0);
        if(choice == 1) { llSay(0,"Where are the fish?");}
        else if(choice == 2) { llSay(0,"This Tux itches !!");}
        else if(choice == 3) { llSay(0,"I'm frozen again, Dang connection !!");}
        else if(choice == 4) { llSay(0,"That tickles, hehe");}
        else if(choice == 5) { llSay(0,"Looks cold down there !");}
        else { llSay(0,"You spotted dinner yet ?");}
    }                

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

Просмотров: 900 | Добавил: volldemar | Рейтинг: 0.0/0 |
Всего комментариев: 0
Имя *:
Email *:
Код *:
Copyright MyCorp © 2025
Сайт управляется системой uCoz