Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Wanted: A script for giving money to object finder.

SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
08-16-2004 17:16
I received a request from Starax (the sculptor) for a script that would be used in a "find an object" game that would automatically pay the finder of the object a certain amount of money.


Here's my primitive 5 minute untested version of such a thing:
CODE

integer paid = FALSE;
integer amount = 1 ;

default
{
state_entry()
{
//llSay(0, "Hello, Avatar!");
paid = FALSE;

}

touch_start(integer total_number)
{
//llSay(0, "Touched.");
if (paid = FALSE)
{ llGiveMoney( llDetectedKey(0), amount);
paid = TRUE ;
}

}
}



Any help will greatly appreciated.
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
08-16-2004 17:33
Almost works. Just add in

if(!llGetPermissions() & PERMISSION_DEBIT) llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);

To state_entry. :)

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Al Bravo
Retired
Join date: 29 Jun 2004
Posts: 373
08-16-2004 17:43
if (paid = FALSE)

should be

if (paid == FALSE)
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
08-16-2004 17:45
err.. you need PERMISSION_DEBIT to use llGiveMoney. So, llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
and use llGiveMoney in the run_time_permissions event.
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
thanks for help, but not working yet
08-16-2004 18:13
I found the "=" instead of "==" error myself, and stuck in
Adam's code in state entry.

It was not asking me for permission to debit, but was instead giving the "Script trying to debit L$ from owner but PERMISSION_DEBIT permission not set!"

Adams's line needed parenthesis around llGetPermissions()&PERMISSION_DEBIT added like so:

CODE

if(! ( llGetPermissions() & PERMISSION_DEBIT) )
{ llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ;
}


This compiled and asked for permission and paid me upon touching it.

Am I overlooking something that would allow the payment to be be catastrophically repeated?

Is the touch event a logical place to put it?

I've never found anything in a hunt game here, I don't know if the found item should attach itself to the finders hand or what the normal finding a thing behavior should be at all.

The revised code looks like this now:

CODE

integer paid = FALSE;
integer amount = 1 ;

default
{
state_entry()
{
//llSay(0, "Hello, Avatar!");
paid = FALSE;

if(! ( llGetPermissions() & PERMISSION_DEBIT) )
{ llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ;
}


}

touch_start(integer total_number)
{
//llSay(0, "Touched.");
if (paid == FALSE)
{ llGiveMoney( llDetectedKey(0), amount);
paid = TRUE ;
}

}
}

Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
08-16-2004 18:34
As I posted previously, you should use the run_time_permissions event after requesting permissions.
http://www.badgeometry.com/wiki/llRequestPermissions
http://www.badgeometry.com/wiki/run_time_permissions
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
08-16-2004 18:35
From: someone
Originally posted by Adam Zaius
Almost works. Just add in

if(!llGetPermissions() & PERMISSION_DEBIT) llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);

To state_entry. :)

-Adam

Hmm Adam, are you sure that works?
From the wiki:

Question: According to the official Linden scripting docs, llRequestPermissions should return an integer. What is returned? Is it the permissions granted, all of the now-available permissions, etc.? Is this integer passed to run_time_permissions?
Answer: No, this is an error in the official guide. It doesn't return an integer. Trying to capture it results in a compile error. My guess is that the help text is right and this function doesn't return anything.

Of course, the wiki may need a little updating.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-16-2004 19:21
From: someone
Originally posted by Adam Zaius
Almost works. Just add in

if(!llGetPermissions() & PERMISSION_DEBIT) llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);

To state_entry. :)

-Adam


WARNING: Boolean operator applied to bitfield integer. Logic-check paused.

Correct syntax:
if ((~llGetPermissions & PERMISSION_DEBIT) == PERMISSION_DEBIT)
(assuming ~ is higher in the order-of-operators list in C then &)

Alternative syntax:
if (!((llGetPermissions() & PERMISSION_DEBIT) == PERMISSION_DEBIT))

Logic check exited with code -1.
$/home/omega:
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-16-2004 19:25
From: someone
Originally posted by Eggy Lippmann
Hmm Adam, are you sure that works?
From the wiki:

Question: According to the official Linden scripting docs, llRequestPermissions should return an integer. What is returned? Is it the permissions granted, all of the now-available permissions, etc.? Is this integer passed to run_time_permissions?
Answer: No, this is an error in the official guide. It doesn't return an integer. Trying to capture it results in a compile error. My guess is that the help text is right and this function doesn't return anything.

Of course, the wiki may need a little updating.

Eggy, is the integer returned from llRequestPermissions relevant in that code snippet? I dont see Adam using it anywhere.
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
08-16-2004 19:46
Must have been a brain fart. It's late :)
EDIT: BTW, where the hell are you, why cant you get in-world?
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-16-2004 23:29
From: someone
Originally posted by Eggy Lippmann
Must have been a brain fart. It's late :)
EDIT: BTW, where the hell are you, why cant you get in-world?

Many reasons, RL is hectic atm :)
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
08-17-2004 01:07
Yeah should have been ~ rather than !. Not thinking straight that early in the mornin. :)

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
08-18-2004 06:16
The line labeled "Correct Syntax" in Chris's latest post is missing the parentheses following llGetPermission.


Perhaps one could use

CODE

if ( ( llGetPermissions() & PERMISSION_DEBIT ) == 0 )
{ llRequestPermission( llGetOwner(), PERMISSION_DEBIT );
}
Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
08-18-2004 07:16
You might also put a check in the touch event to ignore the owner, who will probably be clicking the object(s) by accident when placing them. No sense paying yourself and updating the "paid" var.

CODE

touch(integer num)
{
if (llDetectedKey(0) != llGetOwner() && !paid)
{
// then pay up/update vars and such
paid = TRUE;
llGiveMoney(llDetectedKey(0), amount);
}
}


Boso