Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help changing money on a script

Kea Amarula
Registered User
Join date: 28 Apr 2005
Posts: 8
10-15-2006 18:36
This script gives you a selection of items to choose for 1L.. how do I set it so its for free 0L? Thanks..


----------------------------

integer lkey ;
integer idx ;
integer valid;
key payee ;

// Mango, Papaya, Apricot, Blueberry, Pineapple, Pink Lemonade

list objects = [ ];

default
{
state_entry()
{
llOwnerSay ( "Readin objects - wait a sec ";) ;
idx = 0;
objects = objects + ["Cancel"];
for ( idx= 0;idx<llGetInventoryNumber( INVENTORY_OBJECT );idx++ )
{
string oname =llGetInventoryName( INVENTORY_OBJECT, idx );
if ( llStringLength( oname ) > 24 )
{
llOwnerSay ( ">>> " + oname + " has been rejected as it's name is too long ( 24 characters )" );
}
else
{
objects = objects + [oname];
llOwnerSay ( oname + " added to the menu." );
}
if ( idx == 10 ) {idx = 999 ;}
}
llSetPayPrice( PAY_HIDE,[1,PAY_HIDE,PAY_HIDE,PAY_HIDE]);
llRequestPermissions( llGetOwner(),PERMISSION_DEBIT );
}
run_time_permissions( integer perm )
{
if ( perm & PERMISSION_DEBIT )
{
state ready ;
}
else
{
llOwnerSay ( "Permission is required to issue refunds." );
llResetScript();
}
}
}
state ready
{
state_entry()
{
llSetText( "Juice L$1- 6 Flavors to Choose From" ,<1,1,1>,1 );
}
on_rez( integer r )
{
llResetScript();
}
listen( integer ch, string nm, key id, string mess)
{
llListenRemove( lkey );
llSetTimerEvent( 0 );
if ( mess == "Cancel" )
{ //Refund their $1 as they cancelled
llGiveMoney( id, 1 );
return;
}
valid = FALSE;
for ( idx=0; idx<llGetListLength( objects ) ;idx++ )
{ // find out which object
if ( mess == llList2String( objects,idx ) )
{
llGiveInventory( id,mess ) ;
llWhisper( 0 , "MmMm so delicious. I think I want another" );
return;
}
}
if ( valid ) {return;}
llGiveMoney( id, 1 ); // Refund the money - they didnt use the menu
}
money ( key id, integer amt )
{
payee = id;
if ( amt > 1 )
{
llGiveMoney( id,amt ) ;
llWhisper( 0, " I only accept L$1 - refunding your money " );
return;
}
lkey = llListen( 8888,"",id,"" );
llSetTimerEvent( 60 );
llDialog( id,"Choose your object :" , objects, 8888 );
}
timer()
{
llGiveMoney( payee,1 ) ; // Menu timed out - refund the money
llSetTimerEvent( 0 );
llListenRemove( lkey );
}
changed( integer c )
{
if ( c && CHANGED_INVENTORY )
{
llResetScript();
}
}
}
Gattz Gilman
Banned from RealLife :/
Join date: 29 Feb 2004
Posts: 316
10-15-2006 20:55
since you can pay an object 0L$, using a vendor script wont work. here is a simple dispenser script that uses a menu on touch
CODE

list items;
key user;
integer chan;
integer _l;
GetInv()
{
items = [];
integer i;
integer max = llGetInventoryNumber(INVENTORY_OBJECT);
if(max > 12)
{
llOwnerSay("[ERROR] More then 12 items. Only first 12 will be used.");
max = 12;
}
for(i=0;i<max;i++)
{
if(llStringLength(llGetInventoryName(INVENTORY_OBJECT,i)) > 24)
{
llOwnerSay("[ERROR]Name longer then 24 characters, items discarded from list.");
if(max < llGetInventoryNumber(INVENTORY_OBJECT))
{
max = max + 1;
}
}
else
{
items += [llGetInventoryName(INVENTORY_OBJECT,i)];
}
}
}
default
{
state_entry()
{
chan = (integer)(llFrand(10000) + 10000);
GetInv();
}

touch_start(integer total_number)
{
user = llDetectedKey(0);
_l = llListen(chan,"",user,"");
llDialog(user,"Choose your food.",items,chan);
llSetTimerEvent(10);
}
listen(integer chan, string name, key id, string message)
{
llGiveInventory(user,message);
llListenRemove(_l);
llSetTimerEvent(0);
}
timer()
{
llListenRemove(_l);
llSetTimerEvent(0);
}
on_rez(integer param)
{
llResetScript();
}
changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
GetInv();
}
}
}

_____________________
Tad McConachie
Registered User
Join date: 6 Oct 2006
Posts: 76
10-16-2006 09:56
Can someone tell me just what:

user = llDetectedKey(0);

does? I'm guessing it's setting user to the avatar who is interacting with the object, but that's not at all clear from the wiki page on llDetectedKey.

http://lslwiki.com/lslwiki/wakka.php?wakka=llDetectedKey

Thanks!!
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-16-2006 11:04
From: Tad McConachie
Can someone tell me just what:

user = llDetectedKey(0);

does? I'm guessing it's setting user to the avatar who is interacting with the object, but that's not at all clear from the wiki page on llDetectedKey.

http://lslwiki.com/lslwiki/wakka.php?wakka=llDetectedKey

Thanks!!


To the server everything in SL is assigned a unique number (key). So for it, you are not "Tad McConachie", you are UUID xxxx-xxxx-xxx-xxxxx. In the script posted, it needs to know who touched it to display the choices menu for and to deliver the product too. Read also here in the wiki:

http://lslwiki.com/lslwiki/wakka.php?wakka=detected
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Tad McConachie
Registered User
Join date: 6 Oct 2006
Posts: 76
10-16-2006 11:27
Thanks, Jesse, I kind of understand that, but in what way does the 0 indicate the avatar currently using this device? That's the bit I'm not clear on.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-16-2006 11:38
From the llDetectedName page:
"Q: How do I figure out what to use for number? I'm confused.
A: For most uses, if you're using a one-off event like collision or touch_start, you can use 0, the first object number. If you're using a sensor, try a for loop, with number incrementing, to cycle through all detected objects."

That applies in this case. It is detecting the person that has touched it so it will be set at 0. Scripts like radar will detect multiple objects and will use something besides 0. Take a look at one of the radar scripts to see the difference.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Tad McConachie
Registered User
Join date: 6 Oct 2006
Posts: 76
10-16-2006 12:53
Thanks Jesse! It's more clear now. :)