1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[TUT] How to make units use different effects

Discussion in 'Civ4 - Modding Tutorials & Reference' started by Rabbit, White, Aug 12, 2007.

  1. longer title... How to change effects for units without re-exporting them from max

    Intro

    In this tutorial I will describe a method by which it is possible to change the effect that a unit produces during animation, typically firing a gun or cannon, without having to import it into max, and re-export with modified effects. This method is of course limited because you cannot modify the animation itself, and you are also limited to existing effects. So how is this useful you might ask? Well, if you created a unit that uses existing animations but needs a different effect, then with this method you could do that without changing the effect of the original unit.

    Software

    For this to work you will need a hex editor – which is basically like a text editor but for non-text files. I personally use UltraEdit-32 but there are many alternatives out there, some are free.

    First step – "Effect in a haystack"

    You need to figure out what effect you actually want to change. What I mean is, let’s say you want to switch the tank’s cannon effect to a rifle’s firing effect. Well, you need to know what the tank’s effect is called, which might not always be obvious. Find and open the file CIV4EffectInfos.xml in Assets/XML/Misc. This is the file that defines all the effects in the game.

    Now, right here you might think to yourself, well there’s an effect called EFFECT_WEAPON_CANNONFIRE_MODERN_TANKS, and since there’s no similar effect for non-modern tanks that must mean that both tanks use the same effect. And you’d be right, except that both tanks in fact use the EFFECT_WEAPON_PANZER_FIRE. You will also note that the effect itself calls on the fx_weapon_cannonfire_modern.nif file and in fact the same effects file is used for a lot of units, including destroyers and battleships. (As far as I know the EFFECT_WEAPON_CANNONFIRE_MODERN_TANKS effect is not actually used by any units.)

    So basically this is where a bit of experimentation comes into play. Find the effect that you think is used by the unit and change the <Path> tag to point to a different effect and then run the game and test it. If the unit’s effect has changed then you found the right effect.

    Second step – "A Panzer by any other name"

    So, now that we found what effect the tank uses we want to change it. If you simply change the path, then the effect will change also for modern armors and panzers, and we don’t want that.

    So what you need to do is duplicate the effect definition and give it a different name. It is important that the new name has the exact same length as the old one. In this case I changed it to EFFECT_WEAPON_KRAMER_FIRE (I’ve been watching a lot Seinfield, so sue me! :)). Then change the path to point to the “torrent_of_racial_slurs.nif” file… just kidding ;), change the path to whatever effect you want to be used, in this case it’s the rifle’s firing effect - Art/Effects/weapon_rifleblast_old/fx_rifleblast_old.nif.

    Okay, half the work is done… well, more like 10% but “half” sounds better.

    Third step – “Look Ma - No animations!”

    Now, if all I really wanted to do is change the tank’s effect then I would simply now modify the animations files of the tank and be done with it. However, this tutorial is, for the most part, intended to be used with custom units so I will quickly setup the tank as a typical custom unit. (This part assumes you know how to do that so I'll go over this quickly.)

    I make a copy of the tank folder and call it whatever. Then remove all the animation files (KF/KFM), create a new art entry for it in the CIV4ArtDefines_Unit.xml file. Make sure that the NIFs are referenced from the new folder but the animation is still using the old tank animation path. Then create a new unit in the CIV4UnitInfos.xml file, which points to the new tank art definition. So, at this point, this is your typical custom unit. So, the million dollar question is, how do I make this custom unit use the new effect I defined?

    Fourth step – “Let my animations go!”

    Now we need to put the animations, i.e. KF/KFM files, that the custom unit is using in the same folder it’s located at. This is needed because we're going to be modifying one of these files to use the new effect, and if we modify one then all of them have to be copied into the new locaiton.

    IMPORTANT: In the folder of the custom unit, when you put the animations in, you must put the NIF of the unit who's animations are used by the custom unit, in other words the NIF with the same name as the KFM file being used by the unit. In this case it’ll be tank.nif and it’s already there, but if you created for example a hover tank and called the NIFs hover_tank.nif and hover_tank_fx.nif then you’ll need to copy the original tank.nif together with the tank animation files. This extra NIF file isn't, strictly speaking, used but without it the unit won't work.

    Once you copy the animations you need to change the unit’s art entry so that now the KFM tag points to this new copy of the animations.

    Well, at this point everything is setup, there’s only one last thing to do and you’re good to go.

    Fifth step – "Hexing all the way to the bank"

    Using the hex editor open the appropriate KF file, in this case it’s “tank_md_rangedstrike.kf” (that' gonna be the file for most gun based units - ships, tanks, soldiers, etc.). Scroll to the end of the file and find the section that says something like – "Effect:EFFECT_PANZER_FIRE:EFFECT_WEAPON_PANZER_FIRE". (It will of course be different for other units.) Then change only the EFFECT_WEAPON_PANZER_FIRE part to EFFECT_WEAPON_KRAMER_FIRE. Make sure that you change the last part, not the middle one.

    Spoiler quick break down of the effect entry, if you're interested :

    Effect:EFFECT_PANZER_FIRE:EFFECT_WEAPON_PANZER_FIRE

    Effect - refers to the fact that it's an effect
    EFFECT_PANZER_FIRE - is the name of the node to which the effect is attached, if you open the unit you will find such a node
    EFFECT_WEAPON_PANZER_FIRE - the name of the effect from XMLs

    If you launch the game now the new tank will use the rifle blast, while the old tank will still use the regular tank effect.

    Well, that's it folks. This was one of the less interesting tutorials on something that isn't going to be used by most people but if at least one person found it useful then my job here is done. :hatsoff:

    Cheers
     
  2. woodelf

    woodelf Bard Retired Moderator

    Joined:
    Jun 12, 2003
    Messages:
    15,036
    Location:
    Gallery
    Thanks Rabbit. Looks great!
     
  3. hrochland

    hrochland Prince

    Joined:
    Apr 9, 2006
    Messages:
    2,231
    Location:
    Czech Kingdom
    I will test it :bowdown: 100% :goodjob:
     
  4. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Good tutorial. Btw Niftools is doing the job as well. Just open up any kf file there and change sound or effect strings to your liking. Basically works the same as with a hexeditor but Niftools is more comfortable to my liking.;)
     
  5. yatta77

    yatta77 Emperor

    Joined:
    Mar 22, 2006
    Messages:
    1,041
    Thanks! :) :goodjob: Finally an understandable guide on this subject!

    [I was asking yesterday
    http://forums.civfanatics.com/showthread.php?t=238380
    about some subjects quite close to this].

    I'll surely bookmark this page and try to practice with some experiments. Everything you could add about the subject updating this guide, would be appreciated. Btw, I have 2 quick question, if you have 1 minute to spend :)

    - is there a less requiring hardware alternative to Max and the tool goes with it to edit the units? I wanted to try understand how units works, but my laptop is not recent enough to handle those well (it really takes forever to do whatever).
    - it is possible to edit easily the color of an effect? (example FFH2 glowing fireballs effects: I'd like to edit them to have them in different colors for different of my custom units).

    Thanks.
     
  6. Well, there's blender, which is free and I think other than animations and shaders works as well as max, there's a tutorial on it in the tutorials section. However, if your problem is that you're having performance issues I'm not sure that will be of much help.

    To modify the color of the effects you'll need to change the associated DDS files, which are usually found either in the same folder as the effect itself or in the art/shared folder. You might have to experiment a bit to figure out which dds file is for which effect (flame01.dds and flame02.dds don't help you much ;)) but it's easy.

    And just to quickly go over the stuff you asked about in the other thread, which you already probably figured out but still... the reason the effect was pink was either due to a missing textures from shared folder or due to an unmodified xml file for effects that didn't reference the correct effect.
     
  7. yatta77

    yatta77 Emperor

    Joined:
    Mar 22, 2006
    Messages:
    1,041
    Thank you for helping out with precious advices. :) Really appreciated. What few days ago was unknown, now it's starting to become understood pretty well. If ever something good enough to be released will come out (probably not), I'll definitively give you credit for.

    I was reading your (if I remember right) guide to use max and a tool to be able to change the weapons to the units a while ago. But I ended up with uninstalling everything since was so time consuming dealing with my hardware limitation that it became boring. I'll try to install this other software and read the tut now to see what I can do with it. :)

    That's all?!?!!! :) Cool! ... :D

    I'm quite sure it was the xml references missing. Thanks.

    Well, I really feel sorry to bothering you some more... but that's just a yes/no answer to a question I asked here :D ( http://forums.civfanatics.com/showpost.php?p=5817518&postcount=54 ): did something change in modding units with BtS?
    [Because I'm having trouble with some units modding that works in Vanilla but not in BtS, and I'm quite sure it's not an XML missing issue: the units works well if selected, but they transform (also those without effects) in the unit they got the animation file from when they're not selected. If I know that this shouldn't happen (= there's an error I made somewhere) I would restart all the editing in BtS (hoping to don't make the same error again ;) ), in the other case, I would just do everything in Vanilla...]. Thanks.
     
  8. GeneralMatt

    GeneralMatt Emperor

    Joined:
    Jul 10, 2005
    Messages:
    1,980
    Location:
    Canada
    Thanks! That clears up some stuff for me..
     

Share This Page