Difference between revisions of "Give InvItem every n hours"

From Second Life Wiki
Jump to navigation Jump to search
m (language tags to <source>)
 
(4 intermediate revisions by 3 users not shown)
Line 2: Line 2:
This script will give an inventory item on touch only every n hours, even if somebody touches the object more than once.
This script will give an inventory item on touch only every n hours, even if somebody touches the object more than once.


<lsl>
<source lang="lsl2">
// Idea and written by Criz Collins
// Idea and written by Criz Collins
// Don't sell this FREE script!!!
// Don't sell this FREE script!!!
Line 34: Line 34:
         for (n=0; n<total_number; n++)
         for (n=0; n<total_number; n++)
         {
         {
             integer giveallowed = 0;
             integer giveallowed = FALSE;
             integer index = llListFindList( visitors, [ llDetectedKey(n) ] );
             integer index = llListFindList( visitors, [ llDetectedKey(n) ] );
             if (index == -1)
             if (index == -1)
Line 40: Line 40:
                 visitors = visitors + [ llDetectedKey(n) ];
                 visitors = visitors + [ llDetectedKey(n) ];
                 lastsent = lastsent + [(integer)llGetUnixTime()];
                 lastsent = lastsent + [(integer)llGetUnixTime()];
                 giveallowed = 1;
                 giveallowed = TRUE;
             }
             }
             else
             else
Line 50: Line 50:
                     lastsent = [];
                     lastsent = [];
                     lastsent = newlastsent;
                     lastsent = newlastsent;
                     giveallowed = 1;
                     giveallowed = TRUE;
                }
                else
                {
                    giveallowed = 0;
                 }
                 }
//              else giveallowed = FALSE;
             }
             }
             if (giveallowed == 1)
             if (giveallowed)// == TRUE
             {
             {
                 llGiveInventory(llDetectedKey(n), giveitem);
                 llGiveInventory(llDetectedKey(n), giveitem);
Line 64: Line 61:
     }
     }
}
}
</lsl>
</source>


[[User:Criz Collins|Criz Collins]] 11:14, 11 June 2008 (PDT)
[[User:Criz Collins|Criz Collins]] 11:14, 11 June 2008 (PDT)
{{visl
|Mentors=*
|LSL=*
}}
{{skills
|Builder=*
|Scripter=*
|}}


{{ISO 639-3/cat-speaking/Volunteers|deu}}
{{ISO 639-3/cat-speaking/Volunteers|eng}}
{{ISO 639-3/cat-speaking/Volunteers|gml}}
{{ISO 639-3/cat-speaking/Volunteers|gsg}}
{{ISO 639-3/cat-speaking/Volunteers|nds}}
{{ISO 639-3/cat-speaking|deu}}
{{ISO 639-3/cat-speaking|eng}}
{{ISO 639-3/cat-speaking|gml}}
{{ISO 639-3/cat-speaking|gsg}}
{{ISO 639-3/cat-speaking|nds}}
{{visl
    |Greeters=
    |Mentors=*
    |Helpers=
    |Instructors=
    |Scribe=
    |Linguist=
    |Buddy=*
    |ApprenticeBuddy=
    |Coach=
    |OrientationCoach=
|}}


{{LSLC|Library|Give InvItem every n hours}}
{{LSLC|Library|Give InvItem every n hours}}

Latest revision as of 20:02, 24 January 2015

This script will give an inventory item on touch only every n hours, even if somebody touches the object more than once.

// Idea and written by Criz Collins
// Don't sell this FREE script!!!

string  giveitem    =   "name of item in objects inventory";
float   giveevery   =   24;  // hours!

/////////////////////////////////////////////

list  visitors;
list lastsent;
integer n;

default
{
    on_rez( integer param )
    {
        llResetScript();
    }

    changed(integer change) 
    {
        if (change & CHANGED_INVENTORY) 
        {
            llResetScript();
        }
    }
    
    touch_start(integer total_number)
    {
        for (n=0; n<total_number; n++)
        {
            integer giveallowed = FALSE;
            integer index = llListFindList( visitors, [ llDetectedKey(n) ] );
            if (index == -1)
            {
                visitors = visitors + [ llDetectedKey(n) ];
                lastsent = lastsent + [(integer)llGetUnixTime()];
                giveallowed = TRUE;
            }
            else
            {
                if (llList2Integer(lastsent, index) <= ((integer)llGetUnixTime() - (giveevery * 60 * 60)))
                {
                    list replacer = [(integer)llGetUnixTime()];
                    list newlastsent = llListReplaceList(lastsent, replacer, index, index);
                    lastsent = [];
                    lastsent = newlastsent;
                    giveallowed = TRUE;
                }
//              else giveallowed = FALSE;
            }
            if (giveallowed)// == TRUE
            {
                llGiveInventory(llDetectedKey(n), giveitem);
            }
        }
    }
}

Criz Collins 11:14, 11 June 2008 (PDT)