Difference between revisions of "AntiDelay Node"

From Second Life Wiki
Jump to navigation Jump to search
(Page Created)
 
m (<lsl> tag to <source>)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LSL Header}}
Almost every function in Second Life has a delay associated with it. Ranging from 20 seconds to .2 seconds - delays can get on anyones' nerves. Even the most basic scripters know the easy way to get around this is to have a script and use llMessageLinked to tell it to do something. Below is a more advanced version of that code - that allows for one script to handle almost any type of function with a delay.
Almost every function in Second Life has a delay associated with it. Ranging from 20 seconds to .2 seconds - delays can get on anyones' nerves. Even the most basic scripters know the easy way to get around this is to have a script and use llMessageLinked to tell it to do something. Below is a more advanced version of that code - that allows for one script to handle almost any type of function with a delay.


How To Use:
How To Use:
Use llMessageLinked - the integer is -123, the string is the list of arguments seperated by "|||", and the key is the name of the function.
Use llMessageLinked - the integer is -123, the string is the list of arguments seperated by <nowiki>"~~~"</nowiki>, and the key is the name of the function.
 
<source lang="lsl2">
default
{
    touch_start(integer num_detected)
    {
        string ownerKeyAsString = (string)llGetOwner();


<pre>
         llMessageLinked(LINK_SET, -123,
default {
            ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
    touch_start(integer total_number) {
        string s = llGetOwner();
         llMessageLinked(LINK_SET, -123, s + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
     }
     }
}
}
</pre>
</source>
 
<source lang="lsl2">
default
{
    touch_start(integer num_detected)
    {
        vector currentPosition = llGetPos();
        vector targetPosition =  <128, 128, 300>;
 
        float vectorDistance = ( llVecDist(currentPosition, targetPosition) / 5) + 1;


<pre>
         integer index;
default {
         do
    touch_start(integer total_number) {
         {
        vector v =  <128,128,300>;
             llMessageLinked(LINK_SET, -123, (string)vectorDistance, "setpos");
         integer i = 0;
        float vecDist = llVecDist(llGetPos(), v);
         vecDist /= 5;
         vecDist += 1;
        while (i < vecDist) {
             llMessageLinked(LINK_SET, -123, (string)v, "setpos");
            i++;
         }
         }
        while (++index < vectorDistance);
     }
     }
}
}
</pre>
</source>


And now for the full and complete power of this code *drum roll*. Only 2 scripts are needed for the following code to work.
And now for the full and complete power of this code *drum roll*. Only 2 scripts are needed for the following code to work.
<pre>
<source lang="lsl2">
default {
default
     touch_start(integer total_number) {
{
         string s = llGetOwner();
     touch_start(integer num_detected)
         llMessageLinked(LINK_SET, -123, s + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
    {
         string ownerKeyAsString = (string)llGetOwner();
        float sleepPeriodInSeconds = 1.0;
 
         llMessageLinked(LINK_SET, -123, ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
         llMessageLinked(LINK_SET, -123, "youemail@theaddress.com~~~Subj~~~Body", "email");
         llMessageLinked(LINK_SET, -123, "youemail@theaddress.com~~~Subj~~~Body", "email");
         llSleep(1);
 
         llMessageLinked(LINK_SET, -123, s + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
         llSleep(sleepPeriodInSeconds);
         llSleep(1);
 
         llMessageLinked(LINK_SET, -123, ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
 
         llSleep(sleepPeriodInSeconds);
 
         llMessageLinked(LINK_SET, -123, "youemail@theaddress.com~~~Subj~~~Body", "email");
         llMessageLinked(LINK_SET, -123, "youemail@theaddress.com~~~Subj~~~Body", "email");
          
          
     }
     }
}
}
</pre>
</source>


The code to make it all work:
The code to make it all work:
Line 49: Line 67:


AntiDelay Node Manager:
AntiDelay Node Manager:
<pre>
<source lang="lsl2">
list l = [];
list l;
list functions = ["email", "loadurl", "teleportagenthome", "remoteloadscriptpin", "remotedatareply", "giveinventorylist",  
 
                  "setparcelmusicurl", "instantmessage", "preloadsound", "mapdestination", "dialog", "createlink", "setpos",
list functions = ["email", "loadurl", "teleportagenthome", "remoteloadscriptpin",
                  "setrot", "settexture", "rezobject"];
                    "remotedatareply", "giveinventorylist", "setparcelmusicurl", "instantmessage",
list delays = [20000, 10000, 5000, 3000, 3000, 2000, 2000, 1000, 1000, 1000, 1000, 1000, 200, 200, 200, 100];
                    "preloadsound", "mapdestination", "dialog", "createlink",
                    "setpos", "setrot", "settexture", "rezobject"];
 
list delays = [20000, 10000, 5000, 3000,
                3000, 2000, 2000, 1000,
                1000, 1000, 1000, 1000,
                200, 200, 200, 100];
 
integer count = 1;
integer count = 1;
integer time() {
 
integer time()
{
     string stamp = llGetTimestamp();
     string stamp = llGetTimestamp();
     return (integer) llGetSubString(stamp, 11, 12) * 3600000 +
     return (integer) llGetSubString(stamp, 11, 12) * 3600000 +
           (integer) llGetSubString(stamp, 14, 15) * 60000 +
           (integer) llGetSubString(stamp, 14, 15) * 60000 +
           llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000;
           llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000;
}
}
integer nextFreeScript() {
 
     integer i = 0;
integer nextFreeScript()
     integer curTime = time();
{
     while (i < llGetListLength(l)) {
     integer curTime = llList2Integer(l, i) - time();
         if (llList2Integer(l, i) - curTime <= 0) {
 
             return i;
     integer index;
        }
     do
        ++i;
    {
         if (timeLeft <= 0)
//      {
             return index;
//      }
     }
     }
    while (++index < llGetListLength(l));
     return -1;
     return -1;
}
}


default {
default
     state_entry() {
{
     state_entry()
    {
         llMessageLinked(LINK_SET, -112, "", "");
         llMessageLinked(LINK_SET, -112, "", "");
         llSleep(1);
 
         llSleep(1.0);
 
         llMessageLinked(LINK_SET, -111, "", "");
         llMessageLinked(LINK_SET, -111, "", "");
     }
     }
     link_message(integer send, integer i, string s, key k) {
 
         if (i == -2) {
     link_message(integer sender_num, integer num, string str, key id)
             llMessageLinked(LINK_SET, (integer)s, (string)count, "");
    {
         if (num == -2)
        {
             llMessageLinked(LINK_SET, (integer)str, (string)count, "");
 
             ++count;
             ++count;
             l += time();
 
             llSetTimerEvent(6);
             l += [time()];
 
             llSetTimerEvent(6.0);
         }
         }
     }
     }
     timer() {
 
     timer()
    {
         state run;
         state run;
     }
     }
}
}


state run {
state run
    state_entry() {
{
    }
//  state_entry()
     link_message(integer send, integer i, string s, key k) {
//  {
         if (i == -123) {
//      ;
//  }
 
     link_message(integer sender_num, integer num, string str, key id)
    {
         if (num == -123)
        {
             llOwnerSay("A");
             llOwnerSay("A");
             integer d = llList2Integer(delays, llListFindList(functions, [(string)k]));
 
             integer d = llList2Integer(delays, llListFindList(functions, [(string)id]));
             integer ii = nextFreeScript();
             integer ii = nextFreeScript();
             l = llListReplaceList(l, [time() + d], ii, ii);
             l = llListReplaceList(l, [time() + d], ii, ii);
             llMessageLinked(LINK_SET, ii+1, s, k);
 
             llMessageLinked(LINK_SET, ii + 1, str, id);
         }
         }
     }
     }
}
}
</pre>
</source>






AntiDelay Node:
AntiDelay Node:
<pre>
<source lang="lsl2">
integer myId;
integer myId;
default {
 
     link_message(integer send, integer i, string s, key k) {
default
        if (i == myId && myId) {
{
            myId = (integer)s;
     link_message(integer sender_num, integer num, string str, key id)
            state run;
    {
        }
         if (num == -111)
         if (i == -111) {
        {
             myId = (integer)llFrand(0x7FFFFFFF);
             myId = (integer)llFrand(0x7FFFFFFF);
             llSleep(llFrand(5));
 
             llSleep(llFrand(5.0));
 
             llMessageLinked(LINK_SET, -2, (string)myId, "");
             llMessageLinked(LINK_SET, -2, (string)myId, "");
        }
        else if (num == myId && myId)
        {
            myId = (integer)str;
            state run;
         }
         }
     }
     }
}
}


state run {
state run
     link_message(integer send, integer i, string s, key k) {
{
         list params = llParseString2List(s, ["~~~"], []);
     link_message(integer sender_num, integer num, string str, key id)
         if (i == myId && myId) {
    {
            if (llToLower(k) == "email") {
         list params = llParseString2List(str, ["~~~"], []);
                llEmail(llList2String(params, 0),
 
                    llList2String(params, 1),
         if (num == -112)
                    llList2String(params, 2));
        {
            }
             llResetScript();
            if (llToLower(k) == "loadurl") {
             return;
                llLoadURL((key)llList2String(params, 0),
                    llList2String(params, 1),
                    llList2String(params, 2));
            }
            if (llToLower(k) == "teleportagenthome") {
                llTeleportAgentHome((key)llList2String(params, 0));
            }
            if (llToLower(k) == "remoteloadscriptpin") {
                llRemoteLoadScriptPin((key)llList2String(params, 0),
                    llList2String(params, 1),
                    (integer)llList2String(params, 2),
                    (integer)llList2String(params, 3),
                    (integer)llList2String(params, 4));
            }
            if (llToLower(k) == "remotedatareply") {
                llRemoteDataReply((key)llList2String(params, 0),
                    (key)llList2String(params, 1),
                    llList2String(params, 2),
                    (integer)llList2String(params, 3));
             }
            if (llToLower(k) == "giveinventorylist") {
                llGiveInventoryList((key)llList2String(params, 0),
                    llList2String(params, 1),
                    llCSV2List(llList2String(params, 2)));
             }
            if (llToLower(k) == "setparcelmusicurl") {
                llSetParcelMusicURL(llList2String(params, 0));
            }
            if (llToLower(k) == "instantmessage") {
                llInstantMessage((key)llList2String(params, 0),
                    llList2String(params, 1));
            }
            if (llToLower(k) == "preloadsound") {
                llPreloadSound(llList2String(params, 0));
            }
            if (llToLower(k) == "mapdestination") {
                llMapDestination(llList2String(params, 0),
                    (vector)llList2String(params, 1),
                    (vector)llList2String(params, 2));
            }
            if (llToLower(k) == "dialog") {
                llDialog((key)llList2String(params, 0),
                    llList2String(params, 1),
                    llCSV2List(llList2String(params, 2)),
                    (integer)llList2String(params, 3));
            }
            if (llToLower(k) == "createlink") {
                llCreateLink((key)llList2String(params, 0),
                    (integer)llList2String(params, 1));
            }
            if (llToLower(k) == "setpos") {
                llSetPos((vector)llList2String(params, 0));
            }
            if (llToLower(k) == "setrot") {
                llSetRot((rotation)llList2String(params, 0));
            }
            if (llToLower(k) == "settexture") {
                llSetTexture(llList2String(params, 0),
                    (integer)llList2String(params, 1));
            }
            if (llToLower(k) == "rezobject") {
                llRezObject(llList2String(params, 0),
                    (vector)llList2String(params, 1),
                    (vector)llList2String(params, 2),
                    (rotation)llList2String(params, 3),
                    (integer)llList2String(params, 4));
            }
         }
         }
         if (i == -112) {
 
             llResetScript();
        if (num != myId || !myId)
            return;
 
        string lowerId = llToLower( (string)id );
        string firstParam = llList2String(params, 0);
        string secondParam = llList2String(params, 1);
        string thirdParam = llList2String(params, 2);
        string fourthParam = llList2String(params, 3);
        string fifthParam = llList2String(params, 4);
 
        if (lowerId == "email")
        {
            llEmail(firstParam, secondParam, thirdParam);
        }
        else if (lowerId == "loadurl")
        {
            llLoadURL((key)firstParam, secondParam, thirdParam);
        }
        else if (lowerId == "teleportagenthome")
        {
            llTeleportAgentHome((key)firstParam);
        }
        else if (lowerId == "remoteloadscriptpin")
        {
            llRemoteLoadScriptPin((key)firstParam, secondParam,
                (integer)thirdParam,
                (integer)fourthParam,
                (integer)fifthParam);
        }
        else if (lowerId == "remotedatareply")
        {
            llRemoteDataReply((key)firstParam, (key)secondParam,
                thirdParam, (integer)fourthParam);
        }
        else if (lowerId == "giveinventorylist")
        {
            llGiveInventoryList((key)firstParam,
                secondParam, llCSV2List(thirdParam));
        }
        else if (lowerId == "setparcelmusicurl")
        {
            llSetParcelMusicURL(firstParam);
        }
        else if (lowerId == "instantmessage")
        {
            llInstantMessage((key)firstParam, secondParam);
        }
         else if (lowerId == "preloadsound")
        {
             llPreloadSound(firstParam);
        }
        else if (lowerId == "mapdestination")
        {
            llMapDestination(firstParam,
                (vector)secondParam,
                (vector)thirdParam);
        }
        else if (lowerId == "dialog")
        {
            llDialog((key)firstParam, secondParam,
                llCSV2List(thirdParam), (integer)fourthParam);
        }
        else if (lowerId == "createlink")
        {
            llCreateLink((key)firstParam, (integer)secondParam);
        }
        else if (lowerId == "setpos")
        {
            llSetPos((vector)firstParam);
        }
        else if (lowerId == "setrot")
        {
            llSetRot((rotation)firstParam);
        }
        else if (lowerId == "settexture")
        {
            llSetTexture(firstParam, (integer)secondParam);
        }
        else if (lowerId == "rezobject")
        {
            llRezObject(firstParam, (vector)secondParam, (vector)thirdParam,
                (rotation)fourthParam, (integer)fifthParam);
         }
         }
     }
     }
}
}
</pre>
</source>
{{LSLC|Library}}

Latest revision as of 18:19, 24 January 2015

Almost every function in Second Life has a delay associated with it. Ranging from 20 seconds to .2 seconds - delays can get on anyones' nerves. Even the most basic scripters know the easy way to get around this is to have a script and use llMessageLinked to tell it to do something. Below is a more advanced version of that code - that allows for one script to handle almost any type of function with a delay.

How To Use: Use llMessageLinked - the integer is -123, the string is the list of arguments seperated by "~~~", and the key is the name of the function.

default
{
    touch_start(integer num_detected)
    {
        string ownerKeyAsString = (string)llGetOwner();

        llMessageLinked(LINK_SET, -123,
            ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
    }
}
default
{
    touch_start(integer num_detected)
    {
        vector currentPosition = llGetPos();
        vector targetPosition =  <128, 128, 300>;

        float vectorDistance = ( llVecDist(currentPosition, targetPosition) / 5) + 1;

        integer index;
        do
        {
            llMessageLinked(LINK_SET, -123, (string)vectorDistance, "setpos");
        }
        while (++index < vectorDistance);
    }
}

And now for the full and complete power of this code *drum roll*. Only 2 scripts are needed for the following code to work.

default
{
    touch_start(integer num_detected)
    {
        string ownerKeyAsString = (string)llGetOwner();
        float sleepPeriodInSeconds = 1.0;

        llMessageLinked(LINK_SET, -123, ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
        llMessageLinked(LINK_SET, -123, "youemail@theaddress.com~~~Subj~~~Body", "email");

        llSleep(sleepPeriodInSeconds);

        llMessageLinked(LINK_SET, -123, ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");

        llSleep(sleepPeriodInSeconds);

        llMessageLinked(LINK_SET, -123, "youemail@theaddress.com~~~Subj~~~Body", "email");
        
    }
}

The code to make it all work:


AntiDelay Node Manager:

list l;

list functions = ["email", "loadurl", "teleportagenthome", "remoteloadscriptpin",
                    "remotedatareply", "giveinventorylist", "setparcelmusicurl", "instantmessage",
                    "preloadsound", "mapdestination", "dialog", "createlink",
                    "setpos", "setrot", "settexture", "rezobject"];

list delays = [20000, 10000, 5000, 3000,
                3000, 2000, 2000, 1000,
                1000, 1000, 1000, 1000,
                200, 200, 200, 100];

integer count = 1;

integer time()
{
    string stamp = llGetTimestamp();

    return (integer) llGetSubString(stamp, 11, 12) * 3600000 +
           (integer) llGetSubString(stamp, 14, 15) * 60000 +
           llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000;
}

integer nextFreeScript()
{
    integer curTime = llList2Integer(l, i) - time();

    integer index;
    do
    {
        if (timeLeft <= 0)
//      {
            return index;
//      }
    }
    while (++index < llGetListLength(l));

    return -1;
}

default
{
    state_entry()
    {
        llMessageLinked(LINK_SET, -112, "", "");

        llSleep(1.0);

        llMessageLinked(LINK_SET, -111, "", "");
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == -2)
        {
            llMessageLinked(LINK_SET, (integer)str, (string)count, "");

            ++count;

            l += [time()];

            llSetTimerEvent(6.0);
        }
    }

    timer()
    {
        state run;
    }
}

state run
{
//  state_entry()
//  {
//      ;
//  }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == -123)
        {
            llOwnerSay("A");

            integer d = llList2Integer(delays, llListFindList(functions, [(string)id]));
            integer ii = nextFreeScript();

            l = llListReplaceList(l, [time() + d], ii, ii);

            llMessageLinked(LINK_SET, ii + 1, str, id);
        }
    }
}


AntiDelay Node:

integer myId;

default
{
    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == -111)
        {
            myId = (integer)llFrand(0x7FFFFFFF);

            llSleep(llFrand(5.0));

            llMessageLinked(LINK_SET, -2, (string)myId, "");
        }
        else if (num == myId && myId)
        {
            myId = (integer)str;
            state run;
        }
    }
}

state run
{
    link_message(integer sender_num, integer num, string str, key id)
    {
        list params = llParseString2List(str, ["~~~"], []);

        if (num == -112)
        {
            llResetScript();
            return;
        }

        if (num != myId || !myId)
            return;

        string lowerId = llToLower( (string)id );
        string firstParam = llList2String(params, 0);
        string secondParam = llList2String(params, 1);
        string thirdParam = llList2String(params, 2);
        string fourthParam = llList2String(params, 3);
        string fifthParam = llList2String(params, 4);

        if (lowerId == "email")
        {
            llEmail(firstParam, secondParam, thirdParam);
        }
        else if (lowerId == "loadurl")
        {
            llLoadURL((key)firstParam, secondParam, thirdParam);
        }
        else if (lowerId == "teleportagenthome")
        {
            llTeleportAgentHome((key)firstParam);
        }
        else if (lowerId == "remoteloadscriptpin")
        {
            llRemoteLoadScriptPin((key)firstParam, secondParam,
                (integer)thirdParam,
                (integer)fourthParam,
                (integer)fifthParam);
        }
        else if (lowerId == "remotedatareply")
        {
            llRemoteDataReply((key)firstParam, (key)secondParam,
                thirdParam, (integer)fourthParam);
        }
        else if (lowerId == "giveinventorylist")
        {
            llGiveInventoryList((key)firstParam,
                secondParam, llCSV2List(thirdParam));
        }
        else if (lowerId == "setparcelmusicurl")
        {
            llSetParcelMusicURL(firstParam);
        }
        else if (lowerId == "instantmessage")
        {
            llInstantMessage((key)firstParam, secondParam);
        }
        else if (lowerId == "preloadsound")
        {
            llPreloadSound(firstParam);
        }
        else if (lowerId == "mapdestination")
        {
            llMapDestination(firstParam,
                (vector)secondParam,
                (vector)thirdParam);
        }
        else if (lowerId == "dialog")
        {
            llDialog((key)firstParam, secondParam,
                llCSV2List(thirdParam), (integer)fourthParam);
        }
        else if (lowerId == "createlink")
        {
            llCreateLink((key)firstParam, (integer)secondParam);
        }
        else if (lowerId == "setpos")
        {
            llSetPos((vector)firstParam);
        }
        else if (lowerId == "setrot")
        {
            llSetRot((rotation)firstParam);
        }
        else if (lowerId == "settexture")
        {
            llSetTexture(firstParam, (integer)secondParam);
        }
        else if (lowerId == "rezobject")
        {
            llRezObject(firstParam, (vector)secondParam, (vector)thirdParam,
                (rotation)fourthParam, (integer)fifthParam);
        }
    }
}