Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need to make a vendor check inventory is there?

Keelia DeCuir
Registered User
Join date: 18 Feb 2007
Posts: 19
01-31-2008 11:42
Hi, I've managed to get the below script together to give a particular item depending on the amount paid, but I'm not sure how to make 'checks' on the script, for example if the inventory wasn't in the vendor, this script will still take the money but obviously not give the item.

I'm not a good scripter, so detailed help would be much appreciated! Also, if you see any other problems that can arise, please point them out.


CODE

integer price1 = 100;
integer price2 = 200;
integer price3 = 300;
integer price4 = 400;
string ProductA = "ItemA";
string ProductB = "ItemB";
string ProductC = "ItemC";
string ProductD = "ItemD";
string thank = "Thank you for your purchase!";


default
{
on_rez(integer total_number)
{
llResetScript();
}

touch_start(integer num)
{
integer x;
for(x = 0; x < num ; x++)
llGiveInventory(llDetectedKey(x), llGetInventoryName(INVENTORY_NOTECARD, 0));
llSay(0, "To purchase a product, right click and choose 'Pay'.");
}

state_entry()
{
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
llSetPayPrice(PAY_HIDE, [price1 , price2 , price3 , price4 ]);
}

money(key id, integer amount)
{
if(amount == price1)
{
llSay(0, thank);
llGiveInventory(id, ProductA );
}

else if(amount == price2)
{
llSay(0, thank);
llGiveInventory(id, ProductB);
}

else if(amount == price3)
{
llSay(0, thank);
llGiveInventory(id, ProductC);
}

else if(amount == price4)
{
llSay(0, thank);
llGiveInventory(id, ProductD);
}
}
}


Thanks in advance.


Keelia DeCuir
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
01-31-2008 22:47
The best way would be to, inside default state_entry(), do llGetInventoryType on ProductA - D, and if none return INVENTORY_NONE, enter another state which contains the rest of the code.

Or, you could do those tests, and if an item doesn't return INVENTORY_NONE, add it's respective price to a list. If it does, add PAY_HIDE to that list. Then, pass that list to llSetPayPrice, so if an item isn't present, it's price won't be displayed. Something like:

state_entry()
{
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);

list prices;

if( llGetInventoryType( ProductA ) != INVENTORY_NONE )
prices += price1;
else
prices += PAY_HIDE;


if( llGetInventoryType( ProductB ) != INVENTORY_NONE )
prices += price2;
else
prices += PAY_HIDE;


if( llGetInventoryType( ProductC ) != INVENTORY_NONE )
prices += price3;
else
prices += PAY_HIDE;


if( llGetInventoryType( ProductD ) != INVENTORY_NONE )
prices += price4;
else
prices += PAY_HIDE;

llSetPayPrice(PAY_HIDE, prices );
}

Or, you could do this test at the time of purchase, and if missing, give a "sorry" message and refund the money (since you're already requesting PERMISSION_DEBIT, but nowhere do you actually call llGiveMoney, which is the only reason you'd need debit permission.) Such as:

money(key id, integer amount)
{
if(amount == price1)
{
if( llGetInventoryType( ProductA ) != INVENTORY_NONE )
{
llSay(0, thank);
llGiveInventory(id, ProductA );
}
else
{
llSay( 0, "Sorry, there was an internal error. You money has been refunded." )
llGiveMoney( id, amount )
}
}

// repeat for Products C-D

}