Sure, I can

Ok, there is going to be quite abit more involved than just animations, because just writing an animation script does no good if you can't see it working with your character.
What we are going to do is code a player with the standard animations. We will be using cbabe as the model because she has the normal animations, stand, walk, jump, attack. We will also use what is called FSM(finite state machine) to seperate the characters animations while running. FSM will allow us to give the character behaviours so when we switch from standing to jumping, the state will change and allow the correct animation to run.
Ok, Here we go.
First we need to define our behaviour states:
Code:
define modeState = skill21;
define modeIdle = 0;
define modeWalk = 1;
define modeJump = 2;
define modeAtck = 3;
Don't let modeState confuse you, it allows you to store the current state plus switch to different states for comparison. The different modes will be compared in the player loop, and if a particular behaviour is activated, the modeState will change, and then the correct animation will play.
Next, we need some calcualtion skills:
Code:
define cycleAnims = skill22;
define animSpeed = skill23;
These will be used to calculate the animation distance and the animation speed. Notice, modestate, cycleAnims, animSpeed are entity skills, thus allowing this code to be used by multiple entities at run time.
Now for the animation function. This is the function that allows for checking what mode you are in and running the appropriate animation.
Code:
function animations() {
my.cycleAnims += my.animSpeed * time; // calculate an animation speed
if(my.modeState == modeIdle) {
ent_animate(me,"stand",my.cycleAnims,ANM_CYCLE); // animate stand
}
if(my.modeState == modeWalk) {
ent_animate(me,"walk",my.cycleAnims,ANM_CYCLE); // animate walk
}
if(my.modeState == modeJump) {
ent_animate(me,"jump",my.cycleAnims,ANM_CYCLE); // animate jump
}
if(my.modeState == modeAtck) {
ent_animate(me,"attack",my.cycleAnims,ANM_CYCLE); // animate attack
}
my.cycleAnims %= 100; // run 100% of animation, then start over
}
Look closely, you will see that the IF statements check what mode you are in, and runs the animation scene based on that mode, you can have as many or less modes as you like depending on how many different animations types your model has, and you would add those modes in this function.
Now the fun part, putting the final piece of code in that moves the player, and does the correct animations depending on your key presses.
Code:
action myPlayer {
var dist[3]; // movement distance
var maxZ = 0; // higher jump limit
var distZ = 40; // target height(can change to jump higher or lower)
my.modeState = modeIdle; // set initial state
my.animSpeed = 3; // set initial anim speed
c_setminmax(me); // reset collision hull
while(1) { // run forever
dist.x = (key_w-key_s) * 6 * time; // move distance based on w and s keys presses
trace_mode = ignore_me + ignore_passable + ignore_passents + use_box; // trace mode
dist.z = -c_trace(my.x,vector(0,0,my.z-500),trace_mode); // trace for gravity
if(dist.x != 0) { my.modeState = modeWalk; my.animSpeed = 6; } // set anim mode/speed
else { my.modeState = modeIdle; my.animSpeed = 3; } // set anim mode/speed
c_rotate(me,vector((key_a-key_d*6*time),0,0),USE_AABB); // turning, key a & d
if(mouse_left == 1 && my.cycleAnims != 0) { // attacking left mouse
my.modeState = modeAtck; // set mode
my.animSpeed = 4; // set anim speed
my.cycleAnims = 0; // reset anim cycle
while(my.cycleAnims < 99) { // run full attack anim
animations(); // animate
wait(1);
}
}
if(key_space == 1 && int(dist.z) <= 0) {
my.modestate = modeJump; // set mode
my.animSpeed = 6; // set speed
my.cycleAnims = 0; // reset anim cycle
vec_set(dist,nullvector); // reset dist vector
maxZ = my.z + distZ; // store target height
while(my.z < maxZ) { // run while your z is lower than target
dist.x = 6 * (key_w-key_s) * time; // jump forward if you press the keys
dist.y = 0; // no movement force in this direction
dist.z = 6 * time; // and move up in the air to jump
move_mode = ignore_passable + ignore_passents; // move mode
c_move(me,dist,nullvector,move_mode); // collision movement
animations(); // animate the jumping
wait(1);
}
while(my.z > (target.z-my.min_z)) { // since we are tracing down, run until z is != target
dist.x = 6 * (key_w-key_s) * time; // jump forward if you press the keys
dist.y = 0; // no movement force in this direction
dist.z = -6 * time; // and move down to the ground
trace_mode = ignore_me + ignore_passable + ignore_passents + use_box; // trace mode
c_trace(my.x,vector(0,0,my.z-1000),trace_mode); // trace while falling down
move_mode = ignore_passable + ignore_passents; // move mode
c_move(me,dist,nullvector,move_mode); // collision movement
wait(1);
}
while(my.cycleAnims < 98) { // finish off jumping animations
animations(); // animate ending jump scenes
wait(1);
}
my.cycleAnims = 0; // reset anim cycle
my.modeState = modeWalk; // reset mode
}
animations(); // animate all modes but jump
move_mode = ignore_passable + ignore_passents + glide; // move mode
c_move(me,dist,nullvector,move_mode); // collision movement
wait(1);
}
}
I am not going to go in to too much detail on this action, I have commented every line so you should have an idea what the line does, but what I wanted to show is that using states, you can create behaviour modes for your character, and depending on what you do, i.e. press the space key, press the mouse left button, press the w,a,s,d keys, you can change the mode, thus change your animation behaviour to react accordingly.
Plug the code in to your main script, attach the myPlayer action to your cbabe, and have fun, Study the code, states can be very powerful and can be used for many thing besides animations.
Happy animating

-raiden