CODE
//Simple light switch. Click object with script turns light on and off.
integer light_switch;
vector light_color=< 1,1,1>;
float light_intensity=1.0;
float light_radius=04.0;
float light_falloff=1;
init ()
{
//Set light to off initially
light_switch=0;
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.0,PRIM_POINT_LIGHT, FALSE, light_color, light_intensity, light_radius, light_falloff]);
//llOwnerSay("Set to midnight and click to toggle light!");
}
default
{
state_entry()
{
init();
}
on_rez(integer start_param)
{
init();
}
touch_start(integer total_number)
{
if(light_switch==1)
{
//Light is on, turn off
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.0,PRIM_POINT_LIGHT, FALSE, light_color, light_intensity, light_radius, light_falloff]);
light_switch=0;
//llOwnerSay("Light turned off.");
}
else
{
//Light is off, turn on
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.25,PRIM_POINT_LIGHT, TRUE, light_color, light_intensity, light_radius, light_falloff]);
light_switch=1;
//llOwnerSay("Light turned on.");
}
}
}
and
CODE
vector r_open = < 0.0, 0.0, 90.0>; // This prim's rotations in degrees relative to root prim when this prim is open
vector r_closed = < 0.0, 0.0, 10.0>; // and when it's in the closed state
integer close_on_rez = TRUE; // Change to false to have the prim open on rez
// ================================================== ===== Nothing from here down needs modding.
rotation LocalRot(rotation localrot)
{
rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot());
return LocRot;
}
open(string door)
{
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD))]);
}
close(string door)
{
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD))]);
}
default
{
state_entry()
{
if (close_on_rez)
{
state closed;
}
else
{
state opened;
}
}
on_rez(integer rez)
{
llResetScript();
}
}
state opened
{
state_entry()
{
open("left");
}
on_rez(integer rez)
{
llResetScript();
}
touch_start(integer n)
{
state closed;
}
}
state closed
{
state_entry()
{
close("left");
}
on_rez(integer rez)
{
llResetScript();
}
touch_start(integer n)
{
state opened;
}
}
