News: SMF - Just Installed!
Welcome, Guest. Please login or register.
Did you miss your activation email?

 Raglan Shire ForumsRaglan ShireThe VaultScriptsTopic: Give Random Object on Touch - Trick or Treat :-D
Pages: [1]   Go Down
Print
Author Topic: Give Random Object on Touch - Trick or Treat :-D  (Read 927 times)
Vic Titanium
Friend of the Shire

Offline Offline

Posts: 1


Vic. Vic Titanium


View Profile
« on: October 12, 2009, 08:37:36 PM »

This is a variation of the give contents script on touch, what this does is it will randomly pick and object from the giver prim's contents (the one with the script) and give that.

I wrote this out for a mixed bag trick or treat giver for SHOCKTOBER!

Hopefully you guys can make use of it  Grin


Code:
//-- This script will give a random item in the prim with it except this script itself to anyone who touches the prim. ~ By: EatA Frankfurter
// Random single object giver mod by: Vic Titanium

list gItems;//This will be a list of all the items in this box except this script.

default
{
    changed(integer change)//if this changes
    {
        if(change & CHANGED_INVENTORY)//and that change was a change in inventory
        {
            gItems = [];//Clear the list
            integer i;//number we will increment for the loop
            for(i = 0; i < llGetInventoryNumber(INVENTORY_ALL); ++i)//do the following once for every item in this objects inventory
            {
                if(llGetInventoryName(INVENTORY_ALL, i) != llGetScriptName())//If the current item is not this script
                {
                    gItems += llGetInventoryName(INVENTORY_ALL, i);//add it to our list
                }
            }
        }
    }
    state_entry()//Whenever this script is changed or reset
    {
        llSetText("Trick or Treat Goodies!\nClick to receive a goodie", <1.0, 1.0, 1.0>, 1.0);
        //Add // at the beginning of the above line above to hide floaty text (to remove text set the message to "")
        integer i;//number we will increment for the loop
        for(i = 0; i < llGetInventoryNumber(INVENTORY_ALL); ++i)//do the following once for every item in this objects invnetory
        {
            if(llGetInventoryName(INVENTORY_ALL, i) != llGetScriptName())//If the current item is not this script
            {
                gItems += llGetInventoryName(INVENTORY_ALL, i);//add it to our list
            }
        }
    }
       
    touch_start(integer total)//when someone touches this
    {
        integer i;//number we will increment for each person touching this.
        for(i = 0; i < total; ++i)//do the following once for each person that touches this.
        {
            integer x = (integer)llFrand( llGetListLength( gItems ));
            llGiveInventory(llDetectedKey(i), llList2String( gItems, x ));
        }
    }
}
Logged
Bo Fiddlesticks
Friend of the Shire

Offline Offline

Posts: 73



View Profile
« Reply #1 on: October 12, 2009, 11:37:03 PM »

These are the things we're looking for, w00t!  Lips Sealed

Thanks for posting, Vic!
Logged

Otter of all trades
Kayak Kuu
Raglan U
Friend of the Shire

Offline Offline

Posts: 1



View Profile
« Reply #2 on: October 13, 2009, 02:10:44 PM »

This is a variation of the give contents script on touch, what this does is it will randomly pick and object from the giver prim's contents (the one with the script) and give that.
I wrote this out for a mixed bag trick or treat giver for SHOCKTOBER!
Hopefully you guys can make use of it  Grin

Woot,
Thanks Vic!
I'm looking forward to trying this out inworld.
Can we use it as part of a class Vic?

Kayak :-)
Logged

Otters Rule :-)
Vic Titanium
Friend of the Shire

Offline Offline

Posts: 1


Vic. Vic Titanium


View Profile
« Reply #3 on: October 16, 2009, 02:34:09 PM »

If you want to do a class on it, all OK by me (Im one of them open-source fans, share the knowledge and all that goodness).

but let me post up version 2, it includes a random greeting sayer...

I need to clean up the script first. be up this evening.  Cool
Logged
Vic Titanium
Friend of the Shire

Offline Offline

Posts: 1


Vic. Vic Titanium


View Profile
« Reply #4 on: October 16, 2009, 07:18:47 PM »

Here we go, with this one, you will now also need to have a Notecard also in the objects contents called "greetings", each line will be a message to the trick-or-treater, like:

Code:
Wow, nice costumes!
Aren't you a bit old to be trick-or-treating?
Here ya go.... Now what do you say?

and will be random, just like the treats.

Random Object Giver/Greeter v2.0 code:

Code:
//-- This script will give a random item in the prim with it except this script itself to anyone who touches the prim. ~ By: EatA Frankfurter
// Random and Greeter mods by Vic Titanium
// Free to use or copy, please pass along to friends.

// global variables

// You can change these:

string source = "greetings";  //name of the greetings list notecard

// the floating text above the giver object
string floattext = "Trick OR Treat Goodies\nClick to receive a goodie";

// ============================================================
// don't change past here if you don't know what you are doing.
// ============================================================

list gItems; // This will be a list of all the items in this box except this script.
string invitem; // inventory item for building the object inventory list
key lineNumber;  // lines in greeter card
list sourceData;  // greeter card data
integer randomLine; //line to read from greetings


// user defined function, build inventory list:

getInvList() {
    gItems = [];//Clear the list
    integer i;//number we will increment for the loop
    for(i = 0; i < llGetInventoryNumber(INVENTORY_ALL); ++i)//do the following once for every item in this objects inventory
    {
        if(llGetInventoryName(INVENTORY_ALL, i) != llGetScriptName())//If the current item is not this script
        {
            gItems += llGetInventoryName(INVENTORY_ALL, i);//add it to our list
        }
    }
}

//main loop

default
{
    changed(integer change)//if this changes
    {
        if(change & CHANGED_INVENTORY)//and that change was a change in inventory
        {
            sourceData = [];
            if ( llGetInventoryType( source ) == INVENTORY_NOTECARD )
            lineNumber = llGetNotecardLine(source, randomLine);

            getInvList();  // refresh inventorylist for giver
        }
    }
    state_entry()//Whenever this script is changed or reset
    {
        // random giver prep
        llSetText(floattext, <1.0, 1.0, 1.0>, 1.0);
        //Add // at the beginning of the line above to hide text above the prim (to just remove text set floattext to "")

        getInvList();  // build inventory list for giver
        // random greeting prep
        randomLine = 0;
        sourceData = [];
        if ( llGetInventoryType( source ) == INVENTORY_NOTECARD ) // is there a notecard?
        {
            lineNumber = llGetNotecardLine(source, randomLine);  //open it
        }
    }
    // triggered by llGetNotecardLine will loop till end of file.
    dataserver(key query_id, string data){
        if (query_id == lineNumber)
        {
            if (data != EOF)
            {
                sourceData = (sourceData=[]) + sourceData + data;
                randomLine++ ;
                lineNumber = llGetNotecardLine(source, randomLine);
            }
            else
            {
                llOwnerSay( (string)randomLine+" lines read from card: "+ source );
            }
        }
    }

    touch_start(integer total)//when someone touches this
    {
        // whisper a random greeting
        integer x = (integer)llFrand( llGetListLength( sourceData ));
        llWhisper( PUBLIC_CHANNEL, llList2String( sourceData, x ));

        //give arandom item
        integer i;//number we will increment for each person touching this.
        for(i = 0; i < total; ++i)//do the following once for each person that touches this.
        {
            integer x = (integer)llFrand( llGetListLength( gItems ));
            llGiveInventory(llDetectedKey(i), llList2String( gItems, x ));
        }
    }
}


Enjoy!  Wink
Logged
Azelle Mavendorf
Friend of the Shire

Offline Offline

Posts: 75



View Profile
« Reply #5 on: October 19, 2009, 10:48:09 PM »

A small edit so that the greetings notecard is not given out Smiley

Code:
//-- This script will give a random item in the prim with it except this script itself to anyone who touches the prim. ~ By: EatA Frankfurter
// Random and Greeter mods by Vic Titanium
// Free to use or copy, please pass along to friends.

// global variables

// You can change these:

string source = "greetings";  //name of the greetings list notecard

// the floating text above the giver object
string floattext = "Trick or Treat Goodies\nClick to receive a goodie";

// ============================================================
// don't change past here if you don't know what you are doing.
// ============================================================

list gItems; // This will be a list of all the items in this box except this script.
string invitem; // inventory item for building the object inventory list
key lineNumber;  // lines in greeter card
list sourceData;  // greeter card data
integer randomLine; //line to read from greetings


// user defined function, build inventory list:

getInvList() {
    gItems = [];//Clear the list
    integer i;//number we will increment for the loop
    for(i = 0; i < llGetInventoryNumber(INVENTORY_ALL); ++i)//do the following once for every item in this objects inventory
    {
        if(llGetInventoryName(INVENTORY_ALL, i) != llGetScriptName())//If the current item is not this script
        {
            if(llGetInventoryName(INVENTORY_ALL, i) != source){//and is not the greetings notecard
                gItems += llGetInventoryName(INVENTORY_ALL, i);//add it to our list
            }
        }
    }
}

//main loop

default
{
    changed(integer change)//if this changes
    {
        if(change & CHANGED_INVENTORY)//and that change was a change in inventory
        {
            sourceData = [];
            if ( llGetInventoryType( source ) == INVENTORY_NOTECARD )
            lineNumber = llGetNotecardLine(source, randomLine);

            getInvList();  // refresh inventorylist for giver
        }
    }
    state_entry()//Whenever this script is changed or reset
    {
        // random giver prep
        llSetText(floattext, <1.0, 1.0, 1.0>, 1.0);
        //Add // at the beginning of the line above to hide text above the prim (to just remove text set floattext to "")

        getInvList();  // build inventory list for giver
        // random greeting prep
        randomLine = 0;
        sourceData = [];
        if ( llGetInventoryType( source ) == INVENTORY_NOTECARD ) // is there a notecard?
        {
            lineNumber = llGetNotecardLine(source, randomLine);  //open it
        }
    }
    // triggered by llGetNotecardLine will loop till end of file.
    dataserver(key query_id, string data){
        if (query_id == lineNumber)
        {
            if (data != EOF)
            {
                sourceData = (sourceData=[]) + sourceData + data;
                randomLine++ ;
                lineNumber = llGetNotecardLine(source, randomLine);
            }
            else
            {
                llOwnerSay( (string)randomLine+" lines read from card: "+ source );
            }
        }
    }

    touch_start(integer total)//when someone touches this
    {
        // whisper a random greeting
        integer x = (integer)llFrand( llGetListLength( sourceData ));
        llWhisper( PUBLIC_CHANNEL, llList2String( sourceData, x ));

        //give arandom item
        integer i;//number we will increment for each person touching this.
        for(i = 0; i < total; ++i)//do the following once for each person that touches this.
        {
            integer x = (integer)llFrand( llGetListLength( gItems ));
            llGiveInventory(llDetectedKey(i), llList2String( gItems, x ));
        }
    }
}
Logged

Pages: [1]   Go Up
Print
 Raglan Shire ForumsRaglan ShireThe VaultScriptsTopic: Give Random Object on Touch - Trick or Treat :-D
Jump to: