Call of Duty 4: SP - Using Animations

From COD Modding & Mapping Wiki
Revision as of 15:29, 23 February 2012 by Ingram (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I've read a lot about peoples issues with animations, and how there was no concrete tutorial for how to use one. It took me a lot of code reading to finally figure out how to use animations, but once you've figured it out, It can be a breeze. P.S: This is not the method IW uses. It is less concise then their's, but it works the same.

  • Ok first off, make a new map. Once you've loaded it up, save at as whatever you like. Now, make a large block, then use the hollow tool to hollow that block into a room. Hollow tool is located on the command bar right under the 'brush' menu. It looks like a box with a smaller segmented box inside it.
  • Once you have your room, (which should be rather large), you should make some worldspawn settings for light.
  • Now, right click the 2D grid, then go to 'info' then click 'player_start' to create where the player will spawn in the world. Now place it in the room. Make sure it is not inside a block or you will not spawn. Now right click on the 2D grid agin, go down to 'node', then click 'scripted_node'. A white box will appear in the map. This is where the animation will play from. Place it in the room, a few units off the ground. Click 'E' on the node to enter the entity editor. Name the node like this:
Key: targetname
Value: anim_node
  • Now its time to get an actor to perform this animation.Right click the 2D grid, click 'actor', go to 'ally',( If the actor is an enemy he will shoot you) then choose any actor you want. For this example, I will use a marine with an m16. Again, place this actor in the room, near the anim node. Place a few pathnodes if the actor is farther away from the scripted node. Press E when you have the actor selected. Now name him:
Key: targetname
Value: guy
  • Now its time for scripting. Save your map as test. exit radiant. Now go to your CoD4 folder, go to raw/maps. Create two text documents. Name the first one 'test'. Name the second one 'test_anim'. Open up 'test', click save as, now do this:
name: test.gsc
save as type: all files

Make sure that the .gsc is being saved into the maps folder.

Now go the test_anim file, and do the same thing:

name: test_anim.gsc
save as type: all file

Again, make sure that it is being saved into your maps folder. Now open up test.gsc. Put this code into it:

#include common_scripts\utility;
#include maps\_utility;
#include maps\_anim;

main()
{
    maps\test_anim::main();
    maps\_load::main();

    thread anim();  
}
  • Now save the file, and open up test_anim.gsc. Once thats open, place this code into it:
#include maps\_utility;
#include common_scripts\utility;
#include maps\_anim;

#using_animtree ("generic_human");

main()
{
    level.scr_anim[ "guy" ][ "anim" ] = %combatwalk_f_spin //The important line!
}

Now ill explain this line to you guys. Basically, this line is calling this anim to be used. "guy" is the guy who will perform the anim, and "anim" is the alias we have given the actual anim; combatwalk_f_spin.

Go back to your gsc and put this code in:

#include common_scripts\utility;
#include maps\_utility;
#include maps\_anim;

main()
{
    maps\test_anim::main();
    maps\_load::main();

    thread anim();
}

anim()
{
    level.guy = getent( "guy", "targetname" );
    level.guy.animname = "guy";

    anim_node = getnode( "anim_node", "targetname" );

    level.guy setgoalnode(anim_node);
    level.guy waittill( "goal" );

    anim_node anim_reach_solo( level.guy, "anim" );
    anim_node thread anim_single_solo( level.guy, "anim" );
}

Explanation:

anim()
{
    level.guy = getent( "guy", "targetname" ); // Defines our actor for the ///script///
    level.guy.animname = "guy"; // Gives this guy a animation alias. Make ////sure this alias always matches the one in _anim .gsc. e.g = [ "guy" ].

    anim_node = getnode( "anim_node", "targetname" ); ///Defines the node ////that the actor will play the anim on///

    level.guy setgoalnode(anim_node); ///Sets the actor's goal as the node//
    level.guy waittill( "goal" ); ///Nothing happens till "guy"s goal is reached

    anim_node anim_reach_solo( level.guy, "anim" ); ///Once the goal is ////reached, the anim is played. Remember that the second parameter is calling the anim alias we gave back in the _anim script.////
    anim_node thread anim_single_solo( level.guy, "anim" );
}

This combination will allow you to play any generic human animation you want. To find all the animations in the game find, the xanim folder, located in raw. Go to the raw/maps folder and look through other map's _anim file, like blackout_anim, or scoutsniper_anim, to find out the names of other anims the devs used.


Now we have to wrap up some things. Go to compile tools, compile BSP, reflections, then fast file. Then go to your zone file and add this stuff to the right hand column.

xmodel,viewmodel_base_character
xmodel,viewmodel_base_viewhands
xmodel,weapon_m16basic_sp
xmodel,viewmodel_m16
weapon,sp/m16_basic
xanim,combatwalk_f_spin
weapon,sp/mp5
xmodel,weapon_mp5
xmodel,viewmodel_mp5
rawfile,maps/test.gsc
rawfile,maps/test_anim.gsc

Now click save, build your fast file, and open up CoD4 SP. press the tilde key ~ , then type in: map test.


Now watch your animation play!

Most errors will be due to problems with naming of entities. Also, don't forget your semicolons at the end of each line.

Any issues with this tutorial send me a pm on my profile.


Special thanks to Babycop, as their inclusion of source files in their SP maps have been of invaluable assistance.

By Ediblemittens


Sources: Modsonline.com

--CoDEmanX 02:32, 29 July 2009 (UTC)