Post tutorial RSS [GEN - ZH]Coding Tutorial for ZH

Hello all! This tutorial was made by request, so enjoy! I was asked to do a tutorial for Generals Zero Hour modding so I’ll start with the basics:

Posted by on - Basic Client Side Coding

Hello all! This tutorial was made by request, so enjoy!

I was asked to do a tutorial for Generals Zero Hour modding so I’ll start with the basics and then go up to some more advanced things in other tutorials:

To start off let's take a look at some of the easiest things to code: Weapons and Locomotors as well as some other things.

one of the first things you need to know is that ; marks a comment in the code. for example if you want to explain a bit of code you would do this: ;
this has to be done per line, for example
comment <-- this is going to crash the game because theres now ; in front of it.

anothe important thing is where the codes are located. you can find them in a file called INIZH.big
use this program to extract them to your main ZH directory (it won't overwrite anything unless you have code in the Data\INI folder already) then you can go into the INI folder in the Data folder and edit the code

weapons coding is incredibly easy to do. Here's an example of a weapon code below:

Weapon MarauderTankGun
PrimaryDamage = 60.0 <-- the amount of damage it does
PrimaryDamageRadius = 5.0 <-- the splash damage, if this was 9999 then anything in that radius would take 60 damage
ScatterRadiusVsInfantry = 10.0 <--When this weapon is used against infantry, it can randomly miss by as much as this distance.
AttackRange = 170.0 <-- the range of the weapon
MinTargetPitch = -15 <--the more advanced code, a unit has to be withing the pitch to be fired on
MaxTargetPitch = 15 <--ditto
DamageType = ARMOR_PIERCING <-- the damage type, in this case it will do more damage to vehicles then infantry
DeathType = NORMAL <-- if a unit is killed what death type should it use? eg. explosive damage type for bombs
WeaponSpeed = 300 <--dist/sec, a gun is 9999 because it kills instantly, the higher it is the faster the projectile moves.
WeaponRecoil = 10 <-- the amount of recoil, the higher this is the more the unit will move when the weapon is fired
ProjectileObject = MarauderTankShell <-- the projectile fired by the weapon
FireFX = WeaponFX_GenericTankGunNoTracer <-- the tracer's going out the back of the projectile so you know it's there.
VeterancyFireFX = HEROIC WeaponFX_HeroicGenericTankGunNoTracer <-- same as above but used for level 3 veterancy
ProjectileDetonationFX = WeaponFX_GenericTankShellDetonation <-- the particles to use when the projectile hits a target
FireSound = MarauderTankWeapon <-- the sound that's made when it's fired
RadiusDamageAffects = ALLIES ENEMIES NEUTRALS <-- which sides this weapon can damage
DelayBetweenShots = 2000 <--time between shots, in milliseconds
ClipSize = 0 <-- how many shots in a Clip (0 == infinite)
ClipReloadTime = 0 <--how long to reload a Clip, in milliseconds

; note, these only apply to units that aren't the explicit target
; (ie, units that just happen to "get in the way"... projectiles
; always collide with the Designated Target, regardless of these flags
ProjectileCollidesWith = STRUCTURES WALLS


some other weapon codes are:

ContinuousFireOne = 6 <--How many shots at the same target constitute "Continuous Fire" the unit fires faster
ContinuousFireTwo = 12 <--How many shots at the same target constitute "Continuous Fire Two" even faster
ContinuousFireCoast = 1000 <-- the unit can fire the long at a unit after that unit has left its range
WeaponBonus = CONTINUOUS_FIRE_MEAN RATE_OF_FIRE 200% <--When the object achieves this state, this weapon gets double the rate of fire.
WeaponBonus = CONTINUOUS_FIRE_FAST RATE_OF_FIRE 300% <-- same as above only faster
WeaponBonus = PLAYER_UPGRADE DAMAGE 125% <-- an upgrade to damage for example: ChainGun upgrade
AntiAirborneVehicle = No <-\
AntiAirborneInfantry = No <---\
AntiGround = No <-----------------|> These dictate what the unit can fire at
AntiSmallMissile = No <------/
AntiBallisticMissile = No <-----/

Locomotor coding, like weapon coding, is easy to do. let's take a look at some code:

Locomotor BasicHumanLocomotor
Surfaces = GROUND RUBBLE <-- the surfaces the unit can walk on
Speed = 20 <-- in dist/sec how fast the unit goes
SpeedDamaged = 10 <-- in dist/sec, how fats hte unit goes when damaged
TurnRate = 500 <-- in degrees/sec how fast the unit turns
TurnRateDamaged = 500 <-- in degrees/sec how fast the unit turns when damaged
Acceleration = 100 <--in dist/(sec^2) how fast the unit accelerates
AccelerationDamaged = 50 <--in dist/(sec^2) how fast the unit accelerates when damaged
Braking = 100 <--in dist/(sec^2) how fast the unit brakes (stops)
MinTurnSpeed = 0 <-- in dist/sec the minimum turn speed
ZAxisBehavior = NO_Z_MOTIVE_FORCE < whether or not the unit can move on the Z axis (up and down) i'm pretty sure this is for planes only
Appearance = TWO_LEGS <-- how they appear to move
StickToGround = Yes <-- to prevent infantry from flying if they run off a hill, im pretty sure this is for light vehicles only (liek the bike)
GroupMovementPriority = MOVES_FRONT <-- Moves in the front of a group, behind small arms, ahead of artillery. where the unit moves in a group

for aircraft there are a couple lines added:

Locomotor RaptorJetLocomotor
Surfaces = AIR <-- changed to air
MinSpeed = 60 <-- in dist/sec the minimum airspeed, it must not be reduced below 60 or the game will glitch
Lift = 120 <-- in dist/(sec^2) how fast the unit lifts off
LiftDamaged = 80 <-- in dist/(sec^2) how fast the unit lifts off when damaged
PreferredHeight = 100 <-- the height the aircraft stay at
AllowAirborneMotiveForce = Yes <-- i honestly don't know what this does, keep it at Yes :P
ZAxisBehavior = SURFACE_RELATIVE_HEIGHT <-- the unit will stay at 100 (or whatever the prefferedheight is) when it changes terrain heights
CirclingRadius = 100 <-- the radius in which the unit circles (when idle or guarding)
Appearance = WINGS <-- how it appears to move

PitchInDirectionOfZVelFactor = 1.0 <--how much to pitch according to our z-vel. 0=none, 1=lots (0=default)
PitchStiffness = 0.5 <-- stiffness of the "springs" in the suspension forward & back.
RollStiffness = 0.4 <-- stiffness of the "springs" in the suspension side to side.
PitchDamping = 0.9 <-- How fast it damps. 0=perfect spring, bounces forever. 1=glued to terrain.
RollDamping = 0.8 <-- How fast it damps. 0=perfect spring, bounces forever. 1=glued to terrain.
ForwardVelocityPitchFactor = 0 <-- How much velocity will cause the front to lift/dip
LateralVelocityRollFactor = 0.2 <-- How much cornering will cause the chassis to roll.
Apply2DFrictionWhenAirborne = Yes <-- the firction applied when the unit is in the air
AirborneTargetingHeight = 30 <-- the height the unit will attack targets at
LocomotorWorksWhenDead = Yes <-- when the unti dies it continues moving, it doesn't just stop and fall

Jet's also require a taxiing locomotor for moving around the airport, it's basically the same as the ground locomotor

rank.ini is the file which has the number of generals pints and required EXP to get them.

Rank 1
RankName = INI:RankLevel1 <-- the name of it in the code
SkillPointsNeeded = 0 <-- EXP needed to get this rank. you get EXP by destroying infantry, vehicles and buildings
SciencesGranted = SCIENCE_Rank1 <-- the scinece rank granted (from Science.ini)
SciencePurchasePointsGranted = 1 <-- the amount of points you get

editing this file is useful for testing or cheating. It's also possible to add more ranks but that's more advanced stuff.

Colour and Money
Multiplayer.ini has all the code for ingame colours and money choices. the name of the ini file is misleading in a way. I'm not gonna post the entire ini here but ill post a couple things:

MultiplayerColor ColorRed <-- the colour
RGBColor = R:255 G:0 B:0 <-- the colour (it's in number form but bascially R is red, G is green and B is blue. the highest number for them is 255 so Red 255 is the solid red colour.)
RGBNightColor = R:255 G:0 B:0 <-- the colour... at night
TooltipName = Color:Red <-- the tooltip name from Generals.str which stores all the text for the game

MultiplayerStartingMoneyChoice <-- a money choice
Value = 10000 <-- how much money it is
Default = Yes <-- when you start the game it'll automatically pick this choice

Game data
last but not leat Gamedata.ini this has a few noteable lines of code in, most are used for cheating purposes though.

BuildSpeed = 1.0 <-- how fast you build
MinDistFromEdgeOfMapForBuild = 30.0 <-- buildings may not be constructed this close to a map edge. make this 0 and you can build closer to the edge of the map
SupplyBuildBorder = 20.0 <-- min dist you can put a supply center from a supply source. make this 0 and you can build your supply depot right beside a supply pile.

AllowedHeightVariationForBuilding = 10.0 <-- how "flat" the terrain has to be to be buildable. The higher the number is the more variation. so if it was 9999999 then you could build on the side of a cliff. NOTE you'll need to edit the dozers or workers locomotor so he can walk up cliffs otherwise you won't be able to build on them.

MinLowEnergyProductionSpeed = 0.5 <-- the minimum speed you can build with no energy
MaxLowEnergyProductionSpeed = 0.8 <-- the maximum speed you can build with no energy
for the above 2 lines of code: if this is higher than one then you'll build faster with no power than if you had power! so if these were 2 then you'll build 2 times faster without power!

CommandCenterHealRange = 500.0 <-- the range your command ceneter heals your and allied units. the higher this is then the bigger the range.
CommandCenterHealAmount = 0.01 <-- the amount of health it heals, the higher this is the more it heals.

RefundPercent = 50.0% <----\
SellPercentage = 50% <-|> change these 2 to 100% to get the full amount of money back when you sell a bulding. change them to higher than 100% to get more money back. for example is a building costs 1000 and these numbers are 200% when you sell tht building you'll get 2000 back instead of the regular 500.
UnlookPersistDuration = 5000 <-- How long after you stop looking until the fog grows back, the higher this is the slower the fog grows back. for example if this number was 99999999999999999999999999999999999999999999999999999999999999999999 then technically the fog wouldn't grow back for the entire match (unless the match was like 5 hours :P)

that's all for my basic tutorial. I'll make an Intermediate one later and then eventually an Advanced one :D i hope this was informative to new modders!


That was really in-depth and well written. Thanks for the great post ;)

Reply Good karma Bad karma+3 votes

Good work! Perhaps I need to post my work examples soon! :p

Reply Good karma Bad karma+3 votes

WOW. Seriously informative, very helpful! Is it similar for CnC3? As that's more what I'm aiming to be able to mod.

Could benefit from a little cleanup, does moddb support tags of any sort for tutorials? Not sure exactly how you'd do it but it runs together with everything the same font.

But very, very good job. :)

Reply Good karma Bad karma+2 votes
feillyne Staff

Admiral, I made your comments blue. ;-) Hope you don't mind... that much. ;-) Maybe it will replace need of Elementalist's "tags". ;-)

Reply Good karma+1 vote

for addition, also download "DeeZire Module Listings" (updated by Yayo01):

This text file really useful to help modders to modify the Object INIs
very suggested for beginner to extreme ZH modders.

Reply Good karma Bad karma+2 votes

Very useful!

Reply Good karma Bad karma+2 votes
Admiral-165 Author

to reply to everbody: Thanks for the feedback, i didn't think that everyone would like it this much. also thanks for changing the comments to a different colour, it's easier to read now.

CNC3 modding is more complicated because you need commandprompt and it requires XML coding. if u want to learn how to code CNC3 i'd recommend looking at RA3 tutorials because they're more similar.

Reply Good karma+1 vote

Thanks !!
Merci, une traduction française ?

Reply Good karma Bad karma+2 votes
Admiral-165 Author

pourquoi? tu ne comprends pas cette?

(Je suis desolé si ma français n'est pas bon :P)

Reply Good karma+1 vote

Hm good, nice tutorial for coding newbies. :V

Could you make one for C&C3 + RA3 as well, I don't know **** about XML coding and i want to know how. D:

Reply Good karma Bad karma+4 votes
Admiral-165 Author

XML coding's a bit different because the units code is all in one file instead of different ones, which means it's not consistent in it's location.

also the only XML coding i've done is star wars EAW and FOC which is actually more like ZH (made by petroglyph which was Westwood)

i've done a bit of RA3 coding tho so i guess i could.

Reply Good karma+1 vote

I couldn't understand what Min-/MaxLowEnergyProductionSpeed and ContinuousFireOne/-Two/-Coast is, can someone explain it again please? Anyway, a very nice tutorial!

Reply Good karma Bad karma+1 vote
Admiral-165 Author

Sorry for the late response:
when a building has power, it produces units and such at a certain speed. When that building has no power, its production slows down (like CNC 3)

basically minlowenergy production speed is the minimum speed that the building will produce units or research upgrades... maxlow energy is the fastest speed it will do those things.

continuous fire is a weird thing to explain, it's easier to see it in-game. Basically when a gattling cannon begins it's firing cycle it starts off slow, then gradually gets faster (you can see and hear this buy the amount of bullets and the sound pitch of the firing sound)

so basically the continuous fire and coast commands just state how long and how fast the cannon will shoot. it starts at one, then after a couple seconds switches to two etc. Try firing the gattling cannon in-game and you'll see what i mean.

This also determines how long the cannon can fire out of it's range. For example if an aircraft flies over your base and you're gattling cannon starts firing at the max it will fire for a certain amount of seconds at the aircraft AFTER it leaves the cannons range...

I hope that explains it... if not let me know.

Reply Good karma+1 vote

Can someone make a tutorial for particle coding, to include a list of all priority conditions available, and their sequence from most important to least, as well as each velocity and volume type please?

Reply Good karma Bad karma+1 vote

Nice one. Thank you very much.

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.