Jump to content

Have a script listen to only the seated avatar


BEGOCER Lehmann
 Share

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

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

Recommended Posts

Oh snap its ya boy back at it again with a probably easy fix to a problem that is causing him a ton of issues.

I have yet another vehicle script (how original) that has voice commands on it as it has guest/owner modes. I've got a combat system installed and working and that is where the two voice commands that use channel 0 to turn the system on and off.

However the script listens to all avatars, not just the seated one. 

I've got in my state_entry this:

 state_entry()
    {
         sitting = llAvatarOnSitTarget();
        llListen(0,"",sitting,"");

then in my listen area this:

 listen(integer c,string n,key i,string msg)
    {  
       if(msg == "cs on")
        {
          cson();
           
      }

Technically shouldn't that listen to just the person sitting? Not everyone? As what I've googled up across the forums here  llListen(0,"",llGetOwner()""); just listens to the owner, as it should. 

I've tried adding things like if(sitting == sitting) from other scripts I've found and nothings worked yet (Imagine a fly bumping into a window trying to get out despite the window being open next to it- thats me and how I look when I script. I've probably overlooked so much correct stuff) And I'm probably forgetting something in my script like grabbing keys or something...

I really have no idea how this stuff works after all these years still lol. 

Once more I come to the forums for help!

Link to comment
Share on other sites

Hello BEGOCER Lehmann.

Here's a script that I put in a plain, just-rezzed cylinder.  It listens to a sitter, stop listening when the person stands.  It doesn't listen to anyone else.

Things I learned while working on it: The object must have a sit target or llAvatarOnSitTarget returns NULL_KEY.  If you use that as the key in llListen, then it'll listen to anyone.  My guess is that might be what happened in your situation.

Here's the demo script:
 

integer
HANDLE;

default
{
    state_entry()
    {
        vector offset;
        rotation rot;
        
        llOwnerSay( "Hello, Avatar!" );
        offset = <0.25, 0.0, 0.5>;
        rot = <0, 0, 0, 1>;
        llSitTarget( offset, rot );
    }

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
    }
    
    listen( integer channel, string name, key id, string message ) {
        llOwnerSay( name + " said something" );
    }
    
    changed( integer change ) {
        key sitter;
        
        if (CHANGED_LINK & change) {
            llOwnerSay( "links changed" );
            sitter = llAvatarOnSitTarget();
            if (sitter == NULL_KEY) {
                llOwnerSay( "nobody is sitting" );
                llListenRemove( HANDLE );
            } else {
                llOwnerSay( "Listen to " + llGetDisplayName( sitter ) + "." );
                HANDLE = llListen( 0, "", sitter, "" );
            }
        }
    }
}

 

Link to comment
Share on other sites

On 9/18/2022 at 1:14 PM, BEGOCER Lehmann said:

 state_entry()
    {
         sitting = llAvatarOnSitTarget();
        llListen(0,"",sitting,"");

 

Just as an fyi, in addition to needing an actual sit target defined for llAvatarOnSitTarget to work, you also need to make sure an avatar is sitting on the object before calling that function - otherwise you'll get a null key as well.

It's not exactly clear from the code snippet you posted, but generally speaking it looks like you tried to set up the listen right as the script starts in state_entry. Assuming you're not resetting the script, or switching to a new state after an avatar sits, then when that code runs, it's very likely noone is currently sitting, and thus llAvatarOnSitTarget returns null, giving you an open listen filter.

 

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 594 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...