Sell To Group Only ( V2 )

Written by Kitsune

This is a simple GROUP ONLY vendor script. It can be used to GIVE FREE items to group only too.

    https://d1yjxggot69855.cloudfront.net/skins/monobook/bullet.gif); color: rgb(0, 0, 0); font-family: verdana, helvetica, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">
  • THIS SCRIPT WILL ASK FOR DEBIT PERMISSIONS. THEY MUST BE GRANTED FOR THE SCRIPT TO FUNCTION. L$ WILL BE TAKEN FROM THE OBJECT OWNERS ACCOUNT.
      https://d1yjxggot69855.cloudfront.net/skins/monobook/bullet.gif); ">
    • The debit permissions are required for making refunds in the event of an over or under payment or a payment being made by a non group member.
      • // V2 //
         
        integer cost = 0; // The cost of the contents of this object (A whole round number (No decimal places)).
                          // If this is set to zero, the object will act as a group only freebie giver, however...
                          // ...it will still ask for permissions to debit.
         
        string folder_name = "Folder"; // The Name of the folder in which to give the contents.
         
        integer offer_group_join = TRUE; // Set TRUE or FALSE to offer group membership link on failed purchase attempt.
         
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////// YOU NEED NOT CHANGE ANYTHING BELOW THIS POINT /////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         
        list contents_list = [];
         
        string group_name;
         
        key group_key;
         
        key owner;
         
        default
        {
            on_rez(integer param)
            {
                llResetScript();
            }
            changed(integer change)
            {
                if(change & (CHANGED_OWNER | CHANGED_INVENTORY))
                llResetScript();
            }
            state_entry()
            {
                llSetClickAction(CLICK_ACTION_TOUCH);
                llRequestPermissions((owner = llGetOwner()), PERMISSION_DEBIT);
            }
            run_time_permissions(integer perm)
            {
                if(perm & PERMISSION_DEBIT)
                {
                    integer in = llGetInventoryNumber(INVENTORY_ALL);
                    integer count;
                    string name;
                    do
                    {
                        if((name = llGetInventoryName(INVENTORY_ALL, count)) != llGetScriptName())
                        contents_list += [name];
                    }
                    while((++count) < in);
                    if(llGetListLength(contents_list))
                    {
                        if((group_key = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0)) == NULL_KEY)
                        {
                            llOwnerSay("You NEED to set this object to a group in order to have it sell contents ONLY to that group." +
                                       "\nThis script is resetting. You will need to grant debit permissions again." +
                                       "\n!! ONLY DO THAT AFTER SETTING THIS OBJECT TO THE DESIRED GROUP !!");
                            llResetScript();
                        }
                        else
                        llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
                    }
                    else
                    {
                        llOwnerSay("There are no contents. This object cannot sell thin air. There is no air in SL." +
                                   "\nPlease add the contents to sell." +
                                   "\n!! ONLY RE-GRANT PERMISSIONS WHEN ALL CONTENTS ARE ADDED !!");
                    }
                }
                else
                {
                    llOwnerSay("You MUST grant permissions for this script to function.");
                    llRequestPermissions(owner, PERMISSION_DEBIT);
                }
            }
            http_response(key q, integer status, list metadata, string body)
            {
                if(status == 200)
                {
                    llOwnerSay("This object is set to the group - " +
                               (group_name = llGetSubString(body, (llSubStringIndex(body, "") + 7),
                                                                  (llSubStringIndex(body, "") - 1))) +
                               "\nOnly members of that group will be able to buy this objects contents." +
                               "\nContents for sale - \n" + llDumpList2String(contents_list, "\n") +
                               "\nPrice is " + ((string)cost) + "L$");
                    if(cost)
                    {
                        llSetClickAction(CLICK_ACTION_PAY);
                        llSetPayPrice(PAY_HIDE, [cost, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                        state shoptastic;
                    }
                    else
                    state freebietastic;
                }
                else
                {
                    llOwnerSay("HTTP Request failed. Trying again in 45 seconds. Please wait.");
                    llSleep(45.0);
                    llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
                }
            }
        }
        state freebietastic
        {
            on_rez(integer param)
            {
                llResetScript();
            }
            changed(integer change)
            {
                if(change & (CHANGED_OWNER | CHANGED_INVENTORY))
                llResetScript();
            }
            touch_start(integer nd)
            {
                while(nd)
                {
                    key id = llDetectedKey(--nd);
                    if(llSameGroup(id))
                    llGiveInventoryList(id, folder_name, contents_list);
                    else
                    {
                        string msg = "";
                        if(offer_group_join)
                        msg = "\nYou can join this group by clicking this - \nsecondlife:///app/group/" + ((string)group_key) + "/about";
                        llRegionSayTo(id, 0, "Sorry, this vendor is set to give only to " + group_name + " group members." + msg);
                    }
                }
            }
        }
        state shoptastic
        {
            on_rez(integer param)
            {
                llResetScript();
            }
            changed(integer change)
            {
                if(change & (CHANGED_OWNER | CHANGED_INVENTORY))
                llResetScript();
            }
            money(key id, integer amount)
            {
                if(llSameGroup(id))
                {
                    if(amount >= cost)
                    {
                        if(amount > cost)
                        llGiveMoney(id, (amount - cost));
                        llGiveInventoryList(id, folder_name, contents_list);
                    }
                    else if(amount < cost)
                    {
                        llGiveMoney(id, amount);
                        llRegionSayTo(id, 0, "Sorry, you paid to little.\nThe cost is " + ((string)cost) + "L$");
                    }
                }
                else
                {
                    llGiveMoney(id, amount);
                    string msg = "";
                    if(offer_group_join)
                    msg = "\nYou can join this group by clicking this - \nsecondlife:///app/group/" + ((string)group_key) + "/about";
                    llRegionSayTo(id, 0, "Sorry, this vendor is set to sell only to " + group_name + " group members." + msg);
                }
            }
        }