Drinkinsteins Gatcha Script

Written by: Headmaster
/////////////////////////////////////
/////////////////////////////////////
integer price = 15;  //SET PRICE HERE
/////////////////////////////////////
/////////////////////////////////////
//DrinkInstein Sorbet Open Source Gatcha Script. I am releasing this code under the Simplified BSD License.
//Copyright 2010 "Drinkinstein Sorbet" All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//     provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY "Drinkinstein Sorbet" ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL "Drinkinstein Sorbet OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of "Drinkinstein Sorbet".



key requestid;
string avatar;

default
{
    state_entry()
    {
        llSetPayPrice(PAY_HIDE, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        
    }
    touch_start(integer number)
    {   
        string id = llDetectedKey(0);
        string scriptname = llGetScriptName();
        llPlaySound("0e20b5f9-1b06-843e-446c-49fee8827448", 1.0);
        llInstantMessage(id, "Click pay to play the Gatcha!");
    }
    money(key id, integer amount) 
       {
        list items;
        list finalitems;
        string name;
        string stuff;
        string returnitem;
        integer num = llGetInventoryNumber(INVENTORY_ALL);
        integer finalnum = num - 1;
        string folder = llGetObjectName();
        integer i;
        integer min = 0;
        string scriptname = llGetScriptName();
        
        
        integer random = (integer)llFrand(finalnum);
        if(random == num) {
            random -= 1 ;
            }
        for (i = 0; i < num; ++i) {
            name = llGetInventoryName(INVENTORY_ALL, i);
            items += name;
            }
        integer placeinlist = llListFindList(items, [scriptname]);
        finalitems = llDeleteSubList(items, placeinlist, placeinlist);
        returnitem =  llList2String(finalitems, random);                                   
        
        integer finallen = llGetListLength( finalitems );   
        avatar = llKey2Name(id);
        
       if(amount != price)
            {
            llInstantMessage(id, "You paid "+(string)amount+", which is the wrong amount, the price is: "+(string)price);
            state default;
            }  
        llPlaySound("0e20b5f9-1b06-843e-446c-49fee8827448", 1.0);
        llSleep(2.0);
        llPlaySound("81e91c22-6e1c-9cac-b6ab-7a7cab6a8a70", 1.0);
        llSleep(1.5);
        llInstantMessage(id, "You Purchased " + ": " + returnitem);
        llGiveInventory(id, returnitem);             
             
        }
}