2014-03-03

Simple RLV self-locker script

The other week a friend asked for an easy way to lock an item on their avatar such that it would survive outfit changes -- sort of like a very simple version of the Z&A HUD Locker, only for something worn (okay, technically, HUDs are worn too, but you get the idea...). Given that they used RLV and had no desire to let anyone else lock it on, I quickly knocked up a script to do it.

It's hardly clever, and there are more sophisticated RLV locking scripts out there, no doubt, but I thought I'd post it here in case it was useful to anyone else:

//////////////////////////////////////////////////////////////////////
// Simple owner-only RLV attachment locker.
// By Antony Fairport
//
// Simple script to lock an attachment on an avatar, using RLV. This
// is owner-only touch to lock/unlock. The idea being that it's
// helpful to stop something being knocked off during outfit changes.
//////////////////////////////////////////////////////////////////////
// Allow the object we're in to be removed.
RLVUnlock()
{
llOwnerSay( "@detach=y" );
}
//////////////////////////////////////////////////////////////////////
// Don't allow the object we're in to be removed.
RLVLock()
{
llOwnerSay( "@detach=n" );
}
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
///////////////////////////////////////////////////////////////////
// State entry. We'll just run to the unlocked state.
state_entry()
{
state Unlocked;
}
}
//////////////////////////////////////////////////////////////////////
// Unlocked state.
state Unlocked
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Ensure we can be removed.
RLVUnlock();
// Give a clue as to our state.
llOwnerSay( "Unlocked" );
}
//////////////////////////////////////////////////////////////////
// Handle a touch.
touch_end( integer _ )
{
// Is it the owner touching us?
if ( llDetectedKey( 0 ) == llGetOwner() )
{
// ...sure is. Let's lock this thing!
state Locked;
}
}
}
//////////////////////////////////////////////////////////////////////
// Locked state.
state Locked
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Ensure we can't be removed.
RLVLock();
// Give a clue as to our state.
llOwnerSay( "Locked" );
}
//////////////////////////////////////////////////////////////////
// Ensure we're locked when rezzed.
on_rez( integer _ )
{
// If we're attached...
if ( llGetAttached() )
{
// ...being rezzed while attached normally means that
// we're logging in. So reaffirm the RLV lock.
RLVLock();
}
}
//////////////////////////////////////////////////////////////////
// Handle a touch.
touch_end( integer _ )
{
// Is it the owner touching us?
if ( llDetectedKey( 0 ) == llGetOwner() )
{
// ...sure is. Let's unlock this thing!
state Unlocked;
}
}
}

No comments:

Post a Comment