Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llAttachToAvatar script

Hello Gynoid
Registered User
Join date: 3 Jun 2007
Posts: 6
06-05-2007 12:48
Hello,

For a promotion for a survey I need a script that enables that an avatar can wear a promo board and doing so earns money the time the promo board (prim object) is worn.

I took a camping script and changed it to be usefull for wearing an object and earn money. However it is not working. So I hope somebody can help me?

This is what I made of it:

CODE

integer campmoney = 0; // Initial amount to grant someone upon the VERY first sit after first rez. (Think, Special bonus)
integer campadd = 4; // Payout amount
integer camptime = 600; // Payout time in seconds (Script USES this)
string camptimeM = "10"; // Payout time in minutes (Attract SAYS this)
string reciever = NULL_KEY; // key of Sitter
string _Animation;

default
{
state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT ); //Ask my owner for permission to give money and assume it suceeds
llSetText("Press Wear to earn money by walking around,\nL$"+(string)campadd+" every "+camptimeM+" minutes",<0,1,0>,1); // Set the hovertext to attract mode
}

changed(integer change)
{ // something changed
if (change & CHANGED_LINK)
{ // and it was a link change
if (llGetAttached() != 0 && reciever == NULL_KEY)
{ // if Avatar key isn't empty, somebody is wearing the object
reciever = llDetectedKey(0); // store sitting avatar's key
llSetText("Money: L$"+(string)campmoney,<0,1,0>,1); // Setting hovertext to current amount earned
llSetTimerEvent(camptime); // amount of time between payments in seconds
}
else if( reciever != NULL_KEY )
{ // if the avatar has gotten up
if(campmoney > 0)
{
llGiveMoney(reciever,campmoney); // give the avatar the amount of money he has earned.
reciever = NULL_KEY; // forget who the receiver was
campmoney=0; // reset earning count to 0
}
else
{
reciever = NULL_KEY; // forget who the receiver was
campmoney = 0; // reset earning count to 0
}
llSetText("Press Wear to earn money by walking around,\nL$"+(string)campadd+" every "+camptimeM+" minutes",<0,1,0>,1); // change the hovertext back to attract mode
llSetTimerEvent(0); // Nobody is sitting on me, so no need to call timer(). Disable timer.
}
}
}

timer()
{
campmoney = campmoney+campadd; // current amount + xL$ per camptime
llSetText("Money: L$"+(string)campmoney,<0,1,0>,1); // update hovertext with currently earned amount
if (llGetAttached() == 0)
{ // Noone's sitting on me, reset the vars
reciever = NULL_KEY; // forget who the receiver was
campmoney = 0; // reset earning count to 0
llSetText("sit here for free money,\nL$" + (string)campadd + " every "+camptimeM+" minutes",<0,1,0>,1); // change hovertext back to attract mode
llSetTimerEvent(0); // Nobody is wearing object, so no need to call myself anymore. Disable timer.
}
}
}
CODE


Thanks for your support!

Hello
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-05-2007 13:36
You can only take money from the Owner of the script/object. And as soon as you give the board to another player so that they can wear it, they become the owner.

Alternatives:
1. Have the board track how long it has been worn, then the player can "check in" at an ATM type place you have setup to get paid.

2. Use another object as a server and have the boards llEmail to the server object when they are equiped end removed (not sure what happens if the player logs out while wearing the object).. then the server can fire off Pay events on a timer.
Hello Gynoid
Registered User
Join date: 3 Jun 2007
Posts: 6
06-05-2007 13:48
Milambus, OK. Thanks for quick reply. It helps me to find another way of solution and see which option to take to let an avatar wear the board and submit the payment for the time he/ she worn it.
Merci.
Jacques Groshomme
Registered User
Join date: 16 Mar 2005
Posts: 355
06-05-2007 14:32
You might also want to make sure that the attached location isn't one of the HUD attachment points. If nobody else can see the sandwich board, it isn't doing you much good.
Hello Gynoid
Registered User
Join date: 3 Jun 2007
Posts: 6
06-06-2007 11:42
OK, will keep in mind Jacques , thx for tip!