Difference between revisions of "Random Object Vendor"
Jump to navigation
Jump to search
m (changed PRE to LSL for cute color coded formatting and {{LSLC|Examples}} {{LSLC|Library}}) |
m (minor code revision) |
||
Line 48: | Line 48: | ||
if (amount == (integer)llList2String(prices,0)) | if (amount == (integer)llList2String(prices,0)) | ||
{ | { | ||
integer num_items = llGetListLength(inventory); | integer num_items = llGetListLength(inventory); | ||
integer random_item = (integer)llFrand(num_items + 1); | integer random_item = (integer)llFrand(num_items + 1); | ||
if (num_items < 1) | if (num_items < 1) | ||
llInstantMessage(id, "No items to offer."); | |||
else if (num_items == 1) | else if (num_items == 1) | ||
llGiveInventory(id, llList2String(inventory, 0)); | llGiveInventory(id, llList2String(inventory, 0)); |
Revision as of 23:29, 13 December 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
This script is a simple object vendor that gives out random items when you pay the fixed price. Just drop it in a prim, add items, and change the prices list variable to whatever price you want to sell the items. It will give out the item in a folder named like the container prim.
<lsl>
// Random object vendor by CodeBastard Redgrave // Drop items in the prim containing this script // Pay the set price amount and it will give you a random object // <3
// Pieces stolen from: // Give inventory to whoever touches the prim, written by Sasun Steinbeck (get_inv_list is shweet <3)
list inventory; //holds a list of inventory items to give out on click.
list prices = [1];
get_inv_list()
{
integer i; string name; inventory = []; for (i = 0; i < llGetInventoryNumber(INVENTORY_ALL); i++) { name = llGetInventoryName(INVENTORY_ALL, i); if (name != llGetScriptName()) inventory += [name]; //add everything but this script to the list } llOwnerSay("The following items have been found in this prim and will be given out on touch: " + llList2CSV(inventory) + "."); if (llGetListLength(inventory) > 1) llOwnerSay("These items will be put into a folder named " + llGetObjectName() + ". Rename this object to rename the destination folder.");
}
default {
state_entry() { get_inv_list(); llRequestPermissions(llGetOwner(),PERMISSION_DEBIT); llSetPayPrice(PAY_HIDE, prices);
} money(key id, integer amount) { if (amount == (integer)llList2String(prices,0)) {
integer num_items = llGetListLength(inventory); integer random_item = (integer)llFrand(num_items + 1);
if (num_items < 1) llInstantMessage(id, "No items to offer."); else if (num_items == 1) llGiveInventory(id, llList2String(inventory, 0)); else //multiple items in a folder named after this prim's name { llGiveInventoryList(id, llGetObjectName(), [llList2String(inventory, random_item)]); llInstantMessage(id, "Your items have been given to you in a folder in your inventory named " + llGetObjectName() + ". Thank you!"); } } else { llWhisper(0,"Sorry that is the wrong amount for this item."); llGiveMoney(id, amount); } }
changed(integer change) { if (change & CHANGED_INVENTORY) get_inv_list(); //refresh inventory list }
}
</lsl>