Pages

Saturday, May 22, 2010

Remote control



Mmmmmkay so COKE asked me the other day about making a remote control for some curtains, like if you click a button then all the curtains should open or half shut or close. Well COKE I'll give you a real helpful snippet and hopefully you can figure out where to go from there. Of course if you need more help you're always welcome to ask more questions :P

Kay so here goes.

My super basic remote control script looks like this (it goes in the object that you're using to be the remote):

default
{
state_entry()
{

}

touch_start(integer total_number)
{
llRegionSay(-999, "1");
}
}
And this is the script that would go in the curtains (it would need to be the same script that controls whether they're open or closed and whatnot):

default
{
state_entry()
{
llListen(-999, "", "1bd1faad-303f-748e-bf5c-745d124e751e", "");
}
listen(integer channel, string name, key id, string message)
{
if(message == "1"){
llSay(0, "Hi everybody :)");
}
}
}
Here is an explanation of the llListen function. The parameters are like this: llListen( integer channel, string name, key id, string msg );(thanks wiki :) )
The parameters act as filters for what you want to listen for. This is great for cutting down on lag and makes sure the script doesn't have to sift through tons of unrelated chat. Channel is obviously the channel you want to listen for the message on (I used -999). Name will listen only for chat from specific av's or objects (I used "" to leave that blank). ID will filter for a specific object or avatar UUID. You'll notice that I used the UUID of a specific prim. You can get this really easily from the build menu using Emerald (see fig 1.). Msg will filter for a specific message, but since we will need to use different messages, you should leave that blank too using "".

Fig 1.
I think the "listen" event is pretty self explanatory. I have it set up so that if the message is "1", the prim will say a message. Sooooo, you can set up your remote control script to cycle through saying "open", "half_open", "close", and then set up your listener script to either open, set the curtains to half shut, or closed, based on the message.

Let me know if you have any more questions, you know where to find me :)

Friday, May 21, 2010

Hot Topics (Part 1)

Ok so I've helped several people with several questions pertaining to several things. None of which were answered on the blog so I figure I'll pick and choose and write a post about a few things I've helped with here and there. This one will be a quickie.

Shila was working on a script that reads a notecard, and she wanted to know how to reset the script whenever the notecard is edited and saved. The code for this is pretty quick and simple. All you have to do is add the "changed" event to your code.

changed(integer change){
    if ( change & CHANGED_INVENTORY){
        llResetScript();
    }
    }

Tuesday, May 18, 2010

Get a bunch of info on someone (llRequestAgentData example)

Shila asked how to get an avatar's name , DOB, Payment Info  and online status. Doing this can be lengthy because each of these things need to be handled differently as they return different data types. Here is an example script I wrote this afternoon that gets all of these pieces of information:

key online_query;
string name_query;
string birthday_query;
string payinfo_query;
string owner_name;
string online;
string birthday;
string payinfo;

default
{
   touch_start(integer total_number)
    {
        key id = llDetectedKey(0);
        name_query = llRequestAgentData(id, DATA_NAME);
        online_query = llRequestAgentData(id, DATA_ONLINE);
        birthday_query = llRequestAgentData(id, DATA_BORN);
        payinfo_query = llRequestAgentData(id, DATA_PAYINFO);
    }
    dataserver(key queryid, string data)
    {
        //Find out their name --------------------------------------
        if ( name_query == queryid )
        {
            owner_name = data;
            llSay(0, "The name of the person is : " + owner_name );
        }
       
        //Find out if they are online-------------------------------
        if ( online_query == queryid )
        {
              online = data;
            if (online == "1"){
                llSay(0, "he or she is online");               
            }
            else
            {
                llSay(0, "he or she is offline");          
            }
        }
       
        //Find when their birthday is -------------------------------
        if ( birthday_query == queryid )
        {
            birthday = data;
            llSay(0, "Their birthday is "+ birthday);
        }
       
        //Find out what their payment info status is ----------------
        if ( payinfo_query == queryid )
        {
            payinfo = data;
            if (payinfo == "0"){
            llSay(0, "They have no payment info on file");
            }
            if (payinfo == "1"){
            llSay(0, "They have payment info on file");
            }
            if (payinfo == "3"){
            llSay(0, "Their payment info has been used");
            }//end if(payinfo == "3")
        }//end query if
    }//end dataserver
}//end default
There are a few things you'll notice right away. First of all I have this set up so it gets the info of whoever touched the prim. The next thing is that I have four queries set up for each of the pieces of data we want to get, and finally inside the dataserver event we have four "if" statements that handle each of the queries. The name query returns the avatar's name as a string, their online status returns as an integer disguised as a string (either 1 or 0 depending on their online status), their birthday returns as a string in the format YYYY-MM-DD, and their payment info also returns as integers in string format, 0 for no payment info, 1 for pay info on file, and 3 for pay info used. Don't ask what happened to 2.

So now you know how to get most of the data on someone's avi. If you want to do other things with this info you can put your functions in the dataserver event, inside the if statement pertaining to that piece of information.

Monday, May 17, 2010

Whoopie! (A quick sit detect script)

Nettrice's first question referred to detecting when an avatar has planted their big fat butt on a prim. Of course we've all seen this before with lucky chairs, as well as any poseball. Here's a quick example:

vector sitoffset=<0.0, 0.0, 0.1>; // sit position offset (x = front back, y = left right, z = updown)
default{
    state_entry(){
        llSitTarget(sitoffset, ZERO_ROTATION);
    }
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
           
            if (llAvatarOnSitTarget() != NULL_KEY)
            {
                 llSay(0, "zomgz!!");
            }
               
        }
    }
}
You don't have to do this, but I put in a sit target function (llSitTarget) just so that I could sit on the object easier. I would probably recommend this though, I had a rough time getting my av to sit down on the prim without it ("no room to sit here, try somewhere else").  All you would have to do to change this script to make it do what you want is put all your functions where " llSay(0, "zomgz!!");" is right now, and to implement it into another script just copy and paste everything in the "changed" event.

Happy sitting!

Sunday, May 16, 2010

Collision Detection Goodness

Nettrice had a couple of questions but I've had a long weekend and I'm draggin so I'm going to answer her second question first and save the other one for tomorrow.

Her question was in regards to making part of a ramp/walkway light up as the avatar touches those certain parts, similar to the piano keys you play by walking on (e.g. Tom Hanks in Big).

You can achieve this with just a few lines of code.

default
{
    state_entry()
    {
        llVolumeDetect(TRUE); // Starts llVolumeDetect
    }
    collision_start(integer total_number)
    {
 //Your functions will go here, for example the color changing and sound playing
llPlaySound(yoursound, 1);
          llSetColor(<0.6,0.5,0.4>, ALL_SIDES);
    }
}
 llVolumeDetect triggers the collision_start event, so whatever happens in that event will be triggered when an avatar (or object) collides with that object. There are a few things to keep in mind, the first being that the object will turn phantom, so make sure you have another solid prim under that prim if he is walking on it. The other thing to remember is that this function must be applied to the root object.

Hope this helps! Check back tomorrow for the answer to your first question.