General NPC Question

Creating scripts
Post Reply
User avatar
Adagio Greenwood
Posts: 128
Joined: Wed Jan 16, 2013 7:57 pm
Has thanked: 165 times
Been thanked: 102 times

General NPC Question

Post by Adagio Greenwood »

Okay, I am a total non-scripter but was thinking about using NPC greeters and I got to wondering about the effect of NPCs on Kitely. Do the NPC scripts make any sort of server load that I should be aware of? Since they appear on the maps as avatars, will their presence cause a world to stay active even when no real avatars are present? Are there any problems that using them might cause? Thanks for your help!

Adagio
Ohn Lang
Posts: 142
Joined: Sun Dec 23, 2012 5:11 pm
Has thanked: 38 times
Been thanked: 67 times

Re: General NPC Question

Post by Ohn Lang »

Hi Adiago,

NPCs appear to be avatars to us, but not to the server. Worlds shut down normally. If you want the NPCs to always be present when the world is up, use the changed event and CHANGED_REGION_START to trigger re-rezzing the NPC.

I don't have any numbers to back it up, but from what I have seen, NPCs don't seem put any more of a load on the server than any other script.
User avatar
Adagio Greenwood
Posts: 128
Joined: Wed Jan 16, 2013 7:57 pm
Has thanked: 165 times
Been thanked: 102 times

Re: General NPC Question

Post by Adagio Greenwood »

Great, thanks, Ohn; time for me to get educated re: NPCs. :D

Adagio
These users thanked the author Adagio Greenwood for the post:
Ohn Lang
User avatar
mat mahogany
Posts: 26
Joined: Thu Feb 14, 2013 12:23 am
Has thanked: 13 times
Been thanked: 17 times

Re: General NPC Question

Post by mat mahogany »

Hi Ohn,

I looked for the changed region start but the script im using doesnt seem to have that?

this is the script im using:-

// music to play while bots dance
integer dancetime = 200 ; // total seconds the bots will dance
// this is the root object to control the rory dance bots as linked children
default
{
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
llSetText("",<1,1,1>,1);
llSetAlpha(1.0,ALL_SIDES);
llSetTimerEvent(0);

llShout(0, "Welcome, Won't be a second, Please take a seat."); // just to have play on reset
llVolumeDetect(TRUE); // allow phantom prim to respond to collision
}
collision_end(integer total_number)
{
llVolumeDetect(FALSE);// prevent prim from responding again untill return to default state
llSay(0,"No Cup cakes? Paislee Myrtle has eaten them all!!?");
state bumptstate;
}
}
state bumptstate
{
state_entry()
{
// llSay(0,"root was bumpt");
llSetTimerEvent(dancetime);// this is how many secs bots exist
// music to play while bots dance
//llSetParcelMusicURL("http://www.3dcolab.com/sounds/roryulsterhall.mp3");
llMessageLinked(LINK_SET,0, "dance",NULL_KEY); //tell bots to dance
}
timer()
{ // after xsecs tell bots to disappear
llMessageLinked(LINK_SET,0, "stopdance",NULL_KEY);
llSleep(7);
state default;
}
}

Im looking to get the script to reset each time the region starts? I got the script from someone in another grid, and I stopped the music part.
But if you could guide me to how I can get the script to start Id be gratedull. TY :)
Ohn Lang
Posts: 142
Joined: Sun Dec 23, 2012 5:11 pm
Has thanked: 38 times
Been thanked: 67 times

Re: General NPC Question

Post by Ohn Lang »

Within each state that you have, you can add the changed event, and tell the script what you want it to do when the change detected is a region restart, for example in the snippet from one of my scripts below, I reset the script if the script detects a change in ownership of the object, and if it detects a region restart, in instruct it to recreate an already defined NPC.

Code: Select all

    changed(integer mask)
    {   
        // Triggered when the object containing this script changes owner.
        if(mask & CHANGED_OWNER)
        {
            llResetScript();
        }
        if(mask & CHANGED_REGION_START) {
            //npcs aren't persistent, so when the region shuts down, the npc is removed
            //this recreates the npc everytime a restart is detected
            createNpc(ownerKey);
            state NPCidle;
        
        }

    }//end changed

For more information, see the lsl wiki page: http://wiki.secondlife.com/wiki/Changed

Hope that helps :)
Ohn Lang
Posts: 142
Joined: Sun Dec 23, 2012 5:11 pm
Has thanked: 38 times
Been thanked: 67 times

Re: General NPC Question

Post by Ohn Lang »

Hehe, sorry, I should have just answered your specific question:

so for you, you would just add the changed event to each state like so:

Code: Select all

changed(integer mask)
    {   
       
        if(mask & CHANGED_REGION_START) {
           llResetScript();
        
        }

    }//end changed


User avatar
mat mahogany
Posts: 26
Joined: Thu Feb 14, 2013 12:23 am
Has thanked: 13 times
Been thanked: 17 times

Re: General NPC Question

Post by mat mahogany »

Thank you Ohn,

I've added this to my script, and I'm trying it out now, :)

XXX

Mat
These users thanked the author mat mahogany for the post:
Ohn Lang
User avatar
mat mahogany
Posts: 26
Joined: Thu Feb 14, 2013 12:23 am
Has thanked: 13 times
Been thanked: 17 times

Re: General NPC Question

Post by mat mahogany »

ty Ohn, this works a treat, im adding it to things that need to start when the region starts. koolios, :)

hugzz XXX
Post Reply