Change font size
It is currently Wed Mar 22, 2017 5:07 pm

Forum rules


Image



Post a new topicPost a reply Page 1 of 1   [ 7 posts ]
Author Message
 Post subject: Region Greeter script -- OSSL version
PostPosted: Thu Mar 27, 2014 3:53 pm 
Furious Typer

Joined: Mon Sep 27, 2010 7:12 am
Posts: 53
I recently wrote a fairly basic and simple region greeter script for a couple people who'd asked for one so I thought I'd post a copy of it here for anyone else that wants to use it. I included full instructions at the top of the script as well as a fair number of comments throughout to explain what's happening in case you want to tweak it. Feel free to modify it to suit your own needs.

REQUIRES OSSL (see next post)

Code:
// BASIC REGION GREETER SCRIPT - OSSL
// by Mata Hari/Aine Caoimhe March 2014
//
// This is written specifically for Posh and Doro but can easily be adapted/customized for other purposes. It will:
//  - Greet someone when they first enter the region and (optionally) give them a "welcome notecard". Only that avi will see the message (uses llRegionSayTo(UUID) to send)
//    the message. The notecard is only given on the very first recorded visit to the sim by that avi. After that, they'll be greeted with a welcome back message instead
//  - Log (in a notecard) a complete list of the avatars who have visited the sim and the date (and optionally time) of their most recent arrival
//  - Optionally invite a first-time visitor to join a specified Group.
//  - When the owner touches the prim that contains this script she/he will be given a notecard that lists everyone who has visited the region and the date (and optionally time)
//  of their mostrecent visit.
//
// NOTES:
//  - The name that will display as the sender in messages is the name of the prim that contains this script so give the prim a "friendly" meaningful name.
//  - The visitor log is sorted in the order of most recent visit to oldest, so the people at the top of the list are the latest ones to arrive in the region
//    even if thier first visit was a long time ago.
//  - Date (and time if you use that option) is based on the UTC time zone so it's roughly Greenwich Mean Time except doesn't have daylight savings time applied to it.
//
// REQUIRED: The following OSSL script functions must be enabled for the script-owner:
//      - osGetAvatarList       -- used to detect who is in the region
//      - osKey2Name            -- used to correctly retrieve owner's name
//      - osGetNotecard         -- used to retrive visitor log data
//      - osMakeNotecard        -- used to store visitor log data
//      - osIsNpc               -- used to check whether a detected agent in the region is "real" or an NPC so we don't message NPCs or try to give them notecards :p
//      - osInviteToGroup       -- only needed if you enable the invite to group flag in the USER SETTINGS section
//
// USER SETTINGS:
// set the following variable to whatever values suit your needs
//
string visitorLogNotecard="visitor log";
// visitorLogNotecard is the name to use for the notecard that stores the information about avatars who have visited the region. If the notecard doesn't exist
// it will be created automatically for you. New visitors are automatically added to the notecard to keep a running log of all the people who have ever come
// to your region. If you delete this notecard it's like resetting your log and all avatars who visit the region will be greeted again as though it's their
// first visit so don't deleted it unless you want that to happen. The script reads the names from the card each time the region starts or if the script is
// restarted (that's how it knows who it has already welcomed for the first time). If you restart the script, anyone currently in the region will be welcomed
// again so I'd recommend you not do this very frequently (there really shouldn't be any need to).
//
integer includeTimes=FALSE;
// includeTimes can be set to either TRUE or FALSE (must be capital letters). If set to true, the notecard will contain both date and time of their most recent visit
// but if set to FALSE it will only show the date (I find it easier to read with just the date).
//
string welcomeFirstTimeMessage = "Welcome, INSERT_NAME. Thank you for visiting my region in OSG";
// welcomeFirstTimeMessage is only said to the avatar the very FIRST time they visit the region (or if you've deleted the visitor log). Must be enclosed in quotes.
// if you include the string INSERT_NAME in the message, it will be replaced with the name of the avatar. In the message I added as default, if I visited
// the region it would say "Welcome, Mata Hari. Thank you for visiting my region in OSG" to me the first time I went there.
// Note: if you set the script to invite first-time visitors to join a group. make sure your welcome message encourages them to do so.
//
string welcomeBackMessage = "Welcome back to my OSG region, INSERT_NAME. Please enjoy your stay!";
// welcomeBackMessage is the message that gets sent to the avatar on all subsequent visits (even days later). Again, the string INSERT_NAME will be replaced with the avi name
// so if I returned to the region it would say "Welcome back, Mata Hari. Please enjoy your stay!"
//
float checkTime=30.0;
// checkTime is how often (in seconds) to check whether someone new has arrived in the region. This is the longest possible time it can be between their arrival and the script
// detecting it but will often be faster. I set a default of 30 seconds because it often takes this long for someone to arrive, rez, and start to have the sim rez around them.
// If you want the sim to feel a little more "responsive" to new arrivals try shortening it to only 10 or 15 seconds but avoid very short times (less than 5 seconds) since it
// will result in unnecessary sim resource usage to do checks this frequently.
// FYI this also has a second purpose....if an avatar that was previously welcomed to the region is no longer detected during this check it is flagged as having left so when it
// returns to the region it will be welcomed back. Sommeone who logs out and back in very quickly might not be welcomed back (and doesn't need to be).
//
string welcomeNotecard="";
string welcomeLandmark="";
// welcomeNotecard amd welcomeLandmark are the exact names of a notecard and/or a landmark in the prim's inventory that you want given to a first-time visitor. If the string is
// empty (you leave it at "") it won't try to give anything, otherwise it will try to give that object if it can find it in the prim's inventory. If you only want to give
// a notecard, leave welcomeLandmark at "", or if you only want to give a landmark then leave welcomeNotecard at "". Default is to give nothing at all.
// Note that giving something to an avatar causes the script to stop working for 2 seconds so don't hand out stuff that isn't needed.
//
integer inviteToGroup=FALSE;
// inviteToGroup can either be TRUE or FALSE (must be capital letters). If set to TRUE, a first-time visitor to your region will be invited to join the same group that prim is
// set to (so if you enable this, make sure the prim's group is set correctly!). I'm not 100% sure how the OSSL function checks group permissions so it's probably safest to
// make sure that you have group permissions set to allow you to invite people and to allow people to join any time (not just by invitation). It might work with different group
// permission settings though...you'd have to experiment. If set to FALSE, no group invitation is sent.
//
integer notifyOwner=TRUE;
// notifyOwner can either be TRUE or FALSE (must be capital letters). If set to TRUE, when someone arrives in the region and you are also in the region, you will be notified
// in general chat (but only you will be able to see it).
//
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// # # # DO NOT CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!! # # #
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
list visitorLog=[];     // timestamp|name|UUID
list regionLog=[];      // UUID|pos|name

welcome(key who,string name)
{
    // called when a new key is detected in the region
    // skip if this is the UUID of an NPC
    if (osIsNpc(who)) return;
    // find the index of the visitor in the visitor log
    integer visitorIndex=llListFindList(visitorLog,[who]);
    string strToSay=welcomeBackMessage;        // welcome message we're going to send - set to welcome back as default
    if (visitorIndex==-1)
    {
        // this is a first time visitor and needs to be added to the visitor log
        if (includeTimes) visitorLog+=[llGetTimestamp()];  // user wants timestamp
        else visitorLog+=[llGetDate()];                    // user just wants data
        visitorLog+=[name,who];
        // and we want to send the first-time visitor message instead of the welcome back one
        strToSay=welcomeFirstTimeMessage;
        // don't send anything to them yet though....need to wait until we've sent the welcome message
    }
    else
    {
        // this is a repeat visitor so we need to update the timestamp instead
        if (includeTimes) llListReplaceList(visitorLog,[llGetTimestamp()],visitorIndex-2,visitorIndex-2);   // user wants timestamp
        else llListReplaceList(visitorLog,[llGetDate()],visitorIndex-2,visitorIndex-2);                     // user just wants date
    }
    // sort the list and then store it
    visitorLog=llListSort(visitorLog,3,FALSE);
    if (llGetInventoryType(visitorLogNotecard)==INVENTORY_NOTECARD)
    {
        llRemoveInventory(visitorLogNotecard);
        llSleep(0.2);   // need to delay briefly to give it time to remove the old one
    }
    // build new string to store
    string strToStore;
    integer i;
    integer l=llGetListLength(visitorLog);
    while (i<l)
    {
        strToStore+=llDumpList2String(llList2List(visitorLog,i,i+2),"|") + "\n";        // can't use tabs to store and format nicely because names could include 4 spaces which is treated as a tab
        i+=3;
    }
    //store it
    osMakeNotecard(visitorLogNotecard,strToStore);
    // now send welcome message to the avi after parsing it to replace INSERT_NAME with the name
    while (llSubStringIndex(strToSay,"INSERT_NAME")>-1)
    {
        integer ind=llSubStringIndex(strToSay,"INSERT_NAME");
        strToSay=llDeleteSubString(strToSay,ind,ind+10);
        strToSay=llInsertString(strToSay,ind,name);
    }
    llRegionSayTo(who,0,strToSay);
    // if owner wants to be notified of visitors, send message (as long as it's not the owner being greeted)
    if (notifyOwner && (who!=llGetOwner()) && (llGetAgentSize(llGetOwner())!=ZERO_VECTOR)) llRegionSayTo(llGetOwner(),0,name+" has entered the region and been greeted");
    // if this is a first-time visitor we also may need to send a notecard and/or a landmark and/or a group invite
    if (visitorIndex==-1)
    {
        if ((welcomeNotecard!="") && (llGetInventoryType(welcomeNotecard)==INVENTORY_NOTECARD)) llGiveInventory(who,welcomeNotecard);
        if ((welcomeLandmark!="") && (llGetInventoryType(welcomeLandmark)==INVENTORY_LANDMARK)) llGiveInventory(who,welcomeLandmark);
        if (inviteToGroup)
        {
            key groupKey=llList2Key(llGetObjectDetails(llGetKey(),[OBJECT_GROUP]),0);
            if (groupKey==NULL_KEY) llOwnerSay("Cannot send a group invite because there is no group set for this prim");
            else osInviteToGroup(who);
        }
    }
}
default
{
    state_entry()
    {
        // zero the running visitor log and then read the stored notecard from memory if it exists to get previous visitors
        string logData;
        visitorLog=[];
        if (llGetInventoryType(visitorLogNotecard)==INVENTORY_NOTECARD) logData=osGetNotecard(visitorLogNotecard);
        visitorLog=llParseString2List(logData,["|","\n"],[]);
        visitorLog=llListSort(visitorLog,3,FALSE);
        // zero the in-region log as well
        regionLog=[];
        // start the timer
        llSetTimerEvent(checkTime);
    }
    on_rez(integer start)
    {
        // on first rez remove any existing visitor log
        if (llGetInventoryType(visitorLogNotecard)==INVENTORY_NOTECARD) llRemoveInventory(visitorLogNotecard);
        llResetScript();
    }
    changed (integer change)
    {
        // restart if the owner changes or any time the region is restarted
        if (change & CHANGED_OWNER)
        {
            // on owner change remove any existing visitor log
            if (llGetInventoryType(visitorLogNotecard)==INVENTORY_NOTECARD) llRemoveInventory(visitorLogNotecard);
            llResetScript();
        }
        else if (change & CHANGED_REGION_START) llResetScript();
    }
    touch_start(integer num)
    {
        if (llDetectedKey(0)!=llGetOwner()) return;
        if (llGetInventoryType(visitorLogNotecard)==INVENTORY_NOTECARD)
        {
            llOwnerSay("Sending you the up to date visitor log");
            llGiveInventory(llGetOwner(),visitorLogNotecard);
        }
        else llOwnerSay("ERROR! I could not find a stored visitor log in the prim's inventory. Did you delete it by mistake?");
    }
    timer()
    {
        // update the region log to reflect who is currently in the region. OSSL function doesn't include owner so also add her/him if present
        list oldRegionLog=regionLog;
        regionLog=osGetAvatarList();
        if (llGetAgentSize(llGetOwner())!=ZERO_VECTOR) regionLog+=[llGetOwner(),<1,2,3>,osKey2Name(llGetOwner())];   // we don't do anything with position so just give it any value
        // see if anyone new is in the updated log
        integer checking;
        integer stop=llGetListLength(regionLog);
        while (checking<stop)
        {
            key who=llList2Key(regionLog,checking); // UUID of person to check against the old log
            if (llListFindList(oldRegionLog,[who])==-1) welcome(who,llList2String(regionLog,checking+2));    // not in previous log so welcome them by passing UUID and name to UDF
            checking +=3;   // stride of the regionLog list
        }
    }
}


Top
 Profile  
 
 Post subject: Re: Region Greeter script -- OSSL version
PostPosted: Thu Mar 27, 2014 4:01 pm 
Furious Typer

Joined: Mon Sep 27, 2010 7:12 am
Posts: 53
The above script uses OSSL and one of the functions (osMakeNotecard) requires a VeryHigh threat level that I'd ever recommend to have set to allow globally. Instead, you should only allow the higher threat level functions for trusted scripts -- typically those owned by the ESTATE_OWNER and possibly ESTATE_MANAGER. This is done in Opensim.ini file in the [XEngine] section.

Example: here's what I use

Code:
    AllowOSFunctions = true
    OSFunctionThreatLevel = Low
    ;; *** Threat-Level=Moderate
    Allow_osMessageAttachments = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetNumberOfAttachments = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osDropAttachment = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osDropAttachmentAt = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetGridCustom = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetGridHomeURI = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetGridLoginURI = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetGridName = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetGridNick = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetRegionStats = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetSimulatorMemory = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetSpeed = ESTATE_OWNER, ESTATE_MANAGER
    ;; *** Threat-Level=High
    Allow_osForceDropAttachment = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osForceDropAttachmentAt = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osOwnerSaveAppearance = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osCauseDamage = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osCauseHealing = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetAgentIP = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetLinkPrimitiveParams = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetPrimitiveParams = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetRegionMapTexture = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetScriptEngineName = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetSimulatorVersion = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osMakeNotecard = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osMatchString = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcCreate = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcGetPos = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcGetRot = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcLoadAppearance = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcMoveTo = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcMoveToTarget = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcPlayAnimation = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcRemove = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcSaveAppearance = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcSay = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcSetRot = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcShout = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcSit = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcStand = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcStopAnimation = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcTouch = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osNpcWhisper = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osParcelJoin = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osParcelSubdivide = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osRegionRestart = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetParcelDetails = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetPrimitiveParams = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetProjectionParams = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetRegionWaterHeight = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetStateEvents = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetTerrainHeight = ESTATE_OWNER, ESTATE_MANAGER
    ;; *** Threat-Level=VeryHigh
    Allow_osAvatarPlayAnimation = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osAvatarStopAnimation = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetNotecard = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetNotecardLine = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osGetNumberOfNotecardLines = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osRegionNotice = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osAgentSaveAppearance = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetRot = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osSetParcelDetails = ESTATE_OWNER, ESTATE_MANAGER
    ;; *** Threat-Level=Severe
    Allow_osConsoleCommand = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osKickAvatar = ESTATE_OWNER, ESTATE_MANAGER
    Allow_osTeleportAgent = ESTATE_OWNER, ESTATE_MANAGER


For more information see:
http://opensimulator.org/wiki/Category:OSSL_Functions
http://opensimulator.org/wiki/Threat_level
http://opensimulator.org/wiki/OSSL_Enabling_Functions


Top
 Profile  
 
 Post subject: Re: Region Greeter script -- OSSL version
PostPosted: Sat Mar 29, 2014 5:20 am 
Furious Typer
User avatar

Joined: Sat May 26, 2012 8:56 pm
Posts: 280
Great scripting. I am sure a lot of people will be referring to parts of this script for a long time.


Top
 Profile  
 
 Post subject: Re: Region Greeter script -- OSSL version
PostPosted: Mon Jan 23, 2017 9:36 pm 
Furious Typer
User avatar

Joined: Mon Mar 22, 2010 4:01 pm
Posts: 82
Location: Canada
[quote="Mata Hari"]I recently wrote a fairly basic and simple region greeter script for a couple people who'd asked for one so I thought I'd post a copy of it here for anyone
//
string welcomeFirstTimeMessage = "Welcome, INSERT_NAME. Thank you for visiting my region in OSG";
[/code][/quote]

I know this post is an old one but I thought I'd give it a go, however compiling it is a bit of a problem as it returns a Sintax error at the very start of the WelcomeFirstTime Message line.

I don't script at all - save for the odd minor variation of a simple script. Perhaps you could tell me what's going on?

_________________
<3 Foxxe <3


Top
 Profile  
 
 Post subject: Re: Region Greeter script -- OSSL version
PostPosted: Thu Jan 26, 2017 11:33 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 78
Location: Belgium / Brussels
It works well for me ...

Make sure you have the OSSL functions enabled on your region with the correct Threat Level and permission to create the card with osMakeNotecard.

Good luck! :)

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: Region Greeter script -- OSSL version
PostPosted: Sat Feb 04, 2017 7:48 pm 
Furious Typer
User avatar

Joined: Mon Mar 22, 2010 4:01 pm
Posts: 82
Location: Canada
[quote="dj phil"]It works well for me ...

Make sure you have the OSSL functions enabled on your region with the correct Threat Level and permission to create the card with osMakeNotecard.

Good luck! :)[/quote]

hmmm It seems it uses ThreatLevel = Low which grates against my intersim teleport system that requires ThreatLevel = Severe. I guess that means I can't use it. :/

_________________
<3 Foxxe <3


Top
 Profile  
 
 Post subject: Re: Region Greeter script -- OSSL version
PostPosted: Sun Feb 05, 2017 3:10 pm 

Joined: Tue May 27, 2014 10:22 pm
Posts: 6
Foxxe Wilder wrote:
dj phil wrote:
It works well for me ...

Make sure you have the OSSL functions enabled on your region with the correct Threat Level and permission to create the card with osMakeNotecard.

Good luck! :)


hmmm It seems it uses ThreatLevel = Low which grates against my intersim teleport system that requires ThreatLevel = Severe. I guess that means I can't use it. :/


I strongly recommend that you don't use the threat level, but instead explicitly define each ossl function and set the permissions accordingly. This can be done easily in the osslEnable.ini file. IMHO the threat level settings are very poor to use to control these permissions and offer almost no granularity.

What I prefer to do is enable many of the functions for use only by estate owners and managers and leverage that to control who can make use of the functions. I then leave only a few functions enabled for general use.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 7 posts ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net