Elevator worked fine, now it doesnt
|
|
Sebastiaan Siegel
Registered User
Join date: 2 Feb 2007
Posts: 18
|
03-12-2007 04:11
I changed an already existing elevator script and it worked fine. Everything worked but the unsit. Then i set the objects default action to "Sit" and now the script doesnt work anymore  Please ignore the dutch comments  key av; // detected object key float height = 100; // getal dat het aantal meters aangeeft met hoeveel meter de lift stijgt integer FloorSelection = FALSE; vector StartPos; vector AVsize; // boundingbox vextor
StopSitAnim() // Don't sit on the floor. :p // functie, tijdens het transporteren gebeurd dit... { llStopAnimation("sit_generic"); // hierdoor zit de avatar nog wel maar is zn zitanimatie gestopt waardoor het lijkt alsof hij staat. llStopAnimation("sit"); // hierdoor zit de avatar nog wel maar is zn zitanimatie ges0topt waardoor het lijkt alsof hij staat. llStartAnimation("impatient"); // klokkijken llForceMouselook(1); // mouselook 1 }
ElevatorMove() // FUNCTIE { if(FloorSelection) // if floor selection == true ? { //llLoopSound("jetson3", 1); // achtergrondgeluid tijdens verplaatsen vector TargetPos = <StartPos.x, StartPos.y, StartPos.z + height>; // vector TargetPos = "start" positie + de ingestelde hoogte while(llVecDist(llGetPos(), TargetPos) != 0) // als de afstand tussen de vectors niet gelijk is aan 0 (zelfde plek) IN EEN LOOP! { llForceMouselook(1); // continu gedwongen te mouselooken vanwege de WHILE LOOP llSetPos(TargetPos); // OBJECT WORDT NAAR VECTOR TargetPos gezet } llUnSit(av); // avatar wordt eraf gegooid llSleep(10); // script wacht 1 seconde (???) while(llVecDist(llGetPos(), StartPos) != 0) // als de afstand tussen de vectors niet gelijk is aan 0 (zelfde plek) IN EEN LOOP! { llSetPos(StartPos); // terug naar startpositie (ZONDER avatar) } } else { llStopSound(); //lift is terug llUnSit(av); // TWEEDE unsit? ik snap dit niet waarom deze erin zit wss loze code // OW ik snap het al :D } }
default { state_entry() { llSetSitText("Get on"); // taartpunt zegt Get On normaal staat hier Sit StartPos = llGetPos(); // startpos krijgt zijn gegevens door GetPos } on_rez(integer start_param) { llResetScript(); // reset script, hierdoor krijgt hij zijn nieuwe startpositie terug } changed(integer change) { key av = llDetectedKey(0); // detected object key = av AVsize = llGetAgentSize(av); llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); // Target offset 0,0, avatar gedeelte gedeeld door twee if(change & CHANGED_LINK) // als er een avatar op is gaan zitten... { FloorSelection = TRUE; av = llAvatarOnSitTarget(); // ALS OBJECT KEY GELIJK IS AAN if(av != NULL_KEY) // als de key EEN waarde heeft... { //key av = llDetectedKey(0); // detected object key = av //AVsize = llGetAgentSize(av); // vector == hoogte van de avatar: bounding box llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION); // vraagt toestemming om custom animaties af te spelen } } else { llSay(0,"je bent een beunhaas"); } }
run_time_permissions(integer perm) // toestemming gekregen { StopSitAnim(); // custom FUNCTIE wordt aangeroepen ElevatorMove(); // custom FUNCTIE wordt aangeroepen FloorSelection = FALSE; // INTEGER = false } }
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
03-12-2007 04:37
I've no idea what you mean by "worked" / "doesn't work". Can you describe the specific change in behavior? Also, this code: key av = llDetectedKey(0); // detected object key = av AVsize = llGetAgentSize(av); llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); // Target offset 0,0, avatar gedeelte gedeeld door twee
in the changed() event has issues. First, llDetected* functions are not defined inside of the changed() function, and llDetectedKey(0) itself *should* return NULL_KEY all the time. Second, changing the Sit target *after* the avatar has already sit won't do anything except change where the *next* avatar sits. It won't change the position of the currently-sitting avatar. Further, llForceMouseLook works just like llSitTarget in this respect; ie, you can't force someone into mouselook after they have sat down. Only the next person to sit after you set llForceMouseLook(TRUE) will be affected by it, so you can move that line from your ElevatorMove function to the state_entry event, as it really doesn't do anything there (you never call llForceMouseLook(FALSE), so there's no need to constantly set it to true). Also, though your code should work OK most of the time, your movement loops should be something like: while(llVecDist(llGetPos(), TargetPos) > 0.01) // als de afstand tussen de vectors niet gelijk is aan 0 (zelfde plek) IN EEN LOOP!
That prevents tiny rounding errors from getting your elevator stuck in an infinite loop. Outside of those issues, it looks like it should work OK. Changing the default object action to "Sit" shouldn't have any effect on script operation, unless there is some new bug I haven't heard about. Again, though, I would need more info on what you consider to be "not working" about it to know for sure.
|
|
Sebastiaan Siegel
Registered User
Join date: 2 Feb 2007
Posts: 18
|
03-12-2007 05:06
thanks for quick and usefull reply! I'll read it and put it to some good use. the original script used a menu that would let the user select the prefered height. so before sitting down on the object the user had to touch the object and select the height. I only want it to have on height and the menu remove so with only one click the avatar would step on and move up (or down). First the avatar would sit (stand) on the elevator and it would move, but the avatar wouldnt unsit. Now it only sits on the edge and nothing happens. the weird thing is that i made a backup before i started working on the unsit part. the backup doesnt work anymore either 
|
|
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
|
03-12-2007 06:21
a correction to the above response. I've not heard of any reason that llDetectedKey(0) wouldn't work in the changed event, but really the llAvatarOnSitTarget should be all you need to return the key of the AV who sat on the object. All vehicles use this method to check if it's the owner or not so there's really no reason to use both. The reason why your unsit is not working is because the key "av" is being called as a local variable variable in the changed event and is also listed as a global variable to the whole script, so it is saving the key to the local variable instead and will not carry over the value set in changed. It's trying to Unsit NULL_KEY. To correct, just change the line that says "key av = llDetectedKey(0);" to "av = llAvatarOnSitTarget();"
|
|
Sebastiaan Siegel
Registered User
Join date: 2 Feb 2007
Posts: 18
|
03-12-2007 08:12
AVsize = llGetAgentSize(av); and llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); are causing trouble.
is there a way to get the agentsize without using the touch event?
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
03-12-2007 09:08
From: Tiarnalalon Sismondi a correction to the above response. I've not heard of any reason that llDetectedKey(0) wouldn't work in the changed event, but really the llAvatarOnSitTarget should be all you need to return the key of the AV who sat on the object. All vehicles use this method to check if it's the owner or not so there's really no reason to use both. The llDetection* functions will not give an error if you use them outside of a Detection event, but they are not guaranteed to give any meaningful information if you do so. Hence: From: The Wiki Note: The llDetected* functions will only return a meaningful value in the collision(), collision_start(), collision_end(), sensor(), touch(), touch_start(), or touch_end() events.
|
|
Sebastiaan Siegel
Registered User
Join date: 2 Feb 2007
Posts: 18
|
03-12-2007 09:55
I still cant get it to work :< i came up with the following script. But now the object tends to keep moving towards <0,0,0>  driving me crazy key avatar; // detected AVATAR key float height = 100; // getal dat het aantal meters aangeeft met hoeveel meter de lift stijgt integer CHANNEL; // random Channel, voor verbeterde beveiliging - afgerond getall integer HANDLE; // kanaal + vector? integer FloorSelection = FALSE; vector StartPos; vector avatarsize; // geen idee
//StopSitAnim() // Don't sit on the floor. :p // functie, tijdens het transporteren gebeurd dit... //{ // llStopAnimation("sit_generic"); // hierdoor zit de avatar nog wel maar is zn zitanimatie gestopt waardoor het lijkt alsof hij staat. // llStopAnimation("sit"); // hierdoor zit de avatar nog wel maar is zn zitanimatie ges0topt waardoor het lijkt alsof hij staat. // llStartAnimation("impatient"); // klokkijken // llForceMouselook(1); // mouselook 1 //}
ElevatorMove() { if(FloorSelection) { vector TargetPos = <StartPos.x, StartPos.y, StartPos.z + height>; while(llVecDist(llGetPos(), TargetPos) != 0) { llForceMouselook(1); llSetPos(TargetPos); } llUnSit(avatar); llSleep(1); while(llVecDist(llGetPos(), StartPos) != 0) { llSetPos(StartPos); } } else { llStopSound(); llUnSit(avatar); llWhisper(0, "Plz touch this floor and select where you go first"); } }
//default //{ // state_entry() // { // llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); // llSetSitText("Get on"); // taartpunt zegt Get On normaal staat hier Sit // StartPos = llGetPos(); // startpos krijgt zijn gegevens door GetPos // } // on_rez(integer start_param) // { // llResetScript(); // reset script, hierdoor krijgt hij zijn nieuwe startpositie terug // } // //changed(integer change) // { // if(change & CHANGED_LINK) // als er een avatar op is gaan zitten... // { //key av = llDetectedKey(0); // detected object key = av //AVsize = llGetAgentSize(av); // vector == hoogte van de avatar: bounding box //llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); // Target offset 0,0, avatar gedeelte gedeeld door twee //integer CHANNEL = llRound(llFrand(1000000) - 10000000); // random channel HANDLE = llListen(CHANNEL, "", "", ""); //llDialog(av, "To what floor do you go?", menuList, CHANNEL); // FloorSelection = TRUE; // // // av = llAvatarOnSitTarget(); // ALS OBJECT KEY GELIJK IS AAN // if(av != NULL_KEY) // als de key EEN waarde heeft... // { // // llRequestPermissions(av, PERMISSION_CONTROL_CAMERA); // vraagt toestemming om de camera over te nemen - niet nodig? // llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION); // vraagt toestemming om custom animaties af te spelen // // } // } // } // // run_time_permissions(integer perm) // toestemming gekregen // { // //StopSitAnim(); // custom FUNCTIE wordt aangeroepen // ElevatorMove(); // custom FUNCTIE wordt aangeroepen // FloorSelection = FALSE; // INTEGER = false // }
//touch_start(integer change) // { // //key av = llDetectedKey(0); // detected object key = av // AVsize = llGetAgentSize(av); // vector == hoogte van de avatar: bounding box // llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); // Target offset 0,0, avatar gedeelte gedeeld door twee // integer CHANNEL = llRound(llFrand(1000000) - 10000000); // random channel HANDLE = llListen(CHANNEL, "", "", ""); // //llDialog(av, "To what floor do you go?", menuList, CHANNEL); // Floorselection = TRUE; // } // listen(integer channel, string name, key id, string message) // { // //height = llList2Float(heightList, llListFindList(menuList, [message])); // hoogte uit lijstje // //llListenRemove(HANDLE); // handle verwijderd // //FloorSelection = TRUE; // NU KAN ER GEREDEN WORDEN WIII // } //}
StopSitAnim() // Don't sit on the floor. :p // functie, tijdens het transporteren gebeurd dit... { llStopAnimation("sit_generic"); // hierdoor zit de avatar nog wel maar is zn zitanimatie gestopt waardoor het lijkt alsof hij staat. llStopAnimation("sit"); // hierdoor zit de avatar nog wel maar is zn zitanimatie ges0topt waardoor het lijkt alsof hij staat. llStartAnimation("impatient"); // klokkijken // mouselook 1 }
default { on_rez(integer perm) { llResetScript(); } state_entry() { //avatarsize = llGetAgentSize(avatar); llForceMouselook(FALSE); //avatar = llDetectedKey(0); llSitTarget(<0.0, 0.0, 1>, ZERO_ROTATION); // needed for llAvatarOnSitTarget to work } changed(integer change) { // something changed avatar = llAvatarOnSitTarget(); if (change & CHANGED_LINK) { // and it was a link change llSleep(0.5); // llUnSit works better with this delay if (llAvatarOnSitTarget() != NULL_KEY) { // somebody is sitting on me llRequestPermissions(avatar, PERMISSION_TRIGGER_ANIMATION); // llUnSit(llAvatarOnSitTarget()); // unsit him } } } run_time_permissions(integer perm) // toestemming gekregen { //llSay(0,"BEUNHAAS"); StopSitAnim(); // custom FUNCTIE wordt aangeroepen FloorSelection = TRUE; ElevatorMove(); // custom FUNCTIE wordt aangeroepen FloorSelection = FALSE; // INTEGER = false } }
|
|
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
|
03-12-2007 10:12
From: Sebastiaan Siegel AVsize = llGetAgentSize(av); and llSitTarget(<0, 0, (AVsize.z / 2)>, ZERO_ROTATION); are causing trouble. is there a way to get the agentsize without using the touch event? Well, the problem here is that you're setting the sit target AFTER the person is already sitting on the object, which will not work. So the only way would be to have them Touch it First to set the sit target Before they sit. It's really easier just to establish a generic sit target that may have some taller AV's slightly in the floor (their fault for making grossly oversided AV's...not everyone should be Shaq), or slightly hovering in mid-air if they're too short. Usually if you set it about right for a 6' av, no one will complain as they should be forgiving of minor visual issues caused by their own av settings.... Like I wouldn't complain at someone for my dragon av's tail not fitting inside the thing 
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
03-12-2007 12:23
If you really, really want to have the Sit target move to adjust to the height of the rider, then make an invisible linked child prim at about the average center of most avs (about 1.1m) above the elevator floor and put put a separate script in it which uses llSetPos on that prim, relative to the root to move them up or down according to their size.
Note that this a bit of an advanced task, and will require a bit of experimentation to get it right.
|
|
Sebastiaan Siegel
Registered User
Join date: 2 Feb 2007
Posts: 18
|
03-13-2007 01:54
Haha great ideas  The point of altering the script was that you'd only have to click it once in order to go up (or down) Edit: While taking a shower this morning i realised that "StartPos = llGetPos();" was missing in the state_entry() event...
|