Hawthorne Gray Posted August 26 Posted August 26 This script, which Qie Niangao helped me write along with ChatPGT, works remarkably well with the exception of the de-attach function, which fails: default { state_entry() { llSay(0, "STATE"); } on_rez(integer start_param) { llSay(0, "REZ"); // Retrieve the owner key from the description field // Find out which object rezzed us: key rezzer = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]), 0); // Retrieve the target avatar key from the rezzer's description field: key owner_id = (key)llList2Key(llGetObjectDetails(rezzer, [OBJECT_DESC]), 0); llRequestPermissions(owner_id, PERMISSION_TRIGGER_ANIMATION|PERMISSION_ATTACH); llSay(0, (string)owner_id); } run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION && perm & PERMISSION_ATTACH) { // Play the "hold" animation llStartAnimation("hold"); // Attach to the avatar at the desired attachment point llAttachToAvatarTemp(ATTACH_RHAND); } else { llSay(0, "RUNTIME");} } attach(key id) { if ((id == NULL_KEY) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)) { // Stop the animation when the object is detached llStopAnimation("hold"); } } touch_start(integer total_number) { key toucher = llDetectedKey(0); if ((llGetPermissionsKey() == toucher) && (llGetPermissions() & PERMISSION_ATTACH)) { llDetachFromAvatar(); } else { llSay(0, "NOPE");} } } Not sure where I've gone wrong. Also, if possible, I'd like to add a llGetachFromAvatar() that automatically detaches the item after 300 seconds. Any ideas?
Quistess Alpha Posted August 26 Posted August 26 (edited) 2 hours ago, Hawthorne Gray said: llAttachToAvatarTemp(ATTACH_RHAND); When an object is attached, it (immediately) loses all permissions it has been granted. you need to re-request permissions in the attach() event, or immediately after this function call. Edited August 26 by Quistess Alpha
Hawthorne Gray Posted August 26 Author Posted August 26 1 hour ago, Quistess Alpha said: When an object is attached, it (immediately) loses all permissions it has been granted. you need to re-request permissions in the attach() event, or immediately after this function call. Thanks, Quistess. The thing is, I find permission events confusing so with the help of your tip I turned to chatGPT and got the following script (along with the addition of an auto-detach object action): default { state_entry() { llSay(0, "STATE"); } on_rez(integer start_param) { llSay(0, "REZ"); // Retrieve the owner key from the description field // Find out which object rezzed us: key rezzer = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]), 0); // Retrieve the target avatar key from the rezzer's description field: key owner_id = (key)llList2Key(llGetObjectDetails(rezzer, [OBJECT_DESC]), 0); llRequestPermissions(owner_id, PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH); llSay(0, (string)owner_id); } run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION && perm & PERMISSION_ATTACH) { // Play the "hold" animation llStartAnimation("hold"); // Attach to the avatar at the desired attachment point llAttachToAvatarTemp(ATTACH_RHAND); // Start a timer for 300 seconds (5 minutes) llSetTimerEvent(300.0); } else { llSay(0, "RUNTIME"); } } attach(key id) { if (id != NULL_KEY) { // Re-request permissions when attached llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH); // Start a timer for 300 seconds (5 minutes) llSetTimerEvent(300.0); } else if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) { // Stop the animation when the object is detached llStopAnimation("hold"); // Stop the timer when detached llSetTimerEvent(0.0); } } touch_start(integer total_number) { key toucher = llDetectedKey(0); if ((llGetPermissionsKey() == toucher) && (llGetPermissions() & PERMISSION_ATTACH)) { llDetachFromAvatar(); } else { llSay(0, "NOPE"); } } timer() { // Auto-detach the object llDetachFromAvatar(); // Notify the owner llOwnerSay("Your drink was collected by the bartender."); // Stop the timer llSetTimerEvent(0.0); } }
Recommended Posts
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