Feedback for animation changing script
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
12-26-2006 12:00
I am working on a small script idea that is based on capturing keypresses to start animations. It could be used for a fighting game, or a dancing game. I've had a look at the example scripts on the LSL wiki, and have come up with the following (likely nightmarish) crossbreed. I would really appreciate any input on it, including flame about how horrible it is, and why it wont work (so I can secretly learn). I should probably say that I am not sure it even works, since I am far, far away from a machine that can actually run Second Life^^. // dance/combat script 0.1 - Tyann Toll // A script that puts the avatar into one animation, and then plays other animations when keys are pressed // Based on script examples from lslwiki.com // credit to Ready Jack (pistol script, example control script), Catherine Omega Heavy Industries (basic animation script)
// animations for the various moves and stances
string BaseAnim = "ready"; string Move1 = "punch"; string Move2 = "kick"; string Move3 = "bite"; string Move4 = "claw";
// declare functions for later
say(string message) // This is used to output text to the user { llOwnerSay(message); }
// script begins here
default { attach(key who) { if (who == NULL_KEY) // This means that the item containing the script is detached { if (llGetPermissions() & PERMISSION_TAKE_CONTROLS) { llReleaseControls(); } } else { llRequestPermissions(who, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION); } }
run_time_permissions(integer perms) { integer desired_controls = CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | ;
if (perms & PERMISSION_TAKE_CONTROLS) { llTakeControls(desired_controls, TRUE, TRUE); }
}
control(key id, integer down, integer new) { integer pressed = down & new; integer held = down & ~new; integer released = ~down & new;
say ("Use W,A, S, D to fight!") if ((held & CONTROL_FWD) llStartAnimation(Move1); // Move One while W is pressed if ((held & CONTROL_BACK) llStartAnimation(Move2); // Move Two while S is pressed if ((held & CONTROL_RIGHT) llStartAnimation(Move3); // Move Three while D is pressed if ((held & CONTROL_LEFT) llStartAnimation(Move4); // Move Three while A is pressed } }
*leaps into cover and adopts brace position*
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
12-26-2006 12:16
Looks plausible to me, but I don't know a whole lot.
I think you might need to consider *stopping* the animations, too. There are also some issues with animation priorities, something like if there are two, the higher priority one plays.
good luck
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
12-26-2006 12:20
Thanks Lee! It looks plausible to me too - but I haven't done any scripting in SL before, so I have no idea if it works or it will explode in a shower of FILTHY DOOM.
I know about the animation priority thing though - I was planning to make the triggered animations a higher priority than the standard animations so that they would always break through it.
Now, all I need to do is wait until I am back to a machine that can run SL so I can test it out!!
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
Newgy's 2 pennies worth
12-26-2006 13:10
I think that you dont really want the useage message output everytime you press a key. It should be in the run_time_permissions event handler not the control handler.
Lee's comment concerning stopping of animations is very valid. There may also be a few issues with restarting a new animation before the last has finished, you may want to use the pressed and released rather than held, or use a timer otherwise none of your moves may ever finish as they will be continually restarted.
You may also need to expand for multiple held keys since as it stands CONTROL_LEFT will always override the others. This would allow for combo's to be programmed in i.e. LEFT + RIGHT + FWD = Jumping Spinning kick.
Rather than multiple llStartAnimation calls you may find it advantageous to work with lists and match the list index positition with the animation. this could be used to trigger sequences or any other 'specials' i.e. punch punch punch results in an upper cut rather than a standard punch.
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
12-26-2006 14:33
Good point about the usage message - that probably needs to be moved up so that it is only shown once. About animations starting and stopping: I was thinking of a solution where I start a little loop/delay thing for each of the key-presses. So essentially, when you press a key it waits for the select animation to play, and then stops that animation, restarts the default animation and waits for another keypress.
Thanks for the input!
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
12-26-2006 15:41
Ive had a bit of a rethink, and have come up with this: control(key id, integer down, integer new) { integer pressed = down & new; integer held = down & ~new; integer released = ~down & new;
if ((pressed & CONTROL_FWD)) // When W is pressed llStopAnimation(BaseAnim); // Stops basic animation do { llStartAnimation(Move1); } while ((held & CONTROL_FWD); // repeats the move animation while W is pressed llStopAnimation (Move1); llStartAnimation (BaseAnim); // restarts the basic animation since the DoWhile loop is no longer ative, and thus the key has been released. }
What I am trying to do is to trap the key being pressed, switch off the basic animation, and then repeat the new animation for as long as the key is pressed, and then stop the new one and reactivate the basic animation. The attack animations will all be really short - no more than a second, so I am hoping that this will work nicely. Comments welcome!
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
12-26-2006 16:09
I don't think this will work. If you're sitting in a while loop inside the control handler, you'll never get to know when the keys have changed, because each change is sent to you in a new control event. You'll have to set flags in the control event, and then turn the animations on/off in a timer event, based on the flag values. Or something along those lines.
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
12-26-2006 16:59
*ponders* I toyed with the idea of putting in a delay equal to one repeat of the Move1 animation, and then stopping it and restarting BaseAnim when the timer is up. The llSleep function looks like the job here - although I am not sure if it can handle short fractions of a second, though. This might be a problem if the animation is 45 frames (1 1/2 seconds at 30 FPS). Here is my idea of how to put llSleep into the same event, and delaying it while a 1 1/2 animation plays: control(key id, integer down, integer new) { integer pressed = down & new; integer held = down & ~new; integer released = ~down & new;
if ((pressed & CONTROL_FWD)) { // Triggered when W is pressed llStopAnimation(BaseAnim); // Stops basic animation llStartAnimation(Move1); llSleep (Move1Sec); // waits for the period of time specified llStopAnimation (Move1); llStartAnimation (BaseAnim); // restarts the basic animation } }
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-27-2006 07:47
Delays and loops inside the event handler are probably a bad idea. Better for the control event handler just to set up global variables that are then used by a timer triggered event.
Or you could go the whole hog and use a state per animation without control event handlers , i.e. only process keypresses in the ready stance. But that may just end up queueing them up.
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
12-27-2006 08:16
I can see that I definitely need to stop thinking about scripts and get them into SL and see if they work^^. Curse holidays and slow computers!
|
|
Strollerweb Market
Registered User
Join date: 20 Nov 2006
Posts: 21
|
01-24-2007 10:46
Did you get any further with it?
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
01-25-2007 03:33
Thanks for asking!
I decided it was a bit ambitious to begin with, and started with some simpler scripting, although I'm probably going to give this idea a shot again now that I understand more of how to do things.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
01-25-2007 03:44
From: Tyann Toll Thanks for asking!
I decided it was a bit ambitious to begin with, and started with some simpler scripting, although I'm probably going to give this idea a shot again now that I understand more of how to do things. If you need a hand give me a shout.
|
|
Tyann Toll
It went... where?!
Join date: 17 Dec 2006
Posts: 37
|
01-26-2007 04:24
Thanks! (you may regret that offer)
*makes a note of the name with a grin*
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
01-26-2007 04:28
From: Tyann Toll Thanks! (you may regret that offer)
*makes a note of the name with a grin* You weally weally dont know me vewwy well do you? 
|