Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Guest sharing of vehicles

Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-09-2008 20:59
Hi

I have a vehicle i have made mostly using open source scripts but i would like to make it where i click a button and the permissions change to allow a friend to use it then when they are done i can lock it to me again

thats all really is there a snippet of code i can slot into the script

thanks in advance
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
12-09-2008 21:06
Here is the snippet from the simple car script: Most have a check in the changed event for who is sitting in the vehicle.

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner()) //DELETE THIS WHOLE SECTION IT TO LET ANYONE USE IT
{
llSay(0, not_owner_message);
llUnSit(agent);
llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
}
else //DELETE ABOVE THIS POINT IS YOU DON"T WANT TO CHECK OWNER
{
llTriggerSound("car_start",1);

llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DRIVING", NULL_KEY);
llSleep(.4);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(.1);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);

llSetTimerEvent(0.1);
llLoopSound("car_idle",1);
}
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 04:31
yeah thanks but this is making the car insecure

so anyone can take it all the time

i am after a snippet that means i can make the car owner only after guests have used it

like you click the car and a drop down appears

guest or owner or reset

i select guest and the person can use the car for however long and they say thanks i am done now

and i click the menu and select owner and if they now try they cant it states ' you are not the owner' and ejects them

thanks
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-10-2008 04:52
can't test this in world right now, but i have global variable, integer locked = TRUE; declared right up at the top of the script, before default. Then, in the script itself,
CODE

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)


{
if (agent != llGetOwner() && locked ==TRUE) //DELETE THIS WHOLE SECTION IT TO LET ANYONE USE IT
{
llSay(0, not_owner_message);
llUnSit(agent);
llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE); // to my mind that's a bit OTT
}

else //DELETE ABOVE THIS POINT IS YOU DON"T WANT TO CHECK OWNER
{
llTriggerSound("car_start",1);

llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DRIVING", NULL_KEY);
llSleep(.4);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(.1);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);

llSetTimerEvent(0.1);
llLoopSound("car_idle",1);
}


Then you turn set locked as TRUE or FALSE using your menu or voice commands or whatever.
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 08:03
yeah thats great but how do i set up the

integer channel; // dialog channel

list menu = ["owner", "group", "anyone"]; // access menu

string permit = "owner"; // default menu access

etc

how do i actually tell the vehicle what state to be in

as i tried

}

listen(integer number, string name, key id, string message)
{if (message == "Owner";){FILTER=llGetOwner();llListenRemove(handle);}
if (message == "Anyone";){FILTER=NULL_KEY;llListenRemove(handle);}
if (message == "Reset";){llResetScript();llListenRemove(handle);}

}

but how would i get that to say TRUE OR FALSE and change the script accordingly

if (message == "Owner";){FILTER=llGetOwner();llListenRemove(handle);} .... locked TRUE
if (message == "Anyone";){FILTER=NULL_KEY;llListenRemove(handle);}.... locked FALSE

etc

as it stands i have locked and how do i tell it to unlock
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
12-10-2008 09:17
well in the list for the dialog, you have the letters all lowercase, but in the listen even, you have the tests starting with uppercase letters. as for group only, i've never work with group only scripts so i'm not sure how to toggle that
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 09:48
yeah thats just an example - the case was matched

all i am asking is the integer locked = TRUE

command how would i tell the boat to unlock by using a command thats it really
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2008 09:59
For group only you have to use "llSameGroup".

To make sure that you have the same strings in the dialog and the listen, I often do this:


list buttons = ["fred", "barney", "wilma"];
integer OPTION_FRED = 0;
integer OPTION_BARNEY = 1;
integer OPTION_WILMA = 2;
integer OPTION_NONE = -1;


...

Then I use the usual "llDialog(..., buttons, ...);" call, and in the listen event I do:

integer option = llListFindList(buttons, [msg]); // note that's a list containing the message
if(option == OPTION_FRED) { ... }

That way you're defining all the strings and options in one place, at the top of the script, and you ALWAYS know that you're looking for exactly the same words in the listen that you put in the buttons.

...
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 10:24
For group only you have to use "llSameGroup".

To make sure that you have the same strings in the dialog and the listen, I often do this:


list buttons = ["fred", "barney", "wilma"];
integer OPTION_FRED = 0;
integer OPTION_BARNEY = 1;
integer OPTION_WILMA = 2;
integer OPTION_NONE = -1;


...

Then I use the usual "llDialog(..., buttons, ...);" call, and in the listen event I do:

integer option = llListFindList(buttons, [msg]); // note that's a list containing the message
if(option == OPTION_FRED) { ... }

That way you're defining all the strings and options in one place, at the top of the script, and you ALWAYS know that you're looking for exactly the same words in the listen that you put in the buttons.

///////////////////////////////////////


So where would i put the LOCK = true lock = false and how does this correspond to the texts above regarding making the lock true or false :)

Basically i need to tell a vehicle to have owner only or anybody by pressing a button on the menu and thats it

would i use

if(option == OPTION_Owner) {lock = TRUE}
if(option == OPTION_Anyone) {lock = FALSE}

or summit :\ :)P

thanks
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2008 10:34
From: Junglejim Jonson

So where would i put the LOCK = true lock = false and how does this correspond to the texts above regarding making the lock true or false :)

Basically i need to tell a vehicle to have owner only or anybody by pressing a button on the menu and thats it

would i use

if(option == OPTION_Owner) {lock = TRUE}
if(option == OPTION_Anyone) {lock = FALSE}

or summit :\ :)P

thanks

Something like that. That would work, and that way the compiler will be responsible for making sure that you have the case correct.

I would personally make it:

if(option == OPTION_OWNER) {lock = TRUE;}
else if(option == OPTION_ANYONE) {lock = FALSE;}

That way if it's "OPTION_OWNER" the "else" will keep it from even checking any other options.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 10:51
THANKS FOR THAT :)

i will try it and let you know if that works :)
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 11:53
I keep getting a syntax error

if(option [HERE]== OPTION_OWNER) {locked = TRUE;}

ERROR NAME NOT DEFINED WITHIN SCOPE

I have tried it many different places including the end of the script :\

no idea what to do with it

ah i needed this

integer option;
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2008 12:00
From: Junglejim Jonson
I keep getting a syntax error

if(option [HERE]== OPTION_OWNER) {locked = TRUE;}

ERROR NAME NOT DEFINED WITHIN SCOPE

I have tried it many different places including the end of the script :\

no idea what to do with it
You need to put it after the "integer option = llListFindList(buttons, [msg]);" in the listen(...) event.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 12:16
doesnt work

as both guest and owner can sit in it but neither can now drive it

and there is no way to know what stae the TRUE OR FALSE is in for the locked part

neither seems to work now :\


this part i added
integer option = llListFindList(buttons, [msg]);

just says syntax error
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 12:28
OK TO SUM UP We have this so far


CODE

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)


{
if (agent != llGetOwner() && locked ==TRUE) //DELETE THIS WHOLE SECTION IT TO LET ANYONE USE IT
{
llSay(0, not_owner_message);
llUnSit(agent);
llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE); // to my mind that's a bit OTT
}

else //DELETE ABOVE THIS POINT IS YOU DON"T WANT TO CHECK OWNER
{
llTriggerSound("car_start",1);

llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DRIVING", NULL_KEY);
llSleep(.4);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(.1);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);

llSetTimerEvent(0.1);
llLoopSound("car_idle",1);
}




and

this

for the bottom of the script


}





listen(integer number, string name, key id, string message)
{
if(option == OPTION_OWNER) {locked = TRUE;}
else if(option == OPTION_GUEST) {locked = FALSE;}


}

touch_start(integer total_number)
{
if (llDetectedKey(0)==llGetOwner()){option = llListen(channel, "", NULL_KEY, "" );menu();}
}
}


and this at the top

integer option;
integer msg;

//figure out where to put boat when it is rezzed

menu(){
llDialog(llGetOwner(),"\n \n Vehicle Settings: ",["owner", "guest", "reset"],channel);
}


default {

state_entry() {
//llListen(channel, "", NULL_KEY, "";); // start listening on channel 10
}

on_rez(integer param) {
//reset();
llResetScript();


integer option = llListFindList(buttons, [msg]);




now all of this together with a vehicle script works

but its not locking out guests

and i have no way to know what the state of the LOCK is


and the vehicle no longer moves even if the engine starts
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2008 12:54
From: Junglejim Jonson
OK TO SUM UP We have this so far
You don't have anything setting option in the listen event. You're setting option to a completely unrelated value (the handle returned by the llListen call) in the touch_start event.

Inside the listen event, immediately before you examine option, you have to set option using the "llListFindList" line I showed you in my previous message.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 13:02
what you mean like this

listen(integer number, string name, key id, string message)
{
if(option == OPTION_OWNER) {locked = TRUE;}
else if(option == OPTION_GUEST) {locked = FALSE;}


integer option = llListFindList(buttons, [msg]);
}

touch_start(integer total_number)
{
if (llDetectedKey(0)==llGetOwner()){option = llListen(channel, "", NULL_KEY, "" );menu();}
}
}



this doesnt work and the vehicle physics are now false :\

the terminology you use means nothing to me i am totally new to all this

i would appreciate somebody just telling me how to organise this
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2008 13:16
Unfortunately, this isn't a matter of organizing things, you need to actually understand what a program is doing if you're going to successfully modify it. You need to know what an event is, what the handle returned by llListen is, and so on.

First, get rid of any global definition of 'option' and remove the 'option =' from the llListen line in the touch_start event. That stuff is not supposed to be there.

You have to set the option before you use it. Look at where you're using the option in the listen event... it's right at the top. You need to set the option before that. Move the 'integer option =....' line to the top of the listen event, right before the line where you check the value of option (the 'if(option ==...)' line).

At this point... is the script even running (the checkmark at the bottom next to 'running')?
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 13:32
what like this

yes its running

}





listen(integer number, string name, key id, string message)
{


integer option = llListFindList(buttons, [msg]);

if(option == OPTION_OWNER) {locked = TRUE;}
else if(option == OPTION_GUEST) {locked = FALSE;}



}

touch_start(integer total_number)
{
if (llDetectedKey(0)==llGetOwner()){llListen(channel, "", NULL_KEY, "" );menu();}
}
}



and the physics are false (only particles start on the foward key) on the vehicle and the menu choices seem to do nothing
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2008 13:43
I would recommend you go back to a version where the physics were working, and make the menu changes to that version.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
12-10-2008 14:18
i did

and that turned false too


i think its to do with the locked part as if i ///// out the sections suggested here the script is fine

its a simple vehicle scripted available all over the net and in the wiki

all i need is a snipet of script to change the access to either owenr or guest and back again by clicking the boat

i dont think anyone knows how to do it :) or if they do they simply dont want to say

which is fair enough but learning the basics of scripting is like any knowledge

you need a good source to start with - bit like an encyclopedia if the guys who wrote encyclopedias witheld their knowledge where would we be :) - or made people jump through hoops to access it

if i knew the answer i would just paste the code here - done - i hope someone who understands vehicles and how to set access will be generous enough to tell me - else i guess i wont be able to do it and just give friends a copy of the vehicle and do it that way - probably the simplest solution as i cant seem to get anywhere with this

ho hum :( and its been a long and frustrating day trying these snippets
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-10-2008 19:43
From: Junglejim Jonson

all i need is a snipet of script to change the access to either owenr or guest and back again by clicking the boat

ho hum :( and its been a long and frustrating day trying these snippets


That's why you are getting frustrated... with something as long and complex as a vehicle script, it's not just a matter of dropping in a snippet of code. You've got the vehicle responding to people sitting on it, people touching it and, quite possibly, people talking to it. All of these separate events need looking at when you're changing a vehicle from owner-only to the sort of access you want.

And also, since the script was clearly written on the assumption that only the owner may use the vehicle, you are going to have to look very closely for references to llGetOwner() throughout the script and change them to something more appropriate.

It's not a five-minute job -- I do know how to do this, and it takes me a fair bit of time and careful checking, even though I know what I'm looking for.

What I suggest you do, and probably this isn't the best way but it's reasonably straightforward, is this. Go back to the original script. Go through it and change it so that anyone can use the vehicle. Once you are happy that it works for everyone, put in integer locked = TRUE; up at the top of the script, before default, and then make sure you can toggle locked between TRUE and FALSE.

When I'm having problems following where I've got to setting toggles, I sometimes find it helpful for debugging to put llSetText((string) locked, <1,1,1>,1); in the script immediately after each time where I change between locked and unlocked, so I can -- literally -- see what I'm doing. I also find it helpful to have lots of snippets on the lines of
CODE

if (locked == TRUE)
{
llOwnerSay("I'm locked");
}
else if (locked == FALSE)
{
llOwnerSay("I'm unlocked");
}


whenever anyone touches or says anything to the vehicle -- immediately after the touch_start or listen, before anything else happens -- so i know what's going on.

Anyway, when you've got that working to your satisfaction, I would put in each touch or listen event -- before you do anything else --

CODE

if (llDetectedKey(0) !=llGetOwner() && locked == TRUE) // substitute id for llDetectedKey(0) in listens
{
llSay(0, "Sorry, "+ llDetectedName(0) + " but I'm locked at the moment and only my owner may use me"); //llKey2Name(id) in a listen
return;
}

else // do stuff

Leave the bit about what happens when someone sits on it as I suggested.. I can't see anything wrong with my code, though that's hardly a guarantee.

This should mean that, if it's locked and the wrong person touches it, nothing can happen. If it's not locked, however, the script carries on and lets them use the vehicle, which you already established they can by first making sure anyone can drive it before you started worrying about locking it.

AFTERTHOUGHT .. in listens it's probably going to be safest to say
CODE
 if (llGetOwnerKey(id)!=llGetOwner() && locked == TRUE)  
That's testing, in effect, for "if the message isn't coming either from my owner OR from something belonging to my owner...."
Boreal Latte
Registered User
Join date: 15 Nov 2007
Posts: 104
One thing at a time
12-10-2008 23:40
As Innula Zenovka says, this is not a simple script. My best take on this would be to do as suggested - make the script work so that anyone can ride it.

Then make a different script - unrelated - in a little ply wood box on which you can sit - which unsits everybody who have not been granted permission to sit.

When you have tried that, you move the script from the box to the vehicle. Then you have followed a good practice in scripting and programming - keeping different things separate.