|
Aniam Ingmann
llOwnage(float pwnage);
Join date: 22 Oct 2005
Posts: 206
|
11-24-2007 18:09
so I need a script to do different things when sat on, then gotten off of. I thought to set an integer that changes when sat on, then changes back to the default when gotten off of... but that didn't work. what now? key avatar; integer n; default { state_entry() { n = 0; llSitTarget(<0.0,0.0,0.250>,ZERO_ROTATION); } changed (integer change) { if (change == CHANGED_LINK) { avatar = llAvatarOnSitTarget(); if(n == 0) { n = 1; llOwnerSay(llKey2Name(llAvatarOnSitTarget())); llRequestPermissions(avatar, PERMISSION_TAKE_CONTROLS); } } if (n == 1) { if (llGetPermissionsKey() != NULL_KEY) { n = 0; llOwnerSay(llKey2Name(avatar)+" has gotten up. Releasing controls."); } } } run_time_permissions(integer perm) { if (perm & PERMISSION_TAKE_CONTROLS) { llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_RIGHT| CONTROL_ROT_LEFT, TRUE, FALSE); } } control(key id, integer held, integer change) { integer pressed = held & change; integer down = held & ~change; integer released = ~held & change; integer inactive = ~held & ~change;
if (pressed & CONTROL_FWD) { llOwnerSay("up"); } else if(pressed & CONTROL_BACK) { llOwnerSay("back"); } else if (pressed & CONTROL_ROT_RIGHT) { llOwnerSay("right"); } else if (pressed & CONTROL_ROT_LEFT) { llOwnerSay("left"); } } }
_____________________
From: someone Don't worry, Aniam is here! - Noob
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
11-24-2007 19:34
The changed event occurs when a change is made... hence...
default { state_entry() { llSitTarget(<0, 0, 0.1>, ZERO_ROTATION); // needed for llAvatarOnSitTarget to work } changed(integer change) { // something changed if (change & CHANGED_LINK) { // and it was a link change key av = llAvatarOnSitTarget(); if (av) { // somebody is sitting on me // seated code goes here... } else { // unseated code here } } } }
|
|
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
|
11-24-2007 19:44
i was working on it alittle, and it worked fine just it didnt know when the avatar got off right away, basicly just had to switch the top script around, the first part of the script should the
{ changed stuff* { // avatar gets off what dose script do / releasecontrols() } else { //what script should do when avatar gets on / permision requests } //perm stuff } controls { //ect ect
|
|
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
|
11-24-2007 21:48
You have to use the if - else structure, if you use two "if" the script will enter in both because in the first one you wrote "n = 1", this is what you wrote:
// This is bad
state_entry() { n = 0; }
if (change & CHANGED_LINK) { if (n == 0) // yes it is { n = 1; // now n equals 1 //do something }
if (n = 1) // yes it is { n = 0; // now n equals 0 //do someting } }
This is Ok:
state_entry() { n = FALSE; }
on_rez() {
n = FALSE;
}
if (change & CHANGED_LINK) { if (!n) // is (n == FALSE) { //do something
}
else // n == TRUE; { //do someting }
n = !n ///////// if (n == FALSE) n == TRUE; else n == FALSE; }
-------------------------------------------------------------------------------------------
And one more thing: state_entry() is triggered when you save/reset script and when you enter to a state. So if you rezz an object sate_entry is not triggered, therefore you should use on_rez event.
|
|
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
|
11-25-2007 23:40
Never assume an avatar sat on your object when a link change event occurs.
Always cross-check llAvatarOnSitTarget() with NULL_KEY.
If its NULL_KEY the avatar stood up or the linkset changed. If its NOT NULL_KEY then someone acutally sat down on your object.
But what if somebody sits on your object and you get a link change event? In such a case, someone else obviously sat down on the object too. Though that persons UUID will not show up through llAvatarOnSitTarget(). There are other ways to determine it though.
|