Guide to Adding a New Resource with Custom Reskins

Horem

Emperor
Joined
Apr 1, 2010
Messages
1,721
Location
Wales, UK
Guide to Adding a New Resource with Custom Reskins

Firstly read the OP in this thread

Now you have a basic undertanding of how to add a resource to the game I will try to fill in the gaps from Kyoss's guide.

28/9/2012 - FIRSTLY to have custom 3d Art you must set the mod properties to have Reload Landmark System Checked. This function is slightly bugged and untill Firaxis fix this farms that get changed to a different improvement will cause a CTD, human or AI does not matter, to fix this you either have to disable the farm improvement or change the graphic of it to something else, you can learn more here.

PART ONE

Step One
Tools you will need:-
IndieStoneNexusBuddy, Extract this to the same location as the Nexus.exe and create a shortcut to your desktop.
Paint.net
Adjustments Plugins
Or any other graphics program capable of editing and saving dds files and has similar features.

Step Two
Open Nexus(From the SDK) - set the asset directory to be C:\Program Files (x86)\Steam\steamapps\common\sid meier's civilization.
In the top menu select Nexus > Script Browser > Extract PAK Files. This will unpack all the assets to the directories ...common\sid meier's civilization v\resource(create a shortcut to this folder on your desktop, name it CiV Vanilla Resources). There are three folders, Common, DX9 and dx9_low. The 3d art dds's are all in the DX9 folder with no subfolders, the fsxsml's, gr2's and fxsxml's are all in the Common folder with no subfolders. I have not looked in dx9_low, for when searched it never found anything in that folder to do with resources.

Step Three
Now create a new folder anywhere you feel comfortable with, lets name it CiV Custom Resources, create a shortcut to this folder on your desktop.
For the purpose of this guide we will be using copper as a base for our reskin. Open both the shortcuts you have made on your desktop and "snap" one to the left and one to the right of your screen. Search the Vanilla Resources folder and search for copper. Make a new folder called Blood Iron in you custom resource folder.



Copy all the Copper search results(25 of them) to your new Blood Iron folder.



You can close the vanilla resource window now.

Step Four
Now we have the base files from which we will create our Blood Iron resource. Rename all the files. I usualy just replace copper with what ever the name of the resource I am making, in this case bloodiron.



Step Five
Now open all 7 dds files in Paint.Net(or the graphic program of you choice). Once they are open select bloodiron_diff.



In Adjustments, select black and white. Go back to Adjustments and select Color Balance and set Red to +25.



Save the Image, DTX5 (Explicit Alpha), Cluster Fit, Perceptual.



Step Six
Next select bloodiron_ore_diff, we will want to use the Magic Wand tool for this dds, set the Flood Mode to Global and the Tolerance to 40%. You will need to get as much of the orange and as little of the grey selected with the Magic Wand, this usualy take a few tries.



Goto Adjustments and choose Color Balance, set Red +15, Magenta -5, Blue 5.



Save the Image, DTX5 (Explicit Alpha), Cluster Fit, Perceptual.

Step Seven
Now select bloodiron_decal_diff, zoom to 600%. Goto Adjustments and pick Color Balance, set Red 5, Magenta -2, Blue 2.



Save the Image, DTX5 (Explicit Alpha), Cluster Fit, Perceptual.

Step Eight
Now select mine_bloodiron_decal_d. We will be using the Lasso Select tool for this dds. This tool will take a bit of getting used too, bare with it. We are going too select the top right ore pile in this dds. Select a place to start the drawing around the ore pile, as if you were tracing it(Press and hold left mouse button), you will want to zoom in as much as you feel comfortable with while attempting this, it WILL take a few tries, once you are happy you have it, goto Adjustments and again choose Color Balance, set Red 10, Magenta -5, Blue 2.



You will want to repeat this process with each fo the ore piles in the dds, the 4 main ones and the little ones in the middle. So it will end up like this:



Save the Image, DTX5 (Explicit Alpha), Cluster Fit, Perceptual.
Next is pl_mine_bloodiron_decal_d, changing this is exactly the same as Step Eight and should turn out similar too:



Step Nine
Next is the bloodiron_ore_sref I am not 100% sure on what this does ingame, but to me it seems to lighten or darken the shine/glow of the resource. This it down to you realy, I usualy set this at 15% darker, so for the purpose of this guide thats what we will do. Goto Adjustments, choose Darken and set to 1.15



Save the Image, DTX5 (Explicit Alpha), Cluster Fit, Perceptual. That is all the reskinning done.

Step Ten
Now we need to change the gr2's to reflect the changes we have made to the dds files. We do this with IndieStoneNexusBuddy, which you should have downloaded, extracted and placed a shortcut on you desktop too, Open it up:



Open one of the gr2's we renamed earlier, lets start at the top and work our way down, so select, bloodiron.gr2, once its open it should look like:



We will be changing all reference to copper to point at our nice new dds's. We do this by going to the second window(Material Window) on the left and searching each entry for a Copper reference, Ground is first so click on that. You will see the details displayed on the right, BaseTextureMap, HeightTextureMap, SpecTextureMap, you will notice only BaseTextureMap has any reference to Copper, we need to change this, its calling copper_decal_diff.dds so click on that you will see a little button will apear at the end with ... inside it:



Click it and tell it to choose bloodiron_decal_diff.dds.



Now go to the next entry, Tree Cut, you will notice this has no reference to any copper, this will happen alot while you are searching through the gr2's just leave it and go to the next entry, in this case, ore metal, which has two references to Copper, change both these to the corosponding bloodiron dds files.



Save the gr2.

You will have to repeat this process for all 8 gr2's we copied. Boring but needed. Make sure you check and double check you have got them all and have replaced with the dds that it structured the same(name_decal_d.dds ect).
 
PART TWO

Tools you will need:
Firefox web browser
SQLite Manager plugin for firefox

Step One
Now create a new mod in Modbuddy name it what ever you like. Create three folders in this mod, Art, SQL, XML. Goto the Art folder and create another folder called Blood Iron. Create a new sql in the SQL folder called Resources_ArtDefines.
Create two xml's in the XML folder called Resources.xml and ResourcesText.xml, Follow Kyoss's guide in populating these xmls with the tables you require, they should come out something similar to this:

Resource
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 9/1/2012 3:25:41 PM -->
<GameData>
	<Resources>
		<Row>
			<Type>RESOURCE_BLOODIRON</Type>
			<Description>TXT_KEY_RESOURCE_BLOODIRON</Description>
			<Civilopedia>TXT_KEY_CIV5_RESOURCE_BLOODIRON_TEXT</Civilopedia>
			[COLOR="SeaGreen"]<!-- You can set this to Luxury or Bonus, Even Strategic if you modify the AssignStartingPlots.lua code also, otherwise you will only ever get a quantiy of 1-->[/COLOR]
			<ResourceClassType>RESOURCECLASS_BONUS</ResourceClassType> 
			[COLOR="SeaGreen"]<!-- Our new Art Define -->[/COLOR]
			<ArtDefineTag>ART_DEF_RESOURCE_BLOODIRON</ArtDefineTag>
			[COLOR="SeaGreen"]<!-- Not sure what this does but 4 works so I always use 4 -->[/COLOR]
			<PlacementOrder>4</PlacementOrder>
			<ConstAppearance>50</ConstAppearance>
			<MinAreaSize>3</MinAreaSize>
			<MaxLatitude>90</MaxLatitude>
			<RandApp1>25</RandApp1>
			<RandApp2>25</RandApp2>
			<Unique>1</Unique>
			<TilesPer>5</TilesPer>
			<Flatlands>true</Flatlands>
			<Normalize>true</Normalize>
			[COLOR="SeaGreen"]<!-- You can use custom Icons here if you make the relevant atlases, for the purpose of this 3d art guid we will be using copper icons-->[/COLOR]
			<IconString>[ICON_RES_COPPER]</IconString>
			<PortraitIndex>1</PortraitIndex>
			<IconAtlas>EXPANSION_RESOURCE_ATLAS</IconAtlas>
		</Row>
	</Resources>
	<Resource_YieldChanges>
		<Row>
			<ResourceType>RESOURCE_BLOODIRON</ResourceType>
			<YieldType>YIELD_PRODUCTION</YieldType>
			<Yield>1</Yield>
		</Row>		
	</Resource_YieldChanges>
	<Resource_Flavors>
		<Row>
			<ResourceType>RESOURCE_BLOODIRON</ResourceType>
			<FlavorType>FLAVOR_PRODUCTION</FlavorType>
			<Flavor>10</Flavor>
		</Row>		
	</Resource_Flavors>
	<!-- Now you Can set the Bloeans and Resource Quantities here too but for this we are not going to bother, they do not seem to do anything anyways since its all sorted in AssignStartingPlots.lua-->
</GameData>

Text
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 9/1/2012 3:25:54 PM -->
<GameData>
	<Language_en_US>
		<Row Tag="TXT_KEY_RESOURCE_BLOODIRON">
			<Text>Blood Iron</Text>
		</Row>
		<Row Tag="TXT_KEY_CIV5_RESOURCE_BLOODIRON_TEXT">
			<Text>Whoo Hoo! It worked!</Text>
		</Row>
		<Row Tag="TXT_KEY_RESOURCE_BLOODIRON_HELP">
			<Text>Whoop! I made this.</Text>
		</Row>
	</Language_en_US>
</GameData>

In the Blood Iron art folder Import all your files from the CiV Custom Resources/Blood Iron Folder. Set ALL of these to VFS = True.

Step Two
We need to change all the fxsxml files to point at our new dds files, similar to the gr2's but not so complicated. Open all the fxsxml files(there should be 8) related to Blood Iron.



Now this should be just a matter of replacing Copper with Bloodiron in most entires, there are some model entires that we leave alone, not in this case, which is why I chose Copper as a reskin, the entries would look something like this:
Code:
<TimedTrigger file="FX_Triggers_PL_MED_Mine_Copper.ftsxml" source="Tool" [COLOR="Red"][B][U]model="Copper_Building04"[/U][/B][/COLOR] state="0,1,2,3" />

In a situation like this we would leave the underlined part alone so we would change it to look like:
Code:
<TimedTrigger file="[COLOR="Red"][B]FX_Triggers_PL_MED_Mine_Bloodiron.ftsxml[/B][/COLOR]" source="Tool" model="Copper_Building04" state="0,1,2,3" />

Im guessing a bit here but I think this is related to the model used and since we did not create a new model we leave it to its original. And then replace the rest of the entries relating to Copper.
So go ahead and use a Quick Replace to all opened files, replacing Copper with Bloodiron.
Save and close all the fxsxml's.

Step Three
Now we need to do the ArtDefines. There is three tables we want to add too here:-
  • ArtDefine_LandmarkTypes
  • ArtDefine_Landmarks
  • ArtDefine_StrategicView

I prefer SQL as I find it "cleaner" than xml. What I do here is copy the SQL entries in the database to the resource I am reskinning by using SQLite Manager plugin for Firefox, so open this up(Open Firefox, on the top bar goto Tools/SQLite Manager).



Open the Civ5DebugDatabase(its in the ...My Games/Sid Meier's Civilization 5/Cache folder). Click on the Browse and Search tab. Find the first table listed above.



You will need entry 95, which refrences Copper, right click this and Copy Row(s) as SQL.



Now goto your Resources_ArtDefines.sql and paste what you just copied there:-
Code:
INSERT INTO "someTable" VALUES ("ART_DEF_RESOURCE_COPPER","Resource","Copper");

You need to make some adjustments to what you pasted, like this:-
Code:
INSERT INTO ArtDefine_LandmarkTypes (Type, LandmarkType, FriendlyName) 
VALUES ('ART_DEF_RESOURCE_COPPER','Resource','Copper');

Now goto the second table mentioned above. And copy all the rows related to Copper.



Paste this in the same sql:
Code:
INSERT INTO "someTable" VALUES ("Any","Any","1","ART_DEF_IMPROVEMENT_NONE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","Copper.fxsxml","1",null);
INSERT INTO "someTable" VALUES ("Ancient","UnderConstruction","1","ART_DEF_IMPROVEMENT_MINE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","HB_MED_Copper_Mine.fxsxml","1",null);
INSERT INTO "someTable" VALUES ("Ancient","Constructed","1","ART_DEF_IMPROVEMENT_MINE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","MED_Mine_Copper.fxsxml","1",null);
INSERT INTO "someTable" VALUES ("Ancient","Pillaged","1","ART_DEF_IMPROVEMENT_MINE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","PL_MED_Mine_Copper.fxsxml","1",null);
INSERT INTO "someTable" VALUES ("Industrial","UnderConstruction","1","ART_DEF_IMPROVEMENT_MINE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","HB_IND_Copper_Mine.fxsxml","1",null);
INSERT INTO "someTable" VALUES ("Industrial","Constructed","1","ART_DEF_IMPROVEMENT_MINE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","IND_Mine_Copper.fxsxml","1",null);
INSERT INTO "someTable" VALUES ("Industrial","Pillaged","1","ART_DEF_IMPROVEMENT_MINE","SNAPSHOT","ART_DEF_RESOURCE_COPPER","PL_MED_Mine_Copper.fxsxml","1",null);

Again you will have to make similar changes to the code, I find it easier to use Replace to get the code into the right format/with the right files:
Code:
INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech)
VALUES ('Any','Any','1','ART_DEF_IMPROVEMENT_NONE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/Bloodiron.fxsxml','1',null);

INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech)
VALUES ('Ancient','UnderConstruction','1','ART_DEF_IMPROVEMENT_MINE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/HB_MED_Bloodiron_Mine.fxsxml','1',null);

INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech)
VALUES ('Ancient','Constructed','1','ART_DEF_IMPROVEMENT_MINE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/MED_Mine_Bloodiron.fxsxml','1',null);

INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech)
VALUES ('Ancient','Pillaged','1','ART_DEF_IMPROVEMENT_MINE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/PL_MED_Mine_Bloodiron.fxsxml','1',null);

INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech) 
VALUES ('Industrial','UnderConstruction','1','ART_DEF_IMPROVEMENT_MINE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/HB_IND_Bloodiron_Mine.fxsxml','1',null);

INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech)
VALUES ('Industrial','Constructed','1','ART_DEF_IMPROVEMENT_MINE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/IND_Mine_Bloodiron.fxsxml','1',null);

INSERT INTO ArtDefine_Landmarks(Era, State, Scale, ImprovementType, LayoutHandler, ResourceType, Model, TerrainContour, Tech)
VALUES ('Industrial','Pillaged','1','ART_DEF_IMPROVEMENT_MINE','SNAPSHOT','ART_DEF_RESOURCE_BLOODIRON','Art/Blood Iron/PL_MED_Mine_Bloodiron.fxsxml','1',null);

Lastly we do third table listed above, this is too do with Strategic View icons, we will simple tell it to use the icon for Copper, you can change this if you wish by simply editing the SV_Bloodiron.dds(Keeping the black border). Copy the Copper entry at 213 and paste that into your sql file:
Code:
INSERT INTO "someTable" VALUES ("ART_DEF_RESOURCE_COPPER","Resource","SV_Copper.dds");

Again make the relevant changes:
Code:
INSERT INTO ArtDefine_StrategicView (StrategicViewType, TileType, Asset)
VALUES ('ART_DEF_RESOURCE_BLOODIRON','Resource','Art/Blood Iron/SV_Bloodiron.dds');

Save and close your sql.

Now you must add both Resource.xml and ResourceText.xml along with Resource_ArtDefines.sql to the Actions in the Properties Tab of your mod to:- OnModActivated and UpdateDatabase for all 3 files.

Step Four
Make a new folder in your mod called, Lua.
AssignStartingPlots.lua, you need to import this into you mod, its location is:-
....Steam/steamapps/common/sid meier's civilization v/assets/dlc/expansion/Gameplay/Lua
Once you have it, set its properties to VFS - True. Now Open it up. Goto lines 245, 246, 247, 248. Increase the last numbers on these lines by 1(Line 248 Should always be half the number of the other lines, always rolling down).
Code:
		amounts_of_resources_placed = table.fill(0, [B]46[/B]), -- Stores amounts of each resource ID placed. WARNING: This table uses adjusted resource ID (+1) to account for Lua indexing. Add 1 to all IDs to index this table.
		luxury_assignment_count = table.fill(0, [B]46[/B]), -- Stores amount of each luxury type assigned to regions. WARNING: current implementation will crash if a Luxury is attached to resource ID 0 (default = iron), because this table uses unadjusted resource ID as table index.
		luxury_low_fert_compensation = table.fill(0, [B]46[/B]), -- Stores number of times each resource ID had extras handed out at civ starts. WARNING: Indexed by resource ID.
		region_low_fert_compensation = table.fill(0, [B]23[/B]); -- Stores number of luxury compensation each region received

Now scroll to line 373, add here:-
Code:
		-- New Resources
		bloodiron_ID,
Now scroll to line 592. You need to duplicate the last entry here, Crab, and rename it to reflect our new resource:-
Code:
		elseif resourceType == "RESOURCE_CRAB" then
			self.crab_ID = resourceID;
		elseif resourceType == "RESOURCE_TRUFFLES" then
			self.truffles_ID = resourceID;
		elseif resourceType == "RESOURCE_CRAB" then
			self.crab_ID = resourceID;
[B]		elseif resourceType == "RESOURCE_BLOODIRON" then
			self.bloodiron_ID = resourceID;[/B]
		end
	end
end
Now scroll to line 9619, again duplicate the last entry changing it to reflect your new resource:
Code:
	print("- Fish....: ", self.amounts_of_resources_placed[self.fish_ID + 1]);
	print("- Stone...: ", self.amounts_of_resources_placed[self.stone_ID + 1]);
[B]	print("- NEW BONUS Resources -");
	print("- Blood Iron: ", self.amounts_of_resources_placed[self.bloodiron_ID + 1]);[/B]
	print("-");
	print("-----------------------------------------------------");
end
Now scroll too line 9820, again we will duplicate the last entry and change it to reflect our new resource:
Code:
	local resources_to_place = {
	{self.stone_ID, 1, 100, 1, 2} };
	self:ProcessResourceList(19 * bonus_multiplier, 3, self.desert_flat_no_feature, resources_to_place)

	local resources_to_place = {
	{self.deer_ID, 1, 100, 3, 4} };
	self:ProcessResourceList(25 * bonus_multiplier, 3, self.forest_flat_that_are_not_tundra, resources_to_place)
[B]	-- New Resource Placement
	local resources_to_place = {
	{self.bloodiron_ID, 1, 100, 3, 4} };
	self:ProcessResourceList(25 * bonus_multiplier, 3, self.hills_open_list, resources_to_place)[/B]
end

{self.bloodiron_ID, 1, 100, 3, 4} }; :- The number in bold is what you change for Quantities, set it to 4 and every blood iron resource wll spawn with a quantity of 4 :)
25 * bonus_multiplier:- This bit decides the amount that get placed on the whole map, reduce the number for more, increase it for less.


Save the file, Build the mod and test!
Hopefully I have not left something out :D
 
Wow thanks for the tutorial even do you lost me half way through. I don't think I'll be making any resources any time soon
 
I have a problem with the new resource i implemented into my mod.
the resource now showing up on the map when i start a new game and everything works fine...
beside one thing...the texture won't show up.

the tile is marked with the resource, which i called "Green Energy" and it shows a count of 12...everything correct...but it looks like the tile is empty(i used the emerald model from the gemcollection made by horem) all you can see is an empty tile...

but when i use the ingame editor to place the resource on a tile, the gemstack is shown correctly...but the tiles where the resource is placed on randomly when starting a new game, are empty...

...means...it seems the code works, but for some reason he won't show the grafik when u start a game without the IGE and replacing the new resource tiles...

i hope to get an answer, because the last post has been added 2013.
 
one more thing i found out...
as long as the number of the new resource is set to 1-3 in the IGE the resource can be seen on the map. as soon as i set it to more than 3 i don't see the grafik on the tile anymore...but i set the number to 12 in the lua...that's the reason why i can't see the resource on the map...because every source of "green energy" spawns with 12.
what do i have to do, to make the resource visible on the piles even when it spawns with more than just 1?
 
what do i have to do, to make the resource visible on the piles even when it spawns with more than just 1?

Add your artdefine to the ArtDefineHeavy tag as well as the default one, in resources.xml.
 
Thank you for a most Thorough Tut. Especially as to how to mod the AssignStartingPositions.Lua for resources. 8 to 9000 lines of inflexible code!
 
Top Bottom