Skip to content

Instantly share code, notes, and snippets.

@antonyfairport
Created March 3, 2014 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonyfairport/9330397 to your computer and use it in GitHub Desktop.
Save antonyfairport/9330397 to your computer and use it in GitHub Desktop.
//////////////////////////////////////////////////////////////////////
// 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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment