Jump to content

Vehicle controls with Variable User access


Carbon Philter
 Share

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

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

Recommended Posts

I'm hoping someone can help my continuing struggles with scripting.
I'm attempting to put together a vehicle controls script which also includes variable user options.
The objective is to have the owner of the vehicle able to set the user level - Owner, Group, List, or Anyone, via a "Access" dialog menu using a touch_start event, and then, once the permitted category of user is seated, have a different "Controls" dialog menu come up for them to manage the vehicle and camera controls.
With my limited mastery of scripting and LSL, I've muddled through and got to a stage where it looks as though the script will work as intended once I add in all the permissions/control details, but I seem to have hit a problem where the "Access" dialog box gets called up on the owner's screen when it's not the owner that does the touching. I'm hoping that there's something simple I'm missing but I can't see it, and would appreciate a steer in the right direction.

No doubt I'll hit lots more problems, part‎icularly trying to incorporate both varying camera and seating/passenger positions, but that's for another day.

Apologies if the way I've approached the project doesn't conform to the best of scripting principles, but it works in my head. :)
Thanks for any help/advice.

Script demonstrating the problem is as follows:

list notecardsList;
 
integer listener;
integer mainMenuChannel;
integer accessChannel;
integer captainChannel;
integer passengerChannel;
 
integer notecardLine;

integer sit;

float TIMER_DELAY = 0.1;

vector SitBridge = <0.50, 0.0, 0.50>;
 
key query;
key captain;
 
string access = "Owner";
string ActiveAnim;
string notecardName = "!access";

list accessList;
 
integer randomNumber()
{
    return (integer)(llFrand(99999.0))*-1;
}
 
menu(key user,integer channel,string title,list buttons)
{
    llListenRemove(listener);
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
    llSetTimerEvent(25.0);
}
 
accessMenu(key id)
{
    accessChannel = randomNumber();
    menu(id,accessChannel,"Access Level Menu " + "\n \n \n *Actual Access Level = " + access,["Anyone","Group","Close","Owner","List"]);
}

captainMenu(key id)
{
    captainChannel = randomNumber();
    menu(id,captainChannel,"Ready to Sail",["Engine","Flags","Anims","Camera"]);
}
 
//Returns true if find is on src
integer isOnList(list src, list find)
{
     return (llListFindList(src,find) > -1);
}
 
//The function that checks if the toucher has access to the menu
integer checkAccess(key id)
{
    string name = llToLower(llKey2Name(id)); 
    return (id == llGetOwner()) || (llSameGroup(id) && (access == "Group")) || ( (isOnList(accessList,[name]) && (access == "List") ) || (access == "Anyone") );
}

default
{
    state_entry()
    { 
        if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
        {
            //A notecard named "!access" has been found, lets configure tha acess list
            llOwnerSay("Configuring, please wait...");
            notecardLine = 0;
            query = llGetNotecardLine(notecardName,notecardLine);
        }
        else
        {
            state ready;
        }
    }
 
    dataserver(key requested, string data)
    {
        if (requested == query)
        {
            if (data != EOF)
            {
                if ( (llGetSubString(data,0,0) != "#") && (data != "") ) //Ignore blank lines and lines starting with # (comments)
                {
                    string name = llToLower(llStringTrim(data,STRING_TRIM)); //Get the lowercase name and remove white space at from beginning and end if there are
                     if (llGetFreeMemory() >= 1024) //Script memory check
                    {
                        accessList = (accessList = []) + accessList + [name];
                    }
                    else
                    {
                        llOwnerSay(name + " could not be added because the script is running out of memory");
                        state ready;
                    }
                }
                notecardLine++;
                query = llGetNotecardLine(notecardName,notecardLine);
            }
            else
            {
                state ready;
            }
        }
    }
 
    on_rez(integer n)
    {
        if (llGetInventoryType("!config") == INVENTORY_TEXTURE)
        {
            llOwnerSay("Configuring, please wait...");
            notecardLine = 0;
            query = llGetNotecardLine(notecardName,notecardLine);
        }
        else
        {
            state ready;
        }
    }
}
 
state ready
{
    state_entry()
    {
        llOwnerSay("--- Ready ---");
        llSitTarget(SitBridge, ZERO_ROTATION);
    }
 
    changed (integer c)
    {
        if (c & (CHANGED_INVENTORY | CHANGED_OWNER)) //assume that notecard was edited or owner changed so reload the script
        {
            llResetScript();
        }
        if (c & CHANGED_LINK)
        {
            captain = llAvatarOnSitTarget();
            if (checkAccess(captain))
                    {
                        llSay(0,"Ready to sail");
                    }
             else
                    {
                        llSay(0,"Sorry you don't have permission to sail");
                        llUnSit(captain);
                        llPushObject(captain, <0,0,50>, ZERO_VECTOR, FALSE);
                    }
         }
     }

    
    touch_start(integer total_number)
    {
        key toucher = llDetectedKey(0);
        if (toucher = captain)
        {
            captainMenu(toucher);
        }
        else if (toucher = llGetOwner())
        {
            accessMenu(toucher);
        }
        
        else
        {
            llSay(0,"Sorry you don't have access to the access control menu, current access level: " + access);
        }
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (channel == accessChannel)
        {
            if (message == "Close")
            {
                llOwnerSay("Access set");
                return;
            }
 
            access = message;
            llOwnerSay("Access Mode: " + message);
            accessMenu(id);
        }
        else if(message =="Engine")
        {
            llSay(0,"Engine command heard - do stuff");
        }
        else if(message =="Flags")
        {
            llSay(0,"Flags command heard - do stuff");
        }
        else if(message =="Anims")
        {
            llSay(0,"Anims command heard - do stuff");
        }
        else if(message =="Camera")
        {
            llSay(0,"Camera command heard - do stuff");
        }
    }
 
    timer()
    {
        llListenRemove(listener);
        llSetTimerEvent(0.0);
    }
}

 

Link to comment
Share on other sites

At a quick first glance, I'd say you can clear up at least part of the problem by being more careful with the difference between assignment statements and value comparisons:

 touch_start(integer total_number)    {        key toucher = llDetectedKey(0);        if (toucher == captain) // <<< should be "==", not "="        {            captainMenu(toucher);        }        else if (toucher == llGetOwner()) // <<< should be "==", not "="        {            accessMenu(toucher);        }                else        {            llSay(0,"Sorry you don't have access to the access control menu, current access level: " + access);        }    }

That's an easy mistake to make and fortunately an easy one to spot too.  I'm surprised that your script editor didn't catch it.

Link to comment
Share on other sites

/Me looks really sheepish. Many thanks, Rolig - not being totally comfortable with scripting of any sort, I have to admit to getting confused between == and =. Among other things, that is.

I thought I'd tried both alternatives but obviously not. I'm actually quite amazed at having got as far as I did before asking for help!

C.

Link to comment
Share on other sites

Heh ... Sometimes the most obvious things are least obvious, if that makes sense.  We wander through the jungle, watching out for jaguars and anacondas but it's the tsetse flies that get us.  :smileywink:

FWIW, the single = sign means "take whatever is on the right side and put it in whatever is on the left side."  It's an Assignment of a value to a variable.

The double == sign means "check to see whether the values on both sides are the same."  It's a Comparison of one value with another. 

It's easiest to remember if you keep the distinction between a variable and a value clear in your head. A variable is a container.  A value is whatever you put into a container. 

Good luck.

Link to comment
Share on other sites

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