Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Double Tap for a Sword Script

KeeperS Karu
Registered User
Join date: 18 Oct 2008
Posts: 31
12-05-2008 17:52
Heyla, all!

A friend and I were playing with the sword I made when we realized that, when we go into mouselook, we could not get the animations associated with the rotate left and rotate right keys to play. Obviously, this is because, while in mouselook, the keys that normally rotate the avatar left and right now make the avatar strafe left and right. So, in order to fix the problem, my friend suggested I try a double tap feature that her C:SI swords emply to get another animation to play. After looking around, I found a great suggestion as to how to go about implementing double tap. Unfortunately, my implementation and understanding of the general explanation must not be so good, because I can't seem to get it to work, properly.

Here is what I did:

[Since I can't see the results in mouselook, I decided to see if I can get the double-tap to work in normal mode. So I tried to add some things so that, on double tap, the strafing animation plays, rather than the rotating animation. Nothing happened.]

if (change & held & CONTROL_ROT_LEFT)
{
float storedTime;
float recentTime;
float time;
float interval = 0.5;

recentTime = llGetTime();

time = recentTime - storedTime;
storedTime = recentTime;

if (time <= interval)
{
llStartAnimation(strafeleftanim);
llSetTimerEvent(0.75);
strike_type = SWORDLFT;
}
if (time > interval)
{
llStartAnimation(rotleftanim);
llSetTimerEvent(0.75);
strike_type = SWORDLFT;
}

Here is the same bit of code in the context of the control event:

control(key owner, integer held, integer change)
{
if (held & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON))
{
if (change & held & CONTROL_UP)
{
llApplyImpulse(<0,0,3.5>,FALSE);
llStartAnimation(pgupanim);
llSetTimerEvent(0.25);
strike_type = SPECIALATK;
}
if (change & held & CONTROL_FWD)
{
llStartAnimation(fwdanim);
llSetTimerEvent(0.75);
strike_type = SWORDFWD;
}
if (change & held & CONTROL_ROT_LEFT)
{
float storedTime;
float recentTime;
float time;
float interval = 0.5;

recentTime = llGetTime();

time = recentTime - storedTime;
storedTime = recentTime;

if (time <= interval)
{
llStartAnimation(strafeleftanim);
llSetTimerEvent(0.75);
strike_type = SWORDLFT;
}
if (time > interval)
{
llStartAnimation(rotleftanim);
llSetTimerEvent(0.75);
strike_type = SWORDLFT;
}
}
if (change & held & CONTROL_LEFT)
{
llStartAnimation(strafeleftanim);
llSetTimerEvent(0.75);
strike_type = SWORDLFT;
}
if (change & held & CONTROL_ROT_RIGHT)
{
llStartAnimation(rotrightanim);
llSetTimerEvent(0.75);
strike_type = SWORDRGT;
}if (change & held & CONTROL_RIGHT)
{
llStartAnimation(straferightanim);
llSetTimerEvent(0.75);
strike_type = SWORDRGT;
}
if (change & held & CONTROL_BACK)
{
llStartAnimation(bckanim);
llSetTimerEvent(0.25);
strike_type = KICK;
}
if (held & change & CONTROL_DOWN)
{
llStartAnimation(pgdwnanim);
llTriggerSound(swdswing, 1.0);
llSetTimerEvent(0.01);
strike_type = BLOCK;
llMoveToTarget(llGetPos(), 0.25);
llSleep(1.0);
llStopMoveToTarget();
}
if (~held & change & CONTROL_DOWN)
{
llStopAnimation(pgdwnanim);
}
}
if (~held & change & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON))
{
llStopAnimation(pgdwnanim);
}
}

Thanks to anyone who can tell me what I'm doing wrong!

Keeper S. Karu
KeeperS Karu
Registered User
Join date: 18 Oct 2008
Posts: 31
12-10-2008 12:48
It's okay. I managed to get the help I needed from someone. Thanks for looking, anyhow.