Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

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 rotate
rot.y = 0; //your door slightly out of whack, then the script
rot.z = 0; //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 sucker 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);
}

}



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");
}
}
}

//-----------------------------
//Here is the "Deposit Script" for your other objects as an example -
//I know I still rack my brain over the smallest stuff, so here is the even
//Easier yet llListen script for your Lights / whatever you are activating...
//Just thought I would throw it in here also. ENJOY!
//------------------------------
//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] );
// }
//}
//}
//
//Just remove the "//" in front of each line and you're all set to drop it in your
//Prim and it will light up like the daylights!
// 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 behing a transparency... fun stuff to mess around with.
//------------------------
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
03-22-2007 07:44
/54/b3/172875/1.html
_____________________
i've got nothing. ;)
Lysila Denja
Registered User
Join date: 14 Nov 2007
Posts: 20
02-10-2008 18:53
Thank you for taking the time to post this and share what you have learned. I am actually where you once were. Trying to learn the scripting from the ground up. I got a method for moving and moving back:

default
{
touch_start(integer total_number)
{
llSetPos(llGetPos() + <0,0,1>;);

llSleep(30.0);
llSetPos(llGetPos() + <0,0,-1>;);
}
}


I used the wiki to put that together. It actually moves the object up and then back down after 30 seconds. OK, I am a little proud :D

Anyway, I am looking around to try something a little different. I want to be able to have touch 1 and touch 2. So touch 1 = open and touch 2 = close.

I know this can be done, becuase doors open and close on 2 touches. Can anyone point me in the right direction?

Thanks!