Jump to content

HUD control lights for owner only


Tattooshop
 Share

You are about to reply to a thread that has been inactive for 1581 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello all and Merry Christmas!

So I am scripting a HUD here turning on/off wearable lights. Lights have state entry, listener and timer events. 

But there is a problem. When some one else wearing the lights nearby, I can control them from my HUD. And it not supposed to be.

How to avoid it? If its Owner detect how it should look like? And the most important - if its owner detect - where it goes? Which event, HUD or lights?

Thanks!

Link to comment
Share on other sites

You can solve the problem any way you like.  You can send a message to a specific person with llRegionSayTo, or the person receiving a message can have a script that listens only for message from a specific source or on a specific channel, or only dialog messages generated by the wearer herself ( by checking if (llGetOwner() == llGetObjectOwner(id) )

  • Like 1
Link to comment
Share on other sites

Hiya Tattoo, isn't it better to use llMessageLinked in this case?

just my two cents

regards,

Dargo

edit: never mind, i don't think attachments are truly linked, so llMessageLinked would not work in this case.

   

Q: Can I use link messages to communicate between two attachments, or an attachment and the object the avatar is sitting on?
A: No, they're not truly linked in this case. You'll need to use chat instead.

https://lslwiki.digiworldz.com/lslwiki/wakka.php?wakka=llMessageLinked&show_comments=1

Edited by Kardargo Adamczyk
  • Like 1
Link to comment
Share on other sites

18 minutes ago, Rolig Loon said:

if (llGetOwner() == llGetObjectOwner(id) )

Hi! Thanks! Yes, i tried to add this line to listen event, but it didnt worked. I think this is the best option, just dont know where it goes. And its on a specific channel already. 

Link to comment
Share on other sites

9 minutes ago, Tattooshop said:

Hi! Thanks! Yes, i tried to add this line to listen event, but it didnt worked. I think this is the best option, just dont know where it goes. And its on a specific channel already. 

looks something like this:

     listen(integer channel, string name, key id, string message)
    {
        if (llGetOwner() == llGetOwnerKey(id) ) 
        {
            if (message == "turn on")
            {
                //turn on your light here
            }
            else if (message == "turn off")
            {
                //turn off your light here
            }
        }
    }

 

 

Edited by Kardargo Adamczyk
  • Thanks 1
Link to comment
Share on other sites

I use a little bit of code to calculate the channel based on the owner's UUID. 

See http://wiki.secondlife.com/wiki/UUID2Channel for that specific code.
I usually use the one with the app key, to make sure that each of my projects get a different channel number so that, for example, a texture HUD will not try to use a dance HUD or whatever. It also makes it very unlikely that my HUD will try to control your lights.

Here's some example code:
 

integer AppKey = 123456;    // This is the app key. Create your own app key and make it different for each different project. 
                            // Make sure the HUD and the other object share the same app key!

integer Key2AppChan(key ID, integer App) {
    return 0x80000000 | ((integer)("0x"+(string)ID) ^ App);
}

default
{
    state_entry()
    {
        integer CHANNEL = Key2AppChan(llGetOwner(), AppKey);     // Calculate the channel, based on owner ID and the appkey which we've defined earlier. 
        llOwnerSay("I am going to listen on channel "+(string)CHANNEL);
      	
      	// ADD THE REST OF YOUR CODE HERE
    }
}

 

  • Thanks 1
Link to comment
Share on other sites

13 hours ago, Kardargo Adamczyk said:

looks something like this:


     listen(integer channel, string name, key id, string message)
    {
        if (llGetOwner() == llGetOwnerKey(id) ) 
        {
            if (message == "turn on")
            {
                //turn on your light here
            }
            else if (message == "turn off")
            {
                //turn off your light here
            }
        }
    }

 

 

Thank you very much! It works!

  • Like 1
Link to comment
Share on other sites

7 hours ago, Fritigern Gothly said:

I use a little bit of code to calculate the channel based on the owner's UUID. 

See http://wiki.secondlife.com/wiki/UUID2Channel for that specific code.
I usually use the one with the app key, to make sure that each of my projects get a different channel number so that, for example, a texture HUD will not try to use a dance HUD or whatever. It also makes it very unlikely that my HUD will try to control your lights.

Here's some example code:
 


integer AppKey = 123456;    // This is the app key. Create your own app key and make it different for each different project. 
                            // Make sure the HUD and the other object share the same app key!

integer Key2AppChan(key ID, integer App) {
    return 0x80000000 | ((integer)("0x"+(string)ID) ^ App);
}

default
{
    state_entry()
    {
        integer CHANNEL = Key2AppChan(llGetOwner(), AppKey);     // Calculate the channel, based on owner ID and the appkey which we've defined earlier. 
        llOwnerSay("I am going to listen on channel "+(string)CHANNEL);
      	
      	// ADD THE REST OF YOUR CODE HERE
    }
}

 

Hello! Thank you very much for this example! It goes to Sender HUD? And what goes to listener object? Will be additional changes? For example now its:

    state_entry()
    {
        llListen(-1234567, "", "", "");
    }
    listen(integer channel, string name, key id, string msg)
    {
        if (msg == "run1true") 
        {
            lightsOn();
            // Turn the light ON
        }
        
        if (msg == "run1false") 
        {
            lightsOff();
            // Turn the light OFF 
        }
    }

 

Edited by Tattooshop
Link to comment
Share on other sites

So I made these simple examples based on your code. It works! But still maybe I am doing something wrong?

SENDER

// SENDER

integer AppKey = 123456; // This is the app key. Create your own app key and make it different for each different project. 
// Make sure the HUD and the other object share the same app key!

integer Key2AppChan(key ID, integer App)
{
    return 0x80000000 | ((integer)("0x" + (string) ID) ^ App);
}

default
{
    state_entry()
    {
        integer CHANNEL = Key2AppChan(llGetOwner(), AppKey); // Calculate the channel, based on owner ID and the appkey which we've defined earlier. 
        llOwnerSay("I am going to listen on channel " + (string) CHANNEL);

        // ADD THE REST OF YOUR CODE HERE
    }


    touch_start(integer total_number)
    {
        integer CHANNEL = Key2AppChan(llGetOwner(), AppKey);
        llSay(CHANNEL, "Touched");
    }
}

LISTENER

// LISTENER

integer AppKey = 123456; // This is the app key. Create your own app key and make it different for each different project. 
// Make sure the HUD and the other object share the same app key!

integer Key2AppChan(key ID, integer App)
{
    return 0x80000000 | ((integer)("0x" + (string) ID) ^ App);
}

default
{
    state_entry()
    {
        integer CHANNEL = Key2AppChan(llGetOwner(), AppKey); // Calculate the channel, based on owner ID and the appkey which we've defined earlier. 
        llOwnerSay("I am going to listen on channel " + (string) CHANNEL);
        llListen(CHANNEL, "", "", ""); 

        // ADD THE REST OF YOUR CODE HERE
    }
    listen(integer channel, string name, key id, string msg)
    {
        if (msg == "Touched")
        {
            llSay(0, "Hello!");
        }
    }
}

 

Edited by Tattooshop
Link to comment
Share on other sites

6 hours ago, Tattooshop said:

So I made these simple examples based on your code. It works! But still maybe I am doing something wrong?

Well, it's best to create a new app key for each new project and I saw that you kept my example key.

Imagine you have two different HUDs for two different things. For example, a HUD for shoes that you made, and a HUD for fancy elf ears that you also made. The last thing you want is for your elf ears to get the textures that should go to your shoes. Giving both items a different app key would make sure that will not happen.

So for the shoes you could do 123456 for the app key, and for the ears you could do 123457, or 3287465, or 11118888848 or some other number. Just to make sure that the channel will be different for each project. 

The rest looks good-ish to me, although there are a few issues. 

  1. You should define a global variable for CHANNEL. So place "integer CHANNEL;" a few lines above "default".
  2. Remove "integer CHANNEL = Key2AppChan(llGetOwner(), AppKey);" from inside the touch_stgart() event. It's not needed and will confuse the script.
  3. Remove "integer" from the "integer CHANNEL ... " line inside the state_entry() events, the script already knows that it's supposed to be an integer.
  4. Do read the comments that I added. They will give you some information that you need 🙂 

 

  • Thanks 1
Link to comment
Share on other sites

20 hours ago, Fritigern Gothly said:

Well, it's best to create a new app key for each new project and I saw that you kept my example key.

Imagine you have two different HUDs for two different things. For example, a HUD for shoes that you made, and a HUD for fancy elf ears that you also made. The last thing you want is for your elf ears to get the textures that should go to your shoes. Giving both items a different app key would make sure that will not happen.

So for the shoes you could do 123456 for the app key, and for the ears you could do 123457, or 3287465, or 11118888848 or some other number. Just to make sure that the channel will be different for each project. 

The rest looks good-ish to me, although there are a few issues. 

  1. You should define a global variable for CHANNEL. So place "integer CHANNEL;" a few lines above "default".
  2. Remove "integer CHANNEL = Key2AppChan(llGetOwner(), AppKey);" from inside the touch_stgart() event. It's not needed and will confuse the script.
  3. Remove "integer" from the "integer CHANNEL ... " line inside the state_entry() events, the script already knows that it's supposed to be an integer.
  4. Do read the comments that I added. They will give you some information that you need 🙂 

 

Thank you very much! Hopefully done it correct.

// Sender HUD 2.0

integer AppKey = 654321; // This is the app key. Create your own app key and make it different for each different project. 
// Make sure the HUD and the other object share the same app key!
integer CHANNEL;
integer Key2AppChan(key ID, integer App)
{
    return 0x80000000 | ((integer)("0x" + (string) ID) ^ App);
}

default
{
    state_entry()
    {
        CHANNEL = Key2AppChan(llGetOwner(), AppKey); // Calculate the channel, based on owner ID and the appkey which we've defined earlier. 
        // ADD THE REST OF YOUR CODE HERE
    }

    touch_start(integer total_number)
    {
        llSay(CHANNEL, "Touched");
    }
}
// Receiver HUD 2.0

integer AppKey = 654321; // This is the app key. Create your own app key and make it different for each different project. 
// Make sure the HUD and the other object share the same app key!
integer CHANNEL;
integer Key2AppChan(key ID, integer App)
{
    return 0x80000000 | ((integer)("0x" + (string) ID) ^ App);
}

default
{
    state_entry()
    {
        CHANNEL = Key2AppChan(llGetOwner(), AppKey); // Calculate the channel, based on owner ID and the appkey which we've defined earlier. 
        llListen(CHANNEL, "", "", ""); // Listen to anybody saying anything on CHANNEL 
        // ADD THE REST OF YOUR CODE HERE
    }
    listen(integer channel, string name, key id, string msg) 
    {
        if (msg == "Touched")
        {
            llSay(0, "Hello!");
        }
    }
}

 

Link to comment
Share on other sites

2 hours ago, Tattooshop said:

Thank you very much! Hopefully done it correct.

Without going inworld to test it, I would say it looks good now. 
However, I just got up and did not have coffee yet, so it is possible that I have missed something.

Although, if it works in-world, then I guess you have a nice basis for your other projects. :D

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1581 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...