Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Buy State?

Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
01-18-2007 21:14
When you click to "buy" an object, what LSL state is activated? In other words, how do you trigger a script immediately when an object is bought?
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
01-18-2007 22:50
there is none for buy

you can pay an object, which goes tru the money event ... but not checkbox sell object for Xl$
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
01-19-2007 00:06
When you buy an existing, rezzed object, it's changed event is called, with the CHANGED_OWNER bitflag included in the bitfield parameter.

Please note the details section on the CHANGED_OWNER event on the first wiki page linked above... apparently this event will be called in the original object when buying a copy.

So, basically:
CODE

default
{
changed( integer change )
{
if( change & CHANGED_OWNER )
{
// code here will be executed after purchase
}
}
}
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
01-19-2007 00:13
When you buy an existing, rezzed object, it's changed event is called, with the CHANGED_OWNER bitflag included in the bitfield parameter.

Please note the details section on the CHANGED_OWNER event on the first wiki page linked above... apparently this event will be called in the original object when buying a copy.

So, basically:
CODE

default
{
changed( integer change )
{
if( change & CHANGED_OWNER )
{
// code here will be executed after purchase
}
}
}
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
01-20-2007 14:27
great tip, deanna!

corollary question: how do you get the name of the person who's just bought the object?

it appears llGetOwner() returns the name of the old owner (or creator of the object).
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
01-20-2007 14:35
From: Ina Centaur
how do you get the name of the person who's just bought the object?

If the script is in the object which was purchased (and not the original, in case a copy was purchased), llGetOwner() should return the key of the agent who purchased it.
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-03-2007 04:00
follow up question... is there a LSL way to find out what price the object was sold for?
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
llGetOwner
02-04-2007 15:30
Well, we're talking about 2 different objects here.. in the first object, the owner (the seller in this case) would be the key returned by llGetOwner(). However, this will always be the case unless you put in this:

on_rez (integer number_detected)
{
llResetScript();
}

This resetting of the script forces the script to re-read the owner of the script, which is only done once (and recorded). In fact, if you create a scripted object that uses lLGetOwner(), even after giving away the object, the llGetOwner() will return the previous owner (or in this case, creator). So always put an llResetScript(); into an on rez event, to ensure that the script reads the current owner.

Now, as far as when a copy of an object is purchased (using no script vending), I'm not 100 percent sure how that would work. One thing I've noticed when drag copying scripted objects, the orginal object moves, and the new copy is rezzed in place. I'm not certain what's going on when items are purchased, weather the original item is given away, and the copy is kept, or vice versa. However, when someone is buying via a no script vendor, they're left clicking, or touching, so a touch event should be triggered regardless, so you should be able to simple put an llDetectedKey(0); or llDetectedName(0); to get the key or name of the buyer. So using llGetOwner() isnt really needed here, just a touch event and llDetectedName(0) to return the buyer's name.
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
02-04-2007 15:46
Just to add that when you buy a copy of something, it goes into your inventory - where scripts aren't running. So your code to detect that something was bought wont run until the owner rezzes the item from their inventory, which could be some time later. It could even be given to somebody else before ever being rezzed, so don't count on it to report who bought the item either.
_____________________
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
Detecting purchases on no script vendors
02-04-2007 17:47
Yeah, and that's not all that useful when vending clothing, because the script never gets rezzed, is there any way to detect a purchase at the time of purchase, in the vendor itself?
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-04-2007 19:26
From: Johan Laurasia

Now, as far as when a copy of an object is purchased (using no script vending), I'm not 100 percent sure how that would work. One thing I've noticed when drag copying scripted objects, the orginal object moves, and the new copy is rezzed in place. I'm not certain what's going on when items are purchased, weather the original item is given away, and the copy is kept, or vice versa. However, when someone is buying via a no script vendor, they're left clicking, or touching, so a touch event should be triggered regardless, so you should be able to simple put an llDetectedKey(0); or llDetectedName(0); to get the key or name of the buyer. So using llGetOwner() isnt really needed here, just a touch event and llDetectedName(0) to return the buyer's name.


Hi Johan, llDetectedKey(0) looks like it'd work even if buyer does not actually purchase the object.

When someone buys from a vendor, they're right clicking up a pie menu with either Buy or Pay as the option they want. Would llDetectedKey(0) still work in that case?
Elsewhere Essex
Registered User
Join date: 8 Sep 2006
Posts: 50
02-04-2007 19:44
From: Johan Laurasia
Well, we're talking about 2 different objects here.. in the first object, the owner (the seller in this case) would be the key returned by llGetOwner(). However, this will always be the case unless you put in this:

on_rez (integer number_detected)
{
llResetScript();
}

actually, that is only if you have a globl variable on the llGetOwner() stored, any functions that use llGetOwner() on the fly, like say a:
llListen(99, "", llGetOwner(), "";)
will correctly hear only the new owner.
the confusion lies in that, if you store a global variable of llGetOwner() and use that one variable for all uses of the owners key to follow, this will cause failure after and owner change without a script reset.

while it may be more memory efficient to store a owner key this way, the above described problem is also why many of us do not. at the sake of what, a few bits of memory, i will always use a llGetOwner() in function, called every time needed rather than global store it, for the very fact that upon transfer, i dont have to jump through hoops to get my script to work correctly for the next owner.
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
Busted..
02-07-2007 00:23
Eleswhere.. thanks for the clarification on that.. and yeah, u busted me using globals.. ok, I'm a bit oldschool, and can't quite break the habbit... lol.

Ina.. well, for starters:

There's a big difference between right click (buy) and right click (pay).
right click PAY simply presents you with a dialog to pay money to the object, but does nothing else. You must have a script in the object with a money event to detect the payment, and react accordingly (i.e. if it's enough money, give the object, if not, tell the customer, pay back improper amount), etc.

Buy, on the otherhand recieves the money, and vends either the original item, a copy of the original item, or the contents only of the item. Buy uses the built in vending capacity of prims, where pay simply allows you to pay money to the object and does nothing else (unless scripted).

As far as I can tell, when an item is purchased using "buy", no money event is triggered, however, a money event in a script will enable the Pay option in the pie menu.


As far as llDetectedKey(0) or llDetectedName(0) is concerned... yes, they would work fine, the problem is there is not event to test for to put them into.
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-07-2007 00:25
does anyone know how to fetch the Buy price dynamically through script? something like llGetPrice()?

the new owner can set the new sale price to be different. how can you detect this price dynamically using scripts?
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-07-2007 21:50
From: Johan Laurasia

Buy, on the otherhand recieves the money, and vends either the original item, a copy of the original item, or the contents only of the item. Buy uses the built in vending capacity of prims, where pay simply allows you to pay money to the object and does nothing else (unless scripted).

As far as I can tell, when an item is purchased using "buy", no money event is triggered, however, a money event in a script will enable the Pay option in the pie menu.


ok so for buy... the only way to detect when an object has been purchased would be some time afterwards when it is rezzed and changed_owner flips true (providing that it is rezzed and not worn!)

please confirm this!