Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sheathe and Draw Script

KeeperS Karu
Registered User
Join date: 18 Oct 2008
Posts: 31
11-09-2008 22:51
Heyla!

I used a simple hide and show script as the basis for a script that will allow my avatar to draw and sheathe a sword I had made. The basic script works just fine, but I'm running into trouble when I try to insert a few lines to make the animations play, so that the avatar actually looks as if she's really drawing and sheathing her sword. The problem seems to be that I haven't accquired the proper permission to play the animations, so I looked up what I thought I needed and found this:

integer llRequestPermissions(key avatar, integer perm);

I replaced "integer perm" with PERMISSION_TRIGGER_ANIMATION, but I have no idea what "key avatar" means, and I think that's the reason why I keep getting a syntax error when I try to save the script. I'm very much a beginner in scripting, so I'm most likely missing something very obvious to people who actually know what they're doing.

Here's the script I'm using:

draw()
{
llSetAlpha(1.0, ALL_SIDES);
}

sheathe()
{
llSetAlpha(0, ALL_SIDES);
}

--Here is where I had tried to insert the request animation function, and I keep getting an error.--

default
{
state_entry()
{
llListen(5, "", llGetOwner(), "";);
}

listen(integer channel, string name, key id, string message)
{
message = llToLower(message);

if(message == "draw";)
{
llStartAnimation("hip_draw";);
draw();
return;
}
llStartAnimation("hip_sheathe";);
if(message == "sheathe";)
sheathe();
}

}

So what am I supposed to type in for "key avatar?" And while I'm at it, is there anything else I need to include to get the animations to play?

Thank you for your help,
Keeper S. Karu
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
11-09-2008 23:09
"key avatar" means the UUID of the avatar you want permissions from. In this case, replace it with llGetOwner()

I would put that in an on_rez event, and then capture a true/false variable for wether or not we have animation permissions. While gaining permissions on_rez while attached is plenty reliable, its good practice to make sure you have it first.

You're also not renewing the Owner Listen, which means it'll only listen to you rather than whoever's using it.

Declaring functions for setting Alpha like that is totally needless unless you want it to automatically sheathe on rez or something, as is the use of the "return;" calls.

integer listen_handle;
integer permissions;

default
{
on_rez(integer start_param)
{
if( llGetAttached() );
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
llListenRemove(listen_handle);
listen_handle = llListen(5, "", llGetOwner(), "";);
}
run_time_permissions(integer perms)
{
if( perms & PERMISSION_TRIGGER_ANIMATION )
{
permissions = TRUE;
}
}
listen(integer channel, string name, key id, string message)
{
message = llToLower(message);

if( message == "draw" )
{
if( permissions )
{
llStartAnimation("hip_draw";);
}
llSetAlpha(1.0, ALL_SIDES);
}
else if( message == "sheathe" )
{
if( permissions )
{
llStartAnimation("hip_sheathe";);
}
llSetAlpha(0, ALL_SIDES);
}
}
}
Jenn Yoshikawa
Registered User
Join date: 14 Nov 2007
Posts: 91
11-09-2008 23:11
attach is better then on rez hehe

draw()
{
llSetAlpha(1.0, ALL_SIDES);
}

sheathe()
{
llSetAlpha(0, ALL_SIDES);
}

default
{
state_entry()
{
llListen(5, "", llGetOwner(), "";);
}
attach(key _id)
{
if (_id != NULL_KEY)
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}
listen(integer channel, string name, key id, string message)
{
message = llToLower(message);

if(message == "draw";)
{
llStartAnimation("hip_draw";);
draw();
return;
}
llStartAnimation("hip_sheathe";);
if(message == "sheathe";)
sheathe();
}

}
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
11-09-2008 23:14
True enough. I'm not sure if attach fires on the login-rezzings, so I usually use on_rez with an llGetAttached() check.
Twisted Laws
Registered User
Join date: 19 Jun 2006
Posts: 9
11-10-2008 07:30
by the way...

you can do sheath/draw in one script per object instead of one script per prim that most people use by using llSetLinkAlpha(LINK_SET,alpha_setting,ALL_SIDES) instead of llSetAlpha(alpha_setting,ALL_SIDES);
KeeperS Karu
Registered User
Join date: 18 Oct 2008
Posts: 31
11-10-2008 08:15
NEW EDIT: I decided to play around with the scripts, just to see if there's anything I could discover on my own, and sure enough, there was. For some reason, if I edit the script while it's in the sword, it doesn't do anything. However, if I delete the script and edit the version I have in my inventory, then add it to the sword, the script I used works just fine. Why does it make a difference?

EDIT: I remembered a few other things to mention, near the end.

Thank you all for your help! I had tried a lot of what was said, and while the script compiled successfully when I saved it, nothing seems to be happening. Here is what I used:

integer listen_handle;
integer permissions;

default
{
on_rez(integer start_param)
{
if( llGetAttached() );
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
llListenRemove(listen_handle);
listen_handle = llListen(5, "", llGetOwner(), "";);
}
run_time_permissions(integer perms)
{
if( perms & PERMISSION_TRIGGER_ANIMATION )
{
permissions = TRUE;
}
}
listen(integer channel, string name, key id, string message)
{
message = llToLower(message);

if( message == "draw" )
{
if( permissions )
{
llStartAnimation("hip_draw";);
}
llSetLinkAlpha(LINK_SET,1.0, ALL_SIDES);
}
else if( message == "sheathe" )
{
if( permissions )
{
llStartAnimation("hip_sheathe";);
}
llSetLinkAlpha(LINK_SET,0, ALL_SIDES);
}
}
}

I also tried the one from the second reply. Again, it was a successful compile, but nothing happens.

Is there something I missed? Also, could this conflict with the swordfighting script I'm using?

integer SWORD = 1;
integer PUNCH12 = 2;
integer PUNCHL = 3;
integer KICK = 4;
integer FLIP = 5;

integer strike_type;

default
{
state_entry()
{
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
}
run_time_permissions(integer perm)
{
if (perm)
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT | CONTROL_DOWN, TRUE, TRUE);
}
}

attach(key on)
{
if (on != NULL_KEY)
{
integer perm = llGetPermissions();

if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(on, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
}
else
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
}

}
else
{
llSay(0, "releasing controls";);
llTakeControls(FALSE, TRUE, TRUE);
}
}

timer()
{
if ( (strike_type == FLIP)
|| (strike_type == SWORD))
{
llSensor("", "", ACTIVE | AGENT, 4.0, PI_BY_TWO*0.5);
}
else
{
llSensor("", "", ACTIVE | AGENT, 3.0, PI_BY_TWO*0.5);
}
llSetTimerEvent(0.0);
}

control(key owner, integer level, integer edge)
{
if (level & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON))
{
if (edge & CONTROL_UP)
{
llApplyImpulse(<0,0,3.5>,FALSE);
llStartAnimation("backflip";);
llSetTimerEvent(0.25);
strike_type = FLIP;
}
if (edge & CONTROL_FWD)
{
llStartAnimation("overhead_strike_exaggerated";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
if (edge & (CONTROL_LEFT))
{
llStartAnimation("upward_right_strike_exag";);
llSetTimerEvent(0.25);
strike_type = PUNCHL;
}
if (edge & (CONTROL_ROT_LEFT))
{
llStartAnimation("diagonal_right_strike_exag";);
llSetTimerEvent(0.25);
strike_type = PUNCHL;
}
if (edge & (CONTROL_RIGHT))
{
llStartAnimation("upward_left_strike_exag";);
llSetTimerEvent(0.25);
strike_type = KICK;
}
if (edge & (CONTROL_ROT_RIGHT))
{
llStartAnimation("diagonal_left_strike_exag";);
llSetTimerEvent(0.25);
strike_type = KICK;
}
if (edge & CONTROL_BACK)
{
llStartAnimation("punch_onetwo";);
llSetTimerEvent(0.25);
strike_type = PUNCH12;
}
if (edge & CONTROL_DOWN)
{
llMoveToTarget(llGetPos(), 0.25);
llSleep(1.0);
llStopMoveToTarget();
}
}
}

sensor(integer tnum)
{
vector dir = llDetectedPos(0) - llGetPos();
dir.z = 0.0;
dir = llVecNorm(dir);
rotation rot = llGetRot();
if (strike_type == SWORD)
{
llTriggerSound("crunch", 0.5);
dir += llRot2Up(rot);
dir *= 20.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCH12)
{
llTriggerSound("crunch", 0.2);
dir += dir;
dir *= 20.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCHL)
{
llTriggerSound("crunch", 0.2);
dir -= llRot2Left(rot);
dir *= 20.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == KICK)
{
llTriggerSound("crunch", 0.2);
dir += dir;
dir *= 20.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == FLIP)
{
llTriggerSound("crunch", 0.2);
llPushObject(llDetectedKey(0), <0,0,20>, ZERO_VECTOR, FALSE);
}
strike_type= 0;
}
}

I had put the sheathe script in a different file because I wasn't sure how to fit it into the sword script. But now I'm wondering if that's part of my trouble.
Twisted Laws
Registered User
Join date: 19 Jun 2006
Posts: 9
11-10-2008 08:58
change it a bit....
this is to allow it to be edited and tested without taking it off and putting it back on

default
{
state_entry()
{
if( llGetAttached() );
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
listen_handle = llListen(5, "", llGetOwner(), "";);
}
on_rez(integer sp)
{
llResetScript();
}
..... rest of your script

}
KeeperS Karu
Registered User
Join date: 18 Oct 2008
Posts: 31
11-10-2008 09:10
Oh, cool! Thanks! I will put that in!