Jump to content

Seeking Help with 'Welcome' script.


Serishen Cagney
 Share

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

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

Recommended Posts

Hello, all.

I'm using a very simple script which, upon an avatar nearing an object, emits scenario dialogue.  Unfortunately I can't quite figure out how to input coding that would limit the amount of times an individual avatar can trigger this dialogue, i.e.., Once per every twelve hours, once per day, etc. My goal is to greatly limit chat spam as, at this moment, the script emits the scenario dialogue every time an avatar nears/collides with the object.

Any help would be greatly appreciated!

Link to comment
Share on other sites

list recent_avatars;

add_avatar(string name) {
    if(!seen(name)) {
        recent_avatars += name;
        if (llGetListLength(recent_avatars) > 25) {
            recent_avatars = llDeleteSubList(recent_avatars,0,0);
        }
    }
}
integer seen(string name) {
    if(llListFindList(recent_avatars,[name]) > -1) { return TRUE; }
    return FALSE;
}

 

Something like that would limit per day . 

  • Like 1
Link to comment
Share on other sites

Here is a full example how to use it

this is a notecard giver that uses  limit 1 time per avatar (depending on how busy the place is)

 

add_avatar(string name) {
    if(!seen(name)) {
        recent_avatars += name;
        if (llGetListLength(recent_avatars) > 25) {
            recent_avatars = llDeleteSubList(recent_avatars,0,0);
        }
    }
}
integer seen(string name) {
    if(llListFindList(recent_avatars,[name]) > -1) { return TRUE; }
    return FALSE;
}


default
{

    state_entry() {
        llSensorRepeat("", NULL_KEY, AGENT, 5, PI, 5);
    }
    sensor(integer total_number) {
        if(!seen(llDetectedName(0))) {
        // This line will pick out the first thing of the right type and give it to whomever triggered the event
        llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_NOTECARD,0));

    add_avatar(llDetectedName(0));
    }
}

}


  • Like 1
Link to comment
Share on other sites

If you really want to limit the script to handing each person who touches it only one notecard per day, you'll need a way to recognize when a day has passed since the person's last visit (if there was a last visit).  This would do it....

list gVisitors;  // Save Visitor UUIDslist gVtime;  // Save visit timesdefault{	state_entry()	{		llSetTimerEvent(43200.0); // Start a 12-hour gargage collector	}		touch_start(integer total_number)	{		integer temp = llListFindList(gVisitors,[llDetectedKey(0)]);		if(~temp)  //Has the Av visited before?		{			//Subtract saved Unix time from current Unix time. Was it it > 86400 (1 day) ago?			if((llGetUnixTime() - llList2Integer(gVtime,temp)) > 86400)			{  // If yes .....				gVisitors = llDeleteSubList(gVisitors,temp,temp); //Remove Av from visitor list				gVtime = llDeleteSubList(gVtime,temp,temp);  // Remove Av's visit time too				llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_NOTECARD,0)); //Give card			}		}		else  //No previous visit		{			gVisitors += [llDetectedKey(0)]; // Add to the Visitor list			gVtime += [llGetUnixTime()];  // Add current Unix time to the time list			llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_NOTECARD,0));  // Give card		}		}	timer() //Every 12 hours ...	{		integer i;		for (i=((gVisitors !=[])-1);i>=0;--i) //Look through all the saved visitor times		{  // For each one ...			if((llGetUnixTime() - llList2Integer(gVtime,i))> 86400) // If it was more than a day ago ...			{				gVisitors = llDeleteSubList(gVisitors,i,i); // Remove the person from the Visitor list				gVtime = llDeleteSubList(gVtime,i,i); //Remove the visit time from the list			}		}	}			}

 EDIT: Added a garbage collector to sweep both lists twice a day and remove elements more than a day old.

 

 

  • Like 2
Link to comment
Share on other sites

if doing a touch item (or volume detect), you might actually want to add garbage collection to the touch phase, or at the very least add list limits to prevent stack/heap collision in busy locations if the list overflows. you could still use a push timer (reset the timer each detection) to run garbage collection there if you want.

 

as for the sensor version, you could always try something like this

Link to comment
Share on other sites

That's a good point, Void.  Doing trash collection there would make a lot of sense. There's also no reason to store the entire UUID either.  You don't lose much by saving only a 6 or 8 character substring, and it would let you stretch memory a lot farther before you get a stack/heap error.  I once wrote a high capacity greeter that reduces a UUID to a 3-character element stored in a string variable instead of an entry in a list too. 

Thanks for reminding me about your version.  I've admired it before.

Link to comment
Share on other sites

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