Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Fellow Noobs, I give you Eazy-Cheez

Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
03-21-2007 19:30
Here are a few super easy, not so frilly scripts I wrote myself with help from the standard SL Wiki. I am going to give an example of a vertically opening door (Like a bar flap door) and linked lights via a simple shout script.

WHY? Because it took me a long time to hunt down and find bits and pieces of code to figure out what I wanted and how to write it all myself into very simple, no nonsense code as I am trying to learn from scratch and learn my way up.

I'm hoping this will help others like myself that are trying to understand scripting from a very basic level and see just how the commands so what they do and more importantly WHY.

Some of the fantastic scripts in here are so awesome and work so great, but new scripters can't follow them so here we go. Any and all scripters are welcome to tear apart my scripts at the seams as I'm sure they aren't the best.

1) Easy-Cheez door with timed automatic close.
CODE

// Easy-Cheez Door Script with llSleep timer Auto-Close
// Haplo Voss
// -----------------
// Right off the bat, let's make a short and
// sweet timer to close the door after us.
//
Close()
{
rotation rot = llGetLocalRot();
llSleep(6);
rot.s = 1;
rot.x = 0;
rot.z = 0;
rot.y = 0;
llSetLocalRot(rot);
llResetScript();
}
// Ok that's out of the way. On with the door!

default
{
touch_start(integer total_number)
{

rotation rot = llGetLocalRot(); // Get current variables
// of objects location, and
if (rot.s > 0.6) // load them into an array
{ // called rot
rot.s = 0.707107; //x, y, z, are obvious,
rot.x = 0; //s is basically a way to tell
rot.y = -0.707107; //SL that here is a point in space
rot.z = 0; //to measure all of that from.
llSetLocalRot(rot); //We have our own coordinates, so set the
Close(); //Object where we want it to "Open" when touched,
} //then hop up to "Close()" to pause and revert
//back to our original coordinates where the
//door is in a "closed" state and start over.
//Note: You only need the 'z' and 'y' variable for Vertical doors
//That swing up and down liike a bar flap door. Otherwise 's' and 'x'
//Are all you need for a normal front porch swinging door for example.

else
{
rot.s = 1; //Basically the main reason this is here is if
rot.x = 0; //you or someone were to accidently move or
rot.y = 0; //rotate your door slightly out of whack, then
rot.z = 0; //the script is going to "Close" it irregardless
//of what state it's in when you touch it.
}

llSetLocalRot(rot); //Finish off by telling the door to move
//to its current assigned coordinates as per the script
}
}
//So basically the end result is: Touch the door and it checks to
//see if it is within the guidelines of where it should be to open / pause
//and close again. If the door is not in a closed state, or it a little
//wonky due to some sort of toying around, then it will close the
//wonky anyway and start over. That's it!

//Enjoy. Hope the info made sense, I treid to keep it as informal and
//plain english as possible. Feel free to IM me if you like, I'm by no
//means a Good scripter, but if you need help scripting doors, lights,
//things simple like that from a fellow noob, lemme know.

//All you experts out there... if you find something exceedingly inefficient
//about this little script, then by all means rip it up and spit out the
//much better version! ;) C-me!


2) How to get the coordinates of that door!! This is straight from the SL Wiki. Just put up your door, drop this script into it, click on it, and it will tell you your values to plug into the Easy-Cheez script.
CODE

default
{
touch_start(integer total_number)
{
rotation rot = llGetLocalRot();
string z = (string)rot.z;
string s = (string)rot.s;
string x = (string)rot.x;
string y = (string)rot.y;
llSay (0, "z = " + z + ", s = " + s + "x = " + x + "y = " + y);
}

}


If you just drop this into a single rectangular prim it will rotate in the center. Make your door, then add a thin 'door-jam' piece to one side and link the two together. The smaller prim being the root now, drop in the script and you are good to go.



LIGHTS CAMERA -- Ok.. Just Lights!

3) Light switch and as many lights as you can muster. Easy-Cheez-Light script
Use it for anything in particular, just be careful to use a whacky channel
Or better yet, use a channel calculation method for even better safety - **
By safety I mean safe from other scripts accidently coinciding and messing up
Yours on the same channel. Whether it be by mistake or otherwise ;)
Enjoy -




CODE

//Easy-Cheez Shout - Control Script I wrote for my lights in the Pub.
//Haplo Voss


integer LtSwitch = FALSE;
default
{
touch_start(integer total_number)
{
if(LtSwitch == FALSE)
{
LtSwitch = TRUE;
llShout(1701, "On");
}
else
{
LtSwitch = FALSE;
llShout(1701, "Off");
}
}
}


OKOKOK... here is the drop-in script for your satellite lights. Nice and separated out. :)
CODE

default
{
state_entry()
{
llListen(1701,"","","");
}
listen(integer channel, string name, key id, string message)
{
if(message == "On")
{
llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 10.0, 25.0, 0.75] );
}
else
{
if(message == "Off");
llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 0.0, 3.0, 0.75] );
}
}
}

// 10 = Intensity
// 25 = coverage area
//.75 = drop off / fade out of light as it gets farther away from the
// light source. Play around with the values.. it's pretty fun.
// Change your world to midnight and put a light source behind a
// transparency... fun stuff to mess around with.
//------------------------


ENJOY!

* Remember that using " llShout " has a limited range. I think around 30m. So if your lights are going to be REALLY FAR away... don't get frustrated, just keep looking! *
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
03-22-2007 07:44
/15/61/172800/1.html
_____________________
i've got nothing. ;)
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
03-28-2007 21:19
From: someone

Shouts text on channel. llShout range is a 100m radius sphere centered on the calling object.


100m radius can almost cover an entire sim
Ace Albion
Registered User
Join date: 21 Oct 2005
Posts: 866
03-29-2007 01:47
You can mitigate cross-talk by checking for the same owner in the listen of the lights for where the message "On", "Off" came from.

like (if message == "On" && llDetectedOwner(0) == llGetOwner())

Or by negotiating a new randomly generated channel for the comms to set to.

Or both!
_____________________
Ace's Spaces! at Deco (147, 148, 24)
ace.5pointstudio.com
Daisy Rimbaud
Registered User
Join date: 12 Oct 2006
Posts: 764
03-29-2007 03:25
It's annoying to have to use an extra prim for a door hinge to get round the rotation problem. You would think it would be possible to get a decent rotation about one edge ...

One trick I've seen is to make the door twice as wide as needed, and place the centre where the hinge should be. Then use a texture to make the unwanted half of the door invisible.
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
03-29-2007 03:49
From: Ace Albion
like (if message == "On" && llDetectedOwner(0) == llGetOwner())


from the wiki:
From: someone
Note: The llDetected* functions will only return a meaningful value in the collision(), collision_start(), collision_end(), sensor(), touch(), touch_start(), or touch_end() events.


To get round that, you can run a single sensor sweep for id when a command is first shouted, detect the owner and if it's the correct owner log that id. You can then switch the listener from listening for all on the channel to listening specifically for the switch object.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-29-2007 04:17
From: Daisy Rimbaud
It's annoying to have to use an extra prim for a door hinge to get round the rotation problem. You would think it would be possible to get a decent rotation about one edge ...


You can heres an example

From: Daisy Rimbaud
One trick I've seen is to make the door twice as wide as needed, and place the centre where the hinge should be. Then use a texture to make the unwanted half of the door invisible.


Or just cut it to remove the unwanted portion.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
03-29-2007 20:13
the listen event returns the key of the agent that triggered the event

if (id == llGetOwner());

or you can just setup the listener to only listen to the owner...
Ace Albion
Registered User
Join date: 21 Oct 2005
Posts: 866
03-30-2007 00:20
From: Sys Slade
from the wiki:


To get round that, you can run a single sensor sweep for id when a command is first shouted, detect the owner and if it's the correct owner log that id. You can then switch the listener from listening for all on the channel to listening specifically for the switch object.


I have to check my code when I get in SL (I don't pay much attention to scripting except when I need to) but my object communication relay system does have an owner check on the talking prim. Maybe it's a different command, but it works.
_____________________
Ace's Spaces! at Deco (147, 148, 24)
ace.5pointstudio.com
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
03-30-2007 03:08
I'm only going off the wiki, not in world too much this week, so feel free to correct me if they have changed the rules again :p
Ace Albion
Registered User
Join date: 21 Oct 2005
Posts: 866
04-02-2007 00:46
llGetOwnerKey(idofthethingthatspoke) == llGetOwner()

I think.
_____________________
Ace's Spaces! at Deco (147, 148, 24)
ace.5pointstudio.com
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
04-02-2007 06:42
Yeah, that'd work :)