Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help amending a follower script

ang Dovgal
Registered User
Join date: 17 Jul 2007
Posts: 4
05-18-2008 08:56
Ok i have a project i am working on but i am hopeless at scripting don't know where to start. I have the follower script but what i need to know is what do i need to change in order for it to have a base position and then follow a person in my group when they touch the object. I would be very grateful for any scripting tips on this one.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-18-2008 09:03
go on wiki.secondlife.com and search llSensorRepeat, llSameGroup() and llSetPos() that shold give you a head start on learning the basics of your idea

EDIT:

also touch_start(integer something)
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
05-18-2008 22:29
This is the standard 'follower' script modified to do what you want.

CODE

key id;

default
{
state_entry()
{
llSetBuoyancy( .75 );
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);
id = llGetOwner();
llSensorRepeat("",id,AGENT,20,2*PI,.4);
}

touch_start(integer foo)
{
id = llDetectedKey (0);
llSensorRemove();
llSensorRepeat ("",id,AGENT,20,TWO_PI,.4);
}

sensor(integer total_number)
{
vector pos = llDetectedPos(0);
vector offset =<-1,0,0>;
pos+=offset;
llMoveToTarget(pos,.3);
}
}
ang Dovgal
Registered User
Join date: 17 Jul 2007
Posts: 4
05-19-2008 15:55
ok i have been playing about with the full script and i have nearly got it right you touch it and it asks to register and it then positions itself following above your head so that is exactly what i need. The problem i have is when i touch it again to unregister it will not do anything. I need to be able to touch it and it unregisters you and returns to the original postion. Here is the script and remember i am new to scripting so it probably looks a complete mess but i have been trying to work this out all day lol any help would be gratefully appreciated.




CODE

string CUSTOM_TEXT = "Floating Text\nHERE";
string DEFAULT_TEXT = "";

list DEFAULT_QUICK_PAY_AMOUNTS = [5, 10, 20, 50];

integer DEFAULT_PRICE = PAY_DEFAULT;

// This value is the percentage of tip commissions that go to the tip jar owner.
// For example,
// 90% of the tip to the registered user, 10% of the tip to the owner:
// float OWNER_COMMISSION = 10.0;
// or
// 95% of the tip to the registered user, 5% of the tip to the owner:
// float OWNER_COMMISSION = 5.0;
//
float OWNER_COMMISSION = 10.0;

string DEFAULT_DONOR = "<nobody>";

float PARTICLE_EFFECT_TIMER = 6.0;

vector PARTICLE_EFFECT_COLOUR = <1.0, 0.0, 0.0>;

vector FLOATING_TEXT_COLOUR = <1.0, 1.0, 1.0>;

// If you have more than one tip jar, they should each use a different DIALOG_CHANNEL!
//
integer DIALOG_CHANNEL = -25879;

string DIALOG_REGISTER_TEXT = "Would you like to register with this tip jar?";
string DIALOG_UNREGISTER_TEXT = "Would you like to unregister the user of this tip jar?";
string DIALOG_ACK = "OK";
string DIALOG_NACK = "No Thanks";

string WRONG_GROUP_TEXT = "Sorry, you need to change your active group to be able to register with this tip jar.";

// global variables

integer last_donation = 0;
integer total_donations = 0;

integer dialog_channel_handle = -1;

key last_donor = NULL_KEY;

key owner_id = NULL_KEY;
key registered_id = NULL_KEY;

write_floating_text()
{
string donor = DEFAULT_DONOR;

if (last_donor != NULL_KEY)
{
donor = llKey2Name(last_donor);
}
llSetText(CUSTOM_TEXT +
"\n" +
"Last donation: L$" +
(string)last_donation +
" by " + donor + ".\n" +
"Total donations: L$" +
(string)total_donations + ".\n",
FLOATING_TEXT_COLOUR,
1.0);
}

default_floating_text()
{
llSetText(DEFAULT_TEXT, FLOATING_TEXT_COLOUR, 1.0);
}

enable_particle_effect()
{
llParticleSystem(
[PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE,
PSYS_PART_START_COLOR, PARTICLE_EFFECT_COLOUR,
PSYS_SRC_ANGLE_BEGIN, (DEG_TO_RAD * -90),
PSYS_SRC_ANGLE_END, (DEG_TO_RAD * 90),
PSYS_SRC_BURST_RATE, 0.0,
PSYS_SRC_BURST_PART_COUNT, 5,
PSYS_PART_MAX_AGE, 4.0
] );
}

disable_particle_effect()
{
llParticleSystem([]);
}

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

state_entry()
{
// Request Owners permission to debit money (to pay the registered tip jar user).
llRequestPermissions(llGetOwner(),
PERMISSION_DEBIT);
state unregistered;
}
}

state unregistered
{
on_rez(integer start_param)
{
llResetScript();
}

state_entry()
{
owner_id = llGetOwner();
registered_id = NULL_KEY;
last_donor = NULL_KEY;
last_donation = 0;
total_donations = 0;
dialog_channel_handle = llListen(DIALOG_CHANNEL, "", "", DIALOG_ACK);
llSetPayPrice(DEFAULT_PRICE, DEFAULT_QUICK_PAY_AMOUNTS);
default_floating_text();
llOwnerSay("Tip Jar at " + (string)llGetPos() + " is initialized.");
}

touch(integer detected)
{
key id = llDetectedKey(0);
if (llSameGroup(id) == TRUE)
{
// send dialog asking if they want to register
llDialog(id, DIALOG_REGISTER_TEXT, [DIALOG_ACK, DIALOG_NACK], DIALOG_CHANNEL);
}
else
{
llInstantMessage(id, WRONG_GROUP_TEXT);
}
}

listen(integer channel, string name, key id, string message)
{
if (llSameGroup(id) == TRUE)
{
registered_id = id;
state registered;
}
else
{
llInstantMessage(id, WRONG_GROUP_TEXT);
}
}

state_exit()
{
llListenRemove(dialog_channel_handle);
}
}

state registered
{
on_rez(integer start_param)
{
llResetScript();
}

state_entry()
{
dialog_channel_handle = llListen(DIALOG_CHANNEL, "", "", DIALOG_ACK);
llSetPayPrice(DEFAULT_PRICE, DEFAULT_QUICK_PAY_AMOUNTS);
default_floating_text();
write_floating_text();
llOwnerSay("Tip Jar at " + (string)llGetPos() + " is initialized.");

}

money(key id, integer amount)
{
last_donor = id;
last_donation = amount;
total_donations += amount;
llSay(PUBLIC_CHANNEL, "Thank you for the donation, " + llKey2Name(last_donor) + "!");
llOwnerSay("Tip Jar at " +
(string)llGetPos() +
" was paid " +
(string)last_donation +
" by " +
llKey2Name(last_donor) + ".");
llInstantMessage(registered_id, "Tip Jar at " +
(string)llGetPos() +
" was paid " +
(string)last_donation +
" by " +
llKey2Name(last_donor) + ".");
write_floating_text();

// keep commission percentage for owner and pay the rest to the registered user.
float commission_percentage = OWNER_COMMISSION / 100;
integer owner_commission = llRound((float)last_donation * commission_percentage);

integer user_tip = last_donation - owner_commission;
llGiveMoney(registered_id, user_tip);

enable_particle_effect();
llSetTimerEvent(PARTICLE_EFFECT_TIMER);
}

timer()
{
disable_particle_effect();
llSetTimerEvent(0.0);
}

touch(integer detected)
{
key id = llDetectedKey(0);
if ((id == registered_id) || (id == owner_id))
{
// ask the registered user if they want to unreg.
llDialog(id, DIALOG_UNREGISTER_TEXT, [DIALOG_ACK, DIALOG_NACK], DIALOG_CHANNEL);
}
}

listen(integer channel, string name, key id, string message)
{
if ((id == registered_id) || (id == owner_id))
{
// unregister the tip jar user.
llInstantMessage(registered_id,
"You have been unregistered from this tip jar by " +
llKey2Name(id) +
".");
state unregistered;
}
}

state_exit()
{
llListenRemove(dialog_channel_handle);
}
state_entry()
{
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);

key id = llDetectedKey(0);
if (llSameGroup(id) == TRUE)
{
llSensorRepeat("",id,AGENT,20,2*PI,.4);
}
{
if (llSameGroup(llDetectedKey(0)))
llSensorRemove();
llSensorRepeat ("",id,AGENT,20,TWO_PI,.4);
}}

sensor(integer total_number)
{
vector pos = llDetectedPos(0);
vector offset =<0,0,2>;
pos+=offset;
llMoveToTarget(pos,.3);
}
}
ang Dovgal
Registered User
Join date: 17 Jul 2007
Posts: 4
05-19-2008 16:05
ok it will now unregister when i touch it but it is still following how do i stop it following me when unregistered and return to it rezzed position?
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
05-19-2008 16:50
From: ang Dovgal
ok it will now unregister when i touch it but it is still following how do i stop it following me when unregistered and return to it rezzed position?


Try setting it to non physical when you dont want it to follow...

llSetStatus (STATUS_PHYSICS, FALSE);
Celty Westwick
Registered User
Join date: 24 Jun 2006
Posts: 145
05-20-2008 09:27
Related question, will a follower "follow" an object if the sensor is changed to passive from agent?
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-20-2008 12:56
From: Celty Westwick
Related question, will a follower "follow" an object if the sensor is changed to passive from agent?

It really depends on the rest of the logic. In general it should, but remember that there is a limit of 16 results from a sensor call (and typically a LOT more objects around than avatars), so in order to be an effective object follower, the script is really going to have to filter the sensor search pretty heavily at some point (once it's "locked onto" a specific target given its input, for example).

Oh. Though it's also more likely you'd be following an active object rather than a passive one, since passive objects in general move less. Objects can also switch from passive to active. For many such implementations, it might be best to scan for both (PASSIVE | ACTIVE).