Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help scripting a mini ao

Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
05-19-2007 16:48
Hello. I'm making a mini ao for a staff. I tried everything to remove the standard walk and run animations, but they still show up, even if my animations have a higher priority. Also, I can't get it to use run animation when running and walk animation when walking.

CODE

integer agent;
default
{
attach(key id)
{
llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llStartAnimation("Staff stand 2");
}
run_time_permissions(integer perm)
{
if (perm)
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT, TRUE, TRUE);
}
}
state_entry()
{
agent = llGetAgentInfo(llDetectedKey(0));
if (agent & AGENT_ALWAYS_RUN)
{
llOwnerSay("Run enabled");
}
}
control(key name, integer held, integer change)
{
integer pressed = held & change;
integer down = held & ~change;
integer released = ~held & change;
integer inactive = ~held & ~change;
if ((pressed & CONTROL_FWD) || (pressed & CONTROL_BACK))
{
llStopAnimation("Staff stand 2");
llStopAnimation("walk");
llStopAnimation("female_walk");
llStopAnimation("run");
llGetAgentInfo(llGetOwner());
if (agent & AGENT_ALWAYS_RUN)
{
llStartAnimation("Staff run");
}
else
{
llStartAnimation("Staff walk");
}
}
if ((released & CONTROL_FWD) || (released & CONTROL_BACK))
{
llStopAnimation("Staff walk");
llStopAnimation("Staff run");
llStartAnimation("Staff stand 2");
}
}
}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-20-2007 07:08
The Event Handler state_entry only runs one time, so agent = llGetAgentInfo(llDetectedKey(0)); is not going to be refreshed unless the script resets, or the state changes.

FWIW I've always done this kind of thing using a timer and llGetAnimation(llGetOwner()); where detected animations are then simply overridden by the custom animation.

Some snippets only:

CODE
string lastAnim;
string lastAnimState;

animOverride()
{
string curAnimState = llGetAnimation(llGetOwner());

if (curAnimState != lastAnimState)
{
if (lastAnim != "")
{
llStopAnimation(lastAnim);
lastAnimState = "";
lastAnim = "";
}
if (curAnimState == "Walking")
{
llStartAnimation("Staff walk");
lastAnimState = curAnimState;
lastAnim = "Staff walk";
}
}
}

:
:
timer()
{
animOverride();
}
Your script may work fine if you move the llGetAgentInfo request. :)
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-20-2007 08:44
CODE

agent = llGetAgentInfo(llDetectedKey(0));


in the state_entry() event won't do anything, because llDetectedKey() (and all other llDetected* functions) are meaningless outside of sensor(), touch*(), and collision*() events. In the state_entry() event, it probably returns NULL_KEY, which causes llGetAgentInfo() to return 0 all the time.

Try using llGetOwner() there instead. Also, as Pale suggested above, move or copy it into someplace (like a timer event) else so it can continue to be checked and acted upon.

That's basically the way most AOs work. They detect the specific avatar movement states via repeated calls to llGetAgentInfo() in a fairly short (< 1 second) timer, then stop the normal animations, and start the correct ones.
Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
05-21-2007 03:00
Got it. Thanks.