Jump to content

NEW scripter, would appreciate help with simple script


Virrera
 Share

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

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

Recommended Posts

I don't know what I'm doing wrong with this script that's just an attempt at modifications on basic things in the library while I learn -  I'm sure it's probably a simple error, but I'd appreciate someone pointing out what I did wrong.
I know this is really basic, but you have to start somewhere.  All this does is return the unauthorized response regardless of tag (I put the right group key in the string and changed my group tag several times to check, I imagine that would be the first thing asked of a newbie, which is fair)  I suspect DetectedGroup is the wrong thing to use but I'm not sure how else to do that?  Thanks!


string authgroup = "your group key here";
float sec;

Unauthorized()
{
    string thisScript = llGetScriptName();
 
    llOwnerSay("/me [" + thisScript + "]: Sorry, you're wearing the wrong group tag.");
    llSay(0, "Sorry you are not authorized");
    llSleep(5.0);
    llResetScript();
}

default
{
    touch_start(integer num_detected)
    {
        string haveauth = (string)llDetectedGroup(0);
        if (haveauth != authgroup)
            Unauthorized();
        else
        {
        
        key authuser = llDetectedKey(0);
        list inventoryItems;
        integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);
 
        integer index;
        for ( ; index < inventoryNumber; ++index )
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
            if (itemName != llGetScriptName() )
            {
                if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
                {
                    inventoryItems += itemName;
                }
                else
                {
                    llGiveInventory(authuser, itemName);    // 2.0 seconds delay
                }
            }
        }
        }
 
    }
}

Link to comment
Share on other sites

I don't know what I'm doing wrong with this script that's just an attempt at modifications on basic things in the library while I learn -  I'm sure it's probably a simple error, but I'd appreciate someone pointing out what I did wrong.
I know this is really basic, but you have to start somewhere.  All this does is return the unauthorized response regardless of tag (I put the right group key in the string and changed my group tag several times to check, I imagine that would be the first thing asked of a newbie, which is fair)  I suspect DetectedGroup is the wrong thing to use but I'm not sure how else to do that?  Thanks!


string authgroup = "your group key here";
float sec;

Unauthorized()
{
    string thisScript = llGetScriptName();
 
    llOwnerSay("/me [" + thisScript + "]: Sorry, you're wearing the wrong group tag.");
    llSay(0, "Sorry you are not authorized");
    llSleep(5.0);
    llResetScript();
}

default
{
    touch_start(integer num_detected)
    {
        string haveauth = (string)llDetectedGroup(0);
        if (haveauth != authgroup)
            Unauthorized();
        else
        {
        
        key authuser = llDetectedKey(0);
        list inventoryItems;
        integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);
 
        integer index;
        for ( ; index < inventoryNumber; ++index )
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
            if (itemName != llGetScriptName() )
            {
                if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
                {
                    inventoryItems += itemName;
                }
                else
                {
                    llGiveInventory(authuser, itemName);    // 2.0 seconds delay
                }
            }
        }
        }
 
    }
}

Link to comment
Share on other sites

Try

 

if( !llSameGroup( llDetectedKey(0) ) ){    Unauthorized();}

And then remember to set your scripted object to your group.

BTW, although you can omit curly brackets when the scope of an if test is only one statement long (as you have), that not a good habit to get into.  It's very easy to forget that you did it.  If you then add a second statement later, you'll waste a lot of time trying to figure out why your script is misbehaving.  Is easier to remember to always close your scope with curly brackets.

 

Link to comment
Share on other sites

Welcome to LSL scripting.  You're going about it the right way, starting with something that works and fiddling with it to do something else.  Let me suggest a couple of other things you should look at.  First, there's no need to reset your script in the Unauthorized() function.  After all, the touch_start event only has two choices.  Either the user's touch activates the function, or it doesn't.  Either way, the event ends and the script just sits there, waiting for the next touch.  Second, the Unauthorized function itself is probably best written in line, rather than as a separate function, because it is only used once in the script.  That's a stylistic matter, in a way, but many scripters will argue that it's more efficient to do one-time things locally than to hop out of an event to do them.  So ...

 touch_start(integer num_detected)    {        if (!llSameGroup(llDetectedKey(0)) )        {            string thisScript = llGetScriptName();            llOwnerSay("/me [" + thisScript + ]: Sorry, you're wearing the wrong group tag.");            llSay(0, "Sorry you are not authorized");        }        else        {    // and so forth ....  

 I also wonder quietly why you have both a llOwnerSay statement and a llSay statement, but that doesn't affect the way the script works.

 

Link to comment
Share on other sites

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