Advertisement
Edie_Shoreland

Hey! One Gift to a Customer!

Mar 2nd, 2019
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Roz Wright's "One Lollipop To a Customer" Script
  2. //A combination of and a complete PG rewrite of NawtieNitey's
  3. //"Candybags" script and Evie Moriguchi's "VaGatcha" scripts.
  4.  
  5. //Like "Candybags" and "VaGacha", this script can be placed in any
  6. //non-rigged attachment, if you want a simple no-HUD on-touch sol-
  7. //ution. The "Candybags" scripts are also now on pastebin.com.
  8.  
  9. //This script is designed to discourage visitors from abusing your
  10. //free gift system by repeatedly clicking the dispenser. The script
  11. //can randomly select between several gifts, or give the same gift
  12. //to every visitor.  Type "alert" in the description field (in Edit)
  13. //of the dispenser to be alerted to visitors touching the dispenser.
  14.  
  15. integer visitCycle = 60; //Try to keep this number reasonably low
  16. // You want to discourage visitors from abusing the free gift system
  17. // not store a list of partial avatar keys for eternity.
  18.  
  19. string curr_id;
  20. string prev_id;
  21. list past_users;
  22. string itemName;
  23. integer itemcount;
  24. integer gift;
  25.  
  26. integer alertMe (string ObjDesc)
  27. {
  28.     //AlertMe checks to see if you have the word "alert" in your
  29.     //dispenser's "description" field.  If you do, it returns a
  30.     //TRUE value and you're alerted to someone touching your dis-
  31.     //penser.
  32.     integer giveAlert = FALSE;
  33.     ObjDesc = llToLower(ObjDesc);
  34.     //and here's where the magic happens...
  35.     if (llSubStringIndex(ObjDesc, "alert") != -1) giveAlert = TRUE;
  36.     //I don't need an "else" statement, giveAlert is already FALSE.
  37.     return giveAlert;
  38.     //llSubStringIndex and llGetObjectDesc are an easy way to allow
  39.     //the user to change a simple single parameter without notecards,
  40.     //menus, or opening a listen channel.
  41.     //...and using llGetObjectDetails(id,[OBJECT_DESC]) is a nifty way
  42.     //for an object to pull communication from other unlinked objects
  43.     //without requiring a listen channel.  Just saying...
  44. }
  45.  
  46. string ID_8 (key StoreID)
  47. {
  48.     //ID_8 only stores the first 8 characters of a key in a string to
  49.     //save memory. It's good for speeding up key to list comparisons but
  50.     //not for much else.
  51.     return llList2String(llParseString2List((string)StoreID, ["-"], []),0);
  52.     //Okay, I lied...It's also pretty good for creating key based indexes,
  53.     //where you can look up a partial UUID in a list, which can direct you
  54.     //to additional information stored in other lists.
  55. }
  56.    
  57. default
  58. {
  59.     changed(integer change)
  60.     //If you add or change gifts, this will let you know how many objects
  61.     //are currently in your dispenser's inventory.
  62.     {
  63.         if (change & CHANGED_INVENTORY)        
  64.         {
  65.             itemcount = llGetInventoryNumber(INVENTORY_OBJECT);
  66.             llOwnerSay("There are now " + (string)itemcount + " objects in inventory.");
  67.         }
  68.     }
  69.    
  70.     touch_start(integer num_detected)
  71.     {
  72.         //Let's get the number of items in the dispenser
  73.         itemcount = llGetInventoryNumber(INVENTORY_OBJECT);
  74.         //Let's get the key for the avatar clicking the dispenser
  75.         key commKey = llDetectedKey(0);
  76.         //Let's prepare that key for comparison against a list of
  77.         //recent visitors
  78.         curr_id = ID_8 (commKey);
  79.         //There are three conditionals that result in the visitor not
  80.         //getting an item, so let's assume that the person may not be
  81.         //getting a gift.
  82.         gift = FALSE;
  83.         //Check inventory and make sure there are actually items to give.
  84.         if (itemcount==0)llInstantMessage(commKey, "Sorry, there are no items to give you at this time.");
  85.         //Check to see if the visitor is repeatedly clicking the item.
  86.         else if (curr_id == prev_id)llInstantMessage(commKey, "You have already been sent " + itemName +", please check your inventory.");
  87.  
  88.         //Check to see if the visitor has recently been given a gift.
  89.         else if(~llListFindList(past_users, [curr_id]))
  90.         {
  91.             //singular
  92.             if (itemcount==1)llInstantMessage(commKey, "Welcome back. This item is only available to new visitors at this time.");
  93.             //plural
  94.             else llInstantMessage(commKey, "Welcome back. These items are only available to new visitors at this time.");
  95.         }
  96.        
  97.         //If this is a new visitor (or a really old one) give them a gift.
  98.         else
  99.         { 
  100.             //lets give our conditional a little buffer room so it doesn't have to move
  101.             //around information in the list size every time it evaluates a new toucher.
  102.             if (llGetListLength(past_users) > (visitCycle + 10)) llDeleteSubList(past_users, visitCycle, -1);
  103.             //don't waste time on random gift selection if it's not neccessary.
  104.             if (itemcount > 1)
  105.             {    
  106.                 integer randomIndex = (integer)llFrand(itemcount);
  107.                 itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
  108.             }
  109.             else itemName = llGetInventoryName(INVENTORY_OBJECT, 0);
  110.             llInstantMessage (commKey, "Welcome, you are being sent " + itemName + " as our free gift!");
  111.             llGiveInventory(commKey, itemName);
  112.             //Let's set up a check to make sure the visitor isn't repeatedly
  113.             //clicking the item.
  114.             prev_id = curr_id;
  115.             //Let's add their partial key to the list
  116.             past_users = [prev_id] + past_users;
  117.             //This person is getting a gift, let's set the "gift" flag to TRUE.
  118.             gift = TRUE;
  119.         }
  120.         integer alert = alertMe (llGetObjectDesc());
  121.         //Alert the owner that someone just received a gift.
  122.         if (alert && gift) llInstantMessage(llGetOwner(),llDetectedName(0) + " was given " + itemName + ".");
  123.         //Add a few slashes // to the next line if you don't want alerts on every touch
  124.         else if (alert && !gift) llInstantMessage(llGetOwner(),llDetectedName(0) + " touched me.");
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement