Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Roz Wright's "One Lollipop To a Customer" Script
- //A combination of and a complete PG rewrite of NawtieNitey's
- //"Candybags" script and Evie Moriguchi's "VaGatcha" scripts.
- //Like "Candybags" and "VaGacha", this script can be placed in any
- //non-rigged attachment, if you want a simple no-HUD on-touch sol-
- //ution. The "Candybags" scripts are also now on pastebin.com.
- //This script is designed to discourage visitors from abusing your
- //free gift system by repeatedly clicking the dispenser. The script
- //can randomly select between several gifts, or give the same gift
- //to every visitor. Type "alert" in the description field (in Edit)
- //of the dispenser to be alerted to visitors touching the dispenser.
- integer visitCycle = 60; //Try to keep this number reasonably low
- // You want to discourage visitors from abusing the free gift system
- // not store a list of partial avatar keys for eternity.
- string curr_id;
- string prev_id;
- list past_users;
- string itemName;
- integer itemcount;
- integer gift;
- integer alertMe (string ObjDesc)
- {
- //AlertMe checks to see if you have the word "alert" in your
- //dispenser's "description" field. If you do, it returns a
- //TRUE value and you're alerted to someone touching your dis-
- //penser.
- integer giveAlert = FALSE;
- ObjDesc = llToLower(ObjDesc);
- //and here's where the magic happens...
- if (llSubStringIndex(ObjDesc, "alert") != -1) giveAlert = TRUE;
- //I don't need an "else" statement, giveAlert is already FALSE.
- return giveAlert;
- //llSubStringIndex and llGetObjectDesc are an easy way to allow
- //the user to change a simple single parameter without notecards,
- //menus, or opening a listen channel.
- //...and using llGetObjectDetails(id,[OBJECT_DESC]) is a nifty way
- //for an object to pull communication from other unlinked objects
- //without requiring a listen channel. Just saying...
- }
- string ID_8 (key StoreID)
- {
- //ID_8 only stores the first 8 characters of a key in a string to
- //save memory. It's good for speeding up key to list comparisons but
- //not for much else.
- return llList2String(llParseString2List((string)StoreID, ["-"], []),0);
- //Okay, I lied...It's also pretty good for creating key based indexes,
- //where you can look up a partial UUID in a list, which can direct you
- //to additional information stored in other lists.
- }
- default
- {
- changed(integer change)
- //If you add or change gifts, this will let you know how many objects
- //are currently in your dispenser's inventory.
- {
- if (change & CHANGED_INVENTORY)
- {
- itemcount = llGetInventoryNumber(INVENTORY_OBJECT);
- llOwnerSay("There are now " + (string)itemcount + " objects in inventory.");
- }
- }
- touch_start(integer num_detected)
- {
- //Let's get the number of items in the dispenser
- itemcount = llGetInventoryNumber(INVENTORY_OBJECT);
- //Let's get the key for the avatar clicking the dispenser
- key commKey = llDetectedKey(0);
- //Let's prepare that key for comparison against a list of
- //recent visitors
- curr_id = ID_8 (commKey);
- //There are three conditionals that result in the visitor not
- //getting an item, so let's assume that the person may not be
- //getting a gift.
- gift = FALSE;
- //Check inventory and make sure there are actually items to give.
- if (itemcount==0)llInstantMessage(commKey, "Sorry, there are no items to give you at this time.");
- //Check to see if the visitor is repeatedly clicking the item.
- else if (curr_id == prev_id)llInstantMessage(commKey, "You have already been sent " + itemName +", please check your inventory.");
- //Check to see if the visitor has recently been given a gift.
- else if(~llListFindList(past_users, [curr_id]))
- {
- //singular
- if (itemcount==1)llInstantMessage(commKey, "Welcome back. This item is only available to new visitors at this time.");
- //plural
- else llInstantMessage(commKey, "Welcome back. These items are only available to new visitors at this time.");
- }
- //If this is a new visitor (or a really old one) give them a gift.
- else
- {
- //lets give our conditional a little buffer room so it doesn't have to move
- //around information in the list size every time it evaluates a new toucher.
- if (llGetListLength(past_users) > (visitCycle + 10)) llDeleteSubList(past_users, visitCycle, -1);
- //don't waste time on random gift selection if it's not neccessary.
- if (itemcount > 1)
- {
- integer randomIndex = (integer)llFrand(itemcount);
- itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
- }
- else itemName = llGetInventoryName(INVENTORY_OBJECT, 0);
- llInstantMessage (commKey, "Welcome, you are being sent " + itemName + " as our free gift!");
- llGiveInventory(commKey, itemName);
- //Let's set up a check to make sure the visitor isn't repeatedly
- //clicking the item.
- prev_id = curr_id;
- //Let's add their partial key to the list
- past_users = [prev_id] + past_users;
- //This person is getting a gift, let's set the "gift" flag to TRUE.
- gift = TRUE;
- }
- integer alert = alertMe (llGetObjectDesc());
- //Alert the owner that someone just received a gift.
- if (alert && gift) llInstantMessage(llGetOwner(),llDetectedName(0) + " was given " + itemName + ".");
- //Add a few slashes // to the next line if you don't want alerts on every touch
- else if (alert && !gift) llInstantMessage(llGetOwner(),llDetectedName(0) + " touched me.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement