Modding guide: making new units

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, The Lordz

Post Reply
xriz
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 148
Joined: Tue Oct 21, 2008 2:17 am
Location: Los Angeles

Modding guide: making new units

Post by xriz »

I figured out how to make new units, they don't show up in the production panel but you can deploy them through the scenario file.

This is a guide on how to add a new unit to the game, the Battlecruiser and we will see it deployed in the 1914 scenario.
You'll need to modify these files:
units.lua
1914.lua
english.txt
and add 9 unit icon graphics files and 4 unit graphic files to
Data/Graphics/units
list to follow, you can just copy exiting ones and change name if you want but I am including graphics for you.

To have sounds you need to copy and rename 7 *.wav files at
Data/Sound/
list to follow, I have them pre named for you, below.

1) units.lua
Open up units.lua and copy the text below and paste it after the last unit in the file, take care to make sure you keep the ending parenthesis and don't copy over it.

{
id = 22,
name = "battlecruiser",
type = "naval",
chassis = "water",
class = "naval",
icon = "battlecruiser",
levels =
{
{
hp = 100,
mp = 14,
ap = 1,
LOS = 3,
range = 1,
shock = 2,
attack = 12,
defense = 10,
airattack = 6,
airdefense = 18,
bombard = 4,
assault = 0,
ammunition = 2,
}
},
retreat = 0,
costPP = 70,
costMP = 8,
turns = 20,
upkeepPP = 2,
upkeepMP = 0,
weapon = "heavy",
factions = { 0, 1, 2, 3, 4, 8, 10 },
strengthValue = 25,

stats =
{
groundattack = 1,
airattack = 6,
navalattack = 7,
subattack = 1,
stratattack = 8,
basedefense = 10,
highdefense = 8,
bombard = 3,
shock = 2,
},
firstStrike = 1,
},

2) engilish.txt
Basic text is here, no crash if you leave out, to add text there are several places.
Add lines the line below, look for other unit names with the same layout and add at end of the list like it.

battlecruiser = BATTLECRUISER

battlecruiser_info = Battlecruisers were similar in size and cost to a battleship, and typically carried the same kind of heavy guns, but battlecruisers generally carried less armour and were faster.

advice_battlecruiser_title = Battlecruiser

advice_battlecruiser_text = Battlecruiser are very powerful units, but very expensive too. The Firepower of a Battle ship with the armor and speed of a cruiser, they can out gun anything they can catch and can out run anything they can't.

3) copying graphics files for new unit, copy all the files listed below to, these are the ones that show up on the map.
Data/Graphics/units/

the 4 unit graphics:
battlecruiser_default_1_100.png
battlecruiser_default_1_hud.png
battlecruiser_default_1_info.png
battlecruiser_default_1_queue.png
unit battlecruiser_png.zip
zip file of the 4 graphics files for battlecruiser.
(36.93 KiB) Downloaded 238 times
Custom graphics for battlecruiser, photoshoped the battleship graphics.

the 9 unit icon graphics: (Update alert, its 10 unit icon files graphics the missing one is battlecruiser_100.png, you can copy battleship_100.png and rename it or I have updated the zip file to contain it now- 1/7/2013 3:30pm pst)
battlecruiser_0_25.png
battlecruiser_0_50.png
battlecruiser_0_100.png
battlecruiser_1_25.png
battlecruiser_1_50.png
battlecruiser_1_100.png
battlecruiser_2_25.png
battlecruiser_2_50.png
battlecruiser_2_100.png
Copies of exiting icon graphics for battleship re named.
icon battlecruiser_png.zip
(23.34 KiB) Downloaded 219 times

4) Now the new unit is ready to be deployed:
1914.lua
Open up the 1914.lua and add this line to Austria, to see the battle cruiser next to your regular cruiser first thing when you start a new 1914 scenario game. You can also change out any ship for any country with battlecruiser to see it or set you own location.
{type = "battlecruiser", hex = {104, 42}, facing = "left"},


5) It will work with doing all the above but will be silent if you want sound to go along with it, you will need 7 *.wav files, I just copied the battleship sounds and renamed battleship with battlecruiser, there found at
Data/Sound/
rename to;
battlecruiser_attack_1.wav
battlecruiser_attack_2.wav
battlecruiser_attack_2a.wav
battlecruiser_attack_3.wav
battlecruiser_move_1.wav
battlecruiser_move_2.wav
battlecruiser_move_3.wav
This is what they should look like when done.

And that's it, good luck.
battlecruiser.jpg
battlecruiser.jpg (21.8 KiB) Viewed 5867 times
Last edited by xriz on Mon Jan 07, 2013 11:29 pm, edited 1 time in total.
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

IIRC, the '_25' and '_50' graphics files aren't used, so you don't need to make these.

EDIT: ah, I see that's what you said, sorry I misread your post.
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Thankyou finally the game can be changed as per history,hows about adding Admirals Beatty & Hipper as commanders for their respective Battlecruiser fleets. :D

Could you maybe post these instruction over at the Matrix forum as well please! :roll:
JJ_Pihtari
Lance Corporal - Panzer IA
Lance Corporal - Panzer IA
Posts: 10
Joined: Sat Dec 22, 2012 10:13 am

Re: Modding guide: making new units

Post by JJ_Pihtari »

Thanks xriz, really appreciated!
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

xriz wrote:I figured out how to make new units, they don't show up in the production panel but you can deploy them through the scenario file.

This is a guide on how to add a new unit to the game, the Battlecruiser and we will see it deployed in the 1914 scenario.
You'll need to modify these files:
units.lua
1914.lua
english.txt
and add 9 unit icon graphics files and 4 unit graphic files to
Data/Graphics/units
list to follow, you can just copy exiting ones and change name if you want but I am including graphics for you.

To have sounds you need to copy and rename 7 *.wav files at
Data/Sound/
list to follow, I have them pre named for you, below.

1) units.lua
Open up units.lua and copy the text below and paste it after the last unit in the file, take care to make sure you keep the ending parenthesis and don't copy over it.

{
id = 22,
name = "battlecruiser",
type = "naval",
chassis = "water",
class = "naval",
icon = "battlecruiser",
levels =
{
{
hp = 100,
mp = 14,
ap = 1,
LOS = 3,
range = 1,
shock = 2,
attack = 12,
defense = 10,
airattack = 6,
airdefense = 18,
bombard = 4,
assault = 0,
ammunition = 2,
}
},
retreat = 0,
costPP = 70,
costMP = 8,
turns = 20,
upkeepPP = 2,
upkeepMP = 0,
weapon = "heavy",
factions = { 0, 1, 2, 3, 4, 8, 10 },
strengthValue = 25,

stats =
{
groundattack = 1,
airattack = 6,
navalattack = 7,
subattack = 1,
stratattack = 8,
basedefense = 10,
highdefense = 8,
bombard = 3,
shock = 2,
},
firstStrike = 1,
},

2) engilish.txt
Basic text is here, no crash if you leave out, to add text there are several places.
Add lines the line below, look for other unit names with the same layout and add at end of the list like it.

battlecruiser = BATTLECRUISER

battlecruiser_info = Battlecruisers were similar in size and cost to a battleship, and typically carried the same kind of heavy guns, but battlecruisers generally carried less armour and were faster.

advice_battlecruiser_title = Battlecruiser

advice_battlecruiser_text = Battlecruiser are very powerful units, but very expensive too. The Firepower of a Battle ship with the armor and speed of a cruiser, they can out gun anything they can catch and can out run anything they can't.

3) copying graphics files for new unit, copy all the files listed below to, these are the ones that show up on the map.
Data/Graphics/units/

the 4 unit graphics:
battlecruiser_default_1_100.png
battlecruiser_default_1_hud.png
battlecruiser_default_1_info.png
battlecruiser_default_1_queue.png
unit battlecruiser_png.zip
Custom graphics for battlecruiser, photoshoped the battleship graphics.

the 9 unit icon graphics:
battlecruiser_0_25.png
battlecruiser_0_50.png
battlecruiser_0_100.png
battlecruiser_1_25.png
battlecruiser_1_50.png
battlecruiser_1_100.png
battlecruiser_2_25.png
battlecruiser_2_50.png
battlecruiser_2_100.png
icon battlecruiser_png.zip
Copies of exiting icon graphics for battleship re named.

4) Now the new unit is ready to be deployed:
1914.lua
Open up the 1914.lua and add this line to Austria, to see the battle cruiser next to your regular cruiser first thing when you start a new 1914 scenario game. You can also change out any ship for any country with battlecruiser to see it or set you own location.
{type = "battlecruiser", hex = {104, 42}, facing = "left"},


5) It will work with doing all the above but will be silent if you want sound to go along with it, you will need 7 *.wav files, I just copied the battleship sounds and renamed battleship with battlecruiser, there found at
Data/Sound/
rename to;
battlecruiser_attack_1.wav
battlecruiser_attack_2.wav
battlecruiser_attack_2a.wav
battlecruiser_attack_3.wav
battlecruiser_move_1.wav
battlecruiser_move_2.wav
battlecruiser_move_3.wav
This is what they should look like when done.

And that's it, good luck.
battlecruiser.jpg
Hi regarding ending parenthesis,what is it supposed to look like at the end of the Units lua,my game keeps crashing,could you do me a great favour and post your finished Units Lua or attach it to an email to me at kirkhoggan@btinternet.com

PS : When did Austria start building Battlecruisers your cheating there me thinks! :P
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Ok I have an unknown problem,if I add the Battlecruiser to the game as Austrian as you specified,the game crashes,if I rename it Battleship instead and run the game all works perfectly.I have my Battlecruiser script below can anyone tell what the problem is because I'm stumped?

{
id = 22,
name = "battlecruiser",
type = "naval",
chassis = "water",
class = "naval",
icon = "battlecruiser",
levels =
{
{
hp = 100,
mp = 14,
ap = 1,
LOS = 3,
range = 1,
shock = 2,
attack = 12,
defense = 10,
airattack = 6,
airdefense = 18,
bombard = 4,
assault = 0,
ammunition = 2,
}
},
retreat = 0,
costPP = 70,
costMP = 8,
turns = 20,
upkeepPP = 2,
upkeepMP = 0,
weapon = "heavy",
factions = { 0, 1, 2, 3, 4, 8, 10 },
strengthValue = 25,

stats =
{
groundattack = 1,
airattack = 6,
navalattack = 7,
subattack = 1,
stratattack = 8,
basedefense = 10,
highdefense = 8,
bombard = 3,
shock = 2,
},
firstStrike = 1,
},
},
}
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

That looks like too many closing curly brackets at the end. To be sure I'd need to see the whole file, but it looks like you're closing too many brackets.

EDIT: also, any info in the log?
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Hi these curly brackets I have to admit baffle me,also nothing in the log game just crashes.
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

The curly brackets denote chunks of data, starting with an opening bracket and ending with a closing bracket.

So for example:

Code: Select all

data.units =
{
  -- A load of units
}
Within that, you get nested brackets for each unit:

Code: Select all

data.units =
{
   {
      --unit 1
   },
   {
      -- unit 2
   },
}
And within a unit, you get even more nested brackets for subsections like stats or factions.

The key thing is that you should have the same number of opening brackets as you have closing brackets. If you've got a mismatch, the data isn't properly divided up. It helps a lot to keep the data formatted with tabs. Each time you open a curly bracket, add a tab to the start of the line. It helps to visually distinguish between different chunks of data.


For your specific issue, have a look at the last unit in the unmodified units.lua:

Code: Select all

  {
    id = 21,
    name = "smallgarrison",
    type = "land",
    chassis = "foot",
    class = "ground",
    icon = "garrison",
    levels =
    {
      {
        hp = 100,
        mp = 6,
        ap = 1,
        LOS = 1,
        range = 1,

        shock = 0,
        attack = 6,
        defense = 6,
        airattack = 2,
        airdefense = 2,
        bombard = 0,
        assault = 1,

        ammunition = 0,
      },
    },
    retreat = 0,
    size = 1,
    costPP = 0,
    costMP = 0,
    turns = 1,
    upkeepPP = 0,
    upkeepMP = 0,
    weapon = "light",
    factions = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 },
    strengthValue = 0,
    noPurchase = true,

    stats =
    {
      basedefense   = 0,
      highdefense   = 5,
      groundattack  = 1,
      airattack     = 2,
      armourattack  = 0,
      assault       = 0,
      shock         = 0,
    }, -- Closes the 'stats' group
  }, -- Closes the individual unit
} -- Closes the whole list of units
I've commented on the last three closed brackets. In your example that you posted, you've got this:

Code: Select all

shock = 2,
}, -- Closes the stats group
firstStrike = 1,
}, -- Closes the unit
}, -- Closes the whole unit list
} -- What's this?
It looks like you have one curly bracket too many.

Try replacing your last few lines with this:

Code: Select all

shock = 2,
},
firstStrike = 1,
},
}
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Nope that did not solve the problem,would the game crash because I had renamed the unused unit Miner - predreadnought.Either that or there is something else in one of the other data files somewhere crashing the game,I have had to reinstall the latest patch twice now, just to get the game running again.
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

As a rule I would create a backup of any file you edit.

Could you upload your whole modified file?
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Ok I have attached all scrips files.
Attachments
Commander The Great War Scripts.zip
My in game script files
(51.26 KiB) Downloaded 218 times
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

Ok, I've attached a version of the file where I've fixed you brackets and indenting. This should hopefully work (although I haven't tested it).

For the sake of learning so you see what I've done, I would recommend comparing this with your file to see what was wrong with the curly brackets.
Attachments
units.zip
(2.54 KiB) Downloaded 180 times
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

At least now the game does not crash straight away,but I now get this message saying that a Battlecruiser images is missing,well I have checked and they are all present its a mystery.
Attachments
Battlecruiser image missing.jpg
Battlecruiser image missing.jpg (161.93 KiB) Viewed 5803 times
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Ok I opened up the graphics file again a discovered a file that was not one of the downloads,anyway I copy a battleship file and renamed it Battlecruiser,then run the game,and what do you know the Battlecruisers in game,only thing missing now is the info text,and the name on the unit itself,but I'm sure I will be able to solve that mystery,anyway many thanks for your assistance. :D
Attachments
Here is the missing image
Here is the missing image
battlecruiser_100.png (3.16 KiB) Viewed 5798 times
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

Photo of Battlecruiser in game brilliant! :D
Attachments
Battlecruiser in game info
Battlecruiser in game info
Battlecruiser in game.jpg (175.92 KiB) Viewed 5794 times
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

info and unit name are defined in the lang/english.txt (see the tutorial post)

really glad you've got it working :)
Myrddraal
The Artistocrats
The Artistocrats
Posts: 1505
Joined: Wed Feb 23, 2011 2:49 pm

Re: Modding guide: making new units

Post by Myrddraal »

Ok folks, to complete the picture, here's what you have to do to make your new unit appear in the production panel:

Open Data\Scripts\ui\production_panel.lua

Go to line 473 and insert:

Code: Select all

    if proto.name == "battlecruiser" then
      x = 665
      y = 411
    end
The x/y coordinates refer to screen coordinates for where you want your unit graphic to appear in the prod panel. This example puts the battlecruiser unit in the bottom right.

Enjoy your modding!
xriz
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 148
Joined: Tue Oct 21, 2008 2:17 am
Location: Los Angeles

Re: Modding guide: making new units

Post by xriz »

And the last piece of the puzzle falls into place, thanks Myrddraal! (note, line 473 is right after the entry end for the submarine, I got it working easily).

Sorry about overlooking the 10th file , I did up date the zip file for people, glad you got it working kirk23!

For unique units we don't need to have them show up in the production panel, some people have talked about the BEF or the Turkish fleet headed by the Goeben, which could be unique units that players get at the begging of the scenario but can't be reproduced in the game, you could also probably work an event like the Canadian Corps or Arab revolt to spawn unique units that are not made available through the production panel.
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Modding guide: making new units

Post by kirk23 »

If anyone else wants pre-dreadnought units in game,I have done some art for these over at the Matrix forum.

http://www.matrixgames.com/forums/tm.asp?m=3248274
Post Reply

Return to “Commander the Great War : Mods & Scenario Design”