Start script on Region start & Trigger animations

Creating scripts
Post Reply
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Start script on Region start & Trigger animations

Post by Lunk Portal »

Here is the simple script I have.

Code: Select all

default
{
    state_entry()
    {
        llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
    }
}
I need

1. For the script to start when the region starts (the animesh is always in "T" pose when the region starts now)

2. Trigger Animation when the jukebox plays music (then animesh dances), otherwise, animesh is playing a different animation)

Thank you for any help!
These users thanked the author Lunk Portal for the post:
Ilan Tochner
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Start script on Region start & Trigger animations

Post by Graham Mills »

Modified code below for (1). Need more info for (2) https://wiki.secondlife.com/wiki/Changed
Lunk Portal wrote:
Thu May 26, 2022 9:05 am
Here is the simple script I have.

Code: Select all

default
{
    state_entry()
    {
        llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
    }
    
    changed(integer change)
    {
    	if (change & CHANGED_REGION_START) 
        {
           llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
        }
    }
    
}
I need

1. For the script to start when the region starts (the animesh is always in "T" pose when the region starts now)

2. Trigger Animation when the jukebox plays music (then animesh dances), otherwise, animesh is playing a different animation)

Thank you for any help!
These users thanked the author Graham Mills for the post (total 2):
Ilan TochnerLunk Portal
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Start script on Region start & Trigger animations

Post by Lunk Portal »

Graham Mills wrote:
Thu May 26, 2022 11:11 am
Modified code below for (1). Need more info for (2) https://wiki.secondlife.com/wiki/Changed
Lunk Portal wrote:
Thu May 26, 2022 9:05 am
Here is the simple script I have.

Code: Select all

default
{
    state_entry()
    {
        llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
    }
    
    changed(integer change)
    {
    	if (change & CHANGED_REGION_START) 
        {
           llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
        }
    }
    
}
I need

1. For the script to start when the region starts (the animesh is always in "T" pose when the region starts now)

2. Trigger Animation when the jukebox plays music (then animesh dances), otherwise, animesh is playing a different animation)

Thank you for any help!
I’m at work right now, but what info do you need to help with yhe trigger script? I can post tonight when I get home
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Start script on Region start & Trigger animations

Post by Graham Mills »

Just need to know how the jukebox works. Is it scripted and is the script full-perms?
These users thanked the author Graham Mills for the post:
Lunk Portal
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Start script on Region start & Trigger animations

Post by Lunk Portal »

Graham Mills wrote:
Thu May 26, 2022 4:18 pm
Just need to know how the jukebox works. Is it scripted and is the script full-perms?
I figure its a simple send trigger (start/stop) over a channel the dancer is listening on, but I am pretty clueless about some of this scripting.

Here is the Jukebox Code

Code: Select all

// :CATEGORY:Music
// :NAME:Jukebox_Track_WAV
// :AUTHOR:Anonymous
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:38:55
// :ID:412
// :NUM:568
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// Jukebox Track WAV.lsl
// :CODE:

float INTERVAL = 10.00;

integer LISTEN_CHAN = 2000;
integer SEND_CHAN = 2001;
float VOLUME = 1.0;

integer g_iSound;
integer tottrack;
integer g_iListenCtrl = -1;
integer g_iPlaying;
integer g_iLinked;
integer g_iStop;
integer g_iPod;
string g_sLink;

// DEBUG
integer g_iWasLinked;
integer g_iFinished;
 
Initialize()
{
    //llSetText(llGetObjectName(), <0, 100, 100>, 10);
    llSetText("",<0,0,0>,1.0);
    // reset listeners
    if ( g_iListenCtrl != -1 )
    {
        llListenRemove(g_iListenCtrl);
    }
    g_iListenCtrl = llListen(LISTEN_CHAN,"","","");
    g_iPlaying = 0;
    g_iLinked = 0;
}



PlaySong()
{
    integer i;

    g_iPlaying = 1;    
   // llWhisper(0,"Playing...");
    llSetSoundQueueing(TRUE);
    tottrack = llGetInventoryNumber(INVENTORY_SOUND);
    llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0),VOLUME);
    llPreloadSound(llGetInventoryName(INVENTORY_SOUND, 1));
    llSetTimerEvent(5.0);  // wait 5 seconds before queueing the second file
    g_iSound = 1;
//    for ( i = 1; i < tottrack; i++ )
//    {
//        llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i));
//    }
}


StopSong()
{
    g_iPlaying = 0;
   // llWhisper(0,"Stopping...");
    llStopSound();
    llSetTimerEvent(0.0);
}


integer CheckLink()
{
    string sLink;
    
    sLink = llGetLinkName(1);
    g_sLink = sLink;
    if ( llGetSubString(sLink,0,6) == "Jukebox" )
    {
        return TRUE;
    }
    return FALSE;
}


default
{
    state_entry()
    {
        Initialize();
    }
    
    on_rez(integer start_param)
    {
        Initialize();
        if ( start_param )
        {
            g_iPod = start_param - 1;
            if ( g_iPod )
            {
                llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
            } else {
                // Tell the controller what the CD key is so it can link
               // llWhisper(SEND_CHAN,"LINK " + (string)llGetKey());
            }
        }
    }
    
    changed(integer change)
    {
        if ( change == CHANGED_LINK )
        {
            if ( llGetLinkNumber() == 0 )
            {
                StopSong();
                llDie();
            } else {
                if ( g_iStop )
                {
                    llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
                } else {
                    llMessageLinked(1,llGetLinkNumber(),"LINKID","");
                    g_iWasLinked = 1;
                }
            }
        }
    }
    
    attach(key id)
    {
        if ( id == NULL_KEY )
        {
            llDie();
        } else {
            PlaySong();
        }
    }
    
    run_time_permissions(integer perm)
    {
        if ( perm == PERMISSION_ATTACH )
        {
            llAttachToAvatar(ATTACH_LSHOULDER);
            llSetTexture("clear",ALL_SIDES);
        }
    }
    
    touch_start(integer total_number)
    {
        integer i;
        
        for ( i = 0; i < total_number; i++ )
        {
            if ( llDetectedKey(i) == llGetOwner() )
            {
//llWhisper(0,"DEBUG: g_iPlaying=" + (string)g_iPlaying);
//llWhisper(0,"DEBUG: Link=" + (string)llGetLinkNumber());
//llWhisper(0,"DEBUG: g_iWasLinked=" + (string)g_iWasLinked);
//llWhisper(0,"DEBUG: g_iFinished=" + (string)g_iFinished);
                if ( g_iPlaying )
                {
                   // llWhisper(0,"Stopping...");
                    g_iPlaying = 0;
                    llStopSound();
                    llSetTimerEvent(0.0);
                } else {
                    PlaySong();
                }
            }
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if ( message == "RESET" )
        {
            if ( llGetLinkNumber() == 0 )
            {
                llDie();
            } else {
                llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
            }
        }
        
        if ( message == "STOP" )
        {
            if ( g_iPod )
            {
                StopSong();
                llDetachFromAvatar();
            }
        }
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if ( str == "PLAY" )
        {
            if ( !g_iPlaying )
            {
                PlaySong();
            }
            return;
        }
        
        if ( str == "STOP" )
        {
            g_iStop = 1;
            StopSong();
            llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
        }
        
        if ( str == "VOLUME" )
        {
            VOLUME = (float)num / 10.0;
            llAdjustSoundVolume(VOLUME);
        }
    }
    
    timer()
    {
        if ( g_iPlaying )
        {
            if ( g_iSound == 1 )
            {
                llSetTimerEvent(INTERVAL);
            }
            llPlaySound(llGetInventoryName(INVENTORY_SOUND, g_iSound),VOLUME);
            if ( g_iSound < (tottrack - 1) )
            {
                llPreloadSound(llGetInventoryName(INVENTORY_SOUND, g_iSound+1));
            }
            g_iSound++;
            if ( g_iSound >= tottrack )
            {
                llSetTimerEvent(INTERVAL + 5.0);
                g_iPlaying = 0;
            }
        } else {
            if ( llGetLinkNumber() != 0 )
            {
                llSetTimerEvent(0.0);
                if ( g_iPod )
                {
                    llWhisper(SEND_CHAN,"FINISH");
                    llDetachFromAvatar();
                } else {
                    llMessageLinked(1,0,"FINISH","");
                    g_iFinished = 1;
                }
            }
        }
    }
}
// END //
Thank you for your help!
These users thanked the author Lunk Portal for the post:
Graham Mills
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Start script on Region start & Trigger animations

Post by Graham Mills »

I'm in no position to check whether this works but all I did was to uncomment the jukebox llWhisper statements that whisper "Stopping..." or "Playing..." on public channel 0 and then add a listen handler to the dancer script. It requires the jukebox to be named "jukebox" and the dancer to be within whisper distance; of course you could use a non-public channel to avoid spamming, perhaps a negative one to avoid chat interference.

Lunk Portal wrote:
Thu May 26, 2022 9:05 pm
Graham Mills wrote:
Thu May 26, 2022 4:18 pm
Just need to know how the jukebox works. Is it scripted and is the script full-perms?
I figure its a simple send trigger (start/stop) over a channel the dancer is listening on, but I am pretty clueless about some of this scripting.

Here is the Jukebox Code

Code: Select all

// :CATEGORY:Music
// :NAME:Jukebox_Track_WAV
// :AUTHOR:Anonymous
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:38:55
// :ID:412
// :NUM:568
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// Jukebox Track WAV.lsl
// :CODE:

float INTERVAL = 10.00;

integer LISTEN_CHAN = 2000;
integer SEND_CHAN = 2001;
float VOLUME = 1.0;

integer g_iSound;
integer tottrack;
integer g_iListenCtrl = -1;
integer g_iPlaying;
integer g_iLinked;
integer g_iStop;
integer g_iPod;
string g_sLink;

// DEBUG
integer g_iWasLinked;
integer g_iFinished;
 
Initialize()
{
    //llSetText(llGetObjectName(), <0, 100, 100>, 10);
    llSetText("",<0,0,0>,1.0);
    // reset listeners
    if ( g_iListenCtrl != -1 )
    {
        llListenRemove(g_iListenCtrl);
    }
    g_iListenCtrl = llListen(LISTEN_CHAN,"","","");
    g_iPlaying = 0;
    g_iLinked = 0;
}



PlaySong()
{
    integer i;

    g_iPlaying = 1;    
   llWhisper(0,"Playing...");
    llSetSoundQueueing(TRUE);
    tottrack = llGetInventoryNumber(INVENTORY_SOUND);
    llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0),VOLUME);
    llPreloadSound(llGetInventoryName(INVENTORY_SOUND, 1));
    llSetTimerEvent(5.0);  // wait 5 seconds before queueing the second file
    g_iSound = 1;
//    for ( i = 1; i < tottrack; i++ )
//    {
//        llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i));
//    }
}


StopSong()
{
    g_iPlaying = 0;
   llWhisper(0,"Stopping...");
    llStopSound();
    llSetTimerEvent(0.0);
}


integer CheckLink()
{
    string sLink;
    
    sLink = llGetLinkName(1);
    g_sLink = sLink;
    if ( llGetSubString(sLink,0,6) == "Jukebox" )
    {
        return TRUE;
    }
    return FALSE;
}


default
{
    state_entry()
    {
        Initialize();
    }
    
    on_rez(integer start_param)
    {
        Initialize();
        if ( start_param )
        {
            g_iPod = start_param - 1;
            if ( g_iPod )
            {
                llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
            } else {
                // Tell the controller what the CD key is so it can link
               // llWhisper(SEND_CHAN,"LINK " + (string)llGetKey());
            }
        }
    }
    
    changed(integer change)
    {
        if ( change == CHANGED_LINK )
        {
            if ( llGetLinkNumber() == 0 )
            {
                StopSong();
                llDie();
            } else {
                if ( g_iStop )
                {
                    llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
                } else {
                    llMessageLinked(1,llGetLinkNumber(),"LINKID","");
                    g_iWasLinked = 1;
                }
            }
        }
    }
    
    attach(key id)
    {
        if ( id == NULL_KEY )
        {
            llDie();
        } else {
            PlaySong();
        }
    }
    
    run_time_permissions(integer perm)
    {
        if ( perm == PERMISSION_ATTACH )
        {
            llAttachToAvatar(ATTACH_LSHOULDER);
            llSetTexture("clear",ALL_SIDES);
        }
    }
    
    touch_start(integer total_number)
    {
        integer i;
        
        for ( i = 0; i < total_number; i++ )
        {
            if ( llDetectedKey(i) == llGetOwner() )
            {
//llWhisper(0,"DEBUG: g_iPlaying=" + (string)g_iPlaying);
//llWhisper(0,"DEBUG: Link=" + (string)llGetLinkNumber());
//llWhisper(0,"DEBUG: g_iWasLinked=" + (string)g_iWasLinked);
//llWhisper(0,"DEBUG: g_iFinished=" + (string)g_iFinished);
                if ( g_iPlaying )
                {
                   // llWhisper(0,"Stopping...");
                    g_iPlaying = 0;
                    llStopSound();
                    llSetTimerEvent(0.0);
                } else {
                    PlaySong();
                }
            }
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if ( message == "RESET" )
        {
            if ( llGetLinkNumber() == 0 )
            {
                llDie();
            } else {
                llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
            }
        }
        
        if ( message == "STOP" )
        {
            if ( g_iPod )
            {
                StopSong();
                llDetachFromAvatar();
            }
        }
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if ( str == "PLAY" )
        {
            if ( !g_iPlaying )
            {
                PlaySong();
            }
            return;
        }
        
        if ( str == "STOP" )
        {
            g_iStop = 1;
            StopSong();
            llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
        }
        
        if ( str == "VOLUME" )
        {
            VOLUME = (float)num / 10.0;
            llAdjustSoundVolume(VOLUME);
        }
    }
    
    timer()
    {
        if ( g_iPlaying )
        {
            if ( g_iSound == 1 )
            {
                llSetTimerEvent(INTERVAL);
            }
            llPlaySound(llGetInventoryName(INVENTORY_SOUND, g_iSound),VOLUME);
            if ( g_iSound < (tottrack - 1) )
            {
                llPreloadSound(llGetInventoryName(INVENTORY_SOUND, g_iSound+1));
            }
            g_iSound++;
            if ( g_iSound >= tottrack )
            {
                llSetTimerEvent(INTERVAL + 5.0);
                g_iPlaying = 0;
            }
        } else {
            if ( llGetLinkNumber() != 0 )
            {
                llSetTimerEvent(0.0);
                if ( g_iPod )
                {
                    llWhisper(SEND_CHAN,"FINISH");
                    llDetachFromAvatar();
                } else {
                    llMessageLinked(1,0,"FINISH","");
                    g_iFinished = 1;
                }
            }
        }
    }
}
// END //

Code: Select all

integer CHANNEL = 0;

default
{
    state_entry()
    {
    	llListen(CHANNEL, "jukebox", NULL_KEY, "");
        llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
    }
    
    listen(integer chan, string name, key id, string msg)
    {
    	if (chan == CHANNEL)
    	{
    		if (msg == "Playing...")
    		{
    			llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
    		}
    		else if (msg == "Stopping...")
    		{
    			llStopObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
    		}
    	}
    }
    
    changed(integer change)
    {
    	if (change & CHANGED_REGION_START) 
        {
           llListen(CHANNEL, "jukebox", NULL_KEY, "");
           llStartObjectAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
        }
    }
    
}

Thank you for your help!
These users thanked the author Graham Mills for the post:
Lunk Portal
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Start script on Region start & Trigger animations

Post by Lunk Portal »

Yeah, it's not working. As soon as you put the script in the dancer starts dancing, and it doesn't matter if the jukebox is playing or not. And when the music stops the dancer still dancing.

I wonder if the dancer's script needs to differentiate between the dancing animation and the talking? Both animations are in the inventory but nothing tells the script which is which.
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Start script on Region start & Trigger animations

Post by Lunk Portal »

Changed the names of the animations accordingly and realized "jukebox" was not capitalized in the script...ALL WORKS GREAT!

BUT, when the music stops the dancer dances forever...stuck in a loop.

Here is the updated script

Code: Select all

integer CHANNEL = -456;

default
{
    state_entry()
    {
        llListen(CHANNEL, "Jukebox", NULL_KEY, "");
        llStartObjectAnimation("talk");
    }
    
    listen(integer chan, string name, key id, string msg)
    {
        if (chan == CHANNEL)
        {
            if (msg == "Playing...")
            {
                llStartObjectAnimation("dance");
            }
            else if (msg == "Stopping...")
            {
                llStartObjectAnimation("talk");
            }
        }
    }
    
    changed(integer change)
    {
        if (change & CHANGED_REGION_START) 
        {
           llListen(CHANNEL, "jukebox", NULL_KEY, "");
           llStartObjectAnimation("talk");
        }
    }
    
}
The region starts up, the dancer is sitting and talking..Good

The jukebox starts playing, the dancer starts dancing...Good

The music stops, the dancer dances till the cows come home, and there aren't any cows on Tatooine...Bad

:D We're almost there...
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Start script on Region start & Trigger animations

Post by Lunk Portal »

OK, the problem is the Jukebox doesn't send the "Stopping..." message out unless the owner actually stops the player from playing. SO... I need to add a this line

Code: Select all

llShout(-456,"Stopping...");
Somewhere in the Jukebox to trigger when the song is finished...then it will work. I just need to figure out where to put it now LOL

Here is the Jukebox Code

Code: Select all

// :CATEGORY:Music
// :NAME:Jukebox_Track_WAV
// :AUTHOR:Anonymous
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:38:55
// :ID:412
// :NUM:568
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// Jukebox Track WAV.lsl
// :CODE:

float INTERVAL = 10.00;

integer LISTEN_CHAN = 2000;
integer SEND_CHAN = 2001;
float VOLUME = 1.0;

integer g_iSound;
integer tottrack;
integer g_iListenCtrl = -1;
integer g_iPlaying;
integer g_iLinked;
integer g_iStop;
integer g_iPod;
string g_sLink;

// DEBUG
integer g_iWasLinked;
integer g_iFinished;
 
Initialize()
{
    //llSetText(llGetObjectName(), <0, 100, 100>, 10);
    llSetText("",<0,0,0>,1.0);
    // reset listeners
    if ( g_iListenCtrl != -1 )
    {
        llListenRemove(g_iListenCtrl);
    }
    g_iListenCtrl = llListen(LISTEN_CHAN,"","","");
    g_iPlaying = 0;
    g_iLinked = 0;
}



PlaySong()
{
    integer i;

    g_iPlaying = 1;    
   llShout(-456,"Playing...");
    llSetSoundQueueing(TRUE);
    tottrack = llGetInventoryNumber(INVENTORY_SOUND);
    llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0),VOLUME);
    llPreloadSound(llGetInventoryName(INVENTORY_SOUND, 1));
    llSetTimerEvent(5.0);  // wait 5 seconds before queueing the second file
    g_iSound = 1;
//    for ( i = 1; i < tottrack; i++ )
//    {
//        llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i));
//    }
}


StopSong()
{
    g_iPlaying = 0;
   llShout(-456,"Stopping...");
    llStopSound();
    llSetTimerEvent(0.0);
}


integer CheckLink()
{
    string sLink;
    
    sLink = llGetLinkName(1);
    g_sLink = sLink;
    if ( llGetSubString(sLink,0,6) == "Jukebox" )
    {
        return TRUE;
    }
    return FALSE;
}


default
{
    state_entry()
    {
        Initialize();
    }
    
    on_rez(integer start_param)
    {
        Initialize();
        if ( start_param )
        {
            g_iPod = start_param - 1;
            if ( g_iPod )
            {
                llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
            } else {
                // Tell the controller what the CD key is so it can link
               // llWhisper(SEND_CHAN,"LINK " + (string)llGetKey());
            }
        }
    }
    
    changed(integer change)
    {
        if ( change == CHANGED_LINK )
        {
            if ( llGetLinkNumber() == 0 )
            {
                StopSong();
                llDie();
            } else {
                if ( g_iStop )
                {
                    llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
                } else {
                    llMessageLinked(1,llGetLinkNumber(),"LINKID","");
                    g_iWasLinked = 1;
                }
            }
        }
    }
    
    attach(key id)
    {
        if ( id == NULL_KEY )
        {
            llDie();
        } else {
            PlaySong();
        }
    }
    
    run_time_permissions(integer perm)
    {
        if ( perm == PERMISSION_ATTACH )
        {
            llAttachToAvatar(ATTACH_LSHOULDER);
            llSetTexture("clear",ALL_SIDES);
        }
    }
    
    touch_start(integer total_number)
    {
        integer i;
        
        for ( i = 0; i < total_number; i++ )
        {
            if ( llDetectedKey(i) == llGetOwner() )
            {
//llWhisper(0,"DEBUG: g_iPlaying=" + (string)g_iPlaying);
//llWhisper(0,"DEBUG: Link=" + (string)llGetLinkNumber());
//llWhisper(0,"DEBUG: g_iWasLinked=" + (string)g_iWasLinked);
//llWhisper(0,"DEBUG: g_iFinished=" + (string)g_iFinished);
                if ( g_iPlaying )
                {
                   llShout(-456,"Stopping...");
                    g_iPlaying = 0;
                    llStopSound();
                    llSetTimerEvent(0.0);
                } else {
                    PlaySong();
                }
            }
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if ( message == "RESET" )
        {
            if ( llGetLinkNumber() == 0 )
            {
                llDie();
            } else {
                llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
            }
        }
        
        if ( message == "STOP" )
        {
            if ( g_iPod )
            {
                StopSong();
                llDetachFromAvatar();
            }
        }
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if ( str == "PLAY" )
        {
            if ( !g_iPlaying )
            {
                PlaySong();
            }
            return;
        }
        
        if ( str == "STOP" )
        {
            g_iStop = 1;
            StopSong();
            llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
        }
        
        if ( str == "VOLUME" )
        {
            VOLUME = (float)num / 10.0;
            llAdjustSoundVolume(VOLUME);
        }
    }
    
    timer()
    {
        if ( g_iPlaying )
        {
            if ( g_iSound == 1 )
            {
                llSetTimerEvent(INTERVAL);
            }
            llPlaySound(llGetInventoryName(INVENTORY_SOUND, g_iSound),VOLUME);
            if ( g_iSound < (tottrack - 1) )
            {
                llPreloadSound(llGetInventoryName(INVENTORY_SOUND, g_iSound+1));
            }
            g_iSound++;
            if ( g_iSound >= tottrack )
            {
                llSetTimerEvent(INTERVAL + 5.0);
                g_iPlaying = 0;
            }
        } else {
            if ( llGetLinkNumber() != 0 )
            {
                llSetTimerEvent(0.0);
                if ( g_iPod )
                {
                    llWhisper(SEND_CHAN,"FINISH");
                    llDetachFromAvatar();
                } else {
                    llMessageLinked(1,0,"FINISH","");
                    g_iFinished = 1;
                }
            }
        }
    }
}
// END //
FOR THE LIFE OF ME I don't know where to put the "Stopping" message to stop the dancing when the song ends :(
These users thanked the author Lunk Portal for the post:
Selby Evans
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Start script on Region start & Trigger animations

Post by Lunk Portal »

I resorted to using a sleep timer in the dancer and it works now. Now to set up random phrases!

Thanks for the help!
These users thanked the author Lunk Portal for the post:
Graham Mills
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
Post Reply