Author: Mr.Jox
Original Thread: Add custom animated bow

Add custom animated bow If anyone tried to create and add custom bow he definitely ran through some issues.
Let's split archer on two modes: idle and firing mode.
Obviously, idle mode is when unit does common actions, like idle, walking, running, dying, etc.
Firing mode, we will include here aiming and shooting.
You should've noticed when unit is in idle mode, bow is not animated and there are no problems to add your custom bow, it will appear as you add it.
Another issue comes when you add custom bow but in firing mode bow gets replaced by vanilla bow. Ran through this issue? Then this tutorial is for you.

We are going to add our custom animated bow.

Let's clarify what files you will need to success this operation:
1. Pack File Manager
2. Notepad++
3. Assembly Kit installed
4. 3Ds Max
5. ATTILA Bow skeletons (crossbow is not included)
6. Pack of bow .meta files (crossbow meta files are not included)

So now it begins.

Step 1. Open downloaded bow skeletons.zip file. Extract raw_data and working_data files to your gamedir/assembly_kit root folder. Be sure your files are inserted in correct locations.

Step 2. Extract longbow and shortbow max files wherever it's comfortable to you. Open one of these bows you need to make a custom one. You will see some missing textures because they have an absolute path on my PC but don't worry about it, you will replace it later with yours. You will also see bow model inside, it's put there for you to know how to rig/weight your bow mesh. And you will see the skeleton with 4 bones in there.

Step 3. Import your custom bow file to this skeleton file. Add skin modifier t your bow and assign vertexes to bones. As soon as rigging is completed go to material editor and put your textures. Be sure to check that your material has custom attribute rigid_model (commonly in text field you must write 'weighted'). As soon as you make sure everything is completed (mesh is properly named(with all _lod postfixes), rigged to the skeleton and has properly setup material with proper textures) export your bow as .cs2 file.

Step 4. Go to your exported bow directory. Let's say we exported longbow with filename 'longbow2_bendy' and exported to gamedir/assembly_kit\raw_data\VariantMeshes\VariantModels\man\weapons. So the path to file is:
"gamedir/assembly_kit/raw_data/VariantMeshes/VariantModels/man/weapons/longbow2_bendy.cs2". I recommend to add _bendy postfix to bow name because it will allow us to make some tricks in next step.

Step 5. In directory where we just exported our new bow add/edit rules.bob file. Open it and add this text:
Code:
[+RigidModelV2]    <files> = ..._bendy.cs2
    AnimationType = shortbow_bendy
Explanation:
Most of weapons in weapons folder have no skeleton. So to make everything flexible we will proceed _bendy models with skeleton and rest will be proceeded as common weapons.
Full text of rules.bob file:
Code:
[+RigidModelV2]    AnimationType = 
    
[+RigidModelV2]
    <files> = ..._bendy.cs2
    AnimationType = shortbow_bendy
Step 6. Open BOB file and convert your longbow2_bendy.cs2.

Step 7. Now open downloaded bow metas zip. You can see there're two folders. One for shortbow and one for longbow. You can call these folders as you want.
Extract folders which you need (in our case it's longbow folder) to: gamedir\assembly_kit\working_data\animations\rome2\human\battle\archer\firing
Now open each .meta file with Notepad++. Take a look at text file. There're a lot of weird symbols. DO NOT TOUCH THEM.
NOW VERY CAREFULLY READ.

Step 8. In .meta file you can see a path to vanilla bow. For instance,
Code:
variantmeshes/_variantmodels/man/weapons/celtic_longbow_bendy_03.rigid_model_v2
This is what we are going to replace to your custom bow. Remember, our custom bow path was:
"gamedir/assembly_kit/raw_data/VariantMeshes/VariantModels/man/weapons/longbow2_bendy.cs2". Make it relative path, and replace .cs2 to .rigid_model_v2. And we get:
"VariantMeshes/_VariantModels/man/weapons/longbow2_bendy.rigid_model_v2".
AND NOW VERY TRICKY OPERATION. Amount of symbols of custom bow path+filename+fileextension should be exactly the same as amount of vanilla bow path+filename+fileextension.
I recommend to use this website to make fast count of characters used: www.lettercount.com
Let's put vanilla string to that site counter field: "variantmeshes/_variantmodels/man/weapons/celtic_longbow_bendy_03.rigid_model_v2". Site returns 79 characters. It means our custom bow path should be consisted of 79 symbols too.
Right now our path has 70 symbols according to that site ("VariantMeshes/_VariantModels/man/weapons/longbow2_bendy.rigid_model_v2"). How can we make it 79? Easily. Just rename our bow. Right now we are missing 9 characters. Let's rename our file from "longbow2_bendy" to "custom_longbow_01_bendy".
So now the path looks like: "VariantMeshes/_VariantModels/man/weapons/custom_longbow_01_bendy.rigid_model_v2". Now count amount of characters again. Alright, it's 79 now.
Now open each .meta file and replace vanilla path
from:
Code:
variantmeshes/_variantmodels/man/weapons/celtic_longbow_bendy_03.rigid_model_v2
to:
Code:
variantmeshes/_variantmodels/man/weapons/custom_longbow_01_bendy.rigid_model_v2
As soon as you have replaced all vanilla bows with your own we move ahead.

Step 9. Open Pack File Manager and open your mod.pack file. Add your custom bow, custom bow_bendy and new meta files.
I recommend not to replace vanilla files.
So, all our meta files are in
gamedir\assembly_kit\working_data\animations\rome2\human\battle\archer\firing
Our folder name is custom_longbow. So you should add all these meta files to your pack with following path:
animations\rome2\human\battle\archer\firing\custom_longbow

As soon as you have uploaded all your bow-related files to your mod.pack you have few more steps left to be done.

Step 10. Create your custom animation_fragment for your new longbow. This step is pretty easy. Just take vanilla animation_fragment (since we use longbow, we export animation/animation_fragments/rome_man_longbow_fragment.txt). Open the exported file with Notepad++. Now use search tool and search each meta file name from animations\rome2\human\battle\archer\firing\custom_longbow files.
For example, we have arc_fire_aim_01.meta file changed and uploaded to our pack. Search "arc_fire_aim_01.meta" text in "animation/animation_fragments/rome_man_longbow_fragment.txt" file. As soon as you've found this value (sometimes values are not present in particular fragments) make a correction to the path. By default path is:
metadata = "animations/rome2/human/battle/archer/firing/arc_fire_aim_01.meta"
and we need to link to our new arc_fire_aim_01.meta file. We put it in additional custom_longbow folder so add this folder to the path and we get:
metadata = "animations/rome2/human/battle/archer/firing/custom_longbow/arc_fire_aim_01.meta"
Done. Now search for each changed .meta file in that animation fragment. Replace path of each new meta file and save your animation fragment with new name. In our case we'll call it animation/animation_fragments/rome_man_custom_longbow_fragment.txt
Now add new animation fragment file to your mod.pack.

Almost done and last 2 steps left.

Step 11. Now open vanilla "animations/animation_tables/animation_tables.txt" file. Find vanilla animation_fragment file we've just changed (rome_man_sword_bow_long_foot). Copy this fragment and paste beneath it. Now give to the copy new name and link to our new custombow fragment.
So we change
FROM:
Code:
animation_table rome_man_sword_bow_long_foot{
        skeleton_type        rome_man_game
        skeleton_type_cinematic        rome_man




        fragment        rome_man_unarmed_fragment                
        fragment        rome_man_cinematic_fragment                
        fragment        rome_man_sword_fragment                
        fragment        rome_man_sword_matched_combat_fragment                
        fragment        rome_man_longbow_fragment                
}




animation_table rome_man_sword_bow_reflex_horse
{
        skeleton_type        rome_man_game
        skeleton_type_cinematic        rome_man


        mount_table        rome_mount_horse_sword


        fragment        rome_man_unarmed_fragment                
        fragment        rome_man_cinematic_fragment                
        fragment        rome_man_sword_fragment                
        fragment        rome_man_sword_matched_combat_fragment                
        fragment        rome_man_bow_fragment                
        fragment        rome_man_bow_reflex_fragment                
        fragment        rome_horse_rider_fragment                
        fragment        rome_horse_rider_sword_fragment                
        fragment        rome_horse_rider_sword_matched_combat_fragment                
        fragment        rome_horse_rider_bow_fragment                
        fragment        rome_horse_rider_bow_reflex_fragment                
}
TO:
Code:
animation_table rome_man_sword_bow_long_foot{
        skeleton_type        rome_man_game
        skeleton_type_cinematic        rome_man




        fragment        rome_man_unarmed_fragment                
        fragment        rome_man_cinematic_fragment                
        fragment        rome_man_sword_fragment                
        fragment        rome_man_sword_matched_combat_fragment                
        fragment        rome_man_longbow_fragment                
}




animation_table rome_man_sword_custom_bow_long_foot
{
        skeleton_type        rome_man_game
        skeleton_type_cinematic        rome_man




        fragment        rome_man_unarmed_fragment                
        fragment        rome_man_cinematic_fragment                
        fragment        rome_man_sword_fragment                
        fragment        rome_man_sword_matched_combat_fragment                
        fragment        rome_man_custom_longbow_fragment                
}




animation_table rome_man_sword_bow_reflex_horse
{
        skeleton_type        rome_man_game
        skeleton_type_cinematic        rome_man


        mount_table        rome_mount_horse_sword


        fragment        rome_man_unarmed_fragment                
        fragment        rome_man_cinematic_fragment                
        fragment        rome_man_sword_fragment                
        fragment        rome_man_sword_matched_combat_fragment                
        fragment        rome_man_bow_fragment                
        fragment        rome_man_bow_reflex_fragment                
        fragment        rome_horse_rider_fragment                
        fragment        rome_horse_rider_sword_fragment                
        fragment        rome_horse_rider_sword_matched_combat_fragment                
        fragment        rome_horse_rider_bow_fragment                
        fragment        rome_horse_rider_bow_reflex_fragment                
}
NOTE:
BLUE - old value which we kept with no changes;
RED - copied value which we changed to custom.

Step 12. Final step. Yeah, FINALLY.
Go to your unit table in land_units_tables.
In man_animation column replace old animation to our new we've just copied and renamed (rome_man_custom_longbow_fragment). As soon as you linked your unit to new animation which refers to custom animation_fragment which includes custom meta files which refer to custom bow it's all completed and done.

Now run a game and make sure it works.

Possible bugs you can meet and how to fix them:
1. Bow is replaced by invisible bow. This means your path in .meta files (Step 8) either incorrect (refers to wrong place/mesh) or it refers to correct place and mesh but has different amount of characters from vanilla. Be sure amount of vanilla and replaced(custom) bow path characters are exactly the same.
2. Bow is replaced but looks weird when animating. It happens because of incorrect skeleton in _bendy bow. Longbow is tested by myself and worked correctly so this issue may happen only for shortbow coz I haven't tested it.
3. Be sure you have two separate the same custom bows. One bow without skeleton and has any name you wish and another bow with skeleton and has _bendy postfix. They are both the same but used in two different modes. Common bow is used for idle mode and _bendy bow is used for firing mode.

CREDITS TO WARMAN, ORIGINAL IDEA OF THIS TUTORIAL BELONGS TO HIM.