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:
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:
//-- 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!
