User:Kimm Paulino/Scripts1: Difference between revisions
Kimm Paulino (talk | contribs) |
Kimm Paulino (talk | contribs) |
||
| Line 103: | Line 103: | ||
// Position of the sittarget | // Position of the sittarget | ||
vector SIT_VECTOR = <0.0, 0.0, 0.5>; // In metres - | vector SIT_VECTOR = <0.0, 0.0, 0.5>; // In metres - ZERO_VECTOR to disable | ||
vector SIT_ROTATION = <0.0, 0.0, 0.0>; // In degrees | vector SIT_ROTATION = <0.0, 0.0, 0.0>; // In degrees | ||
| Line 117: | Line 117: | ||
state_entry() | state_entry() | ||
{ | { | ||
if (SIT_VECTOR != | if (SIT_VECTOR != ZERO_VECTOR) | ||
{ | { | ||
llSitTarget (SIT_VECTOR, llEuler2Rot (SIT_ROTATION * DEG_TO_RAD)); | llSitTarget (SIT_VECTOR, llEuler2Rot (SIT_ROTATION * DEG_TO_RAD)); | ||
Revision as of 14:06, 12 July 2012
Rez and Sense
<lsl> // Rezzer that will only rez an object (from inventory) if it // can't detect the specified number of objects in the region nearby already. // // Note: Sensing is limitd to a maximum of 96m in all directions. If the // objects pass out of that range, this won't find them. // // Always looks for (and rezzes) the first object found in inventory. // NB: This must have copy permissions if you want to rez it more than once! // // Kimm Paulino, July 2012
integer MAX_REZZED_OBJECTS = 5; vector REZ_POSITION = <1.0, 0.0, 0.0>; // Relative to the rezzing prim, must be less than 10m away vector REZ_ROTATION = <0.0, 0.0, 0.0>; // In degrees
string gObjectName;
rezObject () {
llRezObject (gObjectName, llGetPos() + REZ_POSITION, ZERO_VECTOR, llEuler2Rot (REZ_ROTATION * DEG_TO_RAD), 0);
}
default {
on_rez (integer start_param)
{
llResetScript();
}
state_entry ()
{
gObjectName = llGetInventoryName (INVENTORY_OBJECT, 0);
if (gObjectName == "")
{
llOwnerSay ("Note to owner: No objects found in this prims inventory");
}
}
touch_start (integer num_detected)
{
if (gObjectName != "")
{
// Trigger a single sensor event for the full range/arc looking for any non-avatar
// objects with the same name as our rezzing object.
llSensor (gObjectName, NULL_KEY, (ACTIVE|PASSIVE), 96.0, PI);
}
}
sensor (integer num_detected)
{
if (num_detected < MAX_REZZED_OBJECTS)
{
rezObject();
}
else
{
llOwnerSay ("Max Objects detected ...");
// Nothing to do
}
}
no_sensor ()
{
// None found, so ok to rez one
rezObject();
}
changed (integer change)
{
if (change & CHANGED_INVENTORY)
{
llResetScript();
}
}
} </lsl>
Derez After Sitting
<lsl> // This will kill the prim it is in, the specified time after someone // sits on the prim. It will unsit them before derezzing. // // Note: This only works when the prim has a sittarget defined. // But this script does not have to be the thing setting it, // if the sit target is set to <0.0,0.0,0.0> in this script, // then no call to llSitTarget is made - so another script // can do it instead. // // It can optionally derez on unsit too - i.e. when they get up. // // It will also automatically derez itself after a specified time // if noone sits down on it. // // Kimm Paulino, July 2012
integer DEREZ_ON_UNSIT = FALSE; // TRUE if want to auto derez when av gets up float DEREZ_TIMEOUT = 60.0; // In seconds (0.0 to disable) float DEREZ_AFTER_SIT_TIMEOUT = 30.0; // In seconds (0.0 to disable)
// Position of the sittarget vector SIT_VECTOR = <0.0, 0.0, 0.5>; // In metres - ZERO_VECTOR to disable vector SIT_ROTATION = <0.0, 0.0, 0.0>; // In degrees
key gAvUuid;
default {
on_rez (integer start_param)
{
llResetScript();
}
state_entry()
{
if (SIT_VECTOR != ZERO_VECTOR)
{
llSitTarget (SIT_VECTOR, llEuler2Rot (SIT_ROTATION * DEG_TO_RAD));
}
llSetTimerEvent (DEREZ_TIMEOUT);
}
timer ()
{
if (gAvUuid)
{
llUnSit (gAvUuid);
}
llSetTimerEvent (0.0);
llDie();
}
changed (integer change)
{
// When someone sits on an object, the av is considered to be
// a linked-in child prim, so the link number changes
if (change & CHANGED_LINK)
{
gAvUuid = llAvatarOnSitTarget();
if (gAvUuid)
{
// Avatar has just sat down
llSetTimerEvent (DEREZ_AFTER_SIT_TIMEOUT);
}
else
{
// Assume av just got up (might not be true - could be unlinking going on)
if (DEREZ_ON_UNSIT)
{
llDie();
}
}
}
}
} </lsl>