Jump to content

Control music stream (URL)


Isobeast
 Share

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

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

Recommended Posts

The plan sounds OK.

have a global variable key OktoSit intiialised to NULL_KEY;

Inside the touch event,

test llDetectectedGroup. If True, set a timer for ten seconds, and set llDetectedKey value as the global variable OktoSit;

if FALSE, set global variable OktoSit to NULL_KEY

If the timer goes before any changed event, set OkoSit to NULL_KEY

Inside changed, in changed link, cancel any timer then test the value for llAvatarOnSitTarget. If it is Not NULL_KEY, then check if it is the same as OktoSit. If different, unsit whoever it was.

If somebody just right-clicks and sits without first touching, OktoSit will be NULL_KEY and so they will get thrown off. If they don't know they must be in the same group they might keep on trying, so when you unsit somebody, whisper a message such as "Please touch me first to perform the group check" Or have a sign or hovertext advising them.

Don't forget that llAvatarOnSitTarget will return NULL_KEY when somebody has just got up, so seperate thoe two conditions carefully.

Edited by Profaitchikenz Haiku
  • Thanks 1
Link to comment
Share on other sites

11 hours ago, Isobeast said:
if( llGetSubString( stream, 0, 3) != "http")

Good idea. I'm about to add a line like that to my own radio scripts. (I'm in a mood for refactoring tonight, and there are some less-than-optimum things about my radio scripts that are nagging me, such as: they don't force user to wait until notecard is finished being read before user can launch menu; they don't check to see that all URLs start with "http" and all station names don't; they don't check to see that the Stations and URLs lists are the same length; they don't use channel numbers unique to each radio; etc.)

  • Like 1
Link to comment
Share on other sites

13 hours ago, Isobeast said:

The plan was this: the avatar clicks on the prim, and if the group matches, then the avatar has, say, ten seconds to sit down. if the group does not match, then there is no way to sit. and then I realized that the avatar can also sit with the right mouse button ... and then I got stuck.

Is it important to the scenario that there be two separate actions here, the touch and then the sit? If it's just as good for touch to automatically seat group members, there's a handy function llSitOnLink() that could go in a touch-related event handler, conditionalized on llDetectedGroup(), and with seating on the object itself limited by PRIM_SCRIPTED_SIT_ONLY.

(Incidentally, in addition to llDetectedGroup(), similar functionality is offered by llSameGroup() inside function or events (such as changed) where Detected functions aren't available. It's also possible to test for different groups, but that's tangential even to this tangent.)

[EDIT: Of course I meant to mention that llSitOnLink() is an Experience-based function, so that limits its applicability unless every group member is sure to belong to the venue's Experience. Even without that, or if the two separate actions are necessary, the PRIM_SCRIPTED_SIT_ONLY could reduce confusion for non-group members: They touch and nothing happens, but group members enable seating. There still should to be a test in CHANGED_LINK in case a non-group member sneaks in between when the group member touches and when they sit.]

Edited by Qie Niangao
  • Thanks 1
Link to comment
Share on other sites

13 hours ago, Profaitchikenz Haiku said:

The plan sounds OK.

have a global variable key OktoSit intiialised to NULL_KEY;

Inside the touch event,

test llDetectectedGroup. If True, set a timer for ten seconds, and set llDetectedKey value as the global variable OktoSit;

if FALSE, set global variable OktoSit to NULL_KEY

If the timer goes before any changed event, set OkoSit to NULL_KEY

Inside changed, in changed link, cancel any timer then test the value for llAvatarOnSitTarget. If it is Not NULL_KEY, then check if it is the same as OktoSit. If different, unsit whoever it was.

If somebody just right-clicks and sits without first touching, OktoSit will be NULL_KEY and so they will get thrown off. If they don't know they must be in the same group they might keep on trying, so when you unsit somebody, whisper a message such as "Please touch me first to perform the group check" Or have a sign or hovertext advising them.

Don't forget that llAvatarOnSitTarget will return NULL_KEY when somebody has just got up, so seperate thoe two conditions carefully.

 

17 minutes ago, Qie Niangao said:

Is it important to the scenario that there be two separate actions here, the touch and then the sit? If it's just as good for touch to automatically seat group members, there's a handy function llSitOnLink() that could go in a touch-related event handler, conditionalized on llDetectedGroup(), and with seating on the object itself limited by PRIM_SCRIPTED_SIT_ONLY.

(Incidentally, in addition to llDetectedGroup(), similar functionality is offered by llSameGroup() inside function or events (such as changed) where Detected functions aren't available. It's also possible to test for different groups, but that's tangential even to this tangent.)

thank you very much! I decided to try what the Prof advised, but nothing came of it. I understand logically, but I cannot transfer it to the script. Here are my changed and timer events.

 

changed(integer change)
{
    if (change & CHANGED_LINK)
    {
        llSetTimerEvent(0);

        key sitter = llAvatarOnSitTarget();

        if (sitter != NULL_KEY)
        {
            if (sitter == OktoSit)
            {
                gListener = llListen(channel, "", "", "");
                llWhisper(0, "Enter the URL of your stream in channel 10. Example: '/10 http://streamurl.com:0000'");

                llRequestPermissions(sitter, PERMISSION_TRIGGER_ANIMATION);
            }
            else UnSit(sitter);
        }
    }
    else
    {
        if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
        {
            llListenRemove(gListener);

            if (animation)
            {
                llStopAnimation(animation);
            }

            llSetAlpha(1.0, ALL_SIDES); // Show prim

            // Read the default URL from the object description:
            key default_url = llGetObjectDesc();

            llSetParcelMusicURL(default_url);
            llWhisper(0, "The parcel stream returned to the radio at the URL: " + (string) default_url);
        }
    }
}

timer()
{
    OktoSit == NULL_KEY;
    llSetTimerEvent(0);
}

 

Link to comment
Share on other sites

And here is the touch event

    touch_start(integer num_detected)
    {
        if (llDetectedGroup(0) == TRUE)
        {
            llSetTimerEvent(10);
            OktoSit = llDetectedKey(0);

            llWhisper(0, (string) OktoSit + "You have 10 seconds");
        }
        else
        {
            OktoSit = NULL_KEY;
            llWhisper(0, "Wrong group tag");
        }
    }

 

Link to comment
Share on other sites

a couple of things Isobeast

in the first code

set the listener to only listen for the sitter. So naughty people can't interfere with the sitter, by changing the stream

gListener = llListen(channel, "", sitter, "");

in the second code, is probably a dev typo but I put it here

(string)OkToSit  will whisper the key of the sitter

whisper their name instead

llWhisper(0, llGetDisplayName(OktoSit) + "You have 10 seconds to sit down");

  • Thanks 1
Link to comment
Share on other sites

10 minutes ago, Mollymews said:

set the listener to only listen for the sitter. So naughty people can't interfere with the sitter, by changing the stream

gListener = llListen(channel, "", sitter, "");

Oh this is a very valuable remark, thank you! 👍

 

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

I managed to do something with the changed event! 👍

but now if you passed the check once, you can sit down over and over again without checking. shouldn't the timer be reset OkToSit to NULL_KEY? I even added a separate reset when getting up, but it didn't help.

 

So far with the changed event ...

not sure if this is ok. please correct me if something is wrong !!

    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            llSetTimerEvent(0);
            
            key sitter = llAvatarOnSitTarget();
            if (sitter != OktoSit)
            {
                llUnSit(sitter);
                llSetAlpha(1.0, ALL_SIDES); // Show prim
                llWhisper(0, "Please touch me first to perform the group check");
            }
            else if (sitter != NULL_KEY)
            {
                gListener = llListen(channel, "", sitter, "");
                llWhisper(0, "Enter the URL of your stream in channel 10. Example: '/10 http://streamurl.com:0000'");

                llRequestPermissions(sitter, PERMISSION_TRIGGER_ANIMATION);
                OktoSit = NULL_KEY;
            }
            else
            {
                if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
                {
                    llListenRemove(gListener);

                    if (animation)
                    {
                        llStopAnimation(animation);
                    }

                    llSetAlpha(1.0, ALL_SIDES); // Show prim

                    // Read the default URL from the object description:
                    key default_url = llGetObjectDesc();

                    llSetParcelMusicURL(default_url);
                    llWhisper(0, "The parcel stream returned to the radio at the URL: " + (string)default_url);
                }
            }
        }
    }

 

Edited by Isobeast
Link to comment
Share on other sites

1 hour ago, Qie Niangao said:

the PRIM_SCRIPTED_SIT_ONLY could reduce confusion for non-group members: They touch and nothing happens, but group members enable seating. There still should to be a test in CHANGED_LINK in case a non-group member sneaks in between when the group member touches and when they sit.]

Could you please give an example of using this method? I have not found any wiki examples and have never used it myself.

Link to comment
Share on other sites

Isobeast, you are quite a long way down the dev path here now but if you want to treat this as a learning experience then we can relook at your design

now that we (you) have a understanding of CHANGED_LINK then we can ask ourselves if the touch_start event and the timer is necessary. And how we can not need to do this

the design requirement is: Only one avatar sitting at a time and the avatar must be in the same group as the seat, yes ?

on this basis then lets introduce some other functions

http://wiki.secondlife.com/wiki/LlGetObjectPrimCount

http://wiki.secondlife.com/wiki/LlGetNumberOfPrims

http://wiki.secondlife.com/wiki/LlGetLinkKey

 

walking thru these by example

// global
key avatar = NULL_KEY;  // the key of the avatar currently sitting on the seat

changed (integer change)
{
   if (change & CHANGED_LINK)
   {
      integer object_prims = llGetObjectPrimCount();
      integer total_prims = llGetNumberOfPrims(); // total_prims includes avatars sitting
      integer number_of_avatars_sitting = total_prims - object_prims;
      
      if (number_of_avatars_sitting == 1)
      {
         if (avatar == NULL_KEY) // check that this is a first time sitter
         {
            key sitter = llAvatarOnSitTarget();
           
            if (... same group ...)
            {
               ... request permissions only here ...
               ... do not set up the listener until the permissions have been obtained
               ...   in the run_time_permissions event ...
            }
            else
            {
                 ... unsit sitter
            }
         }
      }
      else if (number_of_avatars_sitting > 1)
      {
         // here we unsit any rando avatar who has tried to sit on top of our sitter
         //    by getting the key of the last prim in the linkset (which is the key of the rando avatar)   

         llUnSit(llGetLinkKey(total_prims));  
      }
      else // is == 0: nobody is sitting
      {
         if (avatar != NULL_KEY) // reset only when avatar has stood
         {
            ... remove the listener here ...
            ... reset alpha ..
            ... default music stream ...

            ... we do not have to stop animation here...
            ...   the system will stop animation automatically when the avatar stands ...


            avatar = NULL_KEY;  // we do this so that the checks can be done safely   
         }
      }    
   }
}

run_time_permissions(integer perms)
{
   if (perms & PERMISSION_TRIGGER_ANIMATION)
   {
      avatar = llGetPermissionsKey();  // we (the script) have this avatar's permissions
       
      ... start animation ...
      ... set alpha ...
      ... set up the listener
   }
}
Edited by Mollymews
bracket typo
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Isobeast said:

I decided to try what the Prof advised, but nothing came of it.

Actually, you were just about there...

Snippets follow (with a caveat, some days my typing is so bad I would do better if I used my feet instead and chanted "isa you wasa born in Naples? We pressa da grapes together"

 

key isOktoSit = NULL_KEY;

touch_start(integer touches)
{
	if(llDetectedGroup(touches - 1) == TRUE)
	{
		isOktoSit = llDetectedKey(touches - 1);
		llWhisper(0, "You have ten seconds to park your behemoth");
		llSetTimerevent(10.0);
	}
	else
	{
		llWhisper(0, "Must be in the group to us this...");
	}
}
changed(integer change)
{
	if( change & CHANGED_LINK)
	{
		llSetTimerEvent(0.0);
		key avatar = llAvatarOnSitTarget();
		if(avatar != NULL_KEY)
		{
			if(avatar != isOktoSit)
			{
				llUnSit(avatar);
				llWhisper(0,"Must be in the same grou, please touch to try again");
				isOktoSit = NULL_KEY;
			}
		}
		else
		{
			isOktoSit = NULL_KEY;	// in case it was  valid sitter who left the edfice
		}
	}
}

timer()
{
	llSetTimerEvent(0.0);
	isOktoSit = NULL_KEY;
}

 

  • Thanks 1
Link to comment
Share on other sites

18 hours ago, Isobeast said:

Could you please give an example of using this [SCRIPTED_SIT_ONLY] method? I have not found any wiki examples and have never used it myself.

Sorry, I realize it's a little late now, but here's a simple example. (Doesn't do any of the stream control stuff.)


setSeat(integer enabled)
{
    llSetClickAction(llList2Integer([CLICK_ACTION_TOUCH, CLICK_ACTION_SIT], enabled));
    llSetLinkPrimitiveParamsFast(LINK_THIS, [ PRIM_SCRIPTED_SIT_ONLY, !enabled ]);
}

default
{
    state_entry()
    {
        llSitTarget(<0,0,0.5>, ZERO_ROTATION);
        setSeat(FALSE);
    }
    touch_start(integer total_number)
    {
        key toucher = llDetectedKey(0);
        if (llDetectedGroup(0))
        {
            llRegionSayTo(toucher, 0, "This seat is available to a group member for 10 seconds.");
            setSeat(TRUE);
            llSetTimerEvent(10.0);
        }
        else
            llRegionSayTo(toucher, 0, "Perhaps you want to change your active group?");
    }
    changed(integer change)
    {
        if (CHANGED_LINK & change)
        {
            key newestSitter = llGetLinkKey(llGetNumberOfPrims());
            if (NULL_KEY == newestSitter)   // nobody seated
                return;
            else
            if (llSameGroup(newestSitter))  // group member sitting
                setSeat(FALSE);
            else
                llUnSit(newestSitter);  // non-member tried to sit while seat enabled
        }
    }
    timer()
    {
        setSeat(FALSE);
    }
}

Among the crude simplifications, a group member's touch enables the seat for any one group member, not restricted to the toucher.

  • Thanks 1
Link to comment
Share on other sites

On 10/29/2021 at 11:02 AM, Qie Niangao said:

Sorry, I realize it's a little late now, but here's a simple example. (Doesn't do any of the stream control stuff.)


setSeat(integer enabled)
{
    llSetClickAction(llList2Integer([CLICK_ACTION_TOUCH, CLICK_ACTION_SIT], enabled));
    llSetLinkPrimitiveParamsFast(LINK_THIS, [ PRIM_SCRIPTED_SIT_ONLY, !enabled ]);
}

default
{
    state_entry()
    {
        llSitTarget(<0,0,0.5>, ZERO_ROTATION);
        setSeat(FALSE);
    }
    touch_start(integer total_number)
    {
        key toucher = llDetectedKey(0);
        if (llDetectedGroup(0))
        {
            llRegionSayTo(toucher, 0, "This seat is available to a group member for 10 seconds.");
            setSeat(TRUE);
            llSetTimerEvent(10.0);
        }
        else
            llRegionSayTo(toucher, 0, "Perhaps you want to change your active group?");
    }
    changed(integer change)
    {
        if (CHANGED_LINK & change)
        {
            key newestSitter = llGetLinkKey(llGetNumberOfPrims());
            if (NULL_KEY == newestSitter)   // nobody seated
                return;
            else
            if (llSameGroup(newestSitter))  // group member sitting
                setSeat(FALSE);
            else
                llUnSit(newestSitter);  // non-member tried to sit while seat enabled
        }
    }
    timer()
    {
        setSeat(FALSE);
    }
}

Among the crude simplifications, a group member's touch enables the seat for any one group member, not restricted to the toucher.

Thank you very much! Your version works too now! 👍

Link to comment
Share on other sites

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